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

Expand table-like input options for xyz2grd #1566

Merged
merged 4 commits into from
Oct 5, 2021
Merged
Changes from 1 commit
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
15 changes: 9 additions & 6 deletions pygmt/src/xyz2grd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
V="verbose",
)
@kwargs_to_strings(R="sequence")
def xyz2grd(data, **kwargs):
def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
"""
Create a grid file from table data.

Expand All @@ -34,9 +34,10 @@ def xyz2grd(data, **kwargs):
Parameters
----------
data : str or {table-like}
Pass in either a file name to an ASCII data table, a 1D/2D
{table-classes}.

Pass in (x, y, z) or (longitude, latitude, elevation) values by
providing a file name to an ASCII data table, a 2D {table-classes}.
x/y/z : 1d arrays
The arrays of x and y coordinates and z data points.
outgrid : str or None
Optional. The name of the output netCDF file with extension .nc to
store the grid in.
Expand All @@ -51,11 +52,13 @@ def xyz2grd(data, **kwargs):

- :class:`xarray.DataArray`: if ``outgrid`` is not set
- None if ``outgrid`` is set (grid output will be stored in file set by
``outgrid``)```
``outgrid``)
"""
with GMTTempFile(suffix=".nc") as tmpfile:
with Session() as lib:
file_context = lib.virtualfile_from_data(check_kind="vector", data=data)
file_context = lib.virtualfile_from_data(
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
)
with file_context as infile:
if "G" not in kwargs.keys(): # if outgrid is unset, output to tempfile
kwargs.update({"G": tmpfile.name})
seisman marked this conversation as resolved.
Show resolved Hide resolved
Expand Down