diff --git a/exotic/exotic.py b/exotic/exotic.py index 4d0a09e3..89c53ea1 100644 --- a/exotic/exotic.py +++ b/exotic/exotic.py @@ -138,9 +138,9 @@ except ImportError: # package import from .output_files import OutputFiles try: # tools - from util import round_to_2, user_input + from utils import round_to_2, user_input except ImportError: # package import - from .util import round_to_2, user_input + from .utils import round_to_2, user_input try: # simple version from .version import __version__ except ImportError: # package import @@ -1087,7 +1087,7 @@ def transformation(image_data, file_name, roi=1): except Exception as ee: log_info(ee) - log_info(f"Alignment failed: {file_name}", warn=True) + log_info(f"Warning: Alignment failed - {file_name}", warn=True) return SimilarityTransform(scale=1, rotation=0, translation=[0,0]) @@ -1758,7 +1758,7 @@ def main(): log_info("Complete Reduction Routine") log_info("**************************") - init_path, wcs_file, wcs_header = None, None, None + init_path, wcs_file, wcs_header, ra_file, dec_file = None, None, None, None, None generalDark, generalBias, generalFlat = np.empty(shape=(0, 0)), np.empty(shape=(0, 0)), np.empty(shape=(0, 0)) if isinstance(args.reduce, str): @@ -1937,7 +1937,6 @@ def main(): wcs_file = check_wcs(inputfiles[0], exotic_infoDict['save'], exotic_infoDict['plate_opt']) compStarList = exotic_infoDict['comp_stars'] tar_radec, comp_radec = None, [] - ra_file, dec_file = None, None if wcs_file: log_info(f"\nHere is the path to your plate solution: {wcs_file}") @@ -2468,7 +2467,7 @@ def main(): log_info("\n\nOutput File Saved") else: goodTimes, goodFluxes, goodNormUnc, goodAirmasses = [], [], [], [] - bestCompStar = None + bestCompStar, comp_coords = None, None with exotic_infoDict['prered_file'].open('r') as f: for processed_data in f: @@ -2730,6 +2729,17 @@ def main(): log_info(f" Airmass coefficient 1: {round_to_2(myfit.parameters['a1'], myfit.errors['a1'])} +/- {round_to_2(myfit.errors['a1'])}") log_info(f" Airmass coefficient 2: {round_to_2(myfit.parameters['a2'], myfit.errors['a2'])} +/- {round_to_2(myfit.errors['a2'])}") log_info(f" Residual scatter: {round_to_2(100. * np.std(myfit.residuals / np.median(myfit.data)))} %") + if fitsortext == 1: + if minAperture >= 0: + log_info(f" Best Comparison Star: #{bestCompStar} - {comp_coords}") + else: + log_info(" Best Comparison Star: None") + if minAperture == 0: + log_info(" Optimal Method: PSF photometry") + else: + log_info(f" Optimal Aperture: {abs(np.round(minAperture, 2))}") + log_info(f" Optimal Annulus: {np.round(minAnnulus, 2)}") + log_info(f" Transit Duration [day]: {round_to_2(np.mean(durs))} +/- {round_to_2(np.std(durs))}") log_info("*********************************************************") @@ -2738,14 +2748,19 @@ def main(): ########## output_files = OutputFiles(myfit, pDict, exotic_infoDict, durs) - error_txt = "\nPlease report this issue on the Exoplanet Watch Slack Channel in #data-reductions." + error_txt = "\n\tPlease report this issue on the Exoplanet Watch Slack Channel in #data-reductions." try: output_files.final_lightcurve(phase) except Exception as e: log_info(f"\nError: Could not create FinalLightCurve.csv. {error_txt}\n\t{e}", error=True) try: - output_files.final_planetary_params() + if fitsortext == 1: + output_files.final_planetary_params(phot_opt=True, comp_star=bestCompStar, comp_coords=comp_coords, + min_aper=np.round(minAperture, 2), + min_annul=np.round(minAnnulus, 2)) + else: + output_files.final_planetary_params(phot_opt=False) except Exception as e: log_info(f"\nError: Could not create FinalParams.json. {error_txt}\n\t{e}", error=True) try: diff --git a/exotic/inputs.py b/exotic/inputs.py index 75d68f16..31344499 100644 --- a/exotic/inputs.py +++ b/exotic/inputs.py @@ -5,9 +5,9 @@ from astropy.io import fits try: - from util import * + from utils import * except ImportError: - from .util import * + from .utils import * try: from animate import * except ImportError: @@ -304,12 +304,13 @@ def obs_date(date): return date -def latitude(lat, hdr): +def latitude(lat, hdr=None): while True: if not lat: - lat = find(hdr, ['LATITUDE', 'LAT', 'SITELAT']) - if lat: - return lat + if hdr: + lat = find(hdr, ['LATITUDE', 'LAT', 'SITELAT']) + if lat: + return lat lat = user_input("Enter the latitude (in degrees) of where you observed. " "(Don't forget the sign where North is '+' and South is '-')! " "(Example: -32.12): ", type_=str) @@ -333,12 +334,13 @@ def latitude(lat, hdr): lat = None -def longitude(long, hdr): +def longitude(long, hdr=None): while True: if not long: - long = find(hdr, ['LONGITUD', 'LONG', 'LONGITUDE', 'SITELONG']) - if long: - return long + if hdr: + long = find(hdr, ['LONGITUD', 'LONG', 'LONGITUDE', 'SITELONG']) + if long: + return long long = user_input("Enter the longitude (in degrees) of where you observed. " "(Don't forget the sign where East is '+' and West is '-')! " "(Example: +152.51): ", type_=str) @@ -368,9 +370,10 @@ def elevation(elev, lat, long, hdr=None): try: elev = typecast_check(type_=float, val=elev) if not elev: - elev = find(hdr, ['HEIGHT', 'ELEVATION', 'ELE', 'EL', 'OBSGEO-H', 'ALT-OBS', 'SITEELEV']) - if elev: - return int(elev) + if hdr: + elev = find(hdr, ['HEIGHT', 'ELEVATION', 'ELE', 'EL', 'OBSGEO-H', 'ALT-OBS', 'SITEELEV']) + if elev: + return int(elev) log_info("\nEXOTIC is retrieving elevation based on entered " "latitude and longitude from Open Elevation.") animate_toggle(True) diff --git a/exotic/output_files.py b/exotic/output_files.py index 7b11e42b..84b7b09f 100644 --- a/exotic/output_files.py +++ b/exotic/output_files.py @@ -3,9 +3,9 @@ from pathlib import Path try: - from util import round_to_2 + from utils import round_to_2 except ImportError: - from .util import round_to_2 + from .utils import round_to_2 try: from version import __version__ except ImportError: @@ -32,7 +32,7 @@ def final_lightcurve(self, phase): self.fit.transit, self.fit.airmass_model): f.write(f"{bjd}, {phase}, {flux}, {fluxerr}, {model}, {am}\n") - def final_planetary_params(self): + def final_planetary_params(self, phot_opt, comp_star=None, comp_coords=None, min_aper=None, min_annul=None): params_file = self.dir / f"FinalParams_{self.p_dict['pName']}_{self.i_dict['date']}.json" params_num = { @@ -49,10 +49,18 @@ def final_planetary_params(self): "Airmass coefficient 2 (a2)": f"{round_to_2(self.fit.parameters['a2'], self.fit.errors['a2'])} +/- " f"{round_to_2(self.fit.errors['a2'])}", "Scatter in the residuals of the lightcurve fit is": f"{round_to_2(100. * std(self.fit.residuals / median(self.fit.data)))} %", - "Transit Duration (day)": f"{round_to_2(mean(self.durs))} +/- " - f"{round_to_2(std(self.durs))}" } + if phot_opt: + phot_ext = {"Best Comparison Star": f"#{comp_star} - {comp_coords}" if min_aper >= 0 else str(comp_star)} + if min_aper == 0: + phot_ext["Optimal Method"] = "PSF photometry" + else: + phot_ext["Optimal Aperture"] = f"{abs(min_aper)}" + phot_ext["Optimal Annulus"] = f"{min_annul}" + params_num.update(phot_ext) + + params_num["Transit Duration (day)"] = f"{round_to_2(mean(self.durs))} +/- {round_to_2(std(self.durs))}" final_params = {'FINAL PLANETARY PARAMETERS': params_num} with params_file.open('w') as f: @@ -70,7 +78,6 @@ def aavso(self, comp_star, airmasses, ld0, ld1, ld2, ld3): if (self.i_dict['second_obs']).lower() == "n/a": self.i_dict['second_obs'] = "" - with params_file.open('w') as f: f.write("#TYPE=EXOPLANET\n" # fixed f"#OBSCODE={self.i_dict['aavso_num']}\n" # UI diff --git a/exotic/util.py b/exotic/utils.py similarity index 98% rename from exotic/util.py rename to exotic/utils.py index 18ed36ab..ec0ed7c4 100644 --- a/exotic/util.py +++ b/exotic/utils.py @@ -90,7 +90,7 @@ def dms_to_dd(dms_in): return dec -# Provided by: Kalee Tock +# Credit: Kalee Tock def get_val(hdr, ks): for key in ks: if key in hdr.keys(): @@ -103,7 +103,7 @@ def get_val(hdr, ks): return None -# Provided by: Kalee Tock +# Credit: Kalee Tock def add_sign(var): str_var = str(var) m = re.search(r"^[+\-]", str_var) @@ -116,7 +116,7 @@ def add_sign(var): return f"-{float(var)}.6f" -# Provided by: Kalee Tock +# Credit: Kalee Tock def process_lat_long(val, key): m = re.search(r"\'?([+-]?\d+)[\s:](\d+)[\s:](\d+\.?\d*)", val) if m: @@ -136,7 +136,7 @@ def process_lat_long(val, key): print(f"Cannot match value {val}, which is meant to be {key}.") -# Provided by: Kalee Tock +# Credit: Kalee Tock def find(hdr, ks, obs=None): # Special stuff for MObs and Boyce-Astro Observatories boyce = {"LATITUDE": "+32.6135", "LONGITUD": "-116.3334", "HEIGHT": 1405} diff --git a/exotic/version.py b/exotic/version.py index c68196d1..a955fdae 100644 --- a/exotic/version.py +++ b/exotic/version.py @@ -1 +1 @@ -__version__ = "1.2.0" +__version__ = "1.2.1"