1
1
"""
2
2
xyz2grd - Convert data table to a grid.
3
3
"""
4
+ from pygmt .alias import Alias , convert_aliases
4
5
from pygmt .clib import Session
5
6
from pygmt .exceptions import GMTInvalidInput
6
7
from pygmt .helpers import (
7
8
GMTTempFile ,
8
9
build_arg_string ,
9
10
fmt_docstring ,
10
- kwargs_to_strings ,
11
- use_alias ,
12
11
)
13
12
from pygmt .io import load_dataarray
14
13
15
14
__doctest_skip__ = ["xyz2grd" ]
16
15
17
16
18
17
@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
+ ):
38
40
r"""
39
41
Create a grid file from table data.
40
42
@@ -46,8 +48,6 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
46
48
47
49
Full option list at :gmt-docs:`xyz2grd.html`
48
50
49
- {aliases}
50
-
51
51
Parameters
52
52
----------
53
53
data : str, {table-like}
@@ -146,7 +146,25 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
146
146
... x=xx, y=yy, z=zz, spacing=(1.0, 0.5), region=[0, 3, 10, 13]
147
147
... )
148
148
"""
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 :
150
168
raise GMTInvalidInput ("Both 'region' and 'spacing' must be specified." )
151
169
152
170
with GMTTempFile (suffix = ".nc" ) as tmpfile :
@@ -155,10 +173,12 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
155
173
check_kind = "vector" , data = data , x = x , y = y , z = z , required_z = True
156
174
)
157
175
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 ()
160
180
lib .call_module (
161
- module = "xyz2grd" , args = build_arg_string (kwargs , infile = infile )
181
+ module = "xyz2grd" , args = build_arg_string (options , infile = infile )
162
182
)
163
183
164
184
return load_dataarray (outgrid ) if outgrid == tmpfile .name else None
0 commit comments