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

Ensure surface and grdcut loads GMTDataArray accessor info into xarray #539

Merged
merged 2 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions pygmt/gridding.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def surface(x=None, y=None, z=None, data=None, **kwargs):
if outfile == tmpfile.name: # if user did not set outfile, return DataArray
with xr.open_dataarray(outfile) as dataarray:
result = dataarray.load()
_ = result.gmt # load GMTDataArray accessor information
elif outfile != tmpfile.name: # if user sets an outfile, return None
result = None

Expand Down
1 change: 1 addition & 0 deletions pygmt/gridops.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def grdcut(grid, **kwargs):
if outgrid == tmpfile.name: # if user did not set outgrid, return DataArray
with xr.open_dataarray(outgrid) as dataarray:
result = dataarray.load()
_ = result.gmt # load GMTDataArray accessor information
else:
result = None # if user sets an outgrid, return None

Expand Down
2 changes: 2 additions & 0 deletions pygmt/tests/test_grdcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def test_grdcut_file_in_dataarray_out():
"grdcut an input grid file, and output as DataArray"
outgrid = grdcut("@earth_relief_01d", region="0/180/0/90")
assert isinstance(outgrid, xr.DataArray)
assert outgrid.gmt.registration == 1 # Pixel registration
assert outgrid.gmt.gtype == 1 # Geographic type
# check information of the output grid
# the '@earth_relief_01d' is in pixel registration, so the grid range is
# not exactly 0/180/0/90
Expand Down
2 changes: 2 additions & 0 deletions pygmt/tests/test_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def test_surface_input_file():
fname = which("@tut_ship.xyz", download="c")
output = surface(data=fname, spacing="5m", region=[245, 255, 20, 30])
assert isinstance(output, xr.DataArray)
assert output.gmt.registration == 0 # Gridline registration
assert output.gmt.gtype == 0 # Cartesian type
return output


Expand Down