diff --git a/xrtpy/response/data/xrt_contam_on_ccd.geny b/xrtpy/response/data/xrt_contam_on_ccd.geny index 8d7cbab65..e37bd8def 100644 Binary files a/xrtpy/response/data/xrt_contam_on_ccd.geny and b/xrtpy/response/data/xrt_contam_on_ccd.geny differ diff --git a/xrtpy/response/effective_area.py b/xrtpy/response/effective_area.py index 86ef309d4..537fe4098 100644 --- a/xrtpy/response/effective_area.py +++ b/xrtpy/response/effective_area.py @@ -3,8 +3,10 @@ "effective_area", ] +import datetime import math import numpy as np +import os import scipy.io import sunpy.io.special import sunpy.time @@ -39,6 +41,7 @@ _ccd_contam_filename = ( Path(__file__).parent.absolute() / "data" / "xrt_contam_on_ccd.geny" ) + _filter_contam_filename = ( Path(__file__).parent.absolute() / "data" / "xrt_contam_on_filter.geny" ) @@ -97,33 +100,54 @@ def observation_date(self, date): self._observation_date = observation_date @property - def ccd_observation_date_to_seconds(self): - """Converting users observation date into seconds with respect to CCD contamination data. Used for interpolation.""" + def xrt_contam_on_ccd_geny_update(self): + """Return a string of the last time the file was modified.""" + modified_time = os.path.getmtime(_ccd_contam_filename) + modified_time_dt = datetime.datetime.fromtimestamp(modified_time) - ccd_observation_date_to_seconds = [] - for time in _ccd_contamination_file_time: - t0 = _ccd_contamination_file_time[0] - dt = time - t0 - ccd_observation_date_to_seconds.append( - (self.observation_date + timedelta(0, dt)).strftime("%S") - ) - - return ccd_observation_date_to_seconds[0] + return modified_time_dt.strftime("%Y/%m/%d") @property def ccd_data_dates_to_seconds(self): """Converting CCD data dates to datetimes.""" + ccd_data_dates_dt = [] ccd_data_dates_to_seconds = [] for time in _ccd_contamination_file_time: t0 = _ccd_contamination_file_time[0] dt = time - t0 + ccd_data_dates_dt.append(epoch + timedelta(0, dt)) ccd_data_dates_to_seconds.append( float((epoch + timedelta(0, dt)).strftime("%S")) ) + if self.observation_date > ccd_data_dates_dt[-1]: + raise ValueError( + "No contamination data is presently available for " + f"{self.observation_date}.\n The latest available data is on " + f"{ccd_data_dates_dt[-1]}.\n Contamination data is " + "updated periodically. The last update was on " + f"{self.xrt_contam_on_ccd_geny_update}. If this is more " + "than one month ago, please raise an issue at: " + "https://github.com/HinodeXRT/xrtpy/issues/new" + ) return ccd_data_dates_to_seconds + @property + def ccd_observation_date_to_seconds(self): + """Converting users observation date into seconds with + respect to CCD contamination data. Used for interpolation.""" + + ccd_observation_date_to_seconds = [] + for time in _ccd_contamination_file_time: + t0 = _ccd_contamination_file_time[0] + dt = time - t0 + ccd_observation_date_to_seconds.append( + (self.observation_date + timedelta(0, dt)).strftime("%S") + ) + + return ccd_observation_date_to_seconds[0] + @property def filter_observation_date_to_seconds(self): """Converting users observation date into seconds with respect to filter contamination data. Used for interpolation.""" diff --git a/xrtpy/response/tests/test_effective_area.py b/xrtpy/response/tests/test_effective_area.py index 78409a429..043e17784 100644 --- a/xrtpy/response/tests/test_effective_area.py +++ b/xrtpy/response/tests/test_effective_area.py @@ -46,6 +46,8 @@ datetime(year=2015, month=9, day=22, hour=22, minute=1, second=1), datetime(year=2017, month=9, day=22, hour=22, minute=1, second=1), datetime(year=2019, month=9, day=23, hour=22, minute=1, second=1), + datetime(year=2020, month=9, day=23, hour=22, minute=1, second=1), + datetime(year=2021, month=9, day=23, hour=22, minute=1, second=1), datetime(year=2022, month=9, day=23, hour=22, minute=1, second=1), ]