diff --git a/utils.py b/utils.py index 58abe59be45788be2f6bae30728030e541666f76..567ab79216b1eb44d29be3a94250d8fbc7e3c3b3 100644 --- a/utils.py +++ b/utils.py @@ -156,7 +156,7 @@ def get_runs_database(args, database): if args.tcuname is not None: selection = database.loc[database['Target']].isin([args.tcuname]) if args.verbose: - print("Selection of runs based on the TCU name", args.tcuname, ". Only run with the name in the TCU are kept") + print("Selection of runs based on the TCU name", args.tcuname, ". Only runs with the name in the TCU are kept") print(selection.index) # if args.night[0] != 'all': @@ -175,12 +175,12 @@ def get_runs_database(args, database): databaseRuns = np.array(selection.index) if args.runlist is not None: - rl = np.loadtxt(args.runlist, unpack=True, dtype=int) + rl = np.loadtxt(os.environ.get('CONFIG_FOLDER') + '/' + args.runlist, unpack=True, dtype=int) #databaseRuns = np.array([a for a in rl if a in databaseRuns]) databaseRuns = np.array([a for a in rl]) if args.verbose: - print("Final run selection", databaseRuns) + print("Final run selection: ", databaseRuns) return databaseRuns @@ -276,7 +276,7 @@ def get_coordinates(args): """ returns the name and the Ra/Dec of the source """ - + success = False if args.source_name is None: raise ValueError("Please provide the name of the analysed source by using --source_name") @@ -286,13 +286,43 @@ def get_coordinates(args): c = SkyCoord.from_name(args.source_name) ra = c.ra.value dec = c.dec.value + success = True + if args.verbose: + print("Coordinates of ", args.source_name, "found using Astropy: RA ", ra, ", Dec ", dec) except: - print("Cannot resolve target name", args.source_name, "using Astropy. Switch to the Ra and Dec provided.") - if args.ra >= 0 and args.ra < 360 and args.dec >= -90 and args.dec < 90: - ra = args.ra - dec = args.dec - print("Using user provided RA and Dec.") + print("Cannot resolve target name", args.source_name, "using Astropy. Switch to the Ra and Dec provided by the user.") + if all(item is not None for item in [args.ra, args.dec]): + if args.ra >= 0 and args.ra < 360 and args.dec >= -90 and args.dec < 90: + ra = args.ra + dec = args.dec + if args.verbose: + print("Coordinates provided by the user: RA ", ra, ", Dec", dec) else: print("Please provide RA and Dec values by using --ra and --dec") exit(0) + if (success is True and args.ra and args.dec): + if args.ra != ra or args.dec != dec: + print(f"WARNING! Astropy coordinates RA {ra}, Dec {dec} are different than the ones provided by the user RA {args.ra}, Dec {args.dec}.") return ra, dec + + +def print_runs(table, mask, by_date=False): + """ + function to print out the run numbers that survive a certain set of cuts + """ + print(f"{mask.sum()} wobble runs for the selected source") + print(f"Observation time: {table['elapsed_time'][mask].sum()/3600:.2f} hours") + print() + print(np.array2string(np.array(table['runnumber'][mask]), separator=', ')) + + if by_date: + print() + print() + dates = [datetime.utcfromtimestamp(t - 0.5 * 86400).date() for t in table['time'][mask]] + for i, date in enumerate(np.unique(dates)): + rr = [] + for d, run in zip(dates, table['runnumber'][mask]): + if d != date: + continue + rr.append(run) + print(i + 1, ":", date, ":", rr)