Skip to content

Commit

Permalink
Merge pull request #7548 from meeseeksmachine/auto-backport-of-pr-754…
Browse files Browse the repository at this point in the history
…5-on-5.1

Backport PR #7545 on branch 5.1 (Fixed the GEI->HME transformation to preserve the length unit of the coordinate)
  • Loading branch information
nabobalis committed Apr 3, 2024
2 parents 544a09e + f91fc34 commit aeec121
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/7545.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug with any coordinate transformation starting in `~sunpy.coordinates.GeocentricEarthEquatorial` (GEI) returning output with AU as the length unit, rather than preserving the length unit of the initial coordinate.
2 changes: 1 addition & 1 deletion sunpy/coordinates/_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def gei_to_hme(geicoord, hmeframe):
earth_object_int = geicoord.cartesian.transform(rot_matrix)

# Find the Sun-object vector in the intermediate frame
sun_object_int = sun_earth_int + earth_object_int
sun_object_int = earth_object_int + sun_earth_int # add in this order to preserve the original units
int_coord = int_frame.realize_frame(sun_object_int)

# Convert to the final frame through HCRS
Expand Down
30 changes: 30 additions & 0 deletions sunpy/coordinates/tests/test_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,36 @@ def test_rsun_preservation():
assert_quantity_allclose(out_coord.rsun, args_out['rsun'])


_framepairs = [
('hcrs', 'heliographic_stonyhurst'),
('heliographic_stonyhurst', 'heliographic_carrington'),
('heliographic_stonyhurst', 'heliocentricinertial'),
('heliographic_stonyhurst', 'heliocentric'),
('heliocentric', 'helioprojective'),
('heliocentricmeanecliptic', 'heliocentricearthecliptic'),
('heliocentricearthecliptic', 'geocentricsolarecliptic'),
('heliocentricmeanecliptic', 'geocentricearthequatorial'),
('itrs', 'geomagnetic'),
('geomagnetic', 'solarmagnetic'),
('solarmagnetic', 'geocentricsolarmagnetospheric'),
]


@pytest.mark.parametrize(("frame1", "frame2"), _framepairs)
@pytest.mark.parametrize("unit", [u.m, u.AU])
def test_unit_preservation(frame1, frame2, unit):
coord = SkyCoord(CartesianRepresentation(0, 0, 0) * unit,
frame=frame1, obstime="2001-01-01", observer="earth")

# Transform one direction and verify the unit is preserved
result1 = coord.transform_to(frame2)
assert result1.cartesian.xyz.unit == unit

# Transform back and verify the unit is preserved
result2 = result1.transform_to(frame1)
assert result2.cartesian.xyz.unit == unit


def test_propagate_with_solar_surface():
# Test propagating the meridian by 6 days of solar rotation
meridian = SkyCoord(0*u.deg, np.arange(0, 90, 10)*u.deg, 1*u.AU,
Expand Down

0 comments on commit aeec121

Please sign in to comment.