Skip to content

Commit 1080ade

Browse files
authored
Add a test for plotting global grid without the redundant 360 longitude (#3358)
1 parent dd26601 commit 1080ade

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
outs:
2+
- md5: 6145622653eaedd2b4845400aa09ac75
3+
size: 239431
4+
hash: md5
5+
path: test_grdimage_grid_no_redunant_360.png

pygmt/tests/test_grdimage.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import numpy as np
66
import pytest
77
import xarray as xr
8+
from packaging.version import Version
89
from pygmt import Figure
10+
from pygmt.clib import __gmt_version__
911
from pygmt.datasets import load_earth_relief
1012
from pygmt.exceptions import GMTInvalidInput
1113
from pygmt.helpers.testing import check_figures_equal
@@ -252,3 +254,41 @@ def test_grdimage_imgout_fails(grid):
252254
fig.grdimage(grid, img_out="out.png")
253255
with pytest.raises(GMTInvalidInput):
254256
fig.grdimage(grid, A="out.png")
257+
258+
259+
@pytest.mark.xfail(
260+
condition=Version(__gmt_version__) <= Version("6.5.0"),
261+
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/8554",
262+
)
263+
@pytest.mark.mpl_image_compare()
264+
def test_grdimage_grid_no_redunant_360():
265+
"""
266+
Test that global grids with and without redundant 360/0 longitude values work.
267+
268+
Test for https://github.com/GenericMappingTools/pygmt/issues/3331.
269+
"""
270+
# Global grid [-180, 180, -90, 90] with redundant longitude at 180/-180
271+
da1 = load_earth_relief(region=[-180, 180, -90, 90])
272+
# Global grid [0, 360, -90, 90] with redundant longitude at 360/0
273+
da2 = load_earth_relief(region=[0, 360, -90, 90])
274+
275+
# Global grid [-180, 179, -90, 90] without redundant longitude at 180/-180
276+
da3 = da1[:, 0:360]
277+
da3.gmt.registration, da3.gmt.gtype = 0, 1
278+
assert da3.shape == (181, 360)
279+
assert da3.lon.to_numpy().min() == -180.0
280+
assert da3.lon.to_numpy().max() == 179.0
281+
282+
# Global grid [0, 359, -90, 90] without redundant longitude at 360/0
283+
da4 = da2[:, 0:360]
284+
da4.gmt.registration, da4.gmt.gtype = 0, 1
285+
assert da4.shape == (181, 360)
286+
assert da4.lon.to_numpy().min() == 0.0
287+
assert da4.lon.to_numpy().max() == 359.0
288+
289+
fig = Figure()
290+
kwdict = {"projection": "W120/10c", "region": "g", "frame": "+tlon=120"}
291+
fig.grdimage(da3, **kwdict)
292+
fig.shift_origin(xshift="w+2c")
293+
fig.grdimage(da4, **kwdict)
294+
return fig

0 commit comments

Comments
 (0)