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

[Backport 1.1] Added a helper function for testing equality/closeness of longitudes #3816

Merged
merged 1 commit into from
Feb 23, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/3804.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Created a helper function for testing the equality/closeness of longitude angles (i.e., angles with wrapping).
12 changes: 12 additions & 0 deletions sunpy/coordinates/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from astropy.coordinates import Longitude
from astropy.tests.helper import assert_quantity_allclose
import astropy.units as u


def assert_longitude_allclose(actual, desired, atol=None):
"""
This works like :func:`~astropy.tests.helper.assert_quantity_allclose`, except it is intended
for longitude angles (i.e., angles that wrap every 360 degrees).
"""
difference = Longitude(actual - desired, wrap_angle=180*u.deg)
assert_quantity_allclose(difference, 0*u.deg, atol=atol)
7 changes: 4 additions & 3 deletions sunpy/coordinates/tests/test_offset_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from astropy.coordinates import SkyCoord, SkyOffsetFrame

from sunpy.coordinates import NorthOffsetFrame
from .helpers import assert_longitude_allclose


@st.composite
Expand Down Expand Up @@ -44,14 +45,14 @@ def test_transform(lon, lat):
off = NorthOffsetFrame(north=north)
t_north = SkyCoord(lon=0*u.deg, lat=90*u.deg, frame=off)
t_north = t_north.transform_to('heliographic_stonyhurst')
assert_quantity_allclose(north.lon, t_north.lon, atol=1e-6*u.deg)
assert_longitude_allclose(north.lon, t_north.lon, atol=1e-6*u.deg)
assert_quantity_allclose(north.lat, t_north.lat, atol=1e-6*u.deg)


def test_south_pole():
s = SkyCoord(-10*u.deg, 0*u.deg, frame='heliographic_stonyhurst')
off = NorthOffsetFrame(north=s)
assert_quantity_allclose(off.origin.lon, 170*u.deg)
assert_longitude_allclose(off.origin.lon, 170*u.deg)
assert_quantity_allclose(off.origin.lat, -90*u.deg)


Expand All @@ -60,7 +61,7 @@ def test_cartesian():
s = SkyCoord(1, 2, 3, unit=u.m,
representation_type='cartesian', frame='heliographic_stonyhurst')
off = NorthOffsetFrame(north=s)
assert_quantity_allclose(off.origin.lon, np.arctan2(s.y, s.x))
assert_longitude_allclose(off.origin.lon, np.arctan2(s.y, s.x))
assert_quantity_allclose(off.origin.lat, np.arctan2(s.z, np.sqrt(s.x**2 + s.y**2)) - 90*u.deg)


Expand Down