Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Will Barnes <[email protected]>
  • Loading branch information
nabobalis and wtbarnes committed Jan 8, 2025
1 parent 278ee4c commit e9ca377
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions aiapy/calibrate/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@
"0a3f2db39d05c44185f6fdeec928089fb55d1ce1e0a805145050c6356cbc6e98",
)
}
_URL_HASH_CORRECTION_TABLE["latest"] = _URL_HASH_CORRECTION_TABLE[10]
_URL_HASH_ERROR_TABLE["latest"] = _URL_HASH_ERROR_TABLE[3]


@manager.require("correction_table_v10", *_URL_HASH_CORRECTION_TABLE[10])
def _fetch_correction_table_v10():
return manager.get("correction_table_v10")
@manager.require("correction_table_latest", *_URL_HASH_CORRECTION_TABLE["latest"])
def _fetch_correction_table_latest():
return manager.get("correction_table_latest")

Check warning on line 56 in aiapy/calibrate/util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/util.py#L56

Added line #L56 was not covered by tests


@manager.require("error_table_latest", *_URL_HASH_ERROR_TABLE["latest"])
def _fetch_error_table_latest():
return manager.get("error_table_latest")

Check warning on line 61 in aiapy/calibrate/util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/util.py#L61

Added line #L61 was not covered by tests


def get_correction_table(source):
Expand All @@ -69,9 +76,9 @@ def get_correction_table(source):
Parameters
----------
source: pathlib.Path, str
The source of the correction table. If it is a `pathlib.Path`, it must be a file.
A string file path will error as an invalid source.
If source is a string, it must either be "JSOC" which will fetch the most recent version from the JSOC or "SSW" which will fetch the most recent version (V10) from SSW.
The source of the correction table.
It can be a string or `pathlib.Path` for a file .
Otherwise, it must either be "JSOC" which will fetch the most recent version from the JSOC or "SSW" which will fetch the most recent version from SSW.
Returns
-------
Expand All @@ -82,17 +89,17 @@ def get_correction_table(source):
--------
aiapy.calibrate.degradation
"""
if isinstance(source, pathlib.Path):
table = QTable(astropy.io.ascii.read(source))
elif isinstance(source, str) and source.lower() == "ssw":
table = QTable(astropy.io.ascii.read(_fetch_correction_table_v10()))
if isinstance(source, str) and source.lower() == "ssw":
table = QTable(astropy.io.ascii.read(_fetch_correction_table_latest()))

Check warning on line 93 in aiapy/calibrate/util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/util.py#L93

Added line #L93 was not covered by tests
elif isinstance(source, str) and source.lower() == "jsoc":
# NOTE: the [!1=1!] disables the drms PrimeKey logic and enables
# the query to find records that are ordinarily considered
# identical because the PrimeKeys for this series are WAVE_STR
# and T_START. Without the !1=1! the query only returns the
# latest record for each unique combination of those keywords.
table = QTable.from_pandas(_get_data_from_jsoc(query="aia.response[][!1=1!]", key="**ALL**"))

Check warning on line 100 in aiapy/calibrate/util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/util.py#L100

Added line #L100 was not covered by tests
elif isinstance(source, pathlib.Path | str):
table = QTable(astropy.io.ascii.read(source))
else:
msg = f"correction_table must be a file path (pathlib.Path), 'JSOC' or 'SSW'. Not {source}"
raise ValueError(msg)
Expand Down Expand Up @@ -146,8 +153,9 @@ def _select_epoch_from_correction_table(channel: u.angstrom, obstime, correction
table.sort("DATE") # Newest entries will be last
if len(table) == 0:
extra_msg = " Max version is 3." if channel == 4500 * u.AA else ""
msg = f"Correction table does not contain calibration for {channel}.{extra_msg}"

Check warning on line 156 in aiapy/calibrate/util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/util.py#L156

Added line #L156 was not covered by tests
raise ValueError(
f"Correction table does not contain calibration for {channel}." + extra_msg,
msg,
)
# Select the epoch for the given observation time
obstime_in_epoch = np.logical_and(obstime >= table["T_START"], obstime < table["T_STOP"])
Expand Down Expand Up @@ -250,11 +258,6 @@ def get_pointing_table(source, *, time_range=None):
return table


@manager.require("error_table_v3", *_URL_HASH_ERROR_TABLE[3])
def _fetch_error_table_v3():
return manager.get("error_table_v3")


def get_error_table(source="SSW") -> QTable:
"""
Fetches the error table from a SSW mirror or uses a local file if one is
Expand All @@ -263,10 +266,9 @@ def get_error_table(source="SSW") -> QTable:
Parameters
----------
source : pathlib.Path, str, optional
If input is a pathlib.Path, it is assumed to be a file path to a local error table.
If a path is provided as a string, it will error as an invalid source.
Otherwise, the input is allowed to be "SSW" (the default) which will
fetch the most recent version (V3) from SSW.
The input is allowed to be "SSW" (the default) which will
fetch the most recent version from SSW.
Otherwise, it must be a file path.
Returns
-------
Expand All @@ -278,12 +280,12 @@ def get_error_table(source="SSW") -> QTable:
TypeError
If ``error_table`` is not a file path.
"""
if isinstance(source, pathlib.Path):
if isinstance(source, str) and source.lower() == "ssw":
error_table = QTable(astropy.io.ascii.read(_fetch_error_table_latest()))

Check warning on line 284 in aiapy/calibrate/util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/util.py#L284

Added line #L284 was not covered by tests
elif isinstance(source, pathlib.Path | str):
error_table = QTable(astropy.io.ascii.read(source))
elif isinstance(source, str) and source.lower() == "ssw":
error_table = QTable(astropy.io.ascii.read(_fetch_error_table_v3()))
else:
msg = f"source must be a pathlib.Path, or 'SSW', not {source}"
msg = f"source must be a filepath, or 'SSW', not {source}"
raise TypeError(msg)
error_table["DATE"] = Time(error_table["DATE"], scale="utc")
error_table["T_START"] = Time(error_table["T_START"], scale="utc")
Expand Down

0 comments on commit e9ca377

Please sign in to comment.