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

Let surface return xr.DataArray instead of xr.Dataset #408

Merged
merged 1 commit into from
Apr 9, 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
6 changes: 3 additions & 3 deletions pygmt/gridding.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def surface(x=None, y=None, z=None, data=None, **kwargs):
data : str or 2d array
Either a data file name or a 2d numpy array with the tabular data.

spacing (I) :
spacing (I) : str
``'xinc[unit][+e|n][/yinc[unit][+e|n]]'``.
x_inc [and optionally y_inc] is the grid spacing.

Expand Down Expand Up @@ -88,8 +88,8 @@ def surface(x=None, y=None, z=None, data=None, **kwargs):
lib.call_module(module="surface", args=arg_str)

if outfile == tmpfile.name: # if user did not set outfile, return DataArray
with xr.open_dataset(outfile) as dataset:
result = dataset.load()
with xr.open_dataarray(outfile) as dataarray:
result = dataarray.load()
elif outfile != tmpfile.name: # if user sets an outfile, return None
result = None

Expand Down
14 changes: 7 additions & 7 deletions pygmt/tests/test_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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.Dataset)
assert isinstance(output, xr.DataArray)
return output


Expand All @@ -33,7 +33,7 @@ def test_surface_input_data_array():
ship_data = load_sample_bathymetry()
data = ship_data.values # convert pandas.DataFrame to numpy.ndarray
output = surface(data=data, spacing="5m", region=[245, 255, 20, 30])
assert isinstance(output, xr.Dataset)
assert isinstance(output, xr.DataArray)
return output


Expand All @@ -49,7 +49,7 @@ def test_surface_input_xyz():
spacing="5m",
region=[245, 255, 20, 30],
)
assert isinstance(output, xr.Dataset)
assert isinstance(output, xr.DataArray)
return output


Expand Down Expand Up @@ -90,8 +90,8 @@ def test_surface_with_outfile_param():
)
assert output is None # check that output is None since outfile is set
assert os.path.exists(path=TEMP_GRID) # check that outfile exists at path
grid = xr.open_dataset(TEMP_GRID)
assert isinstance(grid, xr.Dataset) # check that netcdf grid loaded properly
grid = xr.open_dataarray(TEMP_GRID)
assert isinstance(grid, xr.DataArray) # check that netcdf grid loaded properly
finally:
os.remove(path=TEMP_GRID)
return output
Expand All @@ -108,8 +108,8 @@ def test_surface_short_aliases():
output = surface(data=data, I="5m", R=[245, 255, 20, 30], G=TEMP_GRID)
assert output is None # check that output is None since outfile is set
assert os.path.exists(path=TEMP_GRID) # check that outfile exists at path
grid = xr.open_dataset(TEMP_GRID)
assert isinstance(grid, xr.Dataset) # check that netcdf grid loaded properly
grid = xr.open_dataarray(TEMP_GRID)
assert isinstance(grid, xr.DataArray) # check that netcdf grid loaded properly
finally:
os.remove(path=TEMP_GRID)
return output