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

Pass in grids to grdimage #197

Merged
merged 4 commits into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
4 changes: 1 addition & 3 deletions gmt/base_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ def grdimage(self, grid, **kwargs):
if kind == "file":
file_context = dummy_context(grid)
elif kind == "grid":
raise NotImplementedError(
"Sorry, DataArray support is not yet functional."
)
file_context = lib.grid_to_vfile(grid)
else:
raise GMTInvalidInput("Unrecognized data type: {}".format(type(grid)))
with file_context as fname:
Expand Down
Binary file added gmt/tests/baseline/test_grdimage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gmt/tests/baseline/test_grdimage_slice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 25 additions & 4 deletions gmt/tests/test_grdimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,38 @@
from ..datasets import load_earth_relief


@pytest.mark.mpl_image_compare
def test_grdimage():
"Plot an image using an xarray grid"
grid = load_earth_relief()
fig = Figure()
fig.grdimage(
grid,
cmap="earth",
projection="W0/6i"
)
return fig

@pytest.mark.mpl_image_compare

Choose a reason for hiding this comment

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

E302 expected 2 blank lines, found 1

def test_grdimage_slice():
"Plot an image using an xarray grid that has been sliced"
grid = load_earth_relief().sel(lat=slice(-30, 30))
fig = Figure()
fig.grdimage(
grid,
cmap="earth",
projection="M6i"
)
return fig

@pytest.mark.mpl_image_compare
def test_grdimage_file():
"Plot an image using file input"
fig = Figure()
fig.grdimage(
"@earth_relief_60m",
cmap="ocean",
region="-180/180/-70/70",
region=[-180, 180, -70, 70],
projection="W0/10i",
shading=True,
)
Expand All @@ -28,6 +52,3 @@ def test_grdimage_fails():
fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.grdimage(np.arange(20).reshape((4, 5)))
grid = load_earth_relief()
with pytest.raises(NotImplementedError):
fig.grdimage(grid)