Skip to content

Commit

Permalink
Final review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Jan 8, 2025
1 parent 9f56c81 commit 278ee4c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 109 deletions.
36 changes: 18 additions & 18 deletions aiapy/calibrate/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import pytest

import astropy.table
import astropy.time
import astropy.units as u
from astropy.table import QTable
from astropy.time import Time

from aiapy.calibrate.util import (
_select_epoch_from_correction_table,
Expand All @@ -15,7 +15,7 @@
from aiapy.tests.data import get_test_filepath

# These are not fixtures so that they can be easily used in the parametrize mark
obstime = astropy.time.Time("2015-01-01T00:00:00", scale="utc")
obstime = Time("2015-01-01T00:00:00", scale="utc")
correction_table_local = get_correction_table(get_test_filepath("aia_V8_20171210_050627_response_table.txt"))


Expand All @@ -29,7 +29,7 @@
)
def test_correction_table(source) -> None:
table = get_correction_table(source=source)
assert isinstance(table, astropy.table.QTable)
assert isinstance(table, QTable)
expected_columns = [
"VER_NUM",
"WAVE_STR",
Expand All @@ -42,14 +42,14 @@ def test_correction_table(source) -> None:
"EFF_WVLN",
]
assert all(cn in table.colnames for cn in expected_columns)
assert isinstance(table["T_START"], astropy.time.Time)
assert isinstance(table["T_STOP"], astropy.time.Time)
assert isinstance(table["T_START"], Time)
assert isinstance(table["T_STOP"], Time)


@pytest.mark.parametrize("wavelength", [94 * u.angstrom, 1600 * u.angstrom])
def test_correction_table_selection(wavelength) -> None:
table = _select_epoch_from_correction_table(wavelength, obstime, correction_table_local)
assert isinstance(table, astropy.table.QTable)
assert isinstance(table, QTable)
expected_columns = [
"VER_NUM",
"WAVE_STR",
Expand All @@ -62,8 +62,8 @@ def test_correction_table_selection(wavelength) -> None:
"EFF_WVLN",
]
assert all(cn in table.colnames for cn in expected_columns)
assert isinstance(table["T_START"], astropy.time.Time)
assert isinstance(table["T_STOP"], astropy.time.Time)
assert isinstance(table["T_START"], Time)
assert isinstance(table["T_STOP"], Time)


def test_invalid_correction_table_input() -> None:
Expand All @@ -80,7 +80,7 @@ def test_invalid_wavelength_raises_exception() -> None:


def test_obstime_out_of_range() -> None:
obstime_out_of_range = astropy.time.Time("2000-01-01T12:00:00", scale="utc")
obstime_out_of_range = Time("2000-01-01T12:00:00", scale="utc")
with pytest.raises(ValueError, match=f"No valid calibration epoch for {obstime_out_of_range}"):
_select_epoch_from_correction_table(94 * u.angstrom, obstime_out_of_range, correction_table_local)

Expand All @@ -95,14 +95,14 @@ def test_pointing_table() -> None:
f"A_{c}_IMSCALE",
f"A_{c}_IMSCALE",
]
t = astropy.time.Time("2011-01-01T00:00:00", scale="utc")
t = Time("2011-01-01T00:00:00", scale="utc")
table_lmsal = get_pointing_table("lmsal")
table_jsoc = get_pointing_table("jsoc", start=t - 3 * u.h, end=t + 3 * u.h)
table_jsoc = get_pointing_table("jsoc", time_range=(t - 3 * u.h, t + 3 * u.h))
for table in [table_lmsal, table_jsoc]:
assert isinstance(table, astropy.table.QTable)
assert isinstance(table, QTable)
assert all(cn in table.colnames for cn in expected_columns)
assert isinstance(table["T_START"], astropy.time.Time)
assert isinstance(table["T_STOP"], astropy.time.Time)
assert isinstance(table["T_START"], Time)
assert isinstance(table["T_STOP"], Time)

Check warning on line 105 in aiapy/calibrate/tests/test_util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_util.py#L98-L105

Added lines #L98 - L105 were not covered by tests
# Ensure that none of the pointing parameters are masked columns
for c in expected_columns[2:]:
assert not hasattr(table[c], "mask")

Check warning on line 108 in aiapy/calibrate/tests/test_util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_util.py#L107-L108

Added lines #L107 - L108 were not covered by tests
Expand All @@ -111,9 +111,9 @@ def test_pointing_table() -> None:
@pytest.mark.remote_data
def test_pointing_table_unavailable() -> None:
# Check that missing pointing data raises a nice error
t = astropy.time.Time("1990-01-01")
t = Time("1990-01-01")
with pytest.raises(RuntimeError, match="No data found for this query"):
get_pointing_table("jsoc", start=t - 3 * u.h, end=t + 3 * u.h)
get_pointing_table("jsoc", time_range=Time([t - 3 * u.h, t + 3 * u.h]))

Check warning on line 116 in aiapy/calibrate/tests/test_util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_util.py#L114-L116

Added lines #L114 - L116 were not covered by tests


@pytest.mark.parametrize(
Expand All @@ -125,7 +125,7 @@ def test_pointing_table_unavailable() -> None:
)
def test_error_table(error_table) -> None:
table = get_error_table(error_table)
assert isinstance(table, astropy.table.QTable)
assert isinstance(table, QTable)
assert len(table) == 10


Expand Down
14 changes: 7 additions & 7 deletions aiapy/calibrate/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _fetch_pointing_table():
return manager.get("pointing_table")

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

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/util.py#L170

Added line #L170 was not covered by tests


def get_pointing_table(source, *, start=None, end=None):
def get_pointing_table(source, *, time_range=None):
"""
Retrieve 3-hourly master pointing table from the given source.
Expand Down Expand Up @@ -209,10 +209,9 @@ def get_pointing_table(source, *, start=None, end=None):
source : str
Name of the source from which to retrieve the pointing table.
Must be one of ``"jsoc"`` or ``"lmsal"``.
start : `~astropy.time.Time`, optional
Start time of the interval. Only required if ``source`` is ``"jsoc"``.
end : `~astropy.time.Time`, optional
End time of the interval. Only required if ``source`` is ``"jsoc"``.
time_range : `~astropy.time.Time`, optional
Time range for which to retrieve the pointing table.
You can pass in a `~astropy.time.Time` object or a tuple of start and end times.
Returns
-------
Expand All @@ -223,9 +222,10 @@ def get_pointing_table(source, *, start=None, end=None):
aiapy.calibrate.update_pointing
"""
if source.lower() == "jsoc":
if start is None or end is None:
msg = "start and end must be provided if source is 'jsoc'"
if time_range is None:
msg = "time_range must be provided if the source is 'jsoc'"
raise ValueError(msg)
start, end = time_range
table = QTable.from_pandas(

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

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/util.py#L224-L229

Added lines #L224 - L229 were not covered by tests
_get_data_from_jsoc(query=f"aia.master_pointing3h[{start.isot}Z-{end.isot}Z]", key="**ALL**")
)
Expand Down
1 change: 0 additions & 1 deletion docs/preparing_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ If you want to do any additional data processing steps (e.g., PSF deconvolution)
* The PSF functions are defined on the level 1 pixel grid so PSF deconvolution **MUST** be done on the level 1 data products (i.e., before image registration).
This is described in the PSF gallery example :ref:`sphx_glr_generated_gallery_skip_psf_deconvolution.py`.
* The pointing update should be done prior to image registration as the updated keywords, namely ``CRPIX1`` and ``CRPIX2``, are used in the image registration step.
More details can be found in this gallery example :ref:`sphx_glr_generated_gallery_update_header_keywords.py`.
* The exposure time normalization and degradation correction (`aiapy.calibrate.correct_degradation`) operations are just scalar multiplication and are thus linear such that their ordering is inconsequential.
* Exposure time normalization can be performed by simply dividing a map by the exposure time property, ``my_map / my_map.exposure_time``.
2 changes: 1 addition & 1 deletion examples/prepping_level_1_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# `aiapy.calibrate.util.get_pointing_table` function.

# Make range wide enough to get closest 3-hour pointing
pointing_table = get_pointing_table("JSOC", start=aia_map.date - 12 * u.h, end=aia_map.date + 12 * u.h)
pointing_table = get_pointing_table("JSOC", time_range=(aia_map.date - 12 * u.h, aia_map.date + 12 * u.h))
aia_map_updated_pointing = update_pointing(aia_map, pointing_table=pointing_table)

###############################################################################
Expand Down
4 changes: 3 additions & 1 deletion examples/skip_download_specific_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
level_1_maps = sunpy.map.Map(files)
# We get the pointing table outside of the loop for the relevant time range.
# Otherwise you're making a call to the JSOC every single time.
pointing_table = get_pointing_table("jsoc", start=level_1_maps[0].date - 3 * u.h, end=level_1_maps[-1].date + 3 * u.h)
pointing_table = get_pointing_table(
"jsoc", time_range=(level_1_maps[0].date - 3 * u.h, level_1_maps[-1].date + 3 * u.h)
)
# The same applies for the correction table.
correction_table = get_correction_table(source="jsoc")

Expand Down
81 changes: 0 additions & 81 deletions examples/update_header_keywords.py

This file was deleted.

0 comments on commit 278ee4c

Please sign in to comment.