diff --git a/changelog/7526.bugfix.rst b/changelog/7526.bugfix.rst new file mode 100644 index 00000000000..fdfd26f9b5a --- /dev/null +++ b/changelog/7526.bugfix.rst @@ -0,0 +1,2 @@ +Added a check in `sunpy.physics.differential_rotation.solar_rotate_coordinate` to ensure the input frame has an "observer" attribute before replicating frame +attributes, preventing potential issues with frames lacking this attribute. diff --git a/sunpy/physics/differential_rotation.py b/sunpy/physics/differential_rotation.py index bb9b77d8db2..fde24a40dc0 100644 --- a/sunpy/physics/differential_rotation.py +++ b/sunpy/physics/differential_rotation.py @@ -255,8 +255,12 @@ def solar_rotate_coordinate(coordinate, observer=None, time=None, **diff_rot_kwa # Calculate where the rotated coordinate appears as seen by new observer # for the coordinate system of the input coordinate. The translational # motion of the Sun will be ignored for the transformation. - frame_newobs = coordinate.frame.replicate_without_data(observer=new_observer, + + if "observer" in coordinate.frame.frame_attributes.keys(): + frame_newobs = coordinate.frame.replicate_without_data(observer=new_observer, obstime=new_observer.obstime) + else: + frame_newobs = coordinate.frame.replicate_without_data(obstime=new_observer.obstime) with transform_with_sun_center(): return heliographic_rotated.transform_to(frame_newobs) diff --git a/sunpy/physics/tests/test_differential_rotation.py b/sunpy/physics/tests/test_differential_rotation.py index c6f831f22e1..6f9372e872c 100644 --- a/sunpy/physics/tests/test_differential_rotation.py +++ b/sunpy/physics/tests/test_differential_rotation.py @@ -5,7 +5,7 @@ import astropy.units as u from astropy.coordinates import SkyCoord from astropy.tests.helper import assert_quantity_allclose -from astropy.time import TimeDelta +from astropy.time import Time, TimeDelta import sunpy.map from sunpy.coordinates import frames, transform_with_sun_center @@ -132,6 +132,16 @@ def test_solar_rotate_coordinate(): # Test that the SkyCoordinate is Helioprojective assert isinstance(d.frame, frames.Helioprojective) + # Test that the function works correctly with a HGS coordinate. + earth_coord = get_earth(Time("2022-03-30")) + coord_hpc = SkyCoord(100*u.arcsec, 100*u.arcsec, frame=frames.Helioprojective(observer=earth_coord)) + + coord_hgs = coord_hpc.transform_to(frames.HeliographicStonyhurst) + with pytest.warns(UserWarning, match="Using 'time' assumes an Earth-based observer"): + rotated_coord_hgs = solar_rotate_coordinate(coord_hgs, time=Time("2022-03-31")) + + assert isinstance(rotated_coord_hgs.frame, frames.HeliographicStonyhurst) + def test_consistency_with_rotatedsunframe(): old_observer = frames.HeliographicStonyhurst(10*u.deg, 20*u.deg, 1*u.AU, obstime='2001-01-01')