From c79598738e348b6efbae33d989ec4e1b12512f99 Mon Sep 17 00:00:00 2001 From: molaes-stsci <43047691+molaes-stsci@users.noreply.github.com> Date: Tue, 10 Nov 2020 17:28:31 -0500 Subject: [PATCH] Updated handling of extrapolated dates (#140) * 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 <2090236+pllim@users.noreply.github.com> --- acstools/acszpt.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/acstools/acszpt.py b/acstools/acszpt.py index ac13f535..2100c342 100644 --- a/acstools/acszpt.py +++ b/acstools/acszpt.py @@ -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 @@ -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: @@ -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 @@ -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 @@ -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)) @@ -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)')