44
55import xarray as xr
66from pygmt ._typing import PathLike
7+ from pygmt .alias import Alias , AliasSystem
78from pygmt .clib import Session
89from pygmt .exceptions import GMTInvalidInput
910from pygmt .helpers import build_arg_list , fmt_docstring , kwargs_to_strings , use_alias
1819 D = "background" ,
1920 F = "color_model" ,
2021 E = "nlevels" ,
21- G = "truncate" ,
2222 H = "output" ,
2323 I = "reverse" ,
2424 L = "limit" ,
25- M = "overrule_bg" ,
26- N = "no_bg" ,
27- Q = "log" ,
2825 R = "region" ,
2926 T = "series" ,
3027 V = "verbose" ,
3128 W = "categorical" ,
3229 Ww = "cyclic" ,
33- Z = "continuous" ,
3430)
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+ ):
3741 r"""
3842 Make linear or histogram-equalized color palette table from grid.
3943
@@ -78,6 +82,11 @@ def grd2cpt(grid: PathLike | xr.DataArray, **kwargs):
7882 Full GMT docs at :gmt-docs:`grd2cpt.html`.
7983
8084 {aliases}
85+ - G = truncate
86+ - M = overrule_bg
87+ - N = no_bg
88+ - Q = log
89+ - Z = continuous
8190
8291 Parameters
8392 ----------
@@ -124,12 +133,12 @@ def grd2cpt(grid: PathLike | xr.DataArray, **kwargs):
124133 refers to the number of such boundaries and not the number of slices.
125134 For details on array creation, see
126135 :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`.
133142 output : str
134143 Optional. The file name with extension .cpt to store the generated CPT
135144 file. If not given or ``False`` [Default], saves the CPT as the current
@@ -142,22 +151,22 @@ def grd2cpt(grid: PathLike | xr.DataArray, **kwargs):
142151 happens before ``truncate`` and ``series`` values are used so the
143152 latter must be compatible with the changed z-range. See also
144153 :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 ].
161170 categorical : bool
162171 Do not interpolate the input color table but pick the output colors
163172 starting at the beginning of the color table, until colors for all
@@ -190,9 +199,17 @@ def grd2cpt(grid: PathLike | xr.DataArray, **kwargs):
190199 if (output := kwargs .pop ("H" , None )) is not None :
191200 kwargs ["H" ] = True
192201
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+
193210 with Session () as lib :
194211 with lib .virtualfile_in (check_kind = "raster" , data = grid ) as vingrd :
195212 lib .call_module (
196213 module = "grd2cpt" ,
197- args = build_arg_list (kwargs , infile = vingrd , outfile = output ),
214+ args = build_arg_list (aliasdict , infile = vingrd , outfile = output ),
198215 )
0 commit comments