Coverage for runAstrometry.py: 0%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

44 statements  

1from spectractor import parameters 

2from spectractor.astrometry import Astrometry 

3from spectractor.logbook import LogBook 

4from spectractor.config import load_config 

5 

6 

7if __name__ == "__main__": 

8 import sys 

9 from argparse import ArgumentParser 

10 

11 parser = ArgumentParser() 

12 parser.add_argument(dest="input", metavar='path', default=["tests/data/reduc_20170530_134.fits"], 

13 help="Input fits file name. It can be a list separated by spaces, or it can use * as wildcard.", 

14 nargs='*') 

15 parser.add_argument("-d", "--debug", dest="debug", action="store_true", 

16 help="Enter debug mode (more verbose and plots).", default=False) 

17 parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", 

18 help="Enter verbose (print more stuff).", default=False) 

19 parser.add_argument("-l", "--logbook", dest="logbook", default="ctiofulllogbook_jun2017_v5.csv", 

20 help="CSV logbook file. (default: ctiofulllogbook_jun2017_v5.csv).") 

21 parser.add_argument("-c", "--config", dest="config", default="config/ctio.ini", 

22 help="INI config file. (default: config.ctio.ini).") 

23 parser.add_argument("-o", "--output_directory", dest="output_directory", default="", 

24 help="Write results in given output directory (default: '' if same directory as input file).") 

25 parser.add_argument("-r", "--radius", dest="radius", default=parameters.CCD_IMSIZE, 

26 help="Radius in pixel around the guessed target position to detect sources " 

27 "and set the new WCS solution (default: parameters.CCD_IMSIZE).") 

28 parser.add_argument("-m", "--maxiter", dest="maxiter", default=20, 

29 help="Maximum iterations to find best WCS (with the lowest residuals with the Gaia catalog).") 

30 parser.add_argument("-x", "--xy", dest="target_xy", default="0,0", 

31 help="X,Y guessed position of the order 0, separated by a comma (default: 0,0).") 

32 parser.add_argument("-t", "--target", dest="target_label", default="", 

33 help="Target label (default: '').") 

34 args = parser.parse_args() 

35 

36 parameters.VERBOSE = args.verbose 

37 radius = int(args.radius) 

38 if args.debug: 

39 parameters.DEBUG = True 

40 parameters.VERBOSE = True 

41 

42 file_names = args.input 

43 

44 load_config(args.config) 

45 

46 logbook = LogBook(logbook=args.logbook) 

47 for file_name in file_names: 

48 disperser_label = "" 

49 if args.target_xy == "0,0" and args.target_label == "": 

50 tag = file_name.split('/')[-1] 

51 tag = tag.replace('sim_', 'reduc_') 

52 disperser_label, target_label, xpos, ypos = logbook.search_for_image(tag) 

53 if target_label is None or xpos is None or ypos is None: 

54 continue 

55 else: 

56 xpos, ypos = args.target_xy.split(",") 

57 target_label = args.target_label 

58 xpos = float(xpos) 

59 ypos = float(ypos) 

60 if target_label == "" or (xpos == 0 and ypos == 0): 

61 sys.exit("Options --xy and --target must be used together, one of these seems not set.") 

62 a = Astrometry(file_name, target_label=target_label, disperser_label=disperser_label, 

63 output_directory=args.output_directory) 

64 extent = ((int(max(0, xpos - radius)), int(min(xpos + radius, parameters.CCD_IMSIZE))), 

65 (int(max(0, ypos - radius)), int(min(ypos + radius, parameters.CCD_IMSIZE)))) 

66 gaia_min_residuals = a.run_full_astrometry(extent=extent, maxiter=int(args.maxiter)) 

67 # overwrite input file 

68 # if args.overwrite: 

69 # a.my_logger.warning(f"Overwrite option is True: {a.file_name} replaced by {a.new_file_name}") 

70 # subprocess.check_output(f"mv {a.new_file_name} {a.file_name}", shell=True)