Skip to content

Commit 5d970e2

Browse files
committed
Add a test for plotting global grids without redundant 360 longitude
1 parent 2d1a8cc commit 5d970e2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pygmt/tests/test_grdimage.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,37 @@ def test_grdimage_imgout_fails(grid):
252252
fig.grdimage(grid, img_out="out.png")
253253
with pytest.raises(GMTInvalidInput):
254254
fig.grdimage(grid, A="out.png")
255+
256+
257+
@pytest.mark.mpl_image_compare()
258+
def test_grdimage_grid_no_redunant_360():
259+
"""
260+
Test that global grids with and without redundant 360/0 longitude values work.
261+
262+
Test for https://github.com/GenericMappingTools/pygmt/issues/3331.
263+
"""
264+
# Global grid [-180, 180, -90, 90] with redundant longitude at 180/-180
265+
da1 = load_earth_relief(region=[-180, 180, -90, 90])
266+
# Global grid [0, 360, -90, 90] with redundant longitude at 0/360
267+
da2 = load_earth_relief(region=[0, 360, -90, 90])
268+
269+
# Global grid [-180, 180, -90, 90] without redundant longitude at -180/180
270+
da3 = da1[:, 0:360]
271+
da3.gmt.registration, da3.gmt.gtype = 0, 1
272+
assert da3.shape == (181, 360)
273+
assert da3.lon.to_numpy().min() == -180.0
274+
assert da3.lon.to_numpy().max() == 179.0
275+
276+
# Global grid [0, 360, -90, 90] without redundant longitude at 0/360
277+
da4 = da2[:, 0:360]
278+
da4.gmt.registration, da4.gmt.gtype = 0, 1
279+
assert da4.shape == (181, 360)
280+
assert da4.lon.to_numpy().min() == 0.0
281+
assert da4.lon.to_numpy().max() == 359.0
282+
283+
fig = Figure()
284+
kwdict = {"projection": "W120/10c", "region": "g", "frame": "+tlon=120"}
285+
fig.grdimage(da3, **kwdict)
286+
fig.shift_origin(xshift="w+2c")
287+
fig.grdimage(da4, **kwdict)
288+
return fig

0 commit comments

Comments
 (0)