diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 7f34d037fc1..1e028b4ecc8 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -3,13 +3,10 @@ splines. """ from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import ( GMTTempFile, build_arg_string, - data_kind, deprecate_parameter, - dummy_context, fmt_docstring, kwargs_to_strings, use_alias, @@ -59,14 +56,14 @@ def surface(x=None, y=None, z=None, data=None, **kwargs): ---------- x/y/z : 1d arrays Arrays of x and y coordinates and values z of the data points. - data : str or 2d array - Either a data file name or a 2d numpy array with the tabular data. + data : str or {table-like} + Pass in (x, y, z) or (longitude, latitude, elevation) values by + providing a file name to an ASCII data table, a 2D + {table-classes}. {I} - region : str or list - *xmin/xmax/ymin/ymax*\[**+r**][**+u**\ *unit*]. - Specify the region of interest. + {R} outgrid : str Optional. The file name for the output netcdf file with extension .nc @@ -92,18 +89,12 @@ def surface(x=None, y=None, z=None, data=None, **kwargs): - None if ``outgrid`` is set (grid output will be stored in file set by ``outgrid``) """ - kind = data_kind(data, x, y, z, required_z=True) - with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - if kind == "file": - file_context = dummy_context(data) - elif kind == "matrix": - file_context = lib.virtualfile_from_matrix(data) - elif kind == "vectors": - file_context = lib.virtualfile_from_vectors(x, y, z) - else: - raise GMTInvalidInput(f"Unrecognized data type: {type(data)}") + # Choose how data will be passed into the module + 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 tmpfile kwargs.update({"G": tmpfile.name})