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

FIX: Allow values less than -180 to be wrapped too #1998

Merged
merged 1 commit into from
Sep 8, 2022
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
2 changes: 1 addition & 1 deletion lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def transform_points(self, src_crs, x, y, z=None, trap=False):
self.is_geodetic()):
# convert from [0,360] to [-180,180]
x = np.array(x, copy=True)
to_180 = x > 180
to_180 = (x > 180) | (x < -180)
x[to_180] = (((x[to_180] + 180) % 360) - 180)
try:
result[:, 0], result[:, 1], result[:, 2] = \
Expand Down
11 changes: 11 additions & 0 deletions lib/cartopy/tests/test_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ def test_transform_points_xyz(self):
assert_arr_almost_eq(glon, soly)
assert_arr_almost_eq(galt, solz)

def test_transform_points_180(self):
# Test that values less than -180 and more than 180
# get mapped to the -180, 180 interval
x = np.array([-190, 190])
y = np.array([0, 0])

proj = ccrs.PlateCarree()

res = proj.transform_points(x=x, y=y, src_crs=proj)
assert_array_equal(res[..., :2], [[170, 0], [-170, 0]])

def test_globe(self):
# Ensure the globe affects output.
rugby_globe = ccrs.Globe(semimajor_axis=9000000,
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/trace.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ cdef class Interpolator:
else:
raise

if self.to_180 and xx > 180 and xx != HUGE_VAL:
if self.to_180 and (xx > 180 or xx < -180) and xx != HUGE_VAL:
xx = (((xx + 180) % 360) - 180)

dest_xy.x = xx * self.dest_scale
Expand Down