Skip to content

Remove expected failures on grdview tests #589

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 11 commits into from
Sep 9, 2020
Merged
276 changes: 136 additions & 140 deletions pygmt/tests/test_grdview.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,262 +3,258 @@
"""
import pytest

from .. import Figure, which
from ..datasets import load_earth_relief
from .. import Figure, grdcut, which
from ..exceptions import GMTInvalidInput
from ..helpers import data_kind
from ..helpers import GMTTempFile, data_kind
from ..helpers.testing import check_figures_equal


@pytest.fixture(scope="module", name="grid")
def fixture_grid():
"Load the grid data from the sample earth_relief file"
return load_earth_relief(registration="gridline").sel(
lat=slice(-49, -42), lon=slice(-118, -107)
)
@pytest.fixture(scope="module", name="region")
def fixture_region():
"Test region as lonmin, lonmax, latmin, latmax"
return (-116, -109, -47, -44)


@pytest.mark.xfail(
reason="Baseline image generated using Cartesian instead of Geographic coordinates"
)
@pytest.mark.mpl_image_compare
def test_grdview_grid_dataarray(grid):
@pytest.fixture(scope="module", name="gridfile")
def fixture_gridfile(region):
"""
Load the NetCDF grid file from the sample earth_relief file
"""
with GMTTempFile(suffix=".nc") as tmpfile:
grdcut(grid="@earth_relief_01d_g", region=region, outgrid=tmpfile.name)
yield tmpfile.name


@pytest.fixture(scope="module", name="xrgrid")
def fixture_xrgrid(region):
"""
Load the xarray.DataArray grid from the sample earth_relief file
"""
return grdcut(grid="@earth_relief_01d_g", region=region)


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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_grid_file_with_region_subset():
def test_grdview_grid_file_with_region_subset(region):
"""
Run grdview by passing in a grid filename, and cropping it to a region.
"""
gridfile = which("@earth_relief_01d_g", download="a")

fig = Figure()
fig.grdview(grid=gridfile, region=[-116, -109, -47, -44])
fig.grdview(grid=gridfile, region=region)
return fig


def test_grdview_wrong_kind_of_grid(grid):
def test_grdview_wrong_kind_of_grid(xrgrid):
"""
Run grdview using grid input that is not an xarray.DataArray or file.
"""
dataset = grid.to_dataset() # convert xarray.DataArray to xarray.Dataset
dataset = xrgrid.to_dataset() # convert xarray.DataArray to xarray.Dataset
assert data_kind(dataset) == "matrix"

fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.grdview(grid=dataset)


@pytest.mark.xfail(
reason="Baseline image generated using Cartesian instead of Geographic coordinates"
)
@pytest.mark.mpl_image_compare
def test_grdview_with_perspective(grid):
@check_figures_equal()
def test_grdview_with_perspective(gridfile, xrgrid):
"""
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 = Figure()
fig.grdview(grid=grid, perspective=[135, 15])
return fig
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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_with_perspective_and_zscale(grid):
@check_figures_equal()
def test_grdview_with_perspective_and_zscale(gridfile, 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 = Figure()
fig.grdview(grid=grid, perspective=[225, 30], zscale=0.005)
return fig
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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_with_perspective_and_zsize(grid):
@check_figures_equal()
def test_grdview_with_perspective_and_zsize(gridfile, 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 = Figure()
fig.grdview(grid=grid, perspective=[225, 30], zsize="10c")
return fig
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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_with_cmap_for_image_plot(grid):
@check_figures_equal()
def test_grdview_with_cmap_for_image_plot(gridfile, xrgrid):
"""
Run grdview by passing in a grid and setting a colormap for producing an
image plot.
"""
fig = Figure()
fig.grdview(grid=grid, cmap="oleron", surftype="i")
return fig
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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_with_cmap_for_surface_monochrome_plot(grid):
@check_figures_equal()
def test_grdview_with_cmap_for_surface_monochrome_plot(gridfile, xrgrid):
"""
Run grdview by passing in a grid and setting a colormap for producing a
surface monochrome plot.
"""
fig = Figure()
fig.grdview(grid=grid, cmap="oleron", surftype="s+m")
return fig
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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_with_cmap_for_perspective_surface_plot(grid):
@check_figures_equal()
def test_grdview_with_cmap_for_perspective_surface_plot(gridfile, xrgrid):
"""
Run grdview by passing in a grid and setting a colormap for producing a
surface plot with a 3D perspective viewpoint.
"""
fig = Figure()
fig.grdview(
grid=grid, cmap="oleron", surftype="s", perspective=[225, 30], zscale=0.005
)
return fig
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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_on_a_plane(grid):
@check_figures_equal()
def test_grdview_on_a_plane(gridfile, xrgrid):
"""
Run grdview by passing in a grid and plotting it on a z-plane, while
setting a 3D perspective viewpoint.
"""
fig = Figure()
fig.grdview(grid=grid, plane=-4000, perspective=[225, 30], zscale=0.005)
return fig
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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_on_a_plane_with_colored_frontal_facade(grid):
@check_figures_equal()
def test_grdview_on_a_plane_with_colored_frontal_facade(gridfile, 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 = Figure()
fig.grdview(grid=grid, plane="-4000+ggray", perspective=[225, 30], zscale=0.005)
return fig
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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_with_perspective_and_zaxis_frame(grid):
@check_figures_equal()
def test_grdview_with_perspective_and_zaxis_frame(gridfile, xrgrid, region):
"""
Run grdview by passing in a grid and plotting an annotated vertical
z-axis frame.
z-axis frame on a Transverse Mercator (T) projection.
"""
fig = Figure()
fig.grdview(grid=grid, perspective=[225, 30], zscale=0.005, frame="zaf")
return fig
fig_ref, fig_test = Figure(), Figure()
projection = f"T{(region[0]+region[1])/2}/{abs((region[2]+region[3])/2)}"
kwargs = dict(
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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_surface_plot_styled_with_contourpen(grid):
@check_figures_equal()
def test_grdview_surface_plot_styled_with_contourpen(gridfile, xrgrid):
"""
Run grdview by passing in a grid with styled contour lines plotted on top
of a surface plot.
"""
fig = Figure()
fig.grdview(grid=grid, cmap="relief", surftype="s", contourpen="0.5p,black,dash")
return fig
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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_surface_mesh_plot_styled_with_meshpen(grid):
@check_figures_equal()
def test_grdview_surface_mesh_plot_styled_with_meshpen(gridfile, xrgrid):
"""
Run grdview by passing in a grid with styled mesh lines plotted on top of a
surface mesh plot.
"""
fig = Figure()
fig.grdview(grid=grid, cmap="relief", surftype="sm", meshpen="0.5p,black,dash")
return fig
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


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


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_grdview_drapegrid_dataarray(grid):
@check_figures_equal()
def test_grdview_drapegrid_dataarray(gridfile, 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 * grid
drapegrid = 1.1 * xrgrid

fig = Figure()
fig.grdview(grid=grid, drapegrid=drapegrid, cmap="oleron", surftype="c")
return fig
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


def test_grdview_wrong_kind_of_drapegrid(grid):
def test_grdview_wrong_kind_of_drapegrid(xrgrid):
"""
Run grdview using drapegrid input that is not an xarray.DataArray or file.
"""
dataset = grid.to_dataset() # convert xarray.DataArray to xarray.Dataset
dataset = xrgrid.to_dataset() # convert xarray.DataArray to xarray.Dataset
assert data_kind(dataset) == "matrix"

fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.grdview(grid=grid, drapegrid=dataset)
fig.grdview(grid=xrgrid, drapegrid=dataset)