Skip to content

Migrate Figure.grdcontour tests to dvc #1158

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 9 commits into from
Apr 2, 2021
Binary file removed pygmt/tests/baseline/test_grdcontour.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_grdcontour.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 438f13a0356e3bec8e3762180ea9c2f0
size: 219869
path: test_grdcontour.png
Binary file removed pygmt/tests/baseline/test_grdcontour_file.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_grdcontour_file.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: fa2f0be00003b6a1cf8cc80da0eb824c
size: 102192
path: test_grdcontour_file.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 7f655c17e068dd4860c5f97b7503a314
size: 38237
path: test_grdcontour_interval_file_full_opts.png
Binary file removed pygmt/tests/baseline/test_grdcontour_labels.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_grdcontour_labels.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 582303f039a43f271c543b78d3a3ff4b
size: 226135
path: test_grdcontour_labels.png
Binary file removed pygmt/tests/baseline/test_grdcontour_slice.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_grdcontour_slice.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: c9538960aae7cd5263bce0f6bda20090
size: 102143
path: test_grdcontour_slice.png
76 changes: 28 additions & 48 deletions pygmt/tests/test_grdcontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pygmt import Figure
from pygmt.datasets import load_earth_relief
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers.testing import check_figures_equal

TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
TEST_CONTOUR_FILE = os.path.join(TEST_DATA_DIR, "contours.txt")
Expand All @@ -22,52 +21,45 @@ def fixture_grid():
return load_earth_relief(registration="gridline")


@check_figures_equal()
@pytest.mark.mpl_image_compare
def test_grdcontour(grid):
"""
Plot a contour image using an xarray grid with fixed contour interval.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(interval="1000", projection="W0/6i")
fig_ref.grdcontour("@earth_relief_01d_g", **kwargs)
fig_test.grdcontour(grid, **kwargs)
return fig_ref, fig_test
fig = Figure()
fig.grdcontour(grid, interval="1000", projection="W0/15c", frame=True)
return fig


@check_figures_equal()
@pytest.mark.mpl_image_compare
def test_grdcontour_labels(grid):
"""
Plot a contour image using a xarray grid with contour labels and alternate
colors.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(
fig = Figure()
fig.grdcontour(
grid,
interval="1000",
annotation="5000",
projection="W0/6i",
projection="W0/15c",
pen=["a1p,red", "c0.5p,black"],
label_placement="d3i",
label_placement="d6c",
frame=True,
)
fig_ref.grdcontour("@earth_relief_01d_g", **kwargs)
fig_test.grdcontour(grid, **kwargs)
return fig_ref, fig_test
return fig


@check_figures_equal()
@pytest.mark.mpl_image_compare
def test_grdcontour_slice(grid):
"""
Plot an contour image using an xarray grid that has been sliced.
"""

fig_ref, fig_test = Figure(), Figure()

grid_ = grid.sel(lat=slice(-30, 30))
kwargs = dict(interval="1000", projection="M6i")
fig_ref.grdcontour(
grid="@earth_relief_01d_g", region=[-180, 180, -30, 30], **kwargs
)
fig_test.grdcontour(grid=grid_, **kwargs)
return fig_ref, fig_test

fig = Figure()
fig.grdcontour(grid=grid_, interval="1000", projection="M15c", frame=True)
return fig


@pytest.mark.mpl_image_compare
Expand All @@ -82,43 +74,31 @@ def test_grdcontour_file():
limit="0",
pen="0.5p,black",
region=[-180, 180, -70, 70],
projection="M10i",
projection="M15c",
frame=True,
)
return fig


@check_figures_equal()
def test_grdcontour_interval_file_full_opts():
@pytest.mark.mpl_image_compare
def test_grdcontour_interval_file_full_opts(grid):
"""
Plot based on external contour level file.
"""
fig_ref, fig_test = Figure(), Figure()
# Use single-character arguments for the reference image
comargs_ref = {
"grid": "@earth_relief_10m",
"R": "-161.5/-154/18.5/23",
"C": TEST_CONTOUR_FILE,
"S": 100,
"J": "M6i",
"Q": 10,
}
fig_ref.grdcontour(**comargs_ref, L="-25000/-1", W=["a1p,blue", "c0.5p,blue"])
fig_ref.grdcontour(**comargs_ref, L="0", W=["a1p,black", "c0.5p,black"])
fig = Figure()

comargs_test = {
comargs = {
"region": [-161.5, -154, 18.5, 23],
"interval": TEST_CONTOUR_FILE,
"grid": "@earth_relief_10m",
"grid": grid,
"resample": "100",
"projection": "M6i",
"projection": "M10c",
"cut": 10,
}
fig_test.grdcontour(
**comargs_test, limit=(-25000, -1), pen=["a1p,blue", "c0.5p,blue"]
)
fig_test.grdcontour(**comargs_test, limit=0, pen=["a1p,black", "c0.5p,black"])
fig.grdcontour(**comargs, limit=(-25000, -1), pen=["a1p,blue", "c0.5p,blue"])
fig.grdcontour(**comargs, limit=0, pen=["a1p,black", "c0.5p,black"], frame=True)

return fig_ref, fig_test
return fig


def test_grdcontour_fails():
Expand Down