Skip to content

Add regression test for grdimage plotting an xarray.DataArray grid subset #1314

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

Merged
merged 2 commits into from
Jun 2, 2021
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
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_grdimage_global_subset.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 8f38333a67076f0125cb2d1828aa244e
size: 39288
path: test_grdimage_global_subset.png
35 changes: 35 additions & 0 deletions pygmt/tests/test_grdimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ def fixture_grid():
return load_earth_relief(registration="gridline")


@pytest.fixture(scope="module", name="grid_360")
def fixture_grid_360(grid):
"""
Earth relief grid with longitude range from 0 to 360 (instead of -180 to
180).
"""
_grid = grid.copy() # get a copy of original earth_relief grid
_grid.encoding.pop("source") # unlink earth_relief NetCDF source
_grid["lon"] = np.arange(0, 361, 1) # convert longitude from -180:180 to 0:360
return _grid


@pytest.fixture(scope="module", name="xrgrid")
def fixture_xrgrid():
"""
Expand Down Expand Up @@ -131,6 +143,29 @@ def test_grdimage_over_dateline(xrgrid):
return fig


@pytest.mark.mpl_image_compare
def test_grdimage_global_subset(grid_360):
"""
Ensure subsets of grids are plotted correctly on a global map.

Specifically checking that xarray.DataArray grids can wrap around the left
and right sides on a Mollweide projection (W) plot correctly. Note that a
Cartesian grid is used here instead of a Geographic grid (i.e.
GMT_GRID_IS_CARTESIAN). This is a regression test for
https://github.com/GenericMappingTools/pygmt/issues/732.
"""
# Get a slice of South America and Africa only (lat=-90:31, lon=-180:41)
sliced_grid = grid_360[0:121, 0:221]
assert sliced_grid.gmt.registration == 0 # gridline registration
assert sliced_grid.gmt.gtype == 0 # Cartesian coordinate system

fig = Figure()
fig.grdimage(
grid=sliced_grid, cmap="vik", region="g", projection="W0/3.5c", frame=True
)
return fig


@check_figures_equal()
@pytest.mark.parametrize("lon0", [0, 123, 180])
@pytest.mark.parametrize("proj_type", ["H", "W"])
Expand Down