Skip to content

Commit

Permalink
Migrate Figure.grdview tests to dvc (#1154)
Browse files Browse the repository at this point in the history
Final round of tests to migrate to DVC for the
`grdview` plotting module. This is related to #1131,
and is almost like reverting #589 actually.

* Migrate test_grdview baseline images to dvc
* Update fig.grdview baseline images for GMT 6.2.0rc1
* Plot fancy frame for test_grdview_with_perspective
* Update fig.grdview baseline images for GMT 6.2.0rc2
* Use projection="Q15c+" for test_grdview_with_perspective
  • Loading branch information
weiji14 committed May 26, 2021
1 parent 823b3cd commit 45887f1
Show file tree
Hide file tree
Showing 31 changed files with 138 additions and 97 deletions.
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_grdview_drapegrid_dataarray.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: d424deb92bd8cb8846cc43155e4d681b
size: 64256
path: test_grdview_drapegrid_dataarray.png
Binary file removed pygmt/tests/baseline/test_grdview_grid_dataarray.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_grdview_grid_dataarray.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 3d78a0f03717f55ccb18e7e926a82fd9
size: 6117
path: test_grdview_grid_dataarray.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 6ec7e9b8e090cf8b239f948c7ba73e0f
size: 13701
path: test_grdview_grid_file_with_region_subset.png
Binary file removed pygmt/tests/baseline/test_grdview_on_a_plane.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_grdview_on_a_plane.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: df3969a299e8a72711bd71c105bf8536
size: 37840
path: test_grdview_on_a_plane.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 6f644dfa49aa144788ee877c6fd86f37
size: 38729
path: test_grdview_on_a_plane_styled_with_facadepen.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 7ca5b177d95e7839f137f1912777b495
size: 38182
path: test_grdview_on_a_plane_with_colored_frontal_facade.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 9da8c13aa8d2c1b1cb26da04ae477cce
size: 45741
path: test_grdview_surface_mesh_plot_styled_with_meshpen.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: ae29730738ddc25623cc112447bc6f2a
size: 62181
path: test_grdview_surface_plot_styled_with_contourpen.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 4a54af50c67c7c7818dc6b3be01047df
size: 68127
path: test_grdview_with_cmap_for_image_plot.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 122aa9d570ec1261265faed6b9c3c285
size: 83556
path: test_grdview_with_cmap_for_perspective_surface_plot.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 994ba2d345a0ba313e85b69d7fd43f25
size: 96043
path: test_grdview_with_cmap_for_surface_monochrome_plot.png
Binary file not shown.
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_grdview_with_perspective.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 6b81f7b66b2793f96bfd855800b74048
size: 21631
path: test_grdview_with_perspective.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 1680961103f85fec593816463d9ad796
size: 216773
path: test_grdview_with_perspective_and_zaxis_frame.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: e84757f6b9a02bcf8c7e1fbe2369f77b
size: 30484
path: test_grdview_with_perspective_and_zscale.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 48b05c4fcd3b16277ae94a310af2f5ce
size: 46070
path: test_grdview_with_perspective_and_zsize.png
175 changes: 78 additions & 97 deletions pygmt/tests/test_grdview.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pygmt import Figure, grdcut, which
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile, data_kind
from pygmt.helpers.testing import check_figures_equal


@pytest.fixture(scope="module", name="region")
Expand Down Expand Up @@ -34,15 +33,14 @@ def fixture_xrgrid(region):
return grdcut(grid="@earth_relief_01d_g", region=region)


@check_figures_equal()
def test_grdview_grid_dataarray(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_grid_dataarray(xrgrid):
"""
Run grdview by passing in a grid as an xarray.DataArray.
"""
fig_ref, fig_test = Figure(), Figure()
fig_ref.grdview(grid=gridfile)
fig_test.grdview(grid=xrgrid)
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=xrgrid)
return fig


@pytest.mark.mpl_image_compare
Expand All @@ -69,184 +67,167 @@ def test_grdview_wrong_kind_of_grid(xrgrid):
fig.grdview(grid=dataset)


@check_figures_equal()
def test_grdview_with_perspective(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_with_perspective(gridfile):
"""
Run grdview by passing in a grid and setting a perspective viewpoint with
an azimuth from the SouthEast and an elevation angle 15 degrees from the
z-plane.
"""
fig_ref, fig_test = Figure(), Figure()
fig_ref.grdview(grid=gridfile, perspective=[135, 15])
fig_test.grdview(grid=xrgrid, perspective=[135, 15])
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=gridfile, projection="Q15c+", perspective=[135, 15], frame=True)
return fig


@check_figures_equal()
def test_grdview_with_perspective_and_zscale(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_with_perspective_and_zscale(xrgrid):
"""
Run grdview by passing in a grid and setting a perspective viewpoint with
an azimuth from the SouthWest and an elevation angle 30 degrees from the
z-plane, plus a z-axis scaling factor of 0.005.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(perspective=[225, 30], zscale=0.005)
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=xrgrid, perspective=[225, 30], zscale=0.005)
return fig


@check_figures_equal()
def test_grdview_with_perspective_and_zsize(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_with_perspective_and_zsize(xrgrid):
"""
Run grdview by passing in a grid and setting a perspective viewpoint with
an azimuth from the SouthWest and an elevation angle 30 degrees from the
z-plane, plus a z-axis size of 10cm.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(perspective=[225, 30], zsize="10c")
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=xrgrid, perspective=[225, 30], zsize="10c")
return fig


@check_figures_equal()
def test_grdview_with_cmap_for_image_plot(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_with_cmap_for_image_plot(xrgrid):
"""
Run grdview by passing in a grid and setting a colormap for producing an
image plot.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(cmap="oleron", surftype="i")
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=xrgrid, cmap="oleron", surftype="i")
return fig


@check_figures_equal()
def test_grdview_with_cmap_for_surface_monochrome_plot(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_with_cmap_for_surface_monochrome_plot(xrgrid):
"""
Run grdview by passing in a grid and setting a colormap for producing a
surface monochrome plot.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(cmap="oleron", surftype="s+m")
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=xrgrid, cmap="oleron", surftype="s+m")
return fig


@check_figures_equal()
def test_grdview_with_cmap_for_perspective_surface_plot(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_with_cmap_for_perspective_surface_plot(xrgrid):
"""
Run grdview by passing in a grid and setting a colormap for producing a
surface plot with a 3D perspective viewpoint.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(cmap="oleron", surftype="s", perspective=[225, 30], zscale=0.005)
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
fig = Figure()
fig.grdview(
grid=xrgrid, cmap="oleron", surftype="s", perspective=[225, 30], zscale=0.005
)
return fig


@check_figures_equal()
def test_grdview_on_a_plane(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_on_a_plane(xrgrid):
"""
Run grdview by passing in a grid and plotting it on a z-plane, while
setting a 3D perspective viewpoint.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(plane=-4000, perspective=[225, 30], zscale=0.005)
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=xrgrid, plane=-4000, perspective=[225, 30], zscale=0.005)
return fig


@check_figures_equal()
def test_grdview_on_a_plane_with_colored_frontal_facade(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_on_a_plane_with_colored_frontal_facade(xrgrid):
"""
Run grdview by passing in a grid and plotting it on a z-plane whose frontal
facade is colored gray, while setting a 3D perspective viewpoint.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(plane="-4000+ggray", perspective=[225, 30], zscale=0.005)
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=xrgrid, plane="-4000+ggray", perspective=[225, 30], zscale=0.005)
return fig


@check_figures_equal()
def test_grdview_with_perspective_and_zaxis_frame(gridfile, xrgrid, region):
@pytest.mark.mpl_image_compare
def test_grdview_with_perspective_and_zaxis_frame(xrgrid, region):
"""
Run grdview by passing in a grid and plotting an annotated vertical z-axis
frame on a Transverse Mercator (T) projection.
"""
fig_ref, fig_test = Figure(), Figure()
fig = Figure()
projection = f"T{(region[0]+region[1])/2}/{abs((region[2]+region[3])/2)}"
kwargs = dict(
fig.grdview(
grid=xrgrid,
projection=projection,
perspective=[225, 30],
zscale=0.005,
frame=["xaf", "yaf", "zaf"],
)
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
return fig


@check_figures_equal()
def test_grdview_surface_plot_styled_with_contourpen(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_surface_plot_styled_with_contourpen(xrgrid):
"""
Run grdview by passing in a grid with styled contour lines plotted on top
of a surface plot.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(cmap="relief", surftype="s", contourpen="0.5p,black,dash")
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=xrgrid, cmap="relief", surftype="s", contourpen="0.5p,black,dash")
return fig


@check_figures_equal()
def test_grdview_surface_mesh_plot_styled_with_meshpen(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_surface_mesh_plot_styled_with_meshpen(xrgrid):
"""
Run grdview by passing in a grid with styled mesh lines plotted on top of a
surface mesh plot.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(cmap="relief", surftype="sm", meshpen="0.5p,black,dash")
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=xrgrid, cmap="relief", surftype="sm", meshpen="0.5p,black,dash")
return fig


@check_figures_equal()
def test_grdview_on_a_plane_styled_with_facadepen(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_on_a_plane_styled_with_facadepen(xrgrid):
"""
Run grdview by passing in a grid and plotting it on a z-plane with styled
lines for the frontal facade.
"""
fig_ref, fig_test = Figure(), Figure()
kwargs = dict(
plane=-4000, perspective=[225, 30], zscale=0.005, facadepen="0.5p,blue,dash"
fig = Figure()
fig.grdview(
grid=xrgrid,
plane=-4000,
perspective=[225, 30],
zscale=0.005,
facadepen="0.5p,blue,dash",
)
fig_ref.grdview(grid=gridfile, **kwargs)
fig_test.grdview(grid=xrgrid, **kwargs)
return fig_ref, fig_test
return fig


@check_figures_equal()
def test_grdview_drapegrid_dataarray(gridfile, xrgrid):
@pytest.mark.mpl_image_compare
def test_grdview_drapegrid_dataarray(xrgrid):
"""
Run grdview by passing in both a grid and drapegrid as an xarray.DataArray,
setting a colormap for producing an image plot.
"""
drapegrid = 1.1 * xrgrid

fig_ref, fig_test = Figure(), Figure()
fig_ref.grdview(grid=gridfile, drapegrid=drapegrid, cmap="oleron", surftype="c")
fig_test.grdview(grid=xrgrid, drapegrid=drapegrid, cmap="oleron", surftype="c")
return fig_ref, fig_test
fig = Figure()
fig.grdview(grid=xrgrid, drapegrid=drapegrid, cmap="oleron", surftype="c")
return fig


def test_grdview_wrong_kind_of_drapegrid(xrgrid):
Expand Down

0 comments on commit 45887f1

Please sign in to comment.