Skip to content

Commit

Permalink
Merge pull request #810 from rzellem/develop
Browse files Browse the repository at this point in the history
v1.2.1: bugfix for pre-reduced data final params file
  • Loading branch information
rzellem authored Jul 20, 2021
2 parents a5d5da7 + 1661e4a commit ebb252d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 32 deletions.
31 changes: 23 additions & 8 deletions exotic/exotic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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("*********************************************************")

Expand All @@ -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:
Expand Down
29 changes: 16 additions & 13 deletions exotic/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 13 additions & 6 deletions exotic/output_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = {
Expand All @@ -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:
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions exotic/util.py → exotic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion exotic/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "1.2.1"

0 comments on commit ebb252d

Please sign in to comment.