Skip to content

Commit b8106c1

Browse files
PaulWesselseisman
andauthored
Update how CPT hinges are handled (#2416)
* Update how CPT hinges are done Separate between soft and hard hinges. Hard hinges are data driven like those for bathymetry or magnetics, while soft hinges are ignored unless +h[hinge] is given. * Updates so far - in progress * Add warning that +h cannot affect hard hinges * Update scripts and PS to show short and hard hinges * Update GMT_tut_17.ps * Update docs Explain soft and hard hinges * Add include files explaining CPT syntax for creation and use * Polish cpt docs * Fix handing of soft hinge assignment * Improve hinge documentationand CPT * Update list of CPTs to indicate hard or soft hinge * Update world.cpt * Update haxby.cpt * Turn wysiwig, haxby, no_green, and world into continuous CPTs Update a few PS files that changed. * Restrict CPT resampling to continuous CPTs We ban the resampling of discrete CPTs to another set of nodes. Only stretching of the range is allowed. * Allow colorlists to pass as discrete input CPT * Strengthening handling of color lists and categorical tables * Update std_opts_classic.rst typo * Add new CPT section on color-lists Adds a new script figure as well * Improve colorlist figure and discussion * Update features.rst * Check hinge and warn if outside data range (and ignore) * Add new CPT test for hinges * Update common_SYN_OPTs.rst_ * Update common_SYN_OPTs.rst_ * Deal with distcalc ref * Better reporting for hinge violations in CPTs * Allow slow or zhigh to equal hinge Not fully working yet. If hinge == zlow or hinge == zhigh we need to eliminate one entry in the resulting CPT (not done yet). * Update doc/rst/source/cookbook/features.rst Co-Authored-By: Dongdong Tian <[email protected]> * Update src/gmt_support.c Co-Authored-By: Dongdong Tian <[email protected]> * Update gmt_api.c * Improve GMT_colorlist.sh script to show options * Update gmt_api.c * Fix CPT stretching with hinges Needed to update tut 19 and its PS. * Fix discrete resampling of CPTs with hinges Trim the CPT if needed before resampling. * Address soft hinge and fix -T parsing check I had labeled a CPT with soft hinge as a hard hinge if +h was given, but it should stay a soft hinge internally. Also, add validation of possible modifiers for parse_array. * Fix print message in validate_cpt function * Leave user zmin/zmax selection as is * Add new test, update cpthinges to new behavior * Avoid freeing same array twice Co-authored-by: Dongdong Tian <[email protected]>
1 parent 8462336 commit b8106c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+683
-379
lines changed

doc/examples/ex19/ex19.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
gmt begin ex19
88
gmt grdmath -Rd -I1 -r Y COSD 2 POW = lat.nc
99
gmt grdmath X = lon.nc
10-
gmt makecpt -Cwhite,blue -T0,1 -Z -N -H > lat.cpt
10+
gmt makecpt -Cwhite,blue -T0/1 -N -H > lat.cpt
1111
gmt makecpt -Crainbow -T-180/180 -H > lon.cpt
1212
gmt subplot begin 3x1 -Fs6.5i/0 -M0 -Bbltr -Rd -JI0/6.5i
1313
# First make a worldmap with graded blue oceans and rainbow continents

doc/rst/source/colorbar_common.rst_

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ Optional Arguments
4848
is given then we read stdin. By default all
4949
color changes are annotated. To use a subset, add an extra column to
5050
the CPT with a L, U, or B to annotate Lower, Upper, or Both
51-
color segment boundaries (but see **-B**). If not given, the module
52-
will read stdin. Like :doc:`grdview`, we can understand
51+
color segment boundaries (but see **-B**). Like :doc:`grdview`, we can understand
5352
pattern specifications in the CPT. For CPTs where the
5453
*z* range is in meters, it may be useful to change to another unit
5554
when plotting. To do so, append **+U**\ *unit* to the file name.

doc/rst/source/common_SYN_OPTs.rst_

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
.. |SYN_OPT-i| replace:: **-i**\ :ref:`flags <-icols_full>`
4242

43-
.. |SYN_OPT-j| replace:: **-j**\ :ref:`flags <distcalc_full>`
43+
.. |SYN_OPT-j| replace:: **-j**\ :ref:`flags <-distcalc_full>`
4444

4545
.. |SYN_OPT-l| replace:: **-l**\ :ref:`flags <-l_full>`
4646

doc/rst/source/cookbook/cpts.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ original color scale, which can be either discrete or continuous, though
1717
some (like **globe**) are a mix of the two. The bottom half the color
1818
bar are built by using :doc:`/makecpt`
1919
**-T**-1/1/0.25, thus splitting the color scale into 8 discrete colors.
20+
Black and white triangles indicate which tables have hard or soft hinges,
21+
respectively.
2022

2123
.. _CPT_files_a:
2224

doc/rst/source/cookbook/features.rst

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,45 +1128,91 @@ Master (dynamic) CPTs
11281128

11291129
The CPTs distributed with GMT are *dynamic*. This means they have several
11301130
special properties that modify the behavior of programs that use them.
1131-
All dynamic CPTs are normalized in one of two ways: If a CPT was designed
1131+
Dynamic CPTs comes in a few different flavors: Some CPTs were designed
11321132
to behave differently across a *hinge* value (e.g., a CPT designed specifically
11331133
for topographic relief may include a discontinuity in color across the
1134-
coastline at *z = 0*), then the CPT's *z*-values will range from -1, via 0
1135-
at the hinge, to +1 at the other end. The hinge value is specified via the special
1136-
comment
1137-
1138-
| ``# HINGE = <hinge-value>``
1139-
1140-
CPTs without a hinge are instead normalized with *z*-values from 0 to 1.
1141-
Dynamic CPTs will need to be stretched to the user's preferred range, and there
1134+
coastline at *z = 0*), and when users select these CPTs they will be stretched
1135+
to fit the user's desired data range separately for each side of this *hard* hinge.
1136+
Basically, a *hard* hinge CPT is the juxtaposition of two different CPTs joined
1137+
at the hinge and these sections are stretched independently. Such CPT files
1138+
are identified as such via the special comment
1139+
1140+
| ``# HARD_HINGE``
1141+
1142+
and all hard hinges occur at data value *z = 0* (but you can change this value by
1143+
adding **+h**\ *value* to the name of the CPT).
1144+
Other CPTs may instead have a *soft* hinge which indicates a natural hinge or transition
1145+
point in the CPT itself, unrelated to any natural data set *per se*. These CPTs
1146+
are flagged by the special comment
1147+
1148+
| ``# SOFT_HINGE``
1149+
1150+
CPTs with soft hinges behave as regular (non-hinge) CPTs *unless* the user activates then by
1151+
appending **+h**\ [*hinge*] to the CPT name. This modifier will convert the soft
1152+
hinge into a hard hinge at the user-specified data value *hinge* [which defaults to 0].
1153+
Note that if your specified data range *excludes* an activated soft or hard hinge then we
1154+
only perform color sampling from the *half* of the CPT that pertains to the data range.
1155+
All dynamic CPTs will need to be stretched to the user's preferred range, and there
11421156
are two modes of such scaling: Some CPTs designed for a specific application
11431157
(again, the topographic relief is a good example) have a *default range*
11441158
specified in the master table via the special comment
11451159

11461160

11471161
| ``# RANGE = <zmin/zmax>``
11481162
1149-
and when used by applications the normalized *z*-values will be stretched to reflect
1150-
this natural range. In contrast, CPTs without a natural range are instead
1163+
and when used by applications the CPT may be automatically stretched to reflect
1164+
this natural range. In contrast, dynamic CPTs *without* a natural range are instead
11511165
stretched to fit the range of the data in question (e.g., a grid's range).
1152-
Exceptions to these rules are implemented in the two CPT-producing modules
1166+
Exceptions to these rules are implemented in the two *CPT-producing* modules
11531167
:doc:`/makecpt` and :doc:`/grd2cpt`, both of which can read dynamic CPTs
11541168
and produce *static* CPTs satisfying a user's specific range needs. These
1155-
tools can also read static CPTs where the new range must be specified (or computed
1169+
tools can also read static CPTs for which a new range must be specified (or computed
11561170
from data), reversing the order of colors, and even isolating a section
1157-
of an incoming CPT. Here, :doc:`/makecpt` can be told the range of compute it from data tables
1158-
while :doc:`/grd2cpt` can derive the range from one or more grids.
1171+
of an incoming CPT. Here, :doc:`/makecpt` can be told the data range or compute
1172+
it from data tables while :doc:`/grd2cpt` can derive the range from one or more grids.
11591173

11601174
.. figure:: /_images/GMT_hinge.*
11611175
:width: 500 px
11621176
:align: center
11631177

1164-
The top color bar is a dynamic master CPT (here, globe) with a hinge at sea level and
1178+
The top color bar is a dynamic master CPT (here, globe) with a hard hinge at sea level and
11651179
a natural range from -10,000 to +10,000 meters. However, our data range
11661180
is asymmetrical, going from -8,000 meter depths up to +3,000 meter elevations.
11671181
Because of the hinge, the two sides of the CPT will be stretched separately
11681182
to honor the desired range while utilizing the full color range.
11691183

1184+
All CPT master tables can be found in Chapter :ref:`Of Colors and Color Legends`
1185+
where those with hard or soft hinges are identified by triangles at their hinges.
1186+
1187+
CPTs from color lists
1188+
~~~~~~~~~~~~~~~~~~~~~
1189+
1190+
GMT can build color tables "on the fly" from a comma-separated list of colors
1191+
and a range of *z*-values to go with them. As illustrated below, there are
1192+
four different ways to create such CPTs. In this example, we will operate with
1193+
a list of three colors: red,yellow and purple, given to modules with the option **-C**\ red,yellow,purple,
1194+
and utilize a fixed data range of *z = 0-6*.
1195+
Four different CPTs result because we either select a *continuous* or *discrete table*, and because the *z*-intervals are
1196+
either *equidistant* or *arbitrary*. The top continuous color table with equidistant spacing (a) is selected
1197+
with the range **-T**\ 0/6, meaning the colors will continuously change from red (at *z = 0*) via
1198+
yellow (at *z = 3*) to purple (at *z = 6*). Next, a discrete table with the same range (b)
1199+
is obtained with **-T**\ 0/6/2, yielding colors that are either constant red (*z = 0-2*), yellow (*z = 2-4*)
1200+
or purple (*z = 4-6*). The next discrete table (c) illustrates how to specify arbitrary
1201+
node points in the CPT by providing a comma-separated list of values (**-T**\ 0,4,5.5,6). Now, the constant
1202+
color intervals have unequal ranges, illustrated by red (*z = 0-4*), yellow (*z = 4-5.5*) and purple (*z = 5.5-6*). Finally, we
1203+
create a continuous color table (d) with arbitrary nodes by giving **-T**\ 0,2,6 and adding **-Z**;
1204+
the latter option forces a continuous CPT pinned to a given list of node values. Now, the colors
1205+
continuously change from red (at *z = 0*) via yellow (at *z = 2*) to purple (at *z = 6*).
1206+
Modules that obtain the *z*-range indirectly (e.g., :doc:`/grdimage`) may use the exact data range
1207+
to set the quivalent of a **-T**\ *min/max* option. You may append **+i**\ *dz* to the
1208+
color list to have the *min* and *max* values rounded down and up to nearest multiple of *dz*, respectively.
1209+
1210+
.. figure:: /_images/GMT_colorlist.*
1211+
:width: 500 px
1212+
:align: center
1213+
1214+
Lists of colors (here red,yellow,purple) can be turned into discrete or continuous CPT tables on the fly.
1215+
11701216
Cyclic (wrapped) CPTs
11711217
~~~~~~~~~~~~~~~~~~~~~
11721218

@@ -1227,7 +1273,10 @@ A few modules (:doc:`/grdimage`, :doc:`/grdview`) that expects a CPT option will
12271273
provide a default CPT if none is provided. By default, the default CPT is the
12281274
"turbo" color table, but this is overridden if the user uses the @eart_relief
12291275
(we select "geo") or @srtm_relief (we select "srtm") data sets. After selection,
1230-
these CPTs are read and scaled to match the range of the grid values.
1276+
these CPTs are read and scaled to match the range of the grid values. You may append
1277+
**+i**\ *dz* to the CPT to have the exact range rounded to nearest multiple of *dz*.
1278+
THis is helpful if you plan to place a colorbar and prefer start and stop *z*-values
1279+
that are multiples of *dz*.
12311280

12321281
The Drawing of Vectors
12331282
----------------------
@@ -2544,4 +2593,3 @@ any of these directories.
25442593
25452594
.. [19]
25462595
Requires building GMT with GDAL.
2547-
File renamed without changes.

doc/rst/source/create_cpt.rst_

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
**-C**\ [*cpt*\ \|\ *master*\ [**+h**\ [*hinge*]][**+i**\ *zinc*][**+u**\ \|\ **U**\ *unit*] \|\ *color1,color2*\ [,\ *color3*\ ,...]]
2+
Name of the CPT. If given a GMT Master soft-hinge CPT (see :ref:`Of Colors and Color Legends`) then
3+
you can enable the hinge at data value *hinge* [0] via **+h**, whereas for hard-hinge CPTs you
4+
can adjust the location of the hinge [0]. For other CPTs, you may convert their *z*-values
5+
from meter to another distance unit (append **+U**\ *unit*) or from another unit to meter (append **+u**\ *unit*),
6+
with *unit* taken from **e**\ \|\ **f**\ \|\ **k**\ \|\ **M**\ \|\ **n**\ \|\ **u**.
7+
Alternatively, give *color1,color2*\ [*,color3*\ ,...]
8+
to build a linear continuous CPT from those colors automatically,
9+
where *z* starts at 0 and is incremented by one for each color.
10+
In this case *color*\ **n** can be a r/g/b triplet, a color name,
11+
or an HTML hexadecimal color (e.g. #aabbcc).

doc/rst/source/explain_distcalc.rst_

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
**-je**\ \|\ **f**\ \|\ **g** :ref:`(more ...) <distcalc_full>`
1+
**-je**\ \|\ **f**\ \|\ **g** :ref:`(more ...) <-distcalc_full>`
22
Determine how spherical distances are calculated.

doc/rst/source/explain_distcalc_full.rst_

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _distcalc_full:
1+
.. _-distcalc_full:
22

33
**-je**\ \|\ **f**\ \|\ **g**
44
Determine how spherical distances are calculated in modules that support this.

doc/rst/source/grd2cpt.rst

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,7 @@ Optional Arguments
9090

9191
.. _-C:
9292

93-
94-
**-C**\ *cpt*
95-
Selects the master color table to use in the interpolation. Choose
96-
among the built-in tables (type **grd2cpt** to see the list) or give
97-
the name of an existing CPT [Default gives the turbo CPT].
98-
Yet another option is to specify -Ccolor1,color2[,color3,...]
99-
to build a linear continuous CPT from those colors automatically.
100-
In this case *color*\ **n** can be a r/g/b triplet, a color name,
101-
or an HTML hexadecimal color (e.g. #aabbcc ).
93+
.. include:: create_cpt.rst_
10294

10395
.. _-D:
10496

@@ -213,30 +205,42 @@ Optional Arguments
213205
**-W**\ [**w**]
214206
Do not interpolate the input color table but pick the output colors
215207
starting at the beginning of the map. This is particularly useful in
216-
combination with a categorical color table. Cannot be used in
217-
combination with **-Z**. Alternatively, use **-Ww** to produce
218-
a wrapped (cyclic) color table that endlessly repeats its range.
208+
combination with a categorical color table. Alternatively, use **-Ww**
209+
to produce a wrapped (cyclic) color table that endlessly repeats its range.
219210

220211
.. _-Z:
221212

222213
**-Z**
223-
Will create a continuous color palette. [Default is discontinuous,
224-
i.e., constant color intervals]
214+
Force a continuous CPT [Default is discontinuous].
225215

226216
.. include:: explain_help.rst_
227217

228218
.. include:: explain_grd_inout_short.rst_
229219

230220
.. include:: explain_transparency.rst_
231221

232-
Color Aliasing
233-
--------------
234-
235-
For best result when **-E** is used we recommend you do no append
236-
a specific *nlevels*. This way the original CPT is used exactly
237-
as is but the *z* boundaries are adjusted to match the grid limits.
238-
Otherwise you may, depending on the nature of the input CPT, miss
239-
aspects of the color changes by aliasing the signal.
222+
Color Hinges
223+
------------
224+
225+
Some of the GMT master dynamic CPTs are actually two separate CPTs
226+
meeting at a *hinge*. Usually, colors may change dramatically across
227+
the hinge, which is used to separate two different domains (e.g., land
228+
and ocean across the shoreline, for instance). CPTs with a hinge will
229+
have their two parts stretched to the required range separately, i.e.,
230+
the bottom part up to the hinge will be stretched independently of the
231+
part from the hinge to the top, according to the prescribed new range.
232+
Hinges are either *hard* or *soft*. Soft hinges must be *activated* by
233+
appending **+h**\ [*hinge*] to the CPT name.
234+
If the selected range does not include an activated soft or hard hinge then
235+
we only resample colors from the half of the CPT that pertains to the range.
236+
See :ref:`Of Colors and Color Legends` for more information.
237+
238+
Discrete versus Continuous CPT
239+
------------------------------
240+
241+
All CPTs can be stretched, but only continuous CPTs can be sampled
242+
at new nodes (i.e., by given an increment in **-T**). We impose this
243+
limitation to avoid aliasing the original CPT.
240244

241245
Examples
242246
--------
@@ -265,7 +269,7 @@ file relief, run
265269

266270
gmt grd2cpt mydata.nc -Crelief -L0/10000 -T0/200/20 > mydata.cpt
267271

268-
.. include:: explain_cpt.rst_
272+
.. include:: cpt_notes.rst_
269273

270274
See Also
271275
--------

doc/rst/source/grd2kml.rst

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,7 @@ Optional Arguments
5454

5555
.. _-C:
5656

57-
**-C**\ [*cpt* \|\ *master*\ [**+i**\ *zinc*] \|\ *color1,color2*\ [,\ *color3*\ ,...]]
58-
Name of the CPT (for *grd_z* only). Alternatively,
59-
supply the name of a GMT color master dynamic CPT [turbo, but geo
60-
for @earth_relief and srtm for @srtm_relief data] to
61-
automatically determine a continuous CPT from
62-
the grid's z-range; you may round up/down the z-range by adding **+i**\ *zinc*.
63-
Yet another option is to specify **-C**\ *color1*\ ,\ *color2*\ [,\ *color3*\ ,...]
64-
to build a linear continuous CPT from those colors automatically.
65-
In this case *color1* etc can be a r/g/b triplet, a color name,
66-
or an HTML hexadecimal color (e.g. #aabbcc ). If no argument is given to **-C**
67-
then under modern mode we select the current CPT.
57+
.. include:: use_cpt_grd.rst_
6858

6959
.. _-E:
7060

doc/rst/source/grdimage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ remotely located Jessica Rabbit::
7575

7676
gmt grdimage -JI15c -Rd http://larryfire.files.wordpress.com/2009/07/untooned_jessicarabbit.jpg -pdf jess
7777

78-
.. include:: explain_cpt.rst_
78+
.. include:: cpt_notes.rst_
7979

8080
See Also
8181
--------

doc/rst/source/grdimage_common.rst_

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,7 @@ Optional Arguments
6666

6767
.. _-C:
6868

69-
**-C**\ [*cpt* \|\ *master*\ [**+i**\ *zinc*] \|\ *color1,color2*\ [,\ *color3*\ ,...]]
70-
Name of the CPT (for *grd_z* only). Alternatively,
71-
supply the name of a GMT color master dynamic CPT [turbo, but geo
72-
for @earth_relief and srtm for @srtm_relief data] to
73-
automatically determine a continuous CPT from
74-
the grid's z-range; you may round up/down the z-range by adding **+i**\ *zinc*.
75-
Yet another option is to specify **-C**\ *color1*\ ,\ *color2*\ [,\ *color3*\ ,...]
76-
to build a linear continuous CPT from those colors automatically.
77-
In this case *color1* etc can be a r/g/b triplet, a color name,
78-
or an HTML hexadecimal color (e.g. #aabbcc ). If no argument is given to **-C**
79-
then under modern mode we select the current CPT.
69+
.. include:: use_cpt_grd.rst_
8070

8171
.. _-D:
8272

doc/rst/source/grdvector_common.rst_

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@ Optional Arguments
3737

3838
.. _-C:
3939

40-
**-C**\ [*cpt* \|\ *master*\ [**+i**\ *zinc*] \|\ *color1,color2*\ [,\ *color3*,...]]
41-
Use *cpt* to assign colors based on vector length. Alternatively,
42-
supply the name of a GMT color master dynamic CPT [turbo] to
43-
automatically determine a continuous CPT from
44-
the grid's z-range; you may round up/down the z-range by adding **+i**\ *zinc*..
45-
Yet another option is to specify **-C**\ *color1,color2*\ [,\ *color3*,...]
46-
to build a linear continuous cpt from those colors automatically.
47-
In this case *color*\ **n** can be a r/g/b triplet, a color name,
48-
or an HTML hexadecimal color (e.g. #aabbcc ). If no argument is given to **-C**
49-
then under modern mode we select the current CPT.
40+
.. include:: use_cpt_grd.rst_
5041

5142
.. _-G:
5243

doc/rst/source/grdview_common.rst_

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,7 @@ Optional Arguments
3333

3434
.. _-C:
3535

36-
**-C**\ [*cpt* \|\ *master*\ [**+i**\ *zinc*] \|\ *color1,color2*\ [,\ *color3*\ ,...]]
37-
The name of the CPT. Must be present if you want
38-
(1) mesh plot with contours (**-Qm**), or
39-
(2) shaded/colored perspective image (**-Qs** or
40-
**-Qi**). For **-Qs**: You can specify that you want to skip a
41-
z-slice by setting the red r/g/b component to -; to use a pattern give red =
42-
**P\|p**\ *pattern*\ [**+b**\ *color*\ ][**+f**\ *color*\ ][**+r**\ *dpi*\ ].
43-
Alternatively, supply the name of a GMT color master dynamic CPT [turbo, but
44-
geo for @earth_relief and srtm for @srtm_relief data] to
45-
automatically determine a continuous CPT from
46-
the grid's z-range; you may round up/down the z-range by adding **+i**\ *zinc*.
47-
If no argument is given to **-C** then under modern mode we select the current CPT.
36+
.. include:: use_cpt_grd.rst_
4837

4938
.. _-G:
5039

0 commit comments

Comments
 (0)