Skip to content

Commit

Permalink
Merge branch 'HinodeXRT:main' into jslavin-patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
jslavin authored Jan 25, 2023
2 parents c87c151 + a8342cf commit bbe1132
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 179 deletions.
24 changes: 15 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ ci:
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-ast
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: .*\.fits
- id: check-merge-conflict
exclude: .*\.rst
- id: requirements-txt-fixer
Expand All @@ -19,8 +20,13 @@ repos:
- id: check-toml
- id: check-yaml

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 0.4.1
hooks:
- id: pyproject-fmt

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.11.4
hooks:
- id: isort
name: isort
Expand All @@ -31,12 +37,12 @@ repos:
- python

- repo: https://github.com/psf/black
rev: 22.8.0
rev: 22.12.0
hooks:
- id: black

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.5.2
rev: 1.6.0
hooks:
- id: nbqa-black
additional_dependencies:
Expand All @@ -50,12 +56,10 @@ repos:
- --nbqa-mutate

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.4.0
rev: v2.5.0
hooks:
- id: pretty-format-ini
args: [--autofix]
- id: pretty-format-toml
args: [--autofix]
- id: pretty-format-yaml
args: [--autofix]

Expand All @@ -74,10 +78,12 @@ repos:
rev: v2.2.2
hooks:
- id: codespell
args: [--config pyproject.toml]
exclude: .*\.fits
additional_dependencies:
- tomli

- repo: https://github.com/asottile/pyupgrade
rev: v2.38.2
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--keep-runtime-typing, --py38-plus]
Expand Down
3 changes: 3 additions & 0 deletions docs/_substitutions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
.. |Quantity| replace:: :class:`~astropy.units.Quantity`
.. |TimeDelta| replace:: :class:`~astropy.time.TimeDelta`
.. |Time| replace:: :class:`~astropy.time.Time`
.. |Channel| replace:: :class:`~xrtpy.response.channel.Channel`
.. |EffectiveAreaFundamental| replace:: :class:`~xrtpy.response.effective_area.EffectiveAreaFundamental`
.. |TemperatureResponseFundamental| replace:: :class:`~xrtpy.response.temperature_response.TemperatureResponseFundamental`

.. A workaround for nested inline literals so that the filename will get
formatted like a file but will be a link. In the text, these get used
Expand Down
4 changes: 1 addition & 3 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ Computing response functions
.. nbgallery::
:glob:

notebooks/*
notebooks/computing_functions/effective_area.ipynb
notebooks/computing_functions/temperature_response.ipynb
notebooks/computing_functions/*
2 changes: 1 addition & 1 deletion docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ to explore properties of the XRT. Visit our Example page for detail example guid

Channel
-------
Channel is an instrument configuration class that explores properties of the XRT. Channel offers a detailed review of instruments for a chosen
|Channel| is an instrument configuration class that explores properties of the XRT. Channel offers a detailed review of instruments for a chosen
filter channel including the Charge-Coupled Device (CCD), Entrance Filter, Focus-Filter(s), Geometry, and Mirror(s).


Expand Down
119 changes: 45 additions & 74 deletions docs/notebooks/computing_functions/effective_area.ipynb

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
[build-system]
requires = ["setuptools >= 50.0",
"setuptools_scm >= 6.0",
"wheel >= 0.34.0"] # ought to mirror 'requirements/build.txt'
build-backend = "setuptools.build_meta"
requires = [
"setuptools>=50",
"setuptools_scm>=6",
"wheel>=0.34",
] # ought to mirror 'requirements/build.txt'

[tool.codespell]
skip = "*.genx,*.geny,*.png,*egg*,.git,.hypothesis,.nox,.tox,.idea,__pycache__,_build"
ignore-words-list = """
circularly"""
circularly,
nd,
sav,
te
"""

[tool.gilesbot]

Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ developer =

[options.package_data]
xrtpy = data/*
xrtpy.response = data/*.txt, data/*.geny
xrtpy.response.tests = data/*/*/*.txt

[tool:pytest]
minversion = 5.4
Expand Down
Binary file modified xrtpy/response/data/xrt_contam_on_ccd.geny
Binary file not shown.
122 changes: 36 additions & 86 deletions xrtpy/response/effective_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"effective_area",
]


import astropy.time
import datetime
import math
import numpy as np
Expand All @@ -12,7 +14,7 @@
import sunpy.time

from astropy import units as u
from datetime import timedelta
from astropy.utils.data import get_pkg_data_filename
from functools import cached_property
from pathlib import Path
from scipy import interpolate
Expand Down Expand Up @@ -50,11 +52,15 @@
_filter_contam_file = scipy.io.readsav(_filter_contam_filename)

# CCD contam geny files keys for time and date.
_ccd_contamination_file_time = _ccd_contam_file["p1"]
_ccd_contamination_file_time = astropy.time.Time(
_ccd_contam_file["p1"], format="utime", scale="utc"
)
_ccd_contamination = _ccd_contam_file["p2"]

# Filter contam geny files keys for time and date.
_filter_contamination_file_time = _filter_contam_file["p1"]
_filter_contamination_file_time = astropy.time.Time(
_filter_contam_file["p1"], format="utime", scale="utc"
)
_filter_contamination = _filter_contam_file["p2"]


Expand Down Expand Up @@ -90,100 +96,44 @@ def observation_date(self) -> str:
@observation_date.setter
def observation_date(self, date):
"""Validating users requested observation date."""
astropy_time = sunpy.time.parse_time(date) # Astropy time in utc
observation_date = astropy_time.datetime

observation_date = sunpy.time.parse_time(date)

if observation_date <= epoch:
raise ValueError(
f"Invalid date: {observation_date}.\n Date must be after September 22nd, 2006 21:36:00."
f"\nInvalid date: {observation_date.datetime}.\n"
f"Date must be after {epoch}."
)
self._observation_date = observation_date

@property
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)

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"))
)
modified_time_path = os.path.getmtime(_ccd_contam_filename)
modified_time = astropy.time.Time(modified_time_path, format="unix")
latest_available_ccd_data = _ccd_contamination_file_time[-1].datetime.strftime(
"%Y/%m/%d"
)
modified_time_datetime = datetime.datetime.fromtimestamp(
modified_time_path
).strftime("%Y/%m/%d")

if self.observation_date > ccd_data_dates_dt[-1]:
if observation_date > modified_time:
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 "
"\nNo contamination data is presently available for "
f"{observation_date.datetime}.\n The latest available data is on "
f"{latest_available_ccd_data}.\n Contamination data is "
"updated periodically. The last update was on "
f"{self.xrt_contam_on_ccd_geny_update}. If this is more "
f"{modified_time_datetime}. 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."""

filter_observation_date_to_seconds = []
for time in _filter_contamination_file_time:
t0 = _filter_contamination_file_time[0]
dt = time - t0
filter_observation_date_to_seconds.append(
(self.observation_date + timedelta(0, dt)).strftime("%S")
)

return filter_observation_date_to_seconds[0]

@property
def filter_data_dates_to_seconds(self):
"""Converting filter contamination data dates to datetimes."""

filter_data_dates_to_seconds = []
for time in _filter_contamination_file_time:
t0 = _filter_contamination_file_time[0]
dt = time - t0
filter_data_dates_to_seconds.append(
float((epoch + timedelta(0, dt)).strftime("%S"))
)

return filter_data_dates_to_seconds
self._observation_date = observation_date

@property
def contamination_on_CCD(self):
"""Calculation of contamination layer on the CCD, thickness given in Angstrom (Å)."""

interpolater = scipy.interpolate.interp1d(
self.ccd_data_dates_to_seconds, _ccd_contamination, kind="linear"
_ccd_contamination_file_time.utime, _ccd_contamination, kind="linear"
)
return interpolater(self.ccd_observation_date_to_seconds)
return interpolater(self.observation_date.utime)

@property
def filter_index_mapping_to_name(self):
Expand All @@ -200,25 +150,25 @@ def filter_wheel_number(self):

@property
def filter_data(self):
"""Collecting filter data."""
"""Collecting filter contamination data."""
return _filter_contamination[self.filter_index_mapping_to_name][
self.filter_wheel_number
]

@property
def contamination_on_filter(self) -> u.angstrom:
"""
Thickness of the contamination layer on a filter."""

"""Thickness of the contamination layer on a filter."""
interpolater = scipy.interpolate.interp1d(
self.filter_data_dates_to_seconds, self.filter_data, kind="linear"
_filter_contamination_file_time.utime, self.filter_data, kind="linear"
)
return interpolater(self.filter_observation_date_to_seconds)
return interpolater(self.observation_date.utime)

@cached_property
def n_DEHP_attributes(self):
"""Diethylhexylphthalate: Wavelength (nm), Delta, Beta."""
_n_DEHP_filename = Path(__file__).parent.absolute() / "data" / "n_DEHP.txt"
_n_DEHP_filename = get_pkg_data_filename(
"data/n_DEHP.txt", package="xrtpy.response"
)

with open(_n_DEHP_filename) as n_DEHP:
list_of_DEHP_attributes = []
Expand Down
6 changes: 4 additions & 2 deletions xrtpy/util/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"epoch",
]

from datetime import datetime, timedelta
import astropy.time

from datetime import timedelta

# Hinode-XRT mission elapsed time "Epoch" is Sept 22, 2006 21:36:00.
epoch = datetime(year=2006, month=9, day=22, hour=21, minute=36, second=0)
epoch = astropy.time.Time("2006-09-22 21:36:00")


def xrt_data_time_to_dt(data_time, epoch):
Expand Down

0 comments on commit bbe1132

Please sign in to comment.