1.. index:: ! makecpt
2.. include:: module_core_purpose.rst_
3
4*******
5makecpt
6*******
7
8|makecpt_purpose|
9
10Synopsis
11--------
12
13.. include:: common_SYN_OPTs.rst_
14
15**gmt makecpt**
16[ |-A|\ *transparency*\ [**+a**] ]
17[ |-C|\ *cpt* ]
18[ |-D|\ [**i**\|\ **o**] ]
19[ |-E|\ [*nlevels*] ]
20[ |-F|\ [**R**\|\ **r**\|\ **h**\|\ **c**][**+c**\ [*label*]][**+k**\ *keys*] ]
21[ |-G|\ *zlo*\ /\ *zhi* ]
22[ |-H| ]
23[ |-I|\ [**c**][**z**] ]
24[ |-M| ]
25[ |-N| ]
26[ |-Q| ]
27[ |-S|\ *mode* ]
28[ |-T|\ [*min*/*max*/*inc*\ [**+b**\|\ **i**\|\ **l**\|\ **n**]\|\ *file*\|\ *list*] ]
29[ |-V|\ [*level*] ]
30[ |-W|\ [**w**] ]
31[ |-Z| ]
32[ |SYN_OPT-bi| ]
33[ |SYN_OPT-di| ]
34[ |SYN_OPT-h| ]
35[ |SYN_OPT-i| ]
36[ |SYN_OPT--| ]
37
38|No-spaces|
39
40Description
41-----------
42
43**makecpt** is a module that will help you make static color palette tables
44(CPTs). In classic mode we write the CPT to standard output, while under
45modern mode we simply save the CPT as the current session CPT (but see **-H**).
46You define an equidistant set of contour intervals or pass
47your own z-table or list, and create a new CPT based on an existing master (dynamic)
48CPT. The resulting CPT can be reversed relative to the master
49cpt, and can be made continuous or discrete.  For color tables beyond the
50standard GMT offerings, visit `cpt-city <http://soliton.vm.bytemark.co.uk/pub/cpt-city/>`_ and
51`Scientific Colour-Maps <http://www.fabiocrameri.ch/colourmaps.php>`_.
52
53The CPT includes three additional colors beyond the range of
54z-values. These are the background color (B) assigned to values lower
55than the lowest *z*-value, the foreground color (F) assigned to values
56higher than the highest *z*-value, and the NaN color (N) painted
57wherever values are undefined.
58
59If the master CPT includes B, F, and N entries, these will be
60copied into the new master file. If not, the parameters
61:term:`COLOR_BACKGROUND`, :term:`COLOR_FOREGROUND`,
62and :term:`COLOR_NAN` from
63the :doc:`gmt.conf` file or the command line will be used. This default
64behavior can be overruled using the options **-D**, **-M** or **-N**.
65
66The color model (RGB, HSV or CMYK) of the palette created by **makecpt**
67will be the same as specified in the header of the master CPT. When
68there is no :term:`COLOR_MODEL` entry in the master CPT, the
69:term:`COLOR_MODEL` specified in the :doc:`gmt.conf` file or on the command
70line will be used.
71
72Required Arguments
73------------------
74
75None.
76
77Optional Arguments
78------------------
79
80.. _-A:
81
82**-A**\ *transparency*\ [**+a**]
83    Sets a constant level of transparency (0-100) for all color slices.
84    Append **+a** to also affect the fore-, back-, and nan-colors
85    [Default is no transparency, i.e., 0 (opaque)].
86
87.. _-C:
88
89.. include:: create_cpt.rst_
90
91.. _-D:
92
93**-D**\ [**i**\|\ **o**]
94    Select the back- and foreground colors to match the colors for
95    lowest and highest *z*-values in the output CPT [Default (**-D** or **-Do**)
96    uses the colors specified in the master file, or those defined by the
97    parameters :term:`COLOR_BACKGROUND`, :term:`COLOR_FOREGROUND`, and
98    :term:`COLOR_NAN`]. Append **i** to match the colors for the lowest and
99    highest values in the input (instead of the output) CPT.
100
101.. _-E:
102
103**-E**\ [*nlevels*]
104    Implies reading data table(s) from given command-line files or standard input.
105    We use the last data column to determine the data range; use **-i** to
106    select another column, and use **-bi** if your data table is native binary.
107    This z-range information is used instead of providing the **-T** option.
108    We create a linear color table by dividing the table data z-range into
109    *nlevels* equidistant slices.  If *nlevels* is not given it defaults to
110    the number of levels in the chosen CPT.
111
112.. _-F:
113
114**-F**\ [**R**\|\ **r**\|\ **h**\|\ **c**][**+c**\ [*label*]][**+k**\ *keys*]
115    Force output CPT to be written with r/g/b codes, gray-scale values
116    or color name (**R**, default) or r/g/b codes only (**r**), or h-s-v
117    codes (**h**), or c/m/y/k codes (**c**).  Optionally or alternatively,
118    append **+c** to write discrete palettes in categorical format.
119    If *label* is appended then we create labels for each category to be used
120    when the CPT is plotted. The *label* may be a comma-separated list of
121    category names (you can skip a category by not giving a name), or give
122    *start*\ [-], where we automatically build monotonically increasing labels
123    from *start* (a single letter or an integer). Append - to build ranges
124    *start*\ -*start+1* instead.  If the categorical CPT should have string
125    keys instead of numerical entries then append **+k**\ *keys*, where
126    *keys* is either a file with one key per record or a single letter (e.g., D),
127    then we build sequential letter keys (e.g., D, E, F, ...) starting at that point.
128    For comma-separated lists of keys, use **-T** instead.  **Note**: If **+cM** is given and the number
129    of categories is 12, then we automatically create a list of month names.
130    Likewise, if **+cD** is given and the number of categories is 7 then we
131    make a list of weekday names.  The format of these labels will depend on the
132    :term:`FORMAT_TIME_PRIMARY_MAP`, :term:`GMT_LANGUAGE` and possibly
133    :term:`TIME_WEEK_START` settings.
134
135.. _-G:
136
137**-G**\ *zlo*\ /\ *zhi*
138    Truncate the incoming CPT so that the lowest and highest z-levels
139    are to *zlo* and *zhi*.  If one of these equal NaN then
140    we leave that end of the CPT alone.  The truncation takes place
141    before any resampling. See also :ref:`manipulating_CPTs`
142
143.. _-H:
144
145**-H**\
146    Modern mode only: Write the CPT to standard output as well [Default saves
147    the CPT as the session current CPT]. Required for scripts used to make
148    animations via :doc:`movie` and :doc:`batch` where we must pass named CPT files.
149
150.. _-I:
151
152**-I**\ [**c**][**z**]
153    Append **c** [Default] to reverse the sense of color progression in the master CPT. Also
154    exchanges the foreground and background colors, including those
155    specified by the parameters :term:`COLOR_BACKGROUND` and
156    :term:`COLOR_FOREGROUND`.
157    Append **z** to reverse the sign of z-values in the color table.  Note that
158    this change of *z*-direction happens before **-G** and **-T** values are used
159    so the latter much be compatible with the changed *z*-range.
160    See also :ref:`manipulating_CPTs`
161
162.. _-M:
163
164**-M**
165    Overrule background, foreground, and NaN colors specified in the
166    master CPT with the values of the parameters
167    :term:`COLOR_BACKGROUND`, :term:`COLOR_FOREGROUND`,
168    and :term:`COLOR_NAN`
169    specified in the :doc:`gmt.conf` file or on the command line. When
170    combined with **-D**, only :term:`COLOR_NAN` is considered.
171
172.. _-N:
173
174**-N**
175    Do not write out the background, foreground, and NaN-color fields [Default will write them].
176
177.. _-Q:
178
179**-Q**
180    For logarithmic interpolation scheme with input given as logarithms.
181    Expects input z-values provided via **-T** to be log10(*z*\ ), assigns colors, and
182    writes out *z*.
183
184.. _-S:
185
186**-S**\ *mode*
187    Determine a suitable range for the **-T** option from the input table(s) (or stdin).
188    Choose from several types of range determinations:
189    **-Sr** will use the data range min/max, **-S**\ *inc*\ [**+d**] will use the data min/max but rounded
190    to nearest *inc* (append **+d** to resample to a discrete CPT), **-Sa**\ *scl* will
191    make a symmetric range around the average (i.e., mean)
192    and ±\ *scl* * *sigma*, **-Sm**\ *scl* will make a symmetric range around the median
193    and ±\ *scl* * *L1_scale*, **-Sp**\ *scl* will make symmetric range around mode (i.e., LMS; least median of squares) and
194    ±\ *scl* * *LMS_scale*, while **-Sq**\ *low/high* sets the range from *low* quartile
195    to *high* quartile (in percentages).  We use the last data column for this calculation;
196    use **i** if you need to adjust the column orders.
197
198.. _-T:
199
200**-T**\ [*min*/*max*/*inc*\ [**+b**\|\ **i**\|\ **l**\|\ **n**]\|\ *file*\|\ *list*]
201    Defines the range of the new CPT by giving the lowest and
202    highest z-value (and optionally an interval).  If **-T** is
203    not given, the existing range in the master CPT will be used intact.
204    The values produces defines the color slice boundaries.  If **+n** is
205    used it refers to the number of such boundaries and not the number of slices.
206    For details on array creation, see `Generate 1D Array`_.  **Note**: To set
207    up categorical CPTs with string keys you can also give a comma-separated
208    list of your keys.
209
210.. |Add_-V| replace:: |Add_-V_links|
211.. include:: explain_-V.rst_
212    :start-after: **Syntax**
213    :end-before: **Description**
214
215.. _-W:
216
217**-W**\ [**w**]
218    Do not interpolate the input color table but pick the output colors
219    starting at the beginning of the color table, until colors for all
220    intervals are assigned. This is particularly useful in combination
221    with a categorical color table, like "categorical". Alternatively,
222    use **-Ww** to produce a wrapped (cyclic) color table that endlessly
223    repeats its range.
224
225.. _-Z:
226
227**-Z**
228    Force a continuous CPT when building from a list of colors and a list of *z*-values [discrete].
229
230.. |Add_-bi| replace:: [Default is the required number of columns given the chosen settings].
231.. include:: explain_-bi.rst_
232
233.. |Add_-di| unicode:: 0x20 .. just an invisible code
234.. include:: explain_-di.rst_
235
236.. |Add_-h| unicode:: 0x20 .. just an invisible code
237.. include:: explain_-h.rst_
238
239.. include:: explain_-icols.rst_
240
241.. include:: explain_help.rst_
242
243.. include:: explain_transparency.rst_
244
245.. include:: explain_array.rst_
246
247Color Hinges
248------------
249
250Some of the GMT master dynamic CPTs are actually two separate CPTs
251meeting at a *hinge*.  Usually, colors may change dramatically across
252the hinge, which is used to separate two different domains (e.g., land
253and ocean across the shoreline, for instance).  CPTs with a hinge will
254have their two parts stretched to the required range separately, i.e.,
255the bottom part up to the hinge will be stretched independently of the
256part from the hinge to the top, according to the prescribed new range.
257Hinges are either *hard* or *soft*.  Soft hinges must be *activated* by
258appending **+h**\ [*hinge*] to the CPT name.
259If the selected range does not include an activated soft or hard hinge then
260we only resample colors from the half of the CPT that pertains to the range.
261See :ref:`Of Colors and Color Legends` for more information.
262
263Discrete versus Continuous CPT
264------------------------------
265
266All CPTs can be stretched, but only continuous CPTs can be sampled
267at new nodes (i.e., by given an increment in **-T**).  We impose this
268limitation to avoid aliasing the original CPT.
269
270Examples
271--------
272
273.. include:: explain_example.rst_
274
275To make a CPT with z-values from -200 to 200, with discrete color
276changes every 25, and using a polar blue-white-red colortable:
277
278   ::
279
280    gmt makecpt -Cpolar -T-200/200/25 > colors.cpt
281
282To make an equidistant CPT from z = -2 to 6 using the
283continuous default turbo rainbow of colors:
284
285   ::
286
287    gmt makecpt -T-2/6 > colors.cpt
288
289To use the GEBCO look-alike CPT with its default range for bathymetry, run
290
291   ::
292
293    gmt makecpt -Cgebco > my_gebco.cpt
294
295or simply use -Cgebco directly in the application that needs the color table.
296To create a 24-level color table suitable for plotting the depths in
297the remote ata table v3206_06.txt (with lon, lat, depths), run
298
299   ::
300
301    gmt makecpt -Cgebco @v3206_06.txt -E24 > my_depths.cpt
302
303To use the gebco color table but reverse the z-values so it can be used for
304positive depth values, try
305
306   ::
307
308    gmt makecpt -Cgebco -Iz > my_positive_gebco.cpt
309
310To make a custom discrete color table for depth of seismicity, using red color for
311hypocenters between 0 and 100 km, green for 100-300 km, and blue for deep (300-1000 km)
312earthquakes, use
313
314   ::
315
316    gmt makecpt -Cred,green,blue -T0,80,300,1000 -N > seis.cpt
317
318To make a continuous CPT from white to blue as z goes from
3193 to 10, try
320
321   ::
322
323    gmt makecpt -Cwhite,blue -T3/10 > cold.cpt
324
325To make a wrapped (cyclic) CPT from the jet table over the interval
3260 to 500, i.e., the color will be wrapped every 500 z-units so that
327we always get a color regardless of the *z* value, try
328
329   ::
330
331    gmt makecpt -Cjet -T0/500 -Ww > wrapped.cpt
332
333To build a categorical table with 3 categories and add specific category
334names to them, try::
335
336    gmt makecpt -Ccubhelix -T0/3/1 -F+cClouds,Trees,Water > cat.cpt
337
338To instead add unique category labels A, B, C, ... to a 10-item categorical CPT, try::
339
340    gmt makecpt -Cjet -T0/10/1 -F+cA
341
342To make a categorical CPT with string keys instead of numerical lookup values, try::
343
344    gmt makecpt -Ccategorical -Twood,water,gold
345
346.. include:: cpt_notes.rst_
347
348Bugs
349----
350
351Since **makecpt** will also interpolate from any existing CPT you
352may have in your directory, you should not use one of the listed cpt names
353as an output filename; hence the my_gebco.cpt in the example.  If you
354do create a CPT of such a name, e.g., rainbow.cpt, then **makecpt** will
355read that file first and not look for the master CPT in the shared GMT
356directory.
357
358See Also
359--------
360
361:doc:`gmt`, :doc:`grd2cpt`
362
363References
364----------
365
366Crameri, F., (2018). Scientific colour-maps. Zenodo. http://doi.org/10.5281/zenodo.1243862
367
368Crameri, F. (2018), Geodynamic diagnostics, scientific visualisation and StagLab 3.0,
369*Geosci. Model Dev.*, 11, 2541-2562, doi:10.5194/gmd-11-2541-2018.
370