Skip to content

Commit

Permalink
ccd_contam_file_error_message (#86)
Browse files Browse the repository at this point in the history
* Created a error message for CCD file without data for requested dates.

* Updated codespell text error

* Fixing a linters issue in the script

* Updated error message to state last updated date of the CCD contam file.

* Update xrtpy/response/effective_area.py

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

* Updated xrt contam on ccd file with update date.

* Updating test for the effective area.

* Update xrtpy/response/effective_area.py

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

* Trying to make test pass.

* Removing code that is not used.

* Updated valid dates to test.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update xrtpy/response/effective_area.py

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

* Update xrtpy/response/effective_area.py

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>

Co-authored-by: Nick Murphy <namurphy@cfa.harvard.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 5, 2022
1 parent 782ad54 commit 0fcd0fd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
Binary file modified xrtpy/response/data/xrt_contam_on_ccd.geny
Binary file not shown.
46 changes: 35 additions & 11 deletions xrtpy/response/effective_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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."""
Expand Down
2 changes: 2 additions & 0 deletions xrtpy/response/tests/test_effective_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]

Expand Down

0 comments on commit 0fcd0fd

Please sign in to comment.