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 all 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
30 changes: 11 additions & 19 deletions aiapy/calibrate/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import copy
import warnings

import astropy.time
import astropy.units as u
import numpy as np
from astropy.coordinates import CartesianRepresentation, HeliocentricMeanEcliptic, SkyCoord
Expand Down Expand Up @@ -48,7 +47,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,21 +122,14 @@ 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.
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"])
# NOTE: In sunpy >=6.0, the reference_date property was introduced which, for
# AIA maps, will always be pulled from "T_OBS"
t_obs_in_interval = np.logical_and(
smap.reference_date >= pointing_table["T_START"], smap.reference_date < pointing_table["T_STOP"]
)
if not t_obs_in_interval.any():
msg = (
f"No valid entries for {t_obs} in pointing table "
f"No valid entries for {smap.reference_date} in pointing table "
f'with first T_START date of {pointing_table[0]["T_START"]} '
f'and a last T_STOP date of {pointing_table[-1]["T_STOP"]}.'
)
Expand All @@ -150,16 +142,16 @@ def update_pointing(smap, *, pointing_table=None):
# of the Sun in CCD pixel coordinates (0-based), but FITS WCS indexing is
# 1-based. See Section 2.2 of
# http://jsoc.stanford.edu/~jsoc/keywords/AIA/AIA02840_K_AIA-SDO_FITS_Keyword_Document.pdf
x0_mp = pointing_table[f"A_{w_str}_X0"][i_nearest].to("pix").value
y0_mp = pointing_table[f"A_{w_str}_Y0"][i_nearest].to("pix").value
x0_mp = pointing_table[f"A_{w_str}_X0"][i_nearest].to_value("pix")
y0_mp = pointing_table[f"A_{w_str}_Y0"][i_nearest].to_value("pix")
crpix1 = x0_mp + 1
crpix2 = y0_mp + 1
cdelt = pointing_table[f"A_{w_str}_IMSCALE"][i_nearest].to("arcsecond / pixel").value
cdelt = pointing_table[f"A_{w_str}_IMSCALE"][i_nearest].to_value("arcsecond / pixel")
# CROTA2 is the sum of INSTROT and SAT_ROT.
# See http://jsoc.stanford.edu/~jsoc/keywords/AIA/AIA02840_H_AIA-SDO_FITS_Keyword_Document.pdf
# NOTE: Is the value of SAT_ROT in the header accurate?
crota2 = pointing_table[f"A_{w_str}_INSTROT"][i_nearest] + smap.meta["SAT_ROT"] * u.degree
crota2 = crota2.to("deg").value
crota2 = crota2.to_value("deg")
# Update headers
for key, value in [
("crpix1", crpix1),
Expand Down
2 changes: 1 addition & 1 deletion aiapy/calibrate/spikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def respike(smap, *, spikes=None):
warnings.warn(
(
f"{smap.scale} is significantly different from the expected level "
"1 plate scale {nominal_scale}. If this map has been interpolated "
f"1 plate scale {nominal_scale}. If this map has been interpolated "
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
"in any way from the level 1 image, the spike data will likely be "
"reinserted in the incorrect pixel positions."
),
Expand Down
8 changes: 0 additions & 8 deletions aiapy/calibrate/tests/test_meta.py
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions changelog/345.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use `~sunpy.map.GenericMap.reference_date` when constructing an observer coordinate and in place
of pulling ``T_OBS`` directly from the header.
Loading