8
8
9
9
@fmt_docstring
10
10
@use_alias (
11
+ A = "transparency" ,
11
12
C = "cmap" ,
12
- T = "series" ,
13
+ D = "background" ,
14
+ F = "color_model" ,
13
15
G = "truncate" ,
14
16
H = "output" ,
15
17
I = "reverse" ,
18
+ M = "overrule_bg" ,
19
+ N = "no_bg" ,
20
+ Q = "log" ,
21
+ T = "series" ,
16
22
V = "verbose" ,
23
+ W = "categorical" ,
24
+ Ww = "cyclic" ,
17
25
Z = "continuous" ,
18
26
)
19
27
@kwargs_to_strings (T = "sequence" , G = "sequence" )
20
28
def makecpt (** kwargs ):
21
29
"""
22
- Creates a static color palette table (CPT).
30
+ Make GMT color palette tables.
31
+
32
+ This is a module that will help you make static color palette tables
33
+ (CPTs). By default, the CPT will simply be saved to the current session,
34
+ but you can use *output* to save it to a file. You define an equidistant
35
+ set of contour intervals or pass your own z-table or list, and create a new
36
+ CPT based on an existing master (dynamic) CPT. The resulting CPT can be
37
+ reversed relative to the master cpt, and can be made continuous or
38
+ discrete. For color tables beyond the standard GMT offerings, visit
39
+ `cpt-city <http://soliton.vm.bytemark.co.uk/pub/cpt-city/>`_ and
40
+ `Scientific Colour-Maps <http://www.fabiocrameri.ch/colourmaps.php>`_.
41
+
42
+ The CPT includes three additional colors beyond the range of z-values.
43
+ These are the background color (B) assigned to values lower than the lowest
44
+ *z*-value, the foreground color (F) assigned to values higher than the
45
+ highest *z*-value, and the NaN color (N) painted wherever values are
46
+ undefined.
47
+
48
+ If the master CPT includes B, F, and N entries, these will be copied into
49
+ the new master file. If not, the parameters :gmt-term:`COLOR_BACKGROUND`,
50
+ :gmt-term:`COLOR_FOREGROUND`, and :gmt-term:`COLOR_NAN` from the
51
+ :gmt-docs:`gmt.conf <gmt.conf>` file or the command line will be used. This
52
+ default behavior can be overruled using the options *background*,
53
+ *overrule_bg* or *no_bg*.
54
+
55
+ The color model (RGB, HSV or CMYK) of the palette created by **makecpt**
56
+ will be the same as specified in the header of the master CPT. When there
57
+ is no :gmt-term:`COLOR_MODEL` entry in the master CPT, the
58
+ :gmt-term:`COLOR_MODEL` specified in the :gmt-docs:`gmt.conf <gmt.conf>`
59
+ file or on the command line will be used.
23
60
24
61
Full option list at :gmt-docs:`makecpt.html`
25
62
26
63
{aliases}
27
64
28
65
Parameters
29
66
----------
67
+ transparency : str
68
+ Sets a constant level of transparency (0-100) for all color slices.
69
+ Append **+a** to also affect the fore-, back-, and nan-colors
70
+ [Default is no transparency, i.e., 0 (opaque)].
30
71
cmap : str
31
72
Selects the master color palette table (CPT) to use in the
32
73
interpolation. Full list of built-in color palette tables can be found
33
74
at :gmt-docs:`cookbook/cpts.html#built-in-color-palette-tables-cpt`.
75
+ background : bool or str
76
+ Select the back- and foreground colors to match the colors for lowest
77
+ and highest *z*-values in the output CPT [Default (``background=True``
78
+ or ``background='o'``) uses the colors specified in the master file, or
79
+ those defined by the parameters :gmt-term:`COLOR_BACKGROUND`,
80
+ :gmt-term:`COLOR_FOREGROUND`, and :gmt-term:`COLOR_NAN`]. Use
81
+ ``background='i'`` to match the colors for the lowest and highest
82
+ values in the input (instead of the output) CPT.
83
+ color_model :
84
+ ``[R|r|h|c][+c[label]]``.
85
+ Force output CPT to be written with r/g/b codes, gray-scale values or
86
+ color name (**R**, default) or r/g/b codes only (**r**), or h-s-v codes
87
+ (**h**), or c/m/y/k codes (**c**). Optionally or alternatively, append
88
+ **+c** to write discrete palettes in categorical format. If *label* is
89
+ appended then we create labels for each category to be used when the
90
+ CPT is plotted. The *label* may be a comma-separated list of category
91
+ names (you can skip a category by not giving a name), or give
92
+ *start*[-], where we automatically build monotonically increasing
93
+ labels from *start* (a single letter or an integer). Append - to build
94
+ ranges *start*-*start+1* instead.
34
95
series : list or str
35
- ``[min/max/inc[+b|l|n]|file|list]``. Defines the range of the new CPT
36
- by giving the lowest and highest z-value (and optionally an interval).
37
- If this is not given, the existing range in the master CPT will be used
38
- intact.
96
+ ``[min/max/inc[+b|l|n]|file|list]``.
97
+ Defines the range of the new CPT by giving the lowest and highest
98
+ z-value (and optionally an interval). If this is not given, the
99
+ existing range in the master CPT will be used intact. The values
100
+ produced defines the color slice boundaries. If **+n** is used it
101
+ refers to the number of such boundaries and not the number of slices.
102
+ For details on array creation, see
103
+ :gmt-docs:`makecpt.html#generate-1d-array`.
39
104
truncate : list or str
40
- ``zlo/zhi``. Truncate the incoming CPT so that the lowest and highest
41
- z-levels are to zlo and zhi. If one of these equal NaN then we leave
42
- that end of the CPT alone. The truncation takes place before any
43
- resampling. See also
44
- :gmt-docs:`cookbook/features.html#manipulating-cpts`.
105
+ ``zlo/zhi``.
106
+ Truncate the incoming CPT so that the lowest and highest z-levels are
107
+ to *zlo* and *zhi*. If one of these equal NaN then we leave that end of
108
+ the CPT alone. The truncation takes place before any resampling. See
109
+ also :gmt-docs:`cookbook/features.html#manipulating-cpts`.
45
110
output : str
46
111
Optional. The file name with extension .cpt to store the generated CPT
47
112
file. If not given or False (default), saves the CPT as the session
@@ -51,19 +116,38 @@ def makecpt(**kwargs):
51
116
progression in the master CPT. Set this to z to reverse the sign of
52
117
z-values in the color table. Note that this change of z-direction
53
118
happens before *truncate* and *series* values are used so the latter
54
- must be compatible with the changed z -range. See also
119
+ must be compatible with the changed *z* -range. See also
55
120
:gmt-docs:`cookbook/features.html#manipulating-cpts`.
121
+ overrule_bg :
122
+ Overrule background, foreground, and NaN colors specified in the master
123
+ CPT with the values of the parameters :gmt-term:`COLOR_BACKGROUND`,
124
+ :gmt-term:`COLOR_FOREGROUND`, and :gmt-term:`COLOR_NAN` specified in
125
+ the :gmt-docs:`gmt.conf <gmt.conf>` file or on the command line. When
126
+ combined with **background**, only :gmt-term:`COLOR_NAN` is considered.
127
+ no_bg : bool
128
+ Do not write out the background, foreground, and NaN-color fields
129
+ [Default will write them, i.e. ``no_bg=False``].
130
+ log : bool
131
+ For logarithmic interpolation scheme with input given as logarithms.
132
+ Expects input z-values provided via **series** to be log10(*z*),
133
+ assigns colors, and writes out *z*.
56
134
continuous : bool
57
- Creates a continuous CPT [Default is discontinuous, i.e., constant
58
- colors for each interval]. This option has no effect when no *series*
59
- is used, or when using *series=[z_min, z_max]*; in the first case the
60
- input CPT remains untouched, in the second case it is only scaled to
61
- match the range z_min/z_max.
62
-
135
+ Force a continuous CPT when building from a list of colors and a list
136
+ of z-values [Default is None, i.e. discrete values].
63
137
{V}
64
-
138
+ categorical : bool
139
+ Do not interpolate the input color table but pick the output colors
140
+ starting at the beginning of the color table, until colors for all
141
+ intervals are assigned. This is particularly useful in combination with
142
+ a categorical color table, like ``cmap='categorical'``.
143
+ cyclic : bool
144
+ Produce a wrapped (cyclic) color table that endlessly repeats its
145
+ range. Note that ``cyclic=True`` cannot be set together with
146
+ ``categorical=True``.
65
147
"""
66
148
with Session () as lib :
149
+ if "W" in kwargs and "Ww" in kwargs :
150
+ raise GMTInvalidInput ("Set only categorical or cyclic to True, not both." )
67
151
if "H" not in kwargs .keys (): # if no output is set
68
152
arg_str = build_arg_string (kwargs )
69
153
elif "H" in kwargs .keys (): # if output is set
0 commit comments