Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1165: Checking datasets for MObs and Conforming w/ New Limb Darkening Updates #1217

Merged
merged 18 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
2e6cb15
- Added testing suite for ld.py
tamimfatahi Aug 8, 2023
a854291
Minor bug squashed
tamimfatahi Aug 8, 2023
9df27e6
Adding additional MicroObservatory default values
tamimfatahi Aug 8, 2023
170fd22
Adding additional MicroObservatory default values and reverting inits…
tamimfatahi Aug 8, 2023
0a0edec
Closes #1165: Updated to-str method to report description accurately.…
jpl-jengelke Aug 8, 2023
6ecb637
Moving test_ld.py file to top level directory
tamimfatahi Aug 9, 2023
bad0f31
Changing grammar for GUI. Closes #1124
tamimfatahi Aug 9, 2023
1e95b72
Allowing CBB and CV filters to be standard with custom ranges from us…
tamimfatahi Aug 9, 2023
54c6dba
Updating test to conform with new changes.
tamimfatahi Aug 9, 2023
be54e8b
Modifying incorrect argument format in inputs.py file.
tamimfatahi Aug 9, 2023
a7d8e26
Issue #1165: Minor grammar change in user feedback...
jpl-jengelke Aug 9, 2023
67a17df
Updating filters.py by adding in aliases and removing unknown FWHM.
tamimfatahi Aug 10, 2023
03f2ea6
Merge remote-tracking branch 'origin/issue_1165' into issue_1165
tamimfatahi Aug 10, 2023
8d7dd70
Moving test_ld.py file to top level directory
tamimfatahi Aug 10, 2023
960e4a4
Modifying ld.py back to previous changes
tamimfatahi Aug 10, 2023
578fae1
Merge remote-tracking branch 'origin/issue_1165' into issue_1165
tamimfatahi Aug 10, 2023
96099d3
Updating ld.py to include both filter and names in description that …
tamimfatahi Aug 11, 2023
f7705d3
Updating exotic.py to work with new additions in ld.py.
tamimfatahi Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions exotic/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
"LCO Pan-STARRS w": "PanSTARRS w",

"Clear (unfiltered) reduced to V sequence": "MObs CV",
jpl-jengelke marked this conversation as resolved.
Show resolved Hide resolved
"Clear (unfiltered) reduced to R sequence": "Cousins R",

"Clear with blue-blocking": "Astrodon ExoPlanet-BB",
"Exop": "Astrodon ExoPlanet-BB",
}
161 changes: 34 additions & 127 deletions exotic/api/ld.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,32 @@


class LimbDarkening:
filter_nonspecific_ids = ('CR', 'CBB', 'CV', 'TB', 'TG', 'TR', ) # prevent misidentification of generic values
filter_generic_ids = ('N/A', 'NA', 'NONE', ) # imply custom filter, always
# standard filters w/o precisely defined FWHM values
filter_nonspecific = {
'CR': "Clear (unfiltered) reduced to R sequence",
'CBB': "Clear with blue-blocking",
'CV': "Clear (unfiltered) reduced to V sequence",
'TB': "DSLR Blue",
'TG': "DSLR Green",
'TR': "DSLR Red",
}
# implies custom filter, always
filter_generic_names = ('N/A', 'NA', 'NONE',)

# include filter maps as references from this class
fwhm = fwhm
fwhm_alias = fwhm_alias

# lookup table: fwhm_map references filters irrespective of spacing and punctuation
# 1 - join optimized str lookups in lookup table
fwhm_lookup = {''.join(k.strip().lower().split()): k for k in fwhm.keys()}
fwhm_lookup.update({''.join(k.strip().lower().split()): v for k, v in fwhm_alias.items()})
# 1 - combine optimized str lookups in lookup table
fwhm_lookup = {k.strip().replace(' ', '').lower(): k for k in fwhm.keys()}
fwhm_lookup.update({k.strip().replace(' ', '').lower(): v for k, v in fwhm_alias.items()})
# 2 - ignore punctuation in lookup table
fwhm_lookup = {re.sub(ld_re_punct_p, '', k): v for k, v in fwhm_lookup.items()}

def __init__(self, stellar):
self.filter_name = self.filter_desc = None
self.ld0 = self.ld1 = self.ld2 = self.ld3 = None
self.ld0 = self.ld1 = self.ld2 = self.ld3 = [0, 0]
self.priors = {
'T*': stellar.get('teff'),
'T*_uperr': stellar.get('teffUncPos'),
Expand Down Expand Up @@ -96,15 +106,18 @@ def check_standard(self, filter_: dict = None, loose: bool = False, loose_len: i
# eliminate errant spaces on edges
filter_[k] = filter_[k].strip()
if k == 'name' and filter_[k]: # format 'name' (if exists) to uppercase, no spaces
filter_[k] = ''.join(filter_[k].upper().split())
filter_[k] = filter_[k].upper().replace(' ', '')
if filter_['filter']: # make matcher by removing spaces, remove punctuation and lowercase
filter_matcher = ''.join(filter_['filter'].lower().split())
filter_matcher = filter_['filter'].lower().replace(' ', '')
filter_matcher = re.sub(ld_re_punct_p, '', filter_matcher)
filter_nonspecific_desc = [re.sub(ld_re_punct_p, '', f.lower().replace(' ', ''))
for f in LimbDarkening.filter_nonspecific.values()]
# identify defined filters via optimized lookup table
if filter_matcher and filter_matcher in LimbDarkening.fwhm_lookup:
if (filter_matcher and filter_matcher in LimbDarkening.fwhm_lookup and
filter_matcher not in filter_nonspecific_desc):
filter_['filter'] = LimbDarkening.fwhm_lookup[filter_matcher] # sets to actual filter reference key
# add always disabled alias values
filter_nonspecific_names = LimbDarkening.filter_nonspecific_ids + LimbDarkening.filter_generic_ids
filter_nonspecific_names = tuple(LimbDarkening.filter_nonspecific.keys()) + LimbDarkening.filter_generic_names
for f in LimbDarkening.fwhm.values():
# match to wavelength values (strict)
if (filter_['wl_min'] and filter_['wl_min'] == f['fwhm'][0] and
Expand Down Expand Up @@ -169,7 +182,7 @@ def check_fwhm(filter_: dict = None) -> bool:
return False
for k in ('wl_min', 'wl_max'): # clean inputs
filter_[k] = filter_.get(k)
filter_[k] = ''.join(str(filter_[k]).strip().split()).rstrip('.') if filter_[k] else filter_[k]
filter_[k] = str(filter_[k]).strip().replace(' ', '').rstrip('.') if filter_[k] else filter_[k]
if not 200. <= float(filter_[k]) <= 4000.: # also fails if nan
raise ValueError(f"FWHM '{k}' is outside of bounds (200., 4000.). ...")
else: # add .0 to end of str to aid literal matching
Expand Down Expand Up @@ -207,119 +220,13 @@ def set_ld(self, ld0, ld1, ld2, ld3):
self.ld3 = ld3
return

def output_ld(self):
print("\nEXOTIC-calculated nonlinear limb-darkening coefficients: ")
print(f"{self.ld0[0]:5f} +/- + {self.ld0[1]:5f}")
print(f"{self.ld1[0]:5f} +/- + {self.ld1[1]:5f}")
print(f"{self.ld2[0]:5f} +/- + {self.ld2[1]:5f}")
print(f"{self.ld3[0]:5f} +/- + {self.ld3[1]:5f}")
return


def test_ld(ld_obj_, filter_):
try:
ld_obj_.check_standard(filter_)
ld_obj_.calculate_ld()
except BaseException as be:
log.exception(be)
log.error("Continuing with default operations. ...")
filter_['filter'] = "Custom"
if filter_['wl_min'] and filter_['wl_max']:
ld_obj_.set_filter('N/A', filter_['filter'], float(filter_['wl_min']), float(filter_['wl_max']))
ld_obj_.calculate_ld()
else:
ld_ = [(filter_[key]["value"], filter_[key]["uncertainty"]) for key in filter_.keys()
if key in ['u0', 'u1', 'u2', 'u3']]
ld_obj_.set_filter('N/A', filter_['filter'], filter_['wl_min'], filter_['wl_max'])
ld_obj_.set_ld(ld_[0], ld_[1], ld_[2], ld_[3])
return


if __name__ == "__main__": # tests
stellar_params = {
'teff': 6001.0,
'teffUncPos': 88.0,
'teffUncNeg': -88.0,
'met': -0.16,
'metUncPos': 0.08,
'metUncNeg': -0.08,
'logg': 4.22,
'loggUncPos': 0.04,
'loggUncNeg': -0.04
}

# Test existing filter
filter_info1 = {
'filter': "CV",
'wl_min': None,
'wl_max': None,
'u0': {"value": None, "uncertainty": None},
'u1': {"value": None, "uncertainty": None},
'u2': {"value": None, "uncertainty": None},
'u3': {"value": None, "uncertainty": None}
}

# Test alias filter
filter_info2 = {
'filter': "LCO SDSS u'",
'wl_min': None,
'wl_max': None,
'u0': {"value": None, "uncertainty": None},
'u1': {"value": None, "uncertainty": None},
'u2': {"value": None, "uncertainty": None},
'u3': {"value": None, "uncertainty": None}
}

# Test given only FWHM
filter_info3 = {
'filter': None,
'wl_min': "350",
'wl_max': "850.0",
'u0': {"value": None, "uncertainty": None},
'u1': {"value": None, "uncertainty": None},
'u2': {"value": None, "uncertainty": None},
'u3': {"value": None, "uncertainty": None}
}

# Test custom-entered ld coefficients
filter_info4 = {
'filter': None,
'wl_min': None,
'wl_max': None,
'u0': {"value": 2.118, "uncertainty": 0.051},
'u1': {"value": -3.88, "uncertainty": 0.21},
'u2': {"value": 4.39, "uncertainty": 0.27},
'u3': {"value": -1.63, "uncertainty": 0.12}
}

filter_info5 = {
'filter': 'N/A',
'wl_min': 351.2,
'wl_max': 3999.,
'u0': {"value": 2.118, "uncertainty": 0.051},
'u1': {"value": -3.88, "uncertainty": 0.21},
'u2': {"value": 4.39, "uncertainty": 0.27},
'u3': {"value": -1.63, "uncertainty": 0.12}
}

ld_obj = LimbDarkening(stellar_params)
LimbDarkening.standard_list()

print(ld_obj.check_fwhm(filter_info5))
print(ld_obj.check_standard(filter_info5, True, 4))
print(ld_obj.check_standard(filter_info5))
print(str(filter_info5))
test_ld(ld_obj, filter_info5)
print(str(filter_info5))
print(f"{ld_obj.filter_desc}, {ld_obj.filter_name}, {ld_obj.wl_min}, {ld_obj.wl_max}")

LimbDarkening.check_fwhm(filter_info5)
LimbDarkening.check_fwhm(filter_info3)
test_ld(ld_obj, filter_info1)
# test_ld(ld_obj, filter_info2)
# test_ld(ld_obj, filter_info3)
# test_ld(ld_obj, filter_info4)

ld = [ld_obj.ld0[0], ld_obj.ld1[0], ld_obj.ld2[0], ld_obj.ld3[0]]
ld_unc = [ld_obj.ld0[1], ld_obj.ld1[1], ld_obj.ld2[1], ld_obj.ld3[1]]
ld_obj.output_ld()
def __str__(self):
return (f"\nFilter Name: {self.filter_name}"
jpl-jengelke marked this conversation as resolved.
Show resolved Hide resolved
f"\nFilter Description: {self.filter_desc}"
f"\nMinimum Wavelength (nm): {self.wl_min}"
f"\nMaxiumum Wavelength (nm):: {self.wl_max}"
"\nEXOTIC-calculated nonlinear limb-darkening coefficients: "
f"\n\t- {self.ld0[0]:5f} +/- + {self.ld0[1]:5f}"
f"\n\t- {self.ld1[0]:5f} +/- + {self.ld1[1]:5f}"
f"\n\t- {self.ld2[0]:5f} +/- + {self.ld2[1]:5f}"
f"\n\t- {self.ld3[0]:5f} +/- + {self.ld3[1]:5f}")
Loading