From 8b35c96f64a6a1622b7ffc7cb170a4ed3d0d750d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 21 Feb 2022 08:52:04 +0000 Subject: [PATCH] Change test_grdcontour.py to use static_earth_relief (#1741) Co-authored-by: Dongdong Tian --- pygmt/tests/baseline/test_grdcontour.png.dvc | 4 +- .../baseline/test_grdcontour_file.png.dvc | 4 -- ...grdcontour_interval_file_full_opts.png.dvc | 4 +- .../baseline/test_grdcontour_labels.png.dvc | 4 +- .../baseline/test_grdcontour_slice.png.dvc | 4 +- pygmt/tests/data/contours.txt | 18 +++---- pygmt/tests/test_grdcontour.py | 52 +++++++------------ 7 files changed, 36 insertions(+), 54 deletions(-) delete mode 100644 pygmt/tests/baseline/test_grdcontour_file.png.dvc diff --git a/pygmt/tests/baseline/test_grdcontour.png.dvc b/pygmt/tests/baseline/test_grdcontour.png.dvc index dea1f734b46..3cecb1619ab 100644 --- a/pygmt/tests/baseline/test_grdcontour.png.dvc +++ b/pygmt/tests/baseline/test_grdcontour.png.dvc @@ -1,4 +1,4 @@ outs: -- md5: 9366e405a1be22b4c2515f24a3acae69 - size: 217638 +- md5: 3a660b618cc84791f6dc85d67b6b10b8 + size: 107934 path: test_grdcontour.png diff --git a/pygmt/tests/baseline/test_grdcontour_file.png.dvc b/pygmt/tests/baseline/test_grdcontour_file.png.dvc deleted file mode 100644 index c044a33f0ac..00000000000 --- a/pygmt/tests/baseline/test_grdcontour_file.png.dvc +++ /dev/null @@ -1,4 +0,0 @@ -outs: -- md5: 717b9f9123c7bb2bfb197a419d459288 - size: 97067 - path: test_grdcontour_file.png diff --git a/pygmt/tests/baseline/test_grdcontour_interval_file_full_opts.png.dvc b/pygmt/tests/baseline/test_grdcontour_interval_file_full_opts.png.dvc index f3e40cd1fe6..01a270035c5 100644 --- a/pygmt/tests/baseline/test_grdcontour_interval_file_full_opts.png.dvc +++ b/pygmt/tests/baseline/test_grdcontour_interval_file_full_opts.png.dvc @@ -1,4 +1,4 @@ outs: -- md5: 25125246f541652071fac1771e5d7e88 - size: 33966 +- md5: 8983696dc93da77fc1e9d7e8d8920836 + size: 30055 path: test_grdcontour_interval_file_full_opts.png diff --git a/pygmt/tests/baseline/test_grdcontour_labels.png.dvc b/pygmt/tests/baseline/test_grdcontour_labels.png.dvc index c7cd373037d..1a73c0817ab 100644 --- a/pygmt/tests/baseline/test_grdcontour_labels.png.dvc +++ b/pygmt/tests/baseline/test_grdcontour_labels.png.dvc @@ -1,4 +1,4 @@ outs: -- md5: 03a7cc6dea35f9383cbfb2683d7b7c1b - size: 223421 +- md5: cce113a8d8a9ba54c3bf08827b518287 + size: 112762 path: test_grdcontour_labels.png diff --git a/pygmt/tests/baseline/test_grdcontour_slice.png.dvc b/pygmt/tests/baseline/test_grdcontour_slice.png.dvc index b28d837a160..ddf8382d73f 100644 --- a/pygmt/tests/baseline/test_grdcontour_slice.png.dvc +++ b/pygmt/tests/baseline/test_grdcontour_slice.png.dvc @@ -1,4 +1,4 @@ outs: -- md5: 48070d23c538d26eb96b5caaf440513a - size: 97314 +- md5: 66f1c57afea5075a02f5f90b2c225185 + size: 53984 path: test_grdcontour_slice.png diff --git a/pygmt/tests/data/contours.txt b/pygmt/tests/data/contours.txt index f4b5430b0e5..59513b26929 100644 --- a/pygmt/tests/data/contours.txt +++ b/pygmt/tests/data/contours.txt @@ -1,10 +1,8 @@ --6000 C --5000 C --4000 A --3000 C --2000 C --1000 C -0 A -1000 C -2000 A -3000 C +200 A +300 C +400 A +500 C +600 A +700 C +800 A +900 C \ No newline at end of file diff --git a/pygmt/tests/test_grdcontour.py b/pygmt/tests/test_grdcontour.py index 2c759afcca6..9163dd96f31 100644 --- a/pygmt/tests/test_grdcontour.py +++ b/pygmt/tests/test_grdcontour.py @@ -6,8 +6,8 @@ import numpy as np import pytest from pygmt import Figure -from pygmt.datasets import load_earth_relief from pygmt.exceptions import GMTInvalidInput +from pygmt.helpers.testing import load_static_earth_relief TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data") TEST_CONTOUR_FILE = os.path.join(TEST_DATA_DIR, "contours.txt") @@ -16,9 +16,9 @@ @pytest.fixture(scope="module", name="grid") def fixture_grid(): """ - Load the grid data from the sample earth_relief file. + Load the grid data from the static_earth_relief file. """ - return load_earth_relief(registration="gridline") + return load_static_earth_relief() @pytest.mark.mpl_image_compare @@ -27,7 +27,9 @@ def test_grdcontour(grid): Plot a contour image using an xarray grid with fixed contour interval. """ fig = Figure() - fig.grdcontour(grid, interval="1000", projection="W0/15c", frame=True) + fig.grdcontour( + grid=grid, interval=50, annotation=200, projection="M10c", frame=True + ) return fig @@ -39,10 +41,10 @@ def test_grdcontour_labels(grid): """ fig = Figure() fig.grdcontour( - grid, - interval="1000", - annotation="5000", - projection="W0/15c", + grid=grid, + interval=50, + annotation=200, + projection="M10c", pen=["a1p,red", "c0.5p,black"], label_placement="d6c", frame=True, @@ -55,28 +57,10 @@ def test_grdcontour_slice(grid): """ Plot an contour image using an xarray grid that has been sliced. """ - grid_ = grid.sel(lat=slice(-30, 30)) + grid_ = grid.sel(lat=slice(-20, -10)) fig = Figure() - fig.grdcontour(grid=grid_, interval="1000", projection="M15c", frame=True) - return fig - - -@pytest.mark.mpl_image_compare -def test_grdcontour_file(): - """ - Plot a contour image using grid file input. - """ - fig = Figure() - fig.grdcontour( - "@earth_relief_01d_g", - interval="1000", - limit="0", - pen="0.5p,black", - region=[-180, 180, -70, 70], - projection="M15c", - frame=True, - ) + fig.grdcontour(grid=grid_, interval=100, projection="M10c", frame=True) return fig @@ -88,15 +72,19 @@ def test_grdcontour_interval_file_full_opts(grid): fig = Figure() comargs = { - "region": [-161.5, -154, 18.5, 23], + "region": [-53, -49, -20, -17], "interval": TEST_CONTOUR_FILE, "grid": grid, - "resample": "100", + "resample": 100, "projection": "M10c", "cut": 10, } - 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) + # Plot contours below 650 in blue + fig.grdcontour( + **comargs, limit=(0, 649), pen=["a1p,blue", "c0.5p,blue"], frame=True + ) + # Plot contours above 650 in black + fig.grdcontour(**comargs, limit=(650, 1000), pen=["a1p,black", "c0.5p,black"]) return fig