Skip to content
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

Ensure plotting xarray grids with different central meridians work on some projections #560

Merged
merged 19 commits into from
Sep 11, 2020
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d4282d0
Revert runfirst workaround for test_grdimage_over_dateline
weiji14 Aug 10, 2020
d6ce55e
Merge branch 'master' into test/central_meridians
weiji14 Sep 2, 2020
a302be6
Revert grdtrack example workaround in #531 crashing due to bad meridian
weiji14 Sep 2, 2020
d1f7df6
Merge branch 'master' into test/central_meridians
weiji14 Sep 4, 2020
1caaac4
Remove unneeded pytest mpl_image_compare and runfirst markers
weiji14 Sep 4, 2020
840fe6b
Merge branch 'master' into test/central_meridians
weiji14 Sep 4, 2020
0d702fd
Test different central meridians and projection system
weiji14 Sep 4, 2020
b83ddbf
Improve tests on different central meridians and standard parallels
weiji14 Sep 5, 2020
e7e51f3
Merge branch 'master' into test/central_meridians
weiji14 Sep 6, 2020
af0cc0a
Test using General Stereographic (S) instead of Transverse Mercator (T)
weiji14 Sep 6, 2020
c26d7a2
Silence pylint complaints on ALLOWED_CHARS & KEYWORD_ONLY variable names
weiji14 Sep 6, 2020
4d7d545
Mention fullname of projections in test_grdimage_central_meridians* docs
weiji14 Sep 6, 2020
ad432e5
Merge branch 'master' into test/central_meridians
weiji14 Sep 7, 2020
0134272
Add result_images folder to gitignore and make clean list
weiji14 Sep 7, 2020
f228e5c
Expect some failures on Cylindrical Equidistant (Q) plots
weiji14 Sep 8, 2020
406f847
Merge branch 'master' into test/central_meridians
weiji14 Sep 11, 2020
b3e063a
Fix doctest failures on helpers/testing.py
weiji14 Sep 11, 2020
8f14fe2
Merge branch 'master' into test/central_meridians
weiji14 Sep 11, 2020
0516b06
Initialize fig_ref and fig_test on one line instead of two
weiji14 Sep 11, 2020
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
38 changes: 32 additions & 6 deletions pygmt/tests/test_grdimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,38 @@ def test_grdimage_over_dateline(xrgrid):


@check_figures_equal()
def test_grdimage_central_longitude(grid):
@pytest.mark.parametrize("lon0", [0, 123, 180])
@pytest.mark.parametrize("proj_type", ["H", "W"])
def test_grdimage_central_meridians(grid, proj_type, lon0):
"""
Test that plotting a grid centred at different longitudes/meridians work.
Test that plotting a grid with different central meridians (lon0) using
Hammer (H) and Mollweide (W) projection systems work.
"""
fig_ref = Figure()
fig_ref.grdimage("@earth_relief_01d_g", projection="W120/15c", cmap="geo")
fig_test = Figure()
fig_test.grdimage(grid, projection="W120/15c", cmap="geo")
fig_ref, fig_test = Figure(), Figure()
fig_ref.grdimage(
"@earth_relief_01d_g", projection=f"{proj_type}{lon0}/15c", cmap="geo"
)
fig_test.grdimage(grid, projection=f"{proj_type}{lon0}/15c", cmap="geo")
return fig_ref, fig_test


# Cylindrical Equidistant (Q) projections plotted with xarray and NetCDF grids
# are still slightly different with an RMS error of 25, see issue at
# https://github.com/GenericMappingTools/pygmt/issues/390
# TO-DO remove tol=1.5 and pytest.mark.xfail once bug is solved in upstream GMT
@check_figures_equal(tol=1.5)
@pytest.mark.parametrize("lat0", [0, 30])
@pytest.mark.parametrize("lon0", [0, 123, 180])
@pytest.mark.parametrize("proj_type", [pytest.param("Q", marks=pytest.mark.xfail), "S"])
def test_grdimage_central_meridians_and_standard_parallels(grid, proj_type, lon0, lat0):
Comment on lines +132 to +140
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using xfail (again) to temporarily allow the Cylindrical Equidistant (Q) tests to pass (instructions at https://docs.pytest.org/en/latest/skipping.html#skip-xfail-with-parametrize). Note that there are **2 xpass**es (because not all projections are wrong), and 4 xfails.

Also, I've set the RMS tolerance to 1.5 to allow the General Stereographic (S) projection tests to pass, for reference, here are the plot diffs (along the Greenwich Meridian):

NetCDF (expected) Xarray (test) Diff
test_grdimage_central_meridians_and_standard_parallels S-0-0-png -expected test_grdimage_central_meridians_and_standard_parallels S-0-0-png test_grdimage_central_meridians_and_standard_parallels S-0-0-png -failed-diff

"""
Test that plotting a grid with different central meridians (lon0) and
standard_parallels (lat0) using Cylindrical Equidistant (Q) and General
Stereographic (S) projection systems work.
"""
fig_ref, fig_test = Figure(), Figure()
fig_ref.grdimage(
"@earth_relief_01d_g", projection=f"{proj_type}{lon0}/{lat0}/15c", cmap="geo"
)
fig_test.grdimage(grid, projection=f"{proj_type}{lon0}/{lat0}/15c", cmap="geo")
return fig_ref, fig_test