11"""
22xyz2grd - Convert data table to a grid.
33"""
4+ from pygmt .alias import Alias , convert_aliases
45from pygmt .clib import Session
56from pygmt .exceptions import GMTInvalidInput
67from pygmt .helpers import (
78 GMTTempFile ,
89 build_arg_string ,
910 fmt_docstring ,
10- kwargs_to_strings ,
11- use_alias ,
1211)
1312from pygmt .io import load_dataarray
1413
1514__doctest_skip__ = ["xyz2grd" ]
1615
1716
1817@fmt_docstring
19- @use_alias (
20- A = "duplicate" ,
21- G = "outgrid" ,
22- I = "spacing" ,
23- J = "projection" ,
24- R = "region" ,
25- V = "verbose" ,
26- Z = "convention" ,
27- b = "binary" ,
28- d = "nodata" ,
29- e = "find" ,
30- f = "coltypes" ,
31- h = "header" ,
32- i = "incols" ,
33- r = "registration" ,
34- w = "wrap" ,
35- )
36- @kwargs_to_strings (I = "sequence" , R = "sequence" )
37- def xyz2grd (data = None , x = None , y = None , z = None , ** kwargs ):
18+ def xyz2grd (
19+ data = None ,
20+ x = None ,
21+ y = None ,
22+ z = None ,
23+ outgrid = None ,
24+ spacing = None ,
25+ duplicate = None ,
26+ projection = None ,
27+ region = None ,
28+ verbose = None ,
29+ convention = None ,
30+ binary = None ,
31+ nodata = None ,
32+ find = None ,
33+ coltypes = None ,
34+ header = None ,
35+ incols = None ,
36+ registration = None ,
37+ wrap = None ,
38+ ** kwargs ,
39+ ):
3840 r"""
3941 Create a grid file from table data.
4042
@@ -46,8 +48,6 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
4648
4749 Full option list at :gmt-docs:`xyz2grd.html`
4850
49- {aliases}
50-
5151 Parameters
5252 ----------
5353 data : str, {table-like}
@@ -146,7 +146,25 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
146146 ... x=xx, y=yy, z=zz, spacing=(1.0, 0.5), region=[0, 3, 10, 13]
147147 ... )
148148 """
149- if kwargs .get ("I" ) is None or kwargs .get ("R" ) is None :
149+ _aliases = [
150+ Alias ("duplicate" , "A" , "" , "" ),
151+ Alias ("outgrid" , "G" , "" , "" ),
152+ Alias ("spacing" , "I" , "" , "/" ),
153+ Alias ("projection" , "J" , "" , "" ),
154+ Alias ("region" , "R" , "" , "/" ),
155+ Alias ("verbose" , "V" , "" , "" ),
156+ Alias ("convention" , "Z" , "" , "" ),
157+ Alias ("binary" , "b" , "" , "" ),
158+ Alias ("nodata" , "d" , "" , "" ),
159+ Alias ("find" , "e" , "" , "" ),
160+ Alias ("coltypes" , "f" , "" , "" ),
161+ Alias ("header" , "h" , "" , "" ),
162+ Alias ("incols" , "i" , "" , "" ),
163+ Alias ("registration" , "r" , "" , "" ),
164+ Alias ("wrap" , "w" , "" , "" ),
165+ ]
166+
167+ if spacing is None or region is None :
150168 raise GMTInvalidInput ("Both 'region' and 'spacing' must be specified." )
151169
152170 with GMTTempFile (suffix = ".nc" ) as tmpfile :
@@ -155,10 +173,12 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
155173 check_kind = "vector" , data = data , x = x , y = y , z = z , required_z = True
156174 )
157175 with file_context as infile :
158- if (outgrid := kwargs .get ("G" )) is None :
159- kwargs ["G" ] = outgrid = tmpfile .name # output to tmpfile
176+ if outgrid is None :
177+ outgrid = tmpfile .name
178+
179+ options = convert_aliases ()
160180 lib .call_module (
161- module = "xyz2grd" , args = build_arg_string (kwargs , infile = infile )
181+ module = "xyz2grd" , args = build_arg_string (options , infile = infile )
162182 )
163183
164184 return load_dataarray (outgrid ) if outgrid == tmpfile .name else None
0 commit comments