From f8ba85a94be7e89ae0a7c53903f22300f1f2cd57 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 3 Oct 2021 21:11:21 +0800 Subject: [PATCH 1/3] Expand table-like input options for xyz2grd --- pygmt/src/xyz2grd.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index bddde2c456c..0bc734bb68f 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -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. @@ -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. @@ -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}) From 8eaf647167ebd3ce83e45a8b6ad6338e79becfaa Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 4 Oct 2021 17:05:56 +0800 Subject: [PATCH 2/3] Move xyz2grd to the tabular data section --- doc/api/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/index.rst b/doc/api/index.rst index 7027ba8641b..36826b1c7d2 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -87,6 +87,7 @@ Operations on tabular data: sphdistance sphinterpolate surface + xyz2grd Operations on grids: @@ -103,7 +104,6 @@ Operations on grids: grdproject grdsample grdtrack - xyz2grd Crossover analysis with x2sys: From cc354f13eae397896948c7f3e266da44fcfa1b05 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 4 Oct 2021 17:15:35 +0800 Subject: [PATCH 3/3] Compact code for arg_str --- pygmt/src/xyz2grd.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 0bc734bb68f..94aa1239b4f 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -63,8 +63,7 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): if "G" not in kwargs.keys(): # if outgrid is unset, output to tempfile kwargs.update({"G": tmpfile.name}) outgrid = kwargs["G"] - arg_str = build_arg_string(kwargs) - arg_str = " ".join([infile, arg_str]) + arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module("xyz2grd", arg_str) return load_dataarray(outgrid) if outgrid == tmpfile.name else None