Skip to content

Commit

Permalink
Merge pull request #1998 from greglucas/neg-180-wrap
Browse files Browse the repository at this point in the history
FIX: Allow values less than -180 to be wrapped too
  • Loading branch information
dopplershift committed Sep 8, 2022
2 parents 8124fcb + c08ab85 commit 34402c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,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 @@ -199,7 +199,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

0 comments on commit 34402c7

Please sign in to comment.