Skip to content

Commit

Permalink
Updated handling of extrapolated dates (#140)
Browse files Browse the repository at this point in the history
* updated minor typo in example

* Removed all instances of 'self._extrapolation_date'. since the value is hard coded and unsustainable over time.

* Added attribute 'self._warnings'.

* Added functionality to detect and log any messages that are returned from the ZPT calculator after "Warnings: ".

Co-authored-by: P. L. Lim <[email protected]>
  • Loading branch information
molaes-stsci and pllim authored Nov 10, 2020
1 parent ebceb10 commit c795987
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions acstools/acszpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
>>> date = '2016-04-01'
>>> detector = 'WFC'
>>> filt = 'F435W'
>>> q = acszpt.Query(date=date, detector=detector, filter=filt)
>>> q = acszpt.Query(date=date, detector=detector, filt=filt)
>>> zpt_table = q.fetch()
>>> print(zpt_table)
FILTER PHOTPLAM PHOTFLAM STmag VEGAmag ABmag
Expand Down Expand Up @@ -153,6 +153,7 @@ def __init__(self, date, detector, filt=None):
'F140LP', 'F150LP', 'F165LP']
}
self._zpt_table = None
self._warnings = []

# Set the private attributes
if filt is None:
Expand All @@ -165,9 +166,6 @@ def __init__(self, date, detector, filt=None):
f'&{self.detector}_filter={self.filt}')
# ACS Launch Date
self._acs_installation_date = dt.datetime(2002, 3, 7)
# The farthest date in future that the component and throughput files
# are valid for. If input date is larger, extrapolation is not valid.
self._extrapolation_date = dt.datetime(2021, 12, 31)
self._msg_div = '-' * 79
self._valid_detectors = ['HRC', 'SBC', 'WFC']
self._response = None
Expand Down Expand Up @@ -270,13 +268,6 @@ def _check_date(self, fmt='%Y-%m-%d'):
result = ('The observation date cannot occur '
'before ACS was installed '
f'({self._acs_installation_date.strftime(fmt)})')
elif dt_obj > self._extrapolation_date:
result = ('The observation date cannot occur after the '
'maximum allowable date, '
f'{self._extrapolation_date.strftime(fmt)}. '
'Extrapolations of the '
'instrument throughput after this date lead to '
'high uncertainties and are therefore invalid.')
finally:
return result

Expand Down Expand Up @@ -319,6 +310,15 @@ def _parse_and_format(self):
# Remove the units attached to PHOTFLAM and PHOTPLAM column names.
td = [val.text.split(' ')[0] for val in td]

# Grab warnings returned by the ZPT calc as marked by stylized h4 tag
warnings = soup.find_all('h4', {'style': "color:red;"})

# Remove tags and 'Warnings: ' label attached to warnings
str_warnings = [w.get_text().replace('Warnings: ', '') for w in warnings]

# Add non-empty strings to _warnings attribute
self._warnings = [w for w in str_warnings if w.strip()]

# Turn the single list into a 2-D numpy array
data = np.reshape(td,
(int(len(td) / self._block_size), self._block_size))
Expand Down Expand Up @@ -375,6 +375,9 @@ def fetch(self):

LOG.info('Parsing the response and formatting the results...')
self._parse_and_format()
for w in self._warnings:
LOG.warning(w)

return self.zpt_table

LOG.error('Please fix the incorrect input(s)')

0 comments on commit c795987

Please sign in to comment.