Skip to content

Commit 2faf05f

Browse files
seismanJosh Sixsmith
authored and
Josh Sixsmith
committed
Expand table-like input options for xyz2grd (GenericMappingTools#1566)
* Expand table-like input options for xyz2grd * Move xyz2grd to the tabular data section * Compact code for arg_str
1 parent 0257f2c commit 2faf05f

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

doc/api/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Operations on tabular data:
8787
sphdistance
8888
sphinterpolate
8989
surface
90+
xyz2grd
9091

9192
Operations on grids:
9293

@@ -103,7 +104,6 @@ Operations on grids:
103104
grdproject
104105
grdsample
105106
grdtrack
106-
xyz2grd
107107

108108
Crossover analysis with x2sys:
109109

pygmt/src/xyz2grd.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
V="verbose",
2121
)
2222
@kwargs_to_strings(R="sequence")
23-
def xyz2grd(data, **kwargs):
23+
def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
2424
"""
2525
Create a grid file from table data.
2626
@@ -34,9 +34,10 @@ def xyz2grd(data, **kwargs):
3434
Parameters
3535
----------
3636
data : str or {table-like}
37-
Pass in either a file name to an ASCII data table, a 1D/2D
38-
{table-classes}.
39-
37+
Pass in (x, y, z) or (longitude, latitude, elevation) values by
38+
providing a file name to an ASCII data table, a 2D {table-classes}.
39+
x/y/z : 1d arrays
40+
The arrays of x and y coordinates and z data points.
4041
outgrid : str or None
4142
Optional. The name of the output netCDF file with extension .nc to
4243
store the grid in.
@@ -51,17 +52,18 @@ def xyz2grd(data, **kwargs):
5152
5253
- :class:`xarray.DataArray`: if ``outgrid`` is not set
5354
- None if ``outgrid`` is set (grid output will be stored in file set by
54-
``outgrid``)```
55+
``outgrid``)
5556
"""
5657
with GMTTempFile(suffix=".nc") as tmpfile:
5758
with Session() as lib:
58-
file_context = lib.virtualfile_from_data(check_kind="vector", data=data)
59+
file_context = lib.virtualfile_from_data(
60+
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
61+
)
5962
with file_context as infile:
6063
if "G" not in kwargs.keys(): # if outgrid is unset, output to tempfile
6164
kwargs.update({"G": tmpfile.name})
6265
outgrid = kwargs["G"]
63-
arg_str = build_arg_string(kwargs)
64-
arg_str = " ".join([infile, arg_str])
66+
arg_str = " ".join([infile, build_arg_string(kwargs)])
6567
lib.call_module("xyz2grd", arg_str)
6668

6769
return load_dataarray(outgrid) if outgrid == tmpfile.name else None

0 commit comments

Comments
 (0)