Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for use of reference_date property #345

Merged
merged 7 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions aiapy/calibrate/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def fix_observer_location(smap):
z=smap.meta["haez_obs"] * u.m,
representation_type=CartesianRepresentation,
frame=HeliocentricMeanEcliptic,
obstime=smap.date,
obstime=smap.reference_date,
).heliographic_stonyhurst
# Update header
new_meta = copy.deepcopy(smap.meta)
Expand Down Expand Up @@ -123,16 +123,10 @@ def update_pointing(smap, *, pointing_table=None):
# NOTE: For SDO data, T_OBS is preferred to DATE-OBS in the case of the
# MPT, using DATE-OBS from near the slot boundary might result in selecting
# an incorrect MPT record.
# FIXME: Beginning in sunpy v6.0.0, AIA maps use T_OBS as the reference date
# As such, once that is the min version supported, the following lines should
# be adjusted to just use smap.reference_date
t_obs = smap.meta.get("T_OBS")
if t_obs is None:
warnings.warn(
"T_OBS key is missing from metadata. Falling back to Map.date. "
"This may result in selecting in incorrect record from the "
"master pointing table.",
AiapyUserWarning,
stacklevel=3,
)
t_obs = smap.date
t_obs = astropy.time.Time(t_obs)
t_obs_in_interval = np.logical_and(t_obs >= pointing_table["T_START"], t_obs < pointing_table["T_STOP"])
if not t_obs_in_interval.any():
Expand Down
14 changes: 3 additions & 11 deletions aiapy/calibrate/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
def test_fix_observer_location(aia_171_map):
smap_fixed = fix_observer_location(aia_171_map)
# NOTE: AIAMap already fixes the .observer_coordinate property with HAE
assert smap_fixed.meta["hgln_obs"] == smap_fixed.observer_coordinate.lon.value
assert smap_fixed.meta["hglt_obs"] == smap_fixed.observer_coordinate.lat.value
assert smap_fixed.meta["dsun_obs"] == smap_fixed.observer_coordinate.radius.value
assert u.allclose(smap_fixed.meta["hgln_obs"], smap_fixed.observer_coordinate.lon.value, atol=None, rtol=1e-6)
assert u.allclose(smap_fixed.meta["hglt_obs"], smap_fixed.observer_coordinate.lat.value, atol=None, rtol=1e-6)
assert u.allclose(smap_fixed.meta["dsun_obs"], smap_fixed.observer_coordinate.radius.value, atol=None, rtol=1e-6)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider adding a test for the use of reference_date

The main code now uses smap.reference_date instead of smap.date. It would be beneficial to add a test that explicitly checks if the reference_date is being used correctly in the fix_observer_location function.

Suggested change
def test_fix_observer_location(aia_171_map):
smap_fixed = fix_observer_location(aia_171_map)
# NOTE: AIAMap already fixes the .observer_coordinate property with HAE
assert smap_fixed.meta["hgln_obs"] == smap_fixed.observer_coordinate.lon.value
assert smap_fixed.meta["hglt_obs"] == smap_fixed.observer_coordinate.lat.value
assert smap_fixed.meta["dsun_obs"] == smap_fixed.observer_coordinate.radius.value
assert u.allclose(smap_fixed.meta["hgln_obs"], smap_fixed.observer_coordinate.lon.value, atol=None, rtol=1e-6)
assert u.allclose(smap_fixed.meta["hglt_obs"], smap_fixed.observer_coordinate.lat.value, atol=None, rtol=1e-6)
assert u.allclose(smap_fixed.meta["dsun_obs"], smap_fixed.observer_coordinate.radius.value, atol=None, rtol=1e-6)
def test_fix_observer_location(aia_171_map):
smap_fixed = fix_observer_location(aia_171_map)
assert u.allclose(smap_fixed.meta["hgln_obs"], smap_fixed.observer_coordinate.lon.value, atol=None, rtol=1e-6)
assert u.allclose(smap_fixed.meta["hglt_obs"], smap_fixed.observer_coordinate.lat.value, atol=None, rtol=1e-6)
assert u.allclose(smap_fixed.meta["dsun_obs"], smap_fixed.observer_coordinate.radius.value, atol=None, rtol=1e-6)
assert smap_fixed.reference_date == aia_171_map.reference_date



@pytest.fixture()
Expand Down Expand Up @@ -86,14 +86,6 @@ def test_update_pointing_accuracy(aia_171_map, pointing_table, t_delt_factor, ex
assert aia_map_updated.reference_pixel.y == pointing_table[expected_entry]["A_171_Y0"]
nabobalis marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.remote_data()
def test_update_pointing_missing_tobs_raises_warning(aia_171_map, pointing_table):
# Tests that a warning is raised if T_OBS is not present.
aia_171_map.meta.pop("T_OBS")
with pytest.warns(AiapyUserWarning, match="T_OBS key is missing from metadata."):
update_pointing(aia_171_map, pointing_table=pointing_table)


@pytest.mark.remote_data()
def test_update_pointing_submap_raises_exception(aia_171_map, pointing_table):
m = aia_171_map.submap(
Expand Down
Loading