4
4
5
5
import xarray as xr
6
6
from pygmt ._typing import PathLike
7
+ from pygmt .alias import Alias , AliasSystem
7
8
from pygmt .clib import Session
8
9
from pygmt .exceptions import GMTInvalidInput
9
10
from pygmt .helpers import build_arg_list , fmt_docstring , kwargs_to_strings , use_alias
18
19
D = "background" ,
19
20
F = "color_model" ,
20
21
E = "nlevels" ,
21
- G = "truncate" ,
22
22
H = "output" ,
23
23
I = "reverse" ,
24
24
L = "limit" ,
25
- M = "overrule_bg" ,
26
- N = "no_bg" ,
27
- Q = "log" ,
28
25
R = "region" ,
29
26
T = "series" ,
30
27
V = "verbose" ,
31
28
W = "categorical" ,
32
29
Ww = "cyclic" ,
33
- Z = "continuous" ,
34
30
)
35
- @kwargs_to_strings (G = "sequence" , L = "sequence" , R = "sequence" , T = "sequence" )
36
- def grd2cpt (grid : PathLike | xr .DataArray , ** kwargs ):
31
+ @kwargs_to_strings (L = "sequence" , R = "sequence" , T = "sequence" )
32
+ def grd2cpt (
33
+ grid : PathLike | xr .DataArray ,
34
+ truncate : tuple [float , float ] | None = None ,
35
+ overrule_bg : bool = False ,
36
+ no_bg : bool = False ,
37
+ log : bool = False ,
38
+ continuous : bool = False ,
39
+ ** kwargs ,
40
+ ):
37
41
r"""
38
42
Make linear or histogram-equalized color palette table from grid.
39
43
@@ -78,6 +82,11 @@ def grd2cpt(grid: PathLike | xr.DataArray, **kwargs):
78
82
Full GMT docs at :gmt-docs:`grd2cpt.html`.
79
83
80
84
{aliases}
85
+ - G = truncate
86
+ - M = overrule_bg
87
+ - N = no_bg
88
+ - Q = log
89
+ - Z = continuous
81
90
82
91
Parameters
83
92
----------
@@ -124,12 +133,12 @@ def grd2cpt(grid: PathLike | xr.DataArray, **kwargs):
124
133
refers to the number of such boundaries and not the number of slices.
125
134
For details on array creation, see
126
135
:gmt-docs:`makecpt.html#generate-1d-array`.
127
- truncate : list or str
128
- *zlow/ zhigh*.
129
- Truncate the incoming CPT so that the lowest and highest z-levels are
130
- to *zlow* and *zhigh*. If one of these equal NaN then we leave that
131
- end of the CPT alone. The truncation takes place before any resampling.
132
- See also :gmt-docs:`reference/features.html#manipulating-cpts`.
136
+ truncate
137
+ ( *zlow*, * zhigh*) .
138
+ Truncate the incoming CPT so that the lowest and highest z-levels are to *zlow*
139
+ and *zhigh*. If one of these equals NaN, then we leave that end of the CPT
140
+ alone. The truncation takes place before any resampling. See also
141
+ :gmt-docs:`reference/features.html#manipulating-cpts`.
133
142
output : str
134
143
Optional. The file name with extension .cpt to store the generated CPT
135
144
file. If not given or ``False`` [Default], saves the CPT as the current
@@ -142,22 +151,22 @@ def grd2cpt(grid: PathLike | xr.DataArray, **kwargs):
142
151
happens before ``truncate`` and ``series`` values are used so the
143
152
latter must be compatible with the changed z-range. See also
144
153
:gmt-docs:`reference/features.html#manipulating-cpts`.
145
- overrule_bg : str
146
- Overrule background, foreground, and NaN colors specified in the master
147
- CPT with the values of the parameters :gmt-term:`COLOR_BACKGROUND`,
148
- :gmt-term:`COLOR_FOREGROUND`, and :gmt-term:`COLOR_NAN` specified in
149
- the :gmt-docs:`gmt.conf <gmt.conf>` file. When combined with
150
- ``background``, only :gmt-term:`COLOR_NAN` is considered.
151
- no_bg : bool
152
- Do not write out the background, foreground, and NaN-color fields
153
- [Default will write them, i.e. ``no_bg=False``].
154
- log : bool
155
- For logarithmic interpolation scheme with input given as logarithms.
156
- Expects input z-values provided via ``series`` to be log10(*z*),
157
- assigns colors, and writes out *z*.
158
- continuous : bool
159
- Force a continuous CPT when building from a list of colors and a list
160
- of z-values [Default is None , i.e. discrete values ].
154
+ overrule_bg
155
+ Overrule background, foreground, and NaN colors specified in the master CPT with
156
+ the values of the parameters :gmt-term:`COLOR_BACKGROUND`,
157
+ :gmt-term:`COLOR_FOREGROUND`, and :gmt-term:`COLOR_NAN` specified in the
158
+ :gmt-docs:`gmt.conf <gmt.conf>` file or by :func:`pygmt.config`. When combined
159
+ with ``background``, only :gmt-term:`COLOR_NAN` is considered.
160
+ no_bg
161
+ Do not write out the background, foreground, and NaN-color fields [Default will
162
+ write them, i.e. ``no_bg=False``].
163
+ log
164
+ For logarithmic interpolation scheme with input given as logarithms. Expects
165
+ input z-values provided via ``series`` to be log10(*z*), assigns colors, and
166
+ writes out *z*.
167
+ continuous
168
+ Force a continuous CPT when building from a list of colors and a list of
169
+ z-values [Default is False , i.e. discrete CPT ].
161
170
categorical : bool
162
171
Do not interpolate the input color table but pick the output colors
163
172
starting at the beginning of the color table, until colors for all
@@ -190,9 +199,17 @@ def grd2cpt(grid: PathLike | xr.DataArray, **kwargs):
190
199
if (output := kwargs .pop ("H" , None )) is not None :
191
200
kwargs ["H" ] = True
192
201
202
+ aliasdict = AliasSystem (
203
+ G = Alias (truncate , name = "truncate" , sep = "/" , size = 2 ),
204
+ M = Alias (overrule_bg , name = "overrule_bg" ),
205
+ N = Alias (no_bg , name = "no_bg" ),
206
+ Q = Alias (log , name = "log" ),
207
+ Z = Alias (continuous , name = "continuous" ),
208
+ ).merge (kwargs )
209
+
193
210
with Session () as lib :
194
211
with lib .virtualfile_in (check_kind = "raster" , data = grid ) as vingrd :
195
212
lib .call_module (
196
213
module = "grd2cpt" ,
197
- args = build_arg_list (kwargs , infile = vingrd , outfile = output ),
214
+ args = build_arg_list (aliasdict , infile = vingrd , outfile = output ),
198
215
)
0 commit comments