Skip to content

Commit 555b135

Browse files
authored
Ensure plotting xarray grids with different central meridians work on some projections (#560)
Adds tests to make sure that plotting xarray.DataArray grids at different central meridians work properly for different projection types. * Test different central meridians and projection systems Testing meridians 0, 123 and 180; for projections H, Q, S and W. * Improve tests on different central meridians and standard parallels Split up tests into projections that only take a central meridian argument (e.g. H, W); and those that also take a standard parallel argument (e.g. Q and S). * Mention fullname of projections in test_grdimage_central_meridians* docs * Expect some failures on Cylindrical Equidistant (Q) plots Also set RMS tolerance to 1.5 to handle small differences along Greenwich Meridian for General Stereographic (S) plots.
1 parent 85c08ef commit 555b135

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

pygmt/tests/test_grdimage.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,38 @@ def test_grdimage_over_dateline(xrgrid):
114114

115115

116116
@check_figures_equal()
117-
def test_grdimage_central_longitude(grid):
117+
@pytest.mark.parametrize("lon0", [0, 123, 180])
118+
@pytest.mark.parametrize("proj_type", ["H", "W"])
119+
def test_grdimage_central_meridians(grid, proj_type, lon0):
118120
"""
119-
Test that plotting a grid centred at different longitudes/meridians work.
121+
Test that plotting a grid with different central meridians (lon0) using
122+
Hammer (H) and Mollweide (W) projection systems work.
120123
"""
121-
fig_ref = Figure()
122-
fig_ref.grdimage("@earth_relief_01d_g", projection="W120/15c", cmap="geo")
123-
fig_test = Figure()
124-
fig_test.grdimage(grid, projection="W120/15c", cmap="geo")
124+
fig_ref, fig_test = Figure(), Figure()
125+
fig_ref.grdimage(
126+
"@earth_relief_01d_g", projection=f"{proj_type}{lon0}/15c", cmap="geo"
127+
)
128+
fig_test.grdimage(grid, projection=f"{proj_type}{lon0}/15c", cmap="geo")
129+
return fig_ref, fig_test
130+
131+
132+
# Cylindrical Equidistant (Q) projections plotted with xarray and NetCDF grids
133+
# are still slightly different with an RMS error of 25, see issue at
134+
# https://github.com/GenericMappingTools/pygmt/issues/390
135+
# TO-DO remove tol=1.5 and pytest.mark.xfail once bug is solved in upstream GMT
136+
@check_figures_equal(tol=1.5)
137+
@pytest.mark.parametrize("lat0", [0, 30])
138+
@pytest.mark.parametrize("lon0", [0, 123, 180])
139+
@pytest.mark.parametrize("proj_type", [pytest.param("Q", marks=pytest.mark.xfail), "S"])
140+
def test_grdimage_central_meridians_and_standard_parallels(grid, proj_type, lon0, lat0):
141+
"""
142+
Test that plotting a grid with different central meridians (lon0) and
143+
standard_parallels (lat0) using Cylindrical Equidistant (Q) and General
144+
Stereographic (S) projection systems work.
145+
"""
146+
fig_ref, fig_test = Figure(), Figure()
147+
fig_ref.grdimage(
148+
"@earth_relief_01d_g", projection=f"{proj_type}{lon0}/{lat0}/15c", cmap="geo"
149+
)
150+
fig_test.grdimage(grid, projection=f"{proj_type}{lon0}/{lat0}/15c", cmap="geo")
125151
return fig_ref, fig_test

0 commit comments

Comments
 (0)