Skip to content

Commit

Permalink
Online tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Jan 1, 2025
1 parent f3eaa64 commit 1306992
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion aiapy/calibrate/spikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def fetch_spikes(smap, *, as_coords=False):
Original intensity values of the spikes
"""
series = "aia.lev1_uv_24s" if smap.wavelength in (1600, 1700, 4500) * u.angstrom else "aia.lev1_euv_12s"
file = get_data_from_jsoc(f'{series}[{smap.date}/12s][WAVELNTH={smap.meta["wavelnth"]}]', seg="spikes")
file = get_data_from_jsoc(f'{series}[{smap.date}/12s][WAVELNTH={smap.meta["wavelnth"]}]', key=None, seg="spikes")

Check warning on line 149 in aiapy/calibrate/spikes.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/spikes.py#L148-L149

Added lines #L148 - L149 were not covered by tests
_, spikes = fits.open(f'http://jsoc.stanford.edu{file["spikes"][0]}')
# Loaded as floats, but they are actually integers
spikes = spikes.data.astype(np.int32)
Expand Down
9 changes: 6 additions & 3 deletions aiapy/calibrate/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_fix_observer_location(aia_171_map) -> None:

@pytest.fixture
def pointing_table(aia_171_map):
return get_pointing_table(aia_171_map.date - 6 * u.h, aia_171_map.date + 6 * u.h)
return get_pointing_table(aia_171_map.date - 6 * u.h, aia_171_map.date + 6 * u.h, source="lmsal")

Check warning on line 24 in aiapy/calibrate/tests/test_meta.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_meta.py#L24

Added line #L24 was not covered by tests


@pytest.fixture
Expand Down Expand Up @@ -52,7 +52,10 @@ def test_fix_pointing(aia_171_map, pointing_table) -> None:
# Remove keys to at least test that they get set
for k in keys:
aia_171_map.meta.pop(k)
aia_map_updated = update_pointing(aia_171_map)
aia_map_updated = update_pointing(

Check warning on line 55 in aiapy/calibrate/tests/test_meta.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_meta.py#L55

Added line #L55 was not covered by tests
aia_171_map,
pointing_table=get_pointing_table(aia_171_map.date - 6 * u.h, aia_171_map.date + 6 * u.h, source="lmsal"),
)
# FIXME: how do we check these values are accurate?
assert all(k in aia_map_updated.meta for k in keys)
# Check the case where we have specified the pointing
Expand Down Expand Up @@ -109,7 +112,7 @@ def test_update_pointing_no_entry_raises_exception(aia_171_map, pointing_table)
# This tests that an exception is thrown when entry corresponding to
# T_START <= T_OBS < T_END cannot be found in the pointing table.
# We explicitly set the T_OBS key
aia_171_map.meta["T_OBS"] = (aia_171_map.date + 1 * u.day).isot
aia_171_map.meta["T_OBS"] = (aia_171_map.date - 1000 * u.day).isot

Check warning on line 115 in aiapy/calibrate/tests/test_meta.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_meta.py#L115

Added line #L115 was not covered by tests
with pytest.raises(IndexError, match="No valid entries for"):
update_pointing(aia_171_map, pointing_table=pointing_table)

Expand Down
20 changes: 14 additions & 6 deletions aiapy/calibrate/tests/test_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_degradation(source, time_correction_truth) -> None:
obstime,
correction_table=correction_table,
)
assert u.allclose(time_correction, time_correction_truth, rtol=1e-10, atol=0.0)
assert u.allclose(time_correction, time_correction_truth, atol=1e-3)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -214,21 +214,29 @@ def test_degradation_all_wavelengths(wavelength, result) -> None:
time_correction = degradation(
wavelength * u.angstrom,
obstime,
correction_table=get_correction_table(10),
)
assert u.allclose(time_correction, result)
assert u.allclose(time_correction, result, atol=1e-3)

Check warning on line 219 in aiapy/calibrate/tests/test_prep.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_prep.py#L219

Added line #L219 was not covered by tests


@pytest.mark.remote_data
def test_degradation_4500() -> None:
def test_degradation_4500_missing() -> None:
# 4500 has a max version of 3, so by default it will error
obstime = astropy.time.Time("2015-01-01T00:00:00", scale="utc")
with pytest.raises(
ValueError,
match="Correction table does not contain calibration for version 10 for 4500.0 Angstrom. Max version is 3",
match="Correction table does not contain calibration for 4500.0 Angstrom. Max version is 3.",
):
degradation(4500 * u.angstrom, obstime)
degradation(4500 * u.angstrom, obstime, correction_table=get_correction_table(10))

Check warning on line 230 in aiapy/calibrate/tests/test_prep.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_prep.py#L230

Added line #L230 was not covered by tests

correction = degradation(4500 * u.angstrom, obstime)

@pytest.mark.xfail(reason="JSOC is down")
@pytest.mark.remote_data
def test_degradation_4500_jsoc() -> None:
# 4500 has a max version of 3, so by default it will error
# and it is missing from the SSW files but not the JSOC
obstime = astropy.time.Time("2015-01-01T00:00:00", scale="utc")
correction = degradation(4500 * u.angstrom, obstime, correction_table=get_correction_table("jsoc"))

Check warning on line 239 in aiapy/calibrate/tests/test_prep.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_prep.py#L238-L239

Added lines #L238 - L239 were not covered by tests
assert u.allclose(correction, 1.0 * u.dimensionless_unscaled)


Expand Down
35 changes: 24 additions & 11 deletions aiapy/calibrate/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
@pytest.mark.parametrize(
"source",
[
pytest.param(None, marks=pytest.mark.remote_data),
pytest.param("jsoc", marks=pytest.mark.remote_data),
pytest.param(3, marks=pytest.mark.remote_data),
pytest.param(4, marks=pytest.mark.remote_data),
pytest.param(5, marks=pytest.mark.remote_data),
pytest.param(6, marks=pytest.mark.remote_data),
pytest.param(7, marks=pytest.mark.remote_data),
pytest.param(8, marks=pytest.mark.remote_data),
pytest.param(9, marks=pytest.mark.remote_data),
pytest.param(10, marks=pytest.mark.remote_data),
get_test_filepath("aia_V8_20171210_050627_response_table.txt"),
],
)
Expand Down Expand Up @@ -87,6 +95,7 @@ def test_obstime_out_of_range() -> None:


@pytest.mark.remote_data
@pytest.mark.xfail(reason="JSOC is down")
def test_pointing_table() -> None:
expected_columns = ["T_START", "T_STOP"]
for c in ["094", "171", "193", "211", "304", "335", "1600", "1700", "4500"]:
Expand All @@ -97,28 +106,32 @@ def test_pointing_table() -> None:
f"A_{c}_IMSCALE",
]
t = astropy.time.Time("2011-01-01T00:00:00", scale="utc")
table = get_pointing_table(t - 3 * u.h, t + 3 * u.h)
assert isinstance(table, astropy.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)
# Ensure that none of the pointing parameters are masked columns
for c in expected_columns[2:]:
assert not hasattr(table[c], "mask")
table_lmsal = get_pointing_table(t - 3 * u.h, t + 3 * u.h, source="lmsal")
table_jsoc = get_pointing_table(t - 3 * u.h, t + 3 * u.h, source="jsoc")
for table in [table_lmsal, table_jsoc]:
assert isinstance(table, astropy.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)

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

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_util.py#L109-L115

Added lines #L109 - L115 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 118 in aiapy/calibrate/tests/test_util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_util.py#L117-L118

Added lines #L117 - L118 were not covered by tests


@pytest.mark.remote_data
@pytest.mark.xfail(reason="JSOC is down")
def test_pointing_table_unavailable() -> None:
# Check that missing pointing data raises a nice error
t = astropy.time.Time("1990-01-01")
with pytest.raises(RuntimeError, match="Could not find any pointing information"):
get_pointing_table(t - 3 * u.h, t + 3 * u.h)
get_pointing_table(t - 3 * u.h, t + 3 * u.h, source="jsoc")

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

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/tests/test_util.py#L127

Added line #L127 was not covered by tests


@pytest.mark.parametrize(
"error_table",
[
pytest.param(None, marks=pytest.mark.remote_data),
pytest.param(2, marks=pytest.mark.remote_data),
pytest.param(3, marks=pytest.mark.remote_data),
get_test_filepath("aia_V3_error_table.txt"),
],
)
Expand Down
2 changes: 1 addition & 1 deletion aiapy/calibrate/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _select_epoch_from_correction_table(channel: u.angstrom, obstime, table):

@manager.require("pointing_table", *_URL_HASH_POINTING_TABLE)
def fetch_pointing_table():
manager.get("pointing_table")
return manager.get("pointing_table")

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

View check run for this annotation

Codecov / codecov/patch

aiapy/calibrate/util.py#L242

Added line #L242 was not covered by tests


def get_pointing_table(start, end, *, source):
Expand Down
2 changes: 1 addition & 1 deletion aiapy/util/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ def test_sdo_location(aia_171_map) -> None:
@pytest.mark.remote_data
def test_sdo_location_raises_error() -> None:
# Confirm that an error is raised for a time without records
with pytest.raises(ValueError, match="No DRMS records near this time"):
with pytest.raises(ValueError, match="No JSOC records near this time: 2001-01-01T00:00:00.000"):

Check warning on line 19 in aiapy/util/tests/test_util.py

View check run for this annotation

Codecov / codecov/patch

aiapy/util/tests/test_util.py#L19

Added line #L19 was not covered by tests
aiapy.util.sdo_location("2001-01-01")

0 comments on commit 1306992

Please sign in to comment.