Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

session-4.rst 16 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
  1. Session Four
  2. ============
  3. In our final session we will concentrate on color images and
  4. perspective views of gridded data sets. Before we start that
  5. discussion we need to cover three important aspects of plotting
  6. that must be understood. These are
  7. #. Color tables and pseudo-colors in GMT.
  8. #. Artificial illumination and how it affects colors.
  9. #. Multi-dimensional grids.
  10. CPTs
  11. ----
  12. The CPT is discussed in detail in the GMT Technical Reference
  13. and Cookbook. Please review the format before experimenting
  14. further.
  15. CPTs can be created in any number of ways. GMT provides
  16. two mechanisms:
  17. #. Create simple, linear color tables given a master color table
  18. (several are built-in) and the desired *z*-values at color boundaries
  19. (:doc:`/makecpt`)
  20. #. Create color tables based on a master CPT color table and the
  21. histogram-equalized distribution of *z*-values in a gridded data file (:doc:`/grd2cpt`)
  22. One can also make these files manually or with awk
  23. or other tools. Here we will limit our discussion to :doc:`/makecpt`.
  24. Its main argument is the name of the master color table (a list is
  25. shown if you run the module with no arguments) and the equidistant
  26. *z*-values to go with it. The main options are given below.
  27. ======= =============================================
  28. Option Purpose
  29. ======= =============================================
  30. **-C** Set the name of the master CPT to use
  31. **-I** Reverse the sense of the color progression
  32. **-V** Run in verbose mode
  33. **-Z** Make a continuous rather than discrete table
  34. ======= =============================================
  35. To make discrete and continuous color CPTs for data that ranges
  36. from -20 to 60, with color changes at every 10, try these two variants:
  37. ::
  38. gmt makecpt -Crainbow -T-20/60/10 > disc.cpt
  39. gmt makecpt -Crainbow -T-20/60/10 -Z > cont.cpt
  40. We can plot these color tables with :doc:`/colorbar`; the options
  41. worth mentioning here are listed below. The placement of the
  42. color bar is particularly important and we refer you to the
  43. :ref:`Plot embellishments <GMT_Embellishments>` section for all
  44. the details.
  45. In addition, the **-B** option can be used to set the title
  46. and unit label (and optionally to set the annotation-, tick-,
  47. and grid-line intervals for the color bars.). Note that the makecpt commands
  48. above are done in classic mode. If you run :doc:`/makecpt` in modern mode
  49. then you usually do not specify an output file via stdout since
  50. modern mode maintains what is known as the current CPT. However,
  51. if you must explicitly name an output CPT then you will need to
  52. add the -H option for modern mode to allow output to stdout.
  53. ======================================================= ==================================================================================
  54. Option Purpose
  55. ======================================================= ==================================================================================
  56. **-C**\ *cpt* The required CPT
  57. **-Dx**\ *xpos/ypos*\ **+w**\ *length/width*\ [**+h**] Sets the position and dimensions of scale bar. Append **+h** to get horizontal bar
  58. **-I**\ *max\_intensity* Add illumination effects
  59. ======================================================= ==================================================================================
  60. Here is an example of four different ways of presenting the color bar:
  61. .. literalinclude:: /_verbatim/GMT_tut_14.txt
  62. Your plot should look like :ref:`our example 14 below <gmt_tut_14>`
  63. .. _gmt_tut_14:
  64. .. figure:: /_images/GMT_tut_14.*
  65. :width: 400 px
  66. :align: center
  67. Result of GMT Tutorial example 14
  68. Exercises:
  69. #. Redo the :doc:`/makecpt` exercise using the master table
  70. *hot* and redo the bar plot.
  71. #. Try specifying **-B**\ 10g5.
  72. Illumination and intensities
  73. ----------------------------
  74. GMT allows for artificial illumination and shading. What this
  75. means is that we imagine an artificial sun placed at infinity in
  76. some azimuth and elevation position illuminating our surface.
  77. The parts of the surface that slope toward the sun should brighten
  78. while those sides facing away should become darker; no shadows are
  79. cast as a result of topographic undulations.
  80. While it is clear that the actual slopes of the surface and the
  81. orientation of the sun enter into these calculations, there is
  82. clearly an arbitrary element when the surface is not topographic
  83. relief but some other quantity. For instance, what does the slope
  84. toward the sun mean if we are plotting a grid of heat flow anomalies?
  85. While there are many ways to accomplish what we want, GMT offers
  86. a relatively simple way: We may calculate the gradient of the surface
  87. in the direction of the sun and normalize these values to fall in
  88. the -1 to +1 range; +1 means maximum sun exposure and -1 means complete
  89. shade. Although we will not show it here, it should be added that
  90. GMT treats the intensities as a separate data set. Thus, while
  91. these values are often derived from the relief surface we want to
  92. image they could be separately observed quantities such as back-scatter
  93. information.
  94. Colors in GMT are specified in the RGB system used for computer
  95. screens; it mixes red, green, and blue light to achieve other colors.
  96. The RGB system is a Cartesian coordinate system and produces a color cube.
  97. For reasons better explained in Appendix I in the Reference book it is
  98. difficult to darken and brighten a color based on its RGB values and an
  99. alternative coordinate system is used instead; here we use the HSV system.
  100. If you hold the color cube so that the black and white corners are along
  101. a vertical axis, then the other 6 corners project onto the horizontal plane to
  102. form a hexagon; the corners of this hexagon are the primary colors Red,
  103. Yellow, Green, Cyan, Blue, and Magenta.
  104. The CMY colors are the complimentary colors and are used when paints are
  105. mixed to produce a new color (this is how printers operate; they also add
  106. pure black (K) to avoid making gray from CMY). In this coordinate system the
  107. angle 0-360° is the hue (H); the Saturation and Value are harder to
  108. explain. Suffice it to say here that we intend to darken any pure color
  109. (on the cube facets) by keeping H fixed and adding black and brighten it by adding white; for
  110. interior points in the cube we will add or remove gray.
  111. This operation is efficiently done in the HSV coordinate system; hence all
  112. GMT shading operations involve translating from RGB to HSV, do the
  113. illumination effect, and transform back the modified RGB values.
  114. Color images
  115. ------------
  116. Once a CPT has been made it is relatively straightforward to generate
  117. a color image of a gridded data. Here, we will extract a subset of the
  118. global 30" DEM called SRTM30+:
  119. ::
  120. gmt grdcut @earth_relief_30s -R-108/-103/35/40 -Gtut_relief.nc
  121. Using :doc:`/grdinfo` we find that the data ranges from about 1000m to
  122. about 4300m so we need to make a CPT with that range.
  123. Color images are made with :doc:`/grdimage` which takes the usual
  124. common command options (by default the **-R** is taken from the data set)
  125. and a CPT; the main other options are:
  126. ==================== ======================================================================
  127. Option Purpose
  128. ==================== ======================================================================
  129. **-E**\ *dpi* Sets the desired resolution of the image [Default is data resolution]
  130. **-I**\ *intenfile* Use artificial illumination using intensities from *intensfile*
  131. **-M** Force gray shade using the (television) YIQ conversion
  132. ==================== ======================================================================
  133. We want to make a plain color map with a color bar superimposed above
  134. the plot. We try
  135. .. literalinclude:: /_verbatim/GMT_tut_15.txt
  136. Your plot should look like :ref:`our example 15 below <gmt_tut_15>`
  137. .. _gmt_tut_15:
  138. .. figure:: /_images/GMT_tut_15.*
  139. :width: 400 px
  140. :align: center
  141. Result of GMT Tutorial example 15
  142. The plain color map lacks detail and fails to reveal the topographic
  143. complexity of this Rocky Mountain region. What it needs is artificial
  144. illumination. We want to simulate shading by a sun source in the east,
  145. hence we derive the required intensities from the gradients of the
  146. topography in the N90°E direction using :doc:`/grdgradient`. Other than the
  147. required input and output filenames, the available options are
  148. +------------------------------------------------------------------+-------------------------------------------------------------------+
  149. | Option | Purpose |
  150. | **-A**\ *azimuth* | Azimuthal direction for gradients |
  151. +------------------------------------------------------------------+-------------------------------------------------------------------+
  152. | **-fg** | Indicates that this is a geographic grid |
  153. +------------------------------------------------------------------+-------------------------------------------------------------------+
  154. | **-N**\ [**t**\|\ **e**][**+s**\ *norm*][**+o**\ *offset*] | Normalize gradients by *norm/offset* [= 1/0 by default]. |
  155. +------------------------------------------------------------------+-------------------------------------------------------------------+
  156. | | Insert **t** to normalize by the inverse tangent transformation. |
  157. +------------------------------------------------------------------+-------------------------------------------------------------------+
  158. | | Insert **e** to normalize by the cumulative Laplace distribution. |
  159. +------------------------------------------------------------------+-------------------------------------------------------------------+
  160. The :ref:`GMT inverse tangent transformation <gmt_atan>` shows that raw slopes from bathymetry tend to be
  161. far from normally distributed (left). By using the inverse tangent
  162. transformation we can ensure a more uniform distribution (right).
  163. The inverse tangent transform simply takes the raw slope estimate
  164. (the *x* value at the arrow) and returns the corresponding inverse
  165. tangent value (normalized to fall in the plus/minus 1 range; horizontal
  166. arrow pointing to the *y*-value).
  167. .. _gmt_atan:
  168. .. figure:: /_images/GMT_atan.*
  169. :width: 600 px
  170. :align: center
  171. How the inverse tangent operation works. Raw slope values (left) are processed
  172. via the inverse tangent operator, turning tan(x) into x and thus compressing
  173. the data range. The transformed slopes are more normally distributed (right).
  174. **-Ne** and **-Nt** yield well behaved gradients. Personally,
  175. we prefer to use the **-Ne** option; the value of
  176. *norm* is subjective and you may experiment somewhat in the
  177. 0.5-5 range. For our case we choose
  178. ::
  179. gmt grdgradient @tut_relief.nc -Ne0.8 -A100 -fg -Gus_i.nc
  180. Given the CPT and the two gridded data sets we can
  181. create the shaded relief image:
  182. .. literalinclude:: /_verbatim/GMT_tut_16.txt
  183. Your plot should look like :ref:`our example 16 below <gmt_tut_16>`
  184. .. _gmt_tut_16:
  185. .. figure:: /_images/GMT_tut_16.*
  186. :width: 400 px
  187. :align: center
  188. Result of GMT Tutorial example 16
  189. Exercises:
  190. #. Force a gray-shade image.
  191. #. Rerun :doc:`/grdgradient` with **-N**\ 1.
  192. Multi-dimensional maps
  193. ----------------------
  194. Climate data, like ocean temperatures or atmospheric pressure, are often provided as
  195. multi-dimensional (3-D, 4-D or 5-D) grids in netCDF format. This section will demonstrate
  196. that GMT is able to plot "horizontal"
  197. slices (spanning latitude and longitude) of such grids without much effort.
  198. As an example we will download the Seasonal Analysed Mean Temperature from the
  199. `World Ocean Atlas 1998 <http://www.cdc.noaa.gov/cdc/data.nodc.woa98.html)>`_
  200. The file in question is named
  201. otemp.anal1deg.nc (ftp://ftp.cdc.noaa.gov/Datasets/nodc.woa98/temperat/seasonal/otemp.anal1deg.nc).
  202. You can look at the information pertained in this file using the program ncdump and
  203. notice that the variable that we want to plot (otemp) is a four-dimensional variable of time,
  204. level (i.e., depth), latitude and longitude.
  205. ::
  206. ncdump -h otemp.anal1deg.nc
  207. We will need to make an appropriate color scale, running from -2°C (freezing temperature of salt
  208. water) to 30°C (highest likely ocean temperature).
  209. Let us focus on the temperatures in Summer (that is the third season, July through
  210. September) at sea level (that is the first level). To plot these in a Mollweide projection we
  211. use:
  212. .. literalinclude:: /_verbatim/GMT_tut_17.txt
  213. The addition "?otemp[2,0]" indicates which variable to retrieve from the netCDF
  214. file (otemp) and that we need the third time step and first level. The numbering of the
  215. time steps and levels starts at zero, therefore "[2,0]". Make sure to put the
  216. whole file name within quotes since the characters ?, [ and ] have
  217. special meaning in Unix.
  218. Your plot should look like :ref:`our example 17 below <gmt_tut_17>`
  219. .. _gmt_tut_17:
  220. .. figure:: /_images/GMT_tut_17.*
  221. :width: 400 px
  222. :align: center
  223. Result of GMT Tutorial example 17
  224. Exercises:
  225. #. Plot the temperatures for Spring at 5000 m depth. (Hint: use ncdump -v level to
  226. figure out what level number that is).
  227. #. Include a color scale at the bottom of the plot.
  228. Perspective views
  229. -----------------
  230. Our final undertaking in this tutorial is to examine three-dimensional
  231. perspective views. The
  232. GMT module that produces perspective views of gridded data files is
  233. :doc:`/grdview`. It can make two kinds of plots:
  234. #. Mesh or wire-frame plot (with or without superimposed contours)
  235. #. Color-coded surface (with optional shading, contours, or draping).
  236. Regardless of plot type, some arguments must be specified; these are
  237. #. *relief\_file*; a gridded data set of the surface.
  238. #. **-J** for the desired map projection.
  239. #. **-JZ**\ *height* for the vertical scaling.
  240. #. **-p**\ *azimuth/elevation* for the vantage point.
  241. In addition, some options may be required:
  242. ========================= =============================================================================================================
  243. Option Purpose
  244. ========================= =============================================================================================================
  245. **-C**\ *cpt* The *cpt* is required for color-coded surfaces and for contoured mesh plots
  246. **-G**\ *drape\_file* Assign colors using *drape\_file* instead of *relief\_file*
  247. **-I**\ *intens\_file* File with illumination intensities
  248. **-Qm** Selects mesh plot
  249. **-Qs**\ [**+m**] Surface plot using polygons; append **+m** to show mesh. This option allows for **-W**
  250. **-Qi**\ *dpi*\ [**g**] Image by scan-line conversion. Specify *dpi*; append **g** to force gray-shade image. **-B** is disabled.
  251. **-W**\ *pen* Draw contours on top of surface (except with **-Qi**)
  252. ========================= =============================================================================================================
  253. Mesh-plot
  254. ~~~~~~~~~
  255. Mesh plots work best on smaller data sets. We again use the small
  256. subset of the ETOPO5 data over Bermuda and will use the ocean CPT.
  257. A simple mesh plot can therefore be obtained with
  258. .. literalinclude:: /_verbatim/GMT_tut_18.txt
  259. Your plot should look like :ref:`our example 18 below <gmt_tut_18>`
  260. .. _gmt_tut_18:
  261. .. figure:: /_images/GMT_tut_18.*
  262. :width: 400 px
  263. :align: center
  264. Result of GMT Tutorial example 18
  265. Exercises:
  266. #. Select another vantage point and vertical height.
  267. Color-coded view
  268. ~~~~~~~~~~~~~~~~
  269. We will make a perspective, color-coded view of the US Rockies
  270. from the southeast. This is done using
  271. .. literalinclude:: /_verbatim/GMT_tut_19.txt
  272. Your plot should look like :ref:`our example 19 below <gmt_tut_19>`
  273. .. _gmt_tut_19:
  274. .. figure:: /_images/GMT_tut_19.*
  275. :width: 400 px
  276. :align: center
  277. Result of GMT Tutorial example 19
  278. This plot is pretty crude since we selected 50 dpi but it is fast
  279. to render and allows us to try alternate values for vantage point
  280. and scaling. When we settle on the final values we select the
  281. appropriate *dpi* for the final output device and let it rip.
  282. Exercises:
  283. #. Choose another vantage point and scaling.
  284. #. Redo :doc:`/grdgradient` with another illumination direction and plot again.
  285. #. Select a higher *dpi*, e.g., 200.
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...