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

GMT_Chapter_7.tex 53 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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
  1. %------------------------------------------
  2. % $Id$
  3. %
  4. % The GMT Documentation Project
  5. % Copyright (c) 2000-2012.
  6. % P. Wessel, W. H. F. Smith, R. Scharroo, and J. Luis
  7. %------------------------------------------
  8. %
  9. \chapter{Creating GMT Graphics}
  10. \label{ch:7}
  11. \thispagestyle{headings}
  12. In this section we will be giving several examples of
  13. typical usage of \GMT\ programs. In general, we will
  14. start with a raw data set, manipulate the numbers in
  15. various ways, then display the results in diagram or
  16. map view. The resulting plots will have in common that
  17. they are all made up of simpler plots that have been
  18. overlaid to create a complex illustration. We will
  19. mostly follow the following format:
  20. \begin{enumerate}
  21. \item We explain what we want to achieve in plain
  22. language.
  23. \item We present an annotated Bourne shell script that contains
  24. all commands used to generate the illustration.
  25. \item We explain the rationale behind the commands.
  26. \item We present the illustration, 50\% reduced in size, and without
  27. the timestamp (\Opt{U}).
  28. \end{enumerate}
  29. A detailed discussion of each command is not given;
  30. we refer you to the manual pages for command line
  31. syntax, etc. We encourage you to run these scripts for yourself.
  32. See Appendix~\ref{app:D} if you would like an electronic version
  33. of all the shell-scripts (both \progname{sh} and \progname{csh} scripts
  34. are available, as or DOS batch files; only the \progname{sh}-scripts are discussed here) and support
  35. data used below. Note that all examples explicitly specifies the
  36. measurement units, so although we use inches you should be able
  37. to run these scripts and get the same plots even if you have cm
  38. as the default measure unit. The examples are all written to be ``quiet'',
  39. that is no information is echoed to the screen. Thus,
  40. these scripts are well suited for background execution.
  41. Note that we also end each script by cleaning up after
  42. ourselves. Because \progname{awk} is broken as designed on some
  43. systems, and \progname{nawk} is not available on others we refer
  44. to \progname{\$AWK} in the scripts below; the \progname{do\_examples.sh}
  45. scripts will set this when running all examples.
  46. Finally, be aware that for practical purposes the output \PS\ file name is stored as the variable \texttt{ps}.
  47. \section{The making of contour maps}
  48. \index{Example!contour maps|(}
  49. We want to create two contour maps of the low order geoid
  50. using the Hammer equal area projection. Our gridded data
  51. file is called \filename{osu91a1f\_16.nc} and contains a global 1\DS\
  52. by 1\DS\ gridded geoid (we will see how to make gridded
  53. files later). We would like to show one map centered on
  54. Greenwich and one centered on the dateline. Positive contours
  55. should be drawn with a solid pen and negative contours with
  56. a dashed pen. Annotations should occur for every 50 m contour
  57. level, and both contour maps should show the continents in
  58. light gray in the background. Finally, we want a rectangular
  59. frame surrounding the two maps. This is how it is done:
  60. \script{example_01}
  61. The first command draws a box surrounding the maps. This is
  62. followed by two sequences of
  63. \GMTprog{pscoast}, \GMTprogi{grdcontour}, \GMTprogi{grdcontour}.
  64. They differ in that the first is centered on Greenwich; the
  65. second on the dateline. We use the limit option (\Opt{L})
  66. in \GMTprog{grdcontour} to select negative contours only and plot
  67. those with a dashed pen, then positive contours only and draw
  68. with a solid pen [Default]. The \Opt{T} option causes tickmarks
  69. pointing in the downhill direction to be drawn on the innermost,
  70. closed contours. For the upper panel we also added - and + to
  71. the local lows and highs. You can find this illustration as
  72. Figure~\ref{fig:GMT_example_01}.
  73. \GMTexample{01}{Contour maps of gridded data.}
  74. \index{Example!contour maps|)}
  75. \section{Image presentations}
  76. \label{sec:example_02}
  77. \index{Example!image presentations|(}
  78. As our second example we will demonstrate how to make color
  79. images from gridded data sets (again, we will defer the
  80. actual making of grid files to later examples). We will
  81. use the supplemental program \GMTprog{grdraster} to extract 2-D
  82. grid files of bathymetry and Geosat geoid heights and put the
  83. two images on the same page. The region of interest is the
  84. Hawaiian islands, and due to the oblique trend of the island
  85. chain we prefer to rotate our geographical data sets using
  86. an oblique Mercator projection defined by the hotspot pole
  87. at (68\DS W, 69\DS N). We choose the point (190\DS ,
  88. 25.5\DS ) to be the center of our projection (e.g., the
  89. local origin), and we want to image a rectangular region
  90. defined by the longitudes and latitudes of the lower left
  91. and upper right corner of region. In our case we choose
  92. (160\DS , 20\DS ) and (220\DS , 30\DS ) as the
  93. corners. We use \GMTprog{grdimage} to make the illustration:
  94. \script{example_02}
  95. The first step extracts the 2-D data sets from the local
  96. data base using \GMTprog{grdraster}, which is a supplemental
  97. utility program (see Appendix~\ref{app:A}) that may be adapted to
  98. reflect the nature of your data base format. It
  99. automatically figures out the required extent of the region
  100. given the two corners points and the projection. The extreme
  101. meridians and parallels enclosing the oblique region is
  102. \Opt{R}159:50/220:10/3:10/47:35. This is
  103. the area extracted by \GMTprog{grdraster}. For your convenience
  104. we have commented out those lines and provided the two
  105. extracted files so you do not need \GMTprog{grdraster} to try
  106. this example. By using the embedded grid file format
  107. mechanism we saved the topography using kilometers as the
  108. data unit. We now have two grid files with bathymetry and
  109. geoid heights, respectively. We use \GMTprog{makecpt} to generate
  110. a linear color palette file \filename{geoid.cpt} for the geoid and use
  111. \GMTprog{grd2cpt} to get a histogram-equalized cpt file \filename{topo.cpt}
  112. for the topography data. To emphasize the structures in
  113. the data we calculate the slopes in the north-south direction
  114. using \GMTprog{grdgradient}; these will be used to modulate the
  115. color image. Next we run \GMTprog{grdimage} to create a
  116. color-code image of the Geosat geoid heights, and draw a
  117. color legend to the right of the image with \GMTprog{psscale}.
  118. Similarly, we run \GMTprog{grdimage} but specify \Opt{Y}4.5i
  119. to plot above the previous image. Adding scale and label
  120. the two plots a) and b) completes the illustration
  121. (Figure~\ref{fig:GMT_example_02}).
  122. \index{Example!image presentations|)}
  123. \GMTexample{02}{Color images from gridded data.}
  124. \section{Spectral estimation and xy-plots}
  125. \index{Example!spectral estimation|(}
  126. \index{Example!xy plots|(}
  127. In this example we will show how to use the \GMT\ programs
  128. \GMTprog{fitcircle}, \GMTprog{project}, \GMTprog{sample1d},
  129. \GMTprog{spectrum1d}, \GMTprog{psxy}, and \GMTprog{pstext}.
  130. Suppose you have (lon, lat, gravity) along a satellite track
  131. in a file called \filename{sat.xyg}, and (lon, lat, gravity)
  132. along a ship track in a file called \filename{ship.xyg}.
  133. You want to make a cross-spectral analysis of these data.
  134. First, you will have to get the two data sets into equidistantly
  135. sampled time-series form. To do this, it will be convenient to
  136. project these along the great circle that best fits the sat track.
  137. We must use \GMTprog{fitcircle} to find this great circle and choose
  138. the L$_2$ estimates of best pole. We project the data using
  139. \GMTprog{project} to find out what their ranges are in the projected
  140. coordinate. The \GMTprog{minmax} utility will report the minimum and
  141. maximum values for multi-column ASCII tables. Use this information
  142. to select the range of the projected distance coordinate they have
  143. in common. The script prompts you for that information after
  144. reporting the values. We decide to make a file of equidistant
  145. sampling points spaced 1 km apart from -1167 to +1169, and use
  146. the \UNIX\ utility \progname{\$AWK} to accomplish this step. We can then
  147. resample the projected data, and carry out the cross-spectral
  148. calculations, assuming that the ship is the input and the satellite
  149. is the output data. There are several intermediate steps that
  150. produce helpful plots showing the effect of the various processing
  151. steps (\filename{example\_03[a--f].ps}), while the final plot
  152. \filename{example\_03.ps} shows
  153. the ship and sat power in one diagram and the coherency on another
  154. diagram, both on the same page. Note the extended use of
  155. \GMTprog{pstext} and \GMTprog{psxy} to put labels and legends directly on
  156. the plots. For that purpose we often use \Opt{Jx}1i and specify
  157. positions in inches directly. Thus, the complete automated
  158. script reads:
  159. \script{example_03}
  160. The final illustration (Figure~\ref{fig:GMT_example_03}) shows that the ship gravity
  161. anomalies have more power than altimetry derived gravity for
  162. short wavelengths and that the coherency between the two
  163. signals improves dramatically for wavelengths $>$ 20 km.
  164. \GMTexample{03}{Spectral estimation and $x/y$-plots.}
  165. \index{Example!spectral estimation|)}
  166. \index{Example!xy plots|)}
  167. \section{A 3-D perspective mesh plot}
  168. \index{Example!3-D mesh plot|(}
  169. This example will illustrate how to make a fairly complicated
  170. composite figure. We need a subset of the ETOPO5 bathymetry\footnote{
  171. These data are available on CD-ROM from NGDC (www.ngdc.noaa.gov).}
  172. and Geosat geoid data sets which we will extract from the local
  173. data bases using \GMTprog{grdraster}. We would like to show a
  174. 2-layer perspective plot where layer one shows a contour map
  175. of the marine geoid with the location of the Hawaiian islands
  176. superposed, and a second layer showing the 3-D mesh plot of
  177. the topography. We also add an arrow pointing north and some
  178. text. This is how to do it:
  179. \script{example_04}
  180. The purpose of the color palette file \filename{zero.cpt} is to have
  181. the positive topography mesh painted light gray (the remainder
  182. is white). The left side of Figure~\ref{fig:GMT_example_04} shows the complete illustration.
  183. \begin{figure}[ht]
  184. \includegraphics[scale=0.42]{example_04}\hfill
  185. \includegraphics[scale=0.42]{example_04c}
  186. \caption{3-D perspective mesh plot (left) and colored version (right).}
  187. \label{fig:GMT_example_04}
  188. \end{figure}
  189. The color version of this figure was used in our first article in \emph{EOS
  190. Trans. AGU} (8 October 1991). Using \GMTprog{grdview} one can choose
  191. to either plot a mesh surface (left) or a color-coded surface (right).
  192. We have also added artificial illumination from a light-source due north,
  193. which is simulated by computing the gradient of the surface grid
  194. in that direction though the \GMTprog{grdgradient} program.
  195. We choose to use the \Opt{Qc} option in \GMTprog{grdview} to
  196. achieve a high degree of smoothness. Here, we select 100 dpi
  197. since that will be the resolution of our final raster
  198. (The EOS raster was 300 dpi).
  199. The following script creates
  200. the color \PS\ file. Note that the size of the
  201. resulting output file is directly dependent on the square of
  202. the dpi chosen for the scanline conversion. A higher value
  203. for dpi in \Opt{Qc} would have resulted in a much larger
  204. output file. The CPT files were taken from Section~\ref{sec:example_02}.
  205. \script{example_04c}
  206. \index{Example!3-D mesh plot|)}
  207. \section{A 3-D illuminated surface in black and white}
  208. \index{Example!3-D illuminated surface|(}
  209. Instead of a mesh plot we may choose to show 3-D surfaces using
  210. artificial illumination. For this example we will use
  211. \GMTprog{grdmath} to make a grid file that contains the surface given
  212. by the function $z(x, y) = \cos (2\pi r/8)\cdot e^{-r/10}$, where
  213. $r^2 = (x^2 + y^2)$. The illumination is obtained by passing
  214. two grid files to \GMTprog{grdview}: One with the \emph{z}-values
  215. (the surface) and another with intensity values (which should
  216. be in the \PM 1 range). We use \GMTprog{grdgradient} to compute
  217. the horizontal gradients in the direction of the artificial
  218. light source. The \filename{gray.cpt} file only has one line that states
  219. that all \emph{z} values should have the gray level 128. Thus,
  220. variations in shade are entirely due to variations in gradients,
  221. or illuminations. We choose to illuminate from the SW and view
  222. the surface from SE:
  223. \script{example_05}
  224. The variations in intensity could be made more dramatic by
  225. using \GMTprog{grdmath} to scale the intensity file before
  226. running \GMTprog{grdview}. For very rough data sets one may
  227. improve the smoothness of the intensities by passing the
  228. output of \GMTprog{grdgradient} to \GMTprog{grdhisteq}. The
  229. shell-script above will result in a plot like the one in
  230. Figure~\ref{fig:GMT_example_05}.
  231. \GMTexample{05}{3-D illuminated surface.}
  232. \index{Example!3-D illuminated surface|)}
  233. \section{Plotting of histograms}
  234. \index{Example!histograms|(}
  235. \GMT\ provides two tools to render histograms: \GMTprog{pshistogram}
  236. and \GMTprog{psrose}. The former takes care of regular histograms
  237. whereas the latter deals with polar histograms (rose diagrams,
  238. sector diagrams, and wind rose diagrams). We will show an
  239. example that involves both programs. The file \filename{fractures.yx}
  240. contains a compilation of fracture lengths and directions as
  241. digitized from geological maps. The file \filename{v3206.t} contains
  242. all the bathymetry measurements from \emph{Vema} cruise 3206.
  243. Our complete figure (Figure~\ref{fig:GMT_example_06}) was made running
  244. this script:
  245. \script{example_06}
  246. \GMTexample{06}{Two kinds of histograms.}
  247. \index{Example!histograms|)}
  248. \section{A simple location map}
  249. \index{Example!location map|(}
  250. Many scientific papers start out by showing a location map
  251. of the region of interest. This map will typically also
  252. contain certain features and labels. This example will
  253. present a location map for the equatorial Atlantic ocean,
  254. where fracture zones and mid-ocean ridge segments have been
  255. plotted. We also would like to plot earthquake locations
  256. and available isochrons. We have obtained one file,
  257. \filename{quakes.xym}, which contains the position and magnitude of
  258. available earthquakes in the region. We choose to use
  259. magnitude/100 for the symbol-size in inches. The digital
  260. fracture zone traces (\filename{fz.xy}) and isochrons (0 isochron as
  261. \filename{ridge.xy}, the rest as \filename{isochrons.xy}) were digitized from
  262. available maps\footnote{These data are available on CD-ROM from NGDC (www.ngdc.noaa.gov).}.
  263. We create the final location map
  264. (Figure~\ref{fig:GMT_example_07}) with the following script:
  265. \script{example_07}
  266. \GMTexample{07}{A typical location map.}
  267. The same figure could equally well be made in color, which
  268. could be rasterized and made into a slide for a meeting
  269. presentation. The script is similar to the one outlined
  270. above, except we would choose a color for land and oceans,
  271. and select colored symbols and pens rather than black and white.
  272. \index{Example!location map|)}
  273. \section{A 3-D histogram}
  274. \index{Example!3-D histogram|(}
  275. The program \GMTprog{psxyz} allows us to plot three-dimensional
  276. symbols, including columnar plots. As a simple demonstration,
  277. we will convert a gridded netCDF of bathymetry into an
  278. ASCII $xyz$ table and use the height information to draw a
  279. 2-D histogram in a 3-D perspective view. Our gridded
  280. bathymetry file is called \filename{guinea\_bay.nc} and covers the region
  281. from 0 to 5 \DS E and 0 to 5 \DS N. Depth ranges from
  282. -5000 meter to sea-level. We produce the Figure~\ref{fig:GMT_example_08} by
  283. running this script:
  284. \script{example_08}
  285. \GMTexample{08}{A 3-D histogram.}
  286. \index{Example!3-D histogram|)}
  287. \section{Plotting time-series along tracks}
  288. \index{Example!wiggles|(}
  289. A common application in many scientific disciplines involves
  290. plotting one or several time-series as as ``wiggles'' along
  291. tracks. Marine geophysicists often display magnetic anomalies
  292. in this manner, and seismologists use the technique when
  293. plotting individual seismic traces. In our example we will
  294. show how a set of Geosat sea surface slope profiles from the
  295. south Pacific can be plotted as ``wiggles'' using the
  296. \GMTprog{pswiggle} program. We will embellish the plot with track
  297. numbers, the location of the Pacific-Antarctic Ridge, recognized
  298. fracture zones in the area, and a ``wiggle'' scale. The
  299. Geosat tracks are stored in the files \filename{*.xys}, the ridge in
  300. \filename{ridge.xy}, and all the fracture zones are stored in the multiple
  301. segment file \filename{fz.xy}. We extract the profile id (which is the
  302. first part of the file name for each profile) and the last point
  303. in each of the track files to construct an input file for
  304. \GMTprog{pstext} that will label each profile with the track
  305. number. We know the profiles trend approximately N40\DS E
  306. so we want the labels to have that same orientation (i.e., the
  307. angle with the baseline must be 50\DS ). We do this by
  308. extracting the last record from each track, paste this file
  309. with the \filename{tracks.lis} file, and use \progname{\$AWK} to create the
  310. format needed for \GMTprog{pstext}. Note we offset the positions
  311. by -0.05 inch with \Opt{D} in order to have a small gap
  312. between the profile and the label:
  313. \script{example_09}
  314. The output shows the sea-surface slopes along 42 descending
  315. Geosat tracks in the Eltanin and Udintsev fracture zone
  316. region in a Mercator projection (Figure~\ref{fig:GMT_example_09}).
  317. \GMTexample{09}{Time-series as ``wiggles'' along a track.}
  318. \index{Example!wiggles|)}
  319. \section{A geographical bar graph plot}
  320. \index{Example!bar graph|(}
  321. Our next and perhaps most business-like example presents a
  322. three-dimensional bar graph plot showing the geographic
  323. distribution of the membership in the American Geophysical
  324. Union (AGU). The input data was taken from the January 2008 AGU
  325. member directory and added up to give total members per
  326. continent. We decide to plot a 3-D column centered on
  327. each continent with a height that is proportional to the
  328. logarithm of the membership. A log$_{10}$-scale is
  329. used since the memberships vary by almost 3 orders of
  330. magnitude. We choose a plain linear projection for the
  331. basemap and add the columns and text on top. Our script that produces Figure~\ref{fig:GMT_example_10} reads:
  332. \script{example_10}
  333. \GMTexample{10}{Geographical bar graph.}
  334. \index{Example!bar graph|)}
  335. \section{Making a 3-D RGB color cube}
  336. \index{Example!3-D RGB color cube|(}
  337. In this example we generate a series of 6 color images,
  338. arranged so that they can be cut out
  339. and assembled into a 3-D color cube. The six faces of
  340. the cube represent the outside of the R-G-B color space.
  341. On each face one of the color components is fixed at either
  342. 0 or 255 and the other two components vary smoothly across
  343. the face from 0 to 255. The cube is configured as a
  344. right-handed coordinate system with \emph{x-y-z} mapping
  345. R-G-B. Hence, the 8 corners of the cube represent the
  346. primaries red, green, and blue, plus the secondaries cyan,
  347. magenta and yellow, plus black and white.
  348. The 6 color faces are generated by feeding \GMTprog{grdimage} three grids, one for each color
  349. component (R, G, and B). In some cases the X or Y axes of a face are reversed by specifying a
  350. negative width or height in order to change the variation of the color value in that direction from
  351. ascending to descending, or vice versa.
  352. A number of rays emanating from the white and black corners indicate the Hue value (ranging from 0 to
  353. 360\DS). The dashed and dotted lines near the white corner reflect saturation levels, running from 0
  354. to 1 (in black font). On these 3 faces the brightness is a constant value of 1.
  355. On the other 3 faces of the cube, around the black corner, the white decimal numbers indicate
  356. brightnesses between 0 and 1, with saturation fixed at 1.
  357. Here is the shell script to generate the RGB cube in Figure~\ref{fig:GMT_example_11}:
  358. \script{example_11}
  359. \GMTexample[width=\textwidth]{11}{The RGB color cube.}
  360. \index{Example!3-D RGB color cube|)}
  361. \section{Optimal triangulation of data}
  362. \label{sec:example_12}
  363. \index{Example!triangulation|(}
  364. Our next example (Figure~\ref{fig:GMT_example_12})
  365. operates on a data set of topographic
  366. readings non-uniformly distributed in the plane (Table
  367. 5.11 in Davis: \emph{Statistics and Data Analysis in Geology},
  368. J. Wiley). We use \GMTprog{triangulate} to perform the optimal
  369. Delaunay triangulation, then use the output to draw the
  370. resulting network. We label the node numbers as well as
  371. the node values, and call \GMTprog{pscontour} to make a contour
  372. map and image directly from the raw data. Thus, in this
  373. example we do not actually make grid files but still
  374. are able to contour and image the data. We use a color
  375. palette table \filename{topo.cpt} (created via \GMTprog{minmax} and \GMTprog{makecpt}).
  376. The script becomes:
  377. \script{example_12}
  378. \GMTexample{12}{Optimal triangulation of data.}
  379. \index{Example!triangulation|)}
  380. \section{Plotting of vector fields}
  381. \index{Example!vector fields|(}
  382. In many areas, such as fluid dynamics and elasticity,
  383. it is desirable to plot vector fields of various kinds.
  384. \GMT\ provides a way to illustrate 2-component vector fields
  385. using the \GMTprog{grdvector} utility. The two components of
  386. the field (Cartesian or polar components) are stored in
  387. separate grid files. In this example we use \GMTprog{grdmath}
  388. to generate a surface $z(x, y) = x \cdot \exp(-x^2 -y^2)$
  389. and to calculate $\nabla z$ by
  390. returning the \emph{x}- and \emph{y}-derivatives separately.
  391. We superpose the gradient vector field and the surface
  392. \emph{z} and also plot the components of the gradient
  393. in separate windows.
  394. A \GMTprog{pstext} call to place a header finishes the plot
  395. (Figure~\ref{fig:GMT_example_13}:
  396. \script{example_13}
  397. \GMTexample{13}{Display of vector fields in \gmt.}
  398. \index{Example!vector fields|)}
  399. \section{Gridding of data and trend surfaces}
  400. \index{Example!gridding and trend surfaces|(}
  401. This example shows how one goes from randomly spaced data
  402. points to an evenly sampled surface. First we plot the
  403. distribution and values of our raw data set (same as in
  404. Section~\ref{sec:example_12}). We choose an equidistant grid and run
  405. \GMTprog{blockmean} which preprocesses the data to avoid aliasing.
  406. The dashed lines indicate the logical blocks used by
  407. \GMTprog{blockmean}; all points inside a given bin will be averaged.
  408. The logical blocks are drawn from a temporary file we make on
  409. the fly within the shell script. The processed data is then
  410. gridded with the \GMTprog{surface} program and contoured every 25
  411. units. A most important point here is that \GMTprog{blockmean},
  412. \GMTprog{blockmedian}, or \GMTprog{blockmode} should always be run
  413. prior to running \GMTprog{surface}, and both of these steps must use the same
  414. grid interval. We use \GMTprog{grdtrend} to fit a bicubic trend
  415. surface to the gridded data, contour it as well, and sample
  416. both grid files along a diagonal transect using \GMTprog{grdtrack}.
  417. The bottom panel compares the gridded (solid line) and bicubic
  418. trend (dashed line) along the transect using \GMTprog{psxy}
  419. (Figure~\ref{fig:GMT_example_14}):
  420. \script{example_14}
  421. \GMTexample[scale=0.6]{14}{Gridding of data and trend surfaces.}
  422. \index{Example!gridding and trend surfaces|)}
  423. \section{Gridding, contouring, and masking of unconstrained areas}
  424. \label{sec:example_15}
  425. \index{Example!gridding, contouring, and masking|(}
  426. This example (Figure~\ref{fig:GMT_example_15}) demonstrates
  427. some off the different ways one
  428. can use to grid data in \GMT, and how to deal with unconstrained
  429. areas. We first convert a large ASCII file to binary with
  430. \GMTprog{gmtconvert} since the binary file will read and process
  431. much faster. Our lower left plot illustrates the results of
  432. gridding using a nearest neighbor technique (\GMTprog{nearneighbor})
  433. which is a local method: No output is given where there are no data.
  434. Next (lower right), we use a minimum curvature technique
  435. (\GMTprog{surface}) which is a global method. Hence, the contours
  436. cover the entire map although the data are only available for
  437. portions of the area (indicated by the gray areas plotted using
  438. \GMTprog{psmask}). The top left scenario illustrates how we can
  439. create a clip path (using \GMTprog{psmask}) based on the data coverage
  440. to eliminate contours outside the constrained area.
  441. Finally (top right) we simply employ \GMTprog{pscoast} to overlay
  442. gray land masses to cover up the unwanted contours, and end by
  443. plotting a star at the deepest point on the map with \GMTprog{psxy}.
  444. This point was extracted from the grid files using \GMTprog{grdinfo}.
  445. \script{example_15}
  446. \GMTexample[scale=0.6]{15}{Gridding, contouring, and masking of data.}
  447. \index{Example!gridding, contouring, and masking|)}
  448. \section{Gridding of data, continued}
  449. \index{Example!gridding|(}
  450. \GMTprog{pscontour} (for contouring) and \GMTprog{triangulate}
  451. (for gridding) use the simplest method of interpolating
  452. data: a Delaunay triangulation (see Section~\ref{sec:example_12}) which
  453. forms $z(x, y)$ as a union of planar triangular facets.
  454. One advantage of this method is that it will not extrapolate
  455. $z(x, y)$ beyond the convex hull of the input (\emph{x, y})
  456. data. Another is that it will not estimate a \emph{z} value
  457. above or below the local bounds on any triangle.
  458. A disadvantage is that the $z(x, y)$ surface is not
  459. differentiable, but has sharp kinks at triangle edges and
  460. thus also along contours. This may not look physically
  461. reasonable, but it can be filtered later (last panel below).
  462. \GMTprog{surface} can be used to generate a higher-order
  463. (smooth and differentiable) interpolation of $z(x, y)$ onto
  464. a grid, after which the grid may be illustrated (\GMTprog{grdcontour},
  465. \GMTprog{grdimage}, \GMTprog{grdview}). \GMTprog{surface} will interpolate
  466. to all (\emph{x, y}) points in a rectangular region, and thus
  467. will extrapolate beyond the convex hull of the data. However,
  468. this can be masked out in various ways (see Section~\ref{sec:example_15}).
  469. A more serious objection is that \GMTprog{surface} may estimate
  470. \emph{z} values outside the local range of the data (note area
  471. near \emph{x} = 0.8, \emph{y} = 5.3). This commonly happens when
  472. the default tension value of zero is used to create a ``minimum
  473. curvature'' (most smooth) interpolant. \GMTprog{surface} can be
  474. used with non-zero tension to partially overcome this problem.
  475. The limiting value $tension = 1$ should approximate the triangulation,
  476. while a value between 0 and 1 may yield a good compromise between
  477. the above two cases. A value of 0.5 is shown here
  478. (Figure~\ref{fig:GMT_example_16}). A side
  479. effect of the tension is that it tends to make the contours turn
  480. near the edges of the domain so that they approach the edge from
  481. a perpendicular direction. A solution is to use \GMTprog{surface}
  482. in a larger area and then use \GMTprog{grdcut} to cut out the desired
  483. smaller area. Another way to achieve a compromise is to
  484. interpolate the data to a grid and then filter the grid using
  485. \GMTprog{grdfft} or \GMTprog{grdfilter}. The latter can handle grids
  486. containing ``NaN'' values and it can do median and mode filters
  487. as well as convolutions. Shown here is \GMTprog{triangulate} followed
  488. by \GMTprog{grdfilter}. Note that the filter has done some
  489. extrapolation beyond the convex hull of the original \emph{x, y}
  490. values. The ``best'' smooth approximation of $z(x, y)$ depends
  491. on the errors in the data and the physical laws obeyed by \emph{z}.
  492. \GMT\ cannot always do the ``best'' thing but it offers great
  493. flexibility through its combinations of tools. We illustrate all
  494. four solutions using a CPT file that contains color fills,
  495. predefined patterns for interval (900,925) and NaN, an image pattern for interval (875,900),
  496. and a ``skip slice'' request for interval (700,725).
  497. \script{example_16}
  498. \GMTexample[scale=0.6]{16}{More ways to grid data.}
  499. \index{Example!gridding|)}
  500. \section{Images clipped by coastlines}
  501. \index{Example!image clipping|(}
  502. This example demonstrates how \GMTprog{pscoast} can be used
  503. to set up clip paths based on coastlines. This approach
  504. is well suited when different gridded data sets are to be
  505. merged on a plot using different color palette files.
  506. Merging the files themselves may not be doable since they
  507. may represent different data sets, as we show in this example.
  508. Here, we lay down a color map of the geoid field near India
  509. with \GMTprog{grdimage}, use \GMTprog{pscoast} to set up land
  510. clip paths, and then overlay topography from the ETOPO5 data
  511. set with another call to \GMTprog{grdimage}. We finally undo
  512. the clippath with a second call to \GMTprog{pscoast} with the
  513. option \Opt{Q} (Figure~\ref{fig:GMT_example_17}):
  514. \script{example_17}
  515. \GMTexample{17}{Clipping of images using coastlines.}
  516. We also plot a color legend on top of the land. So here we basically have three
  517. layers of ``paint'' stacked on top of each other: the underlaying geoid map,
  518. the land mask, and finally the color legend. This legend makes clear how
  519. \GMTprog{grd2cpt} distributed the colors over the range: they are not of equal
  520. length put are associated with equal amounts of area in the plot. Since the high
  521. amounts (in red) are not very prevalent, that color spans a long range.
  522. For this image it is appropriate to use the \Opt{I} option in \GMTprog{psscale}
  523. so the legend gets shaded, similar to the geoid grid.
  524. See Appendix~\ref{app:M} to learn more about color palettes and ways to draw color legends.
  525. \index{Example!image clipping|)}
  526. \section{Volumes and Spatial Selections}
  527. \index{Example!spatial selections|(}
  528. To demonstrate potential usage of the new programs
  529. \GMTprog{grdvolume} and \GMTprog{gmtselect} we extract a subset
  530. of the Sandwell \& Smith altimetric gravity field\footnote{
  531. See http://topex.ucsd.edu/marine\_grav/mar\_grav.html.}
  532. for the northern Pacific and decide to isolate all seamounts that
  533. (1) exceed 50 mGal in amplitude and (2) are within 200 km
  534. of the Pratt seamount. We do this by dumping the 50 mGal
  535. contours to disk, then making a simple \progname{\$AWK} script
  536. \filename{center.awk} that returns the mean location of the points
  537. making up each closed polygon, and then pass these locations
  538. to \GMTprog{gmtselect} which retains only the points within 200
  539. km of Pratt. We then mask out all the data outside this
  540. radius and use \GMTprog{grdvolume} to determine the combined
  541. area and volumes of the chosen seamounts.
  542. Our illustration is presented in Figure~\ref{fig:GMT_example_18}.
  543. \script{example_18}
  544. \GMTexample{18}{Volumes and geo-spatial selections.}
  545. \index{Example!spatial selections|)}
  546. \section{Color patterns on maps}
  547. \index{Example!color patterns|(}
  548. \index{Example!PostScript inclusions|(}
  549. \GMT\ 3.1 introduced color patterns and this examples give
  550. a few cases of how to use this new feature. We make a phony
  551. poster that advertises an international conference on \GMT\
  552. in Honolulu. We use \GMTprog{grdmath}, \GMTprog{makecpt}, and
  553. \GMTprog{grdimage} to draw pleasing color backgrounds on maps,
  554. and overlay \GMTprog{pscoast} clip paths to have the patterns
  555. change at the coastlines. The middle panel demonstrates a
  556. simple \GMTprog{pscoast} call where the built-in pattern \# 86
  557. is drawn at 100 dpi but with the black and white pixels
  558. replaced with color combinations. At the same time the ocean is filled with a repeating
  559. image of a circuit board (provides in Sun raster format).
  560. The text \GMT\ in the center is an off-line \PS\ file that was overlaid using \GMTprog{psimage}.
  561. The final panel repeats the top panel except that the land and sea images have changed places
  562. (Figure~\ref{fig:GMT_example_19}).
  563. \script{example_19}
  564. \GMTexample[width=0.9\textwidth]{19}{Using color patterns and additional PostScript material in illustrations.}
  565. \index{Example!PostScript inclusions|)}
  566. \index{Example!color patterns|)}
  567. \section{Custom plot symbols}
  568. \index{Example!custom plot symbols|(}
  569. One is often required to make special maps that shows the
  570. distribution of certain features but one would prefer to
  571. use a custom symbol instead of the built-in circles,
  572. squares, triangles, etc. in the \GMT\ plotting programs
  573. \GMTprog{psxy} and \GMTprog{psxyz}. Here we demonstrate one
  574. approach that allows for a fair bit of flexibility in
  575. designing ones own symbols. The following recipe is used
  576. when designing a new symbol.
  577. \begin{enumerate}
  578. \item Use \GMTprog{psbasemap} (or
  579. engineering paper!) to set up an empty grid that goes from
  580. -0.5 to +0.5 in both \emph{x} and \emph{y}. Use ruler and
  581. compass to draw your new symbol using straight lines,
  582. arcs of circles, and stand-alone geometrical objects (see \GMTprog{psxy} man page for
  583. a full description of symbol design). In this Section we will create two new symbols:
  584. a volcano and a bulls eye.
  585. \begin{figure}[ht]
  586. \centering\includegraphics{GMT_volcano}
  587. \end{figure}
  588. \item After designing the symbol we will encode it using a
  589. simple set of rules. In our case we describe our volcano and bulls eye
  590. using these three freeform polygon generators:
  591. \begin{tabbing}
  592. $x_0$ $y_0$ $r$ \textbf{C} [ \Opt{G}\emph{fill} ] [ \Opt{W}\emph{pen} ] \=Draw \kill
  593. $x_0$ $y_0$ \textbf{M} [ \Opt{G}\emph{fill} ] [ \Opt{W}\emph{pen} ] \> Start new element at $x_0$, $y_0$ \\
  594. $x_1$ $y_1$ \textbf{D} \> Draw straight line from current point to $x_1$, $y_1$ around ($x_0$, $y_0$) \\
  595. $x_0$ $y_0$ $r$ $\alpha_1$ $\alpha_2$ \textbf{A} \> Draw
  596. arc segment of radius $r$ from angle $\alpha_1$ to $\alpha_2$
  597. \end{tabbing}
  598. We also add a few stand-alone circles (for other symbols, see \GMTprog{psxy} man page):
  599. \begin{tabbing}
  600. $x_0$ $y_0$ $r$ \textbf{C} [ \Opt{G}\emph{fill} ] [ \Opt{W}\emph{pen} ] \=Draw \kill
  601. $x_0$ $y_0$ $r$ \textbf{c} [ \Opt{G}\emph{fill} ] [ \Opt{W}\emph{pen} ] \> Draw
  602. single circle of radius $r$ around $x_0$, $y_0$ \\
  603. \end{tabbing}
  604. The optional \Opt{G} and \Opt{W} can be used to hardwire
  605. the color fill and pen for segments (use \textbf{--} to disallow
  606. fill or line for any specific feature). By default the segments
  607. are painted based on the values of the command line settings.
  608. Manually applying these rules to our volcano symbol results in a
  609. definition file \filename{volcano.def}:
  610. \script{volcano}
  611. Without much further discussion we also make a definition file \filename{bullseye.def} for a multi-colored bulls eye symbol.
  612. Note that the symbol can be created beyond the -0.5 to +0.5 range, as shown by the red lines. There is no limit in
  613. \GMT\ to the size of the symbols. The center, however, will always be at (0,0). This is the point to which the
  614. coordinates in \GMTprog{psxy} refers.
  615. \script{bullseye}
  616. The values refer to positions and dimensions illustrated in the Figure above.
  617. \item Given proper definition files we may now use them with \GMTprog{psxy} or \GMTprog{psxyz}.
  618. \end{enumerate}
  619. We are now ready to give it a try. Based on the hotspot
  620. locations in the file \filename{hotspots.d} (with a 3rd column
  621. giving the desired symbol sizes in inches) we lay down a
  622. world map and overlay red volcano symbols using our custom-built
  623. volcano symbol and \GMTprog{psxy}. We do something similar with the bulls eye symbols.
  624. Without the \Opt{G} option, however, they get the colors defined in \filename{bullseye.def}.
  625. Here is our final map script that produces Figure~\ref{fig:GMT_example_20}:
  626. \script{example_20}
  627. \GMTexample{20}{Using custom symbols in \gmt.}
  628. Given these guidelines you can easily make your own symbols.
  629. Symbols with more than one color can be obtained by making
  630. several symbol components. E.g., to have yellow smoke coming
  631. out of red volcanoes we would make two symbols: one with just
  632. the cone and caldera and the other with the bubbles. These
  633. would be plotted consecutively using the desired colors.
  634. Alternatively, like in \filename{bullseye.def}, we may
  635. specify colors directly for the various segments. Note that
  636. the custom symbols (Appendix~\ref{app:N}), unlike the built-in symbols in \GMT, can
  637. be used with the built-in patterns (Appendix~\ref{app:E}). Other
  638. approaches are also possible, of course.
  639. \index{Example!custom map symbols|)}
  640. \section{Time-series of RedHat stock price}
  641. \index{Example!RedHat stock price|(}
  642. As discussed in Section~\ref{sec:timeaxis}, the annotation of time-series
  643. is generally more complicated due to the extra degrees of freedom afforded
  644. by the dual annotation system. In this example we will display the trend
  645. of the stock price of RedHat (RHAT) from their initial public offering until
  646. late 2006. The data file is a comma-separated table and the records
  647. look like this:
  648. \begin{verbatim}
  649. Date,Open,High,Low,Close,Volume,Adj.Close*
  650. 12-Mar-04,17.74,18.49,17.67,18.02,4827500,18.02
  651. 11-Mar-04,17.60,18.90,17.37,18.09,7700400,18.09
  652. \end{verbatim}
  653. Hence, we have a single header record and various prices in USD for each
  654. day of business. We will plot the trend of the opening price as a red line superimposed on
  655. a yellow envelope representing the low-to-high fluctuation during each day. We
  656. also indicate when and at what cost Paul Wessel bought a few shares, and zoom in
  657. on the developments since 2004; in the inset we label the time-axis in Finnish in honor
  658. of Linus Thorvalds. Because the time coordinates are Y2K-challenged and the
  659. order is backwards (big units of years come \emph{after} smaller units like
  660. days) we must change the default input/output formats used by \GMT. Finally,
  661. we want to prefix prices with the \$ symbol to indicate the currency. Here is
  662. how it all comes out:
  663. \script{example_21}
  664. which produces the plot in Figure~\ref{fig:GMT_example_21}, suggesting Wessel
  665. has missed a few trains if he had hoped to cash in on the Internet bubble...
  666. \GMTexample{21}{Time-series of RedHat stock price since IPO.}
  667. \index{Example!RedHat stock price|)}
  668. \section{World-wide seismicity the last 7 days}
  669. \index{Example!world-wide seismicity|(}
  670. The next example uses the command-line tool \progname{wget} to obtain a data file
  671. from a specified URL\footnote{You can also use the utility \progname{curl}}.
  672. In the example script this line is commented out so the
  673. example will run even if you do not have \progname{wget} (we use the supplied
  674. \filename{neic\_quakes.d} which normally would be created by \progname{wget}); remove the comment to
  675. get the actual current seismicity plot using the live data. The main purpose of
  676. this script is not to show how to plot a map background and a few circles, but
  677. rather demonstrate how a map legend may be composed using the new tool \GMTprog{pslegend}.
  678. Some scripting is used to pull out information from the data file that is later
  679. used in the legend. The legend will normally have the email address of the script
  680. owner; here that command is commented out and the user is hardwired to ``GMT guru''.
  681. The USGS logo, taken from their web page and converted to a Sun raster file, is used
  682. to spice up the legend.
  683. \script{example_22}
  684. \GMTexample{22}{World-wide seismicity the last 7 days.}
  685. The script produces the plot in Figure~\ref{fig:GMT_example_22}, giving the URL
  686. where these and similar data can be obtained.
  687. \index{Example!world-wide seismicity|)}
  688. \section{All great-circle paths lead to Rome}
  689. \label{sec:example_23}
  690. \index{Example!paths to Rome|(}
  691. While motorists recently have started to question the old saying ``all roads lead to Rome'',
  692. aircraft pilots have known from the start that only one great-circle path connects the
  693. points of departure and arrival\footnote{Pedants who wish to argue about the ``other''
  694. arc going the long way should consider using it.}. This provides the inspiration for our next
  695. example which uses \GMTprog{grdmath} to calculate distances from Rome to anywhere on
  696. Earth and \GMTprog{grdcontour} to contour these distances. We pick five cities that
  697. we connect to Rome with great circle arcs, and label these cities with their names and
  698. distances (in km) from Rome, all laid down on top of a beautiful world map. Note that
  699. we specify that contour labels only be placed along the straight map-line connecting
  700. Rome to its antipode, and request curved labels that follows the shape of the contours.
  701. \script{example_23}
  702. \GMTexample{23}{All great-circle paths lead to Rome.}
  703. The script produces the plot in Figure~\ref{fig:GMT_example_23}; note how
  704. interesting the path to Seattle appears in this particular projection (Hammer).
  705. We also note that Rome's antipode lies somewhere near the Chatham plateau (antipodes
  706. will be revisited in Section~\ref{sec:example_25}).
  707. \index{Example!paths to Rome|)}
  708. \section{Data selection based on geospatial criteria}
  709. \index{Example!geospatial criteria|(}
  710. Although we are not seismologists, we have yet another example involving seismicity.
  711. We use seismicity data for the Australia/New Zealand region to demonstrate how we can
  712. extract subsets of data using geospatial criteria. In particular, we wish to plot
  713. the epicenters given in the file \filename{oz\_quakes.d} as red or green circles.
  714. Green circles should only be used for epicenters that satisfy the following three criteria:
  715. \begin{enumerate}
  716. \item They are located in the ocean and not on land
  717. \item They are within 3000 km of Hobart
  718. \item They are more than 1000 km away from the International Dateline
  719. \end{enumerate}
  720. All remaining earthquakes should be plotted in red. Rather that doing the selection
  721. process twice we simply plot all quakes as red circles and then replot those that
  722. pass our criteria. Most of the work here is done by \GMTprog{gmtselect}; the rest
  723. is carried out by the usual \GMTprog{pscoast} and \GMTprog{psxy} workhorses. Note
  724. for our purposes the Dateline is just a line along the 180\DS\ meridian.
  725. \script{example_24}
  726. \GMTexample{24}{Data selection based on geospatial criteria.}
  727. The script produces the plot in Figure~\ref{fig:GMT_example_24}. Note that the
  728. horizontal distance from the dateline seems to increase as we go south; however that
  729. is just the projected distance (Mercator distortion) and not the actual distance
  730. which remains constant at 1000 km.
  731. \index{Example!geospatial criteria|)}
  732. \section{Global distribution of antipodes}
  733. \label{sec:example_25}
  734. \index{Example!distribution of antipodes|(}
  735. As promised in Section~\ref{sec:example_23}, we will study antipodes. The antipode of a point at
  736. $(\phi, \lambda)$ is the point at $(-\phi, \lambda + 180)$. We seek an answer
  737. to the question that has plagued so many for so long: Given the distribution of
  738. land and ocean, how often is the antipode of a point on land also on land? And
  739. what about marine antipodes? We use \GMTprog{grdlandmask} and \GMTprog{grdmath}
  740. to map these distributions and calculate the area of the Earth (in percent)
  741. that goes with each of the three possibilities. To make sense of our \GMTprog{grdmath}
  742. equations below, note that we first calculate a grid that is +1 when a point and its
  743. antipode is on land, -1 if both are in the ocean, and 0 elsewhere. We then
  744. seek to calculate the area distribution of dry antipodes by only pulling out the nodes
  745. that equal +1. As each point represent an area approximated by $\Delta \phi \times \Delta \lambda$
  746. where the $\Delta \lambda$ term's actual dimension depends on $\cos (\phi)$, we need
  747. to allow for that shrinkage, normalize our sum to that of the whole area of the Earth,
  748. and finally convert that ratio to percent. Since the $\Delta \lambda$, $\Delta \phi$ terms
  749. appear twice in these expressions they cancel out, leaving the somewhat
  750. intractable expressions below where the sum of $\cos (\phi)$ for all $\phi$ is known to equal $2N_y / \pi$:
  751. \script{example_25}
  752. In the end we obtain a funny-looking map depicting the antipodal distribution as
  753. well as displaying in legend form the requested percentages (Figure~\ref{fig:GMT_example_25}).
  754. Note that the script is set to evaluate a global 30 minute grid for expediency ($D = 30$), hence
  755. several smaller land masses that do have terrestrial antipodes do not show up. If you want
  756. a more accurate map you can set the parameter $D$ to a smaller increment (try 5 and wait a
  757. few minutes).
  758. The call to \GMTprog{grdimage} includes the \Opt{-Sn} to suspend interpolation and only
  759. return the value of the nearest neighbor. This option is particularly practical for plotting
  760. categorical data, like these, that should not be interpolated.
  761. \GMTexample[width=\textwidth]{25}{Global distribution of antipodes.}
  762. \index{Example!distribution of antipodes|)}
  763. \section{General vertical perspective projection}
  764. \index{Example!vertical perspective projection|(}
  765. Next, we present a recent extension to the \Opt{JG} projection option which allows the user
  766. to specify a particular altitude (this was always at infinity before), as well as several
  767. further parameters to limit the view from the chosen vantage point. In this example we show
  768. a view of the eastern continental US from a height of 160 km. Below we add a view with a specific tilt of
  769. 55\DS\ and azimuth 210\DS; here we have chosen a boresight twist of 45\DS. We view the land from
  770. New York towards Washington, D.C.
  771. \script{example_26}
  772. At this point the full projection has not been properly optimized and the map annotations will need
  773. additional work. Also, note that the projection is only implemented in \GMTprog{pscoast} and \GMTprog{grdimage}.
  774. We hope to refine this further and extend the availability of the full projection to all of the
  775. \GMT\ mapping programs.
  776. \GMTexample{26}{General vertical perspective projection.}
  777. \index{Example!vertical perspective projection|)}
  778. \section{Plotting Sandwell/Smith Mercator img grids}
  779. \index{Example!Mercator img grids|(}
  780. Next, we show how to plot a data grid that is distributed in projected form. The gravity and
  781. predicted bathymetry grids produced by David Sandwell and Walter H. F. Smith are not geographical
  782. grids but instead given on a spherical Mercator grid. The \GMT\ supplement imgsrc has tools to
  783. extract subsets of these large grids. If you need to make a non-Mercator map then you must extract
  784. a geographic grid using \GMTprog{img2grd} and then plot it using your desired map projection.
  785. However, if you want to make a Mercator map then you can save time and preserve data quality by
  786. avoiding to re-project the data set twice since it is already in a Mercator projection. This example
  787. shows how this is accomplished. We use the \Opt{M} option in \GMTprog{img2grd}\footnote{You could
  788. also use \GMTprog{img2mercgrd} directly -- your only option under DOS} to pull out the
  789. grid in Mercator units (i.e., do \emph{not} invert the Mercator projection) and then simply plot the
  790. grid using a linear projection with a suitable scale (here 0.25 inches per degrees of longitude).
  791. To overlay basemaps and features that has geographic longitude/latitude coordinates we must remember
  792. two key issues:
  793. \begin{enumerate}
  794. \item This is a \emph{spherical} Mercator grid so we must use \textbf{--PROJ\_ELLIPSOID}=Sphere with all
  795. commands that involve projections (or use \GMTprog{gmtset} to change the setting).
  796. \item Select Mercator projection and use the same scale that was used with the linear projection.
  797. \end{enumerate}
  798. \script{example_27}
  799. This map of the Tasman Sea shows the marine gravity anomalies with land painted black. A color scale bar
  800. was then added to complete the illustration.
  801. \GMTexample{27}{Plotting Sandwell/Smith Mercator img grids.}
  802. \index{Example!Mercator img grids|)}
  803. \section{Mixing UTM and geographic data sets}
  804. \index{Example!Mixing UTM and geographic data|(}
  805. Next, we present a similar case: We wish to plot a data set given in UTM coordinates and want it
  806. to be properly registered with overlying geographic data, such as coastlines or data points. The
  807. mistake many \GMT\ rookies make is to specify the UTM projection with their UTM
  808. data. However, that data have already been projected and is now in linear meters. The only
  809. sensible way to plot such data is with a linear projection, yielding a UTM map. In this step one can
  810. choose to annotate or tick the map in UTM meters as well. To plot geographic (lon/lat) data on
  811. the same map there are a few things you must consider:
  812. \begin{enumerate}
  813. \item You need to know the lower left and upper right UTM coordinates of your map. Given
  814. the UTM zone you can use \GMTprog{mapproject} to recover the lon/lat of those two points.
  815. Conversely, if you instead know the lon/lat corners then you need to convert those
  816. to UTM coordinates. You now have the ability to specify two domains with the \Opt{R} setting:
  817. The linear UTM meter domain when plotting UTM data and the geographic domain (remember to use the
  818. rectangular variant of \Opt{R} that ends with the modifier \textbf{r}) when plotting lon/lat data.
  819. \item Make sure you use the same scale (and not width) with both the linear and UTM projection.
  820. \end{enumerate}
  821. \script{example_28}
  822. Our script illustrates how we would plot a UTM grid of elevations near Kilauea volcano on the Big Island
  823. of Hawaii. Given we are in UTM zone 5Q, the script determines the geographic coordinates of the
  824. lower left and upper right corner of the UTM grid, then uses that region when overlaying the coastline
  825. and light blue ocean. We place a scale bar and label Kilauea crater to complete the figure.
  826. \GMTexample{28}{Mixing UTM and geographic data sets requires knowledge of the map region domain in both
  827. UTM and lon/lat coordinates and consistent use of the same map scale.}
  828. \index{Example!Mixing UTM and geographic data|)}
  829. \section{Gridding spherical surface data using splines}
  830. \index{Example!Gridding spherical surface data using splines|(}
  831. Finally, we demonstrate how gridding on a spherical surface can be accomplished using Green's functions
  832. of surface splines, with or without tension. Global gridding does not work particularly well in
  833. Cartesian coordinates hence the chosen approach. We use \GMTprog{greenspline} to produce a crude
  834. topography grid for Mars based on radii estimates from the Mariner 9 and Viking Orbiter spacecrafts.
  835. This data comes from \emph{Smith and Zuber} [Science, 1996] and is used here as a small (\emph{N} = 370) data set we
  836. can use to demonstrate spherical surface gridding. Since \GMTprog{greenspline} must solve a \emph{N} by \emph{N}
  837. matrix system your system memory may impose limits on how large data sets you can handle; also note that
  838. the spherical surface spline in tension is particularly slow to compute.
  839. \script{example_29}
  840. Our script must first estimate the ellipsoidal shape of Mars from the parameters given by \emph{Smith and Zuber}
  841. so that we can remove this reference surface from the gridded radii. We run the gridding twice: First with
  842. no tension using \emph{Parker}'s [1990] method and then with tension using the \emph{Wessel and Becker} [2008] method.
  843. The grids are then imaged with \GMTprog{grdimage} and \GMTprog{grdcontour} and a color scale is placed between
  844. them.
  845. \GMTexample{29}{Gridding of spherical surface data using Green's function splines.}
  846. \index{Example!Gridding spherical surface data using splines|)}
  847. \section{Trigonometric functions plotted in graph mode}
  848. \index{Example!Trigonometric functions plotted in graph mode|(}
  849. Finally, we end with a simple mathematical illustration of sine and cosine, highlighting the
  850. \emph{graph} mode for linear projections and the new curved vectors for angles.
  851. \script{example_30}
  852. The script simply draws a graph basemap, computes sine and cosine and plots them as lines, then
  853. indicates on a circle that these quantities are simply the projections of an unit vector on the
  854. x- and y-axis, at the given angle.
  855. \GMTexample{30}{Trigonometric functions plotted in graph mode.}
  856. \index{Example!Trigonometric functions plotted in graph mode|)}
  857. \section{Using non-default fonts in \PS}
  858. \label{sec:non-default-fonts-example}
  859. \index{Example!Using non-default fonts in \PS|(}
  860. This example illustrates several possibilities to create \GMT\
  861. plots with non-default fonts. As these fonts are not part of the
  862. standard \PS\ font collection they have to be embedded in the PS-
  863. or PDF-file with \progname{Ghostscript}. See also
  864. Appendix~\ref{sec:non-default-fonts} for further information. The
  865. script includes the following steps:
  866. \begin{itemize}
  867. \item create a \filename{CUSTOM\_font\_info.d} file;
  868. \item set the \GMT\ parameters \verb#MAP_DEGREE_SYMBOL#,
  869. \verb#PS_CHAR_ENCODING#, and \verb#FONT#;
  870. \item replace the default Helvetica font in the \GMT-\PS-File with
  871. sed;
  872. \item create a \PS-File with outlined fonts (optional);
  873. \item convert \GMT's \PS\ output to PDF or any image format
  874. (optional).
  875. \end{itemize}
  876. \script{example_31}
  877. The script produces the plot in
  878. Figure~\ref{fig:GMT_example_31}. All standard fonts have been
  879. substituted by the free OpenType fonts Linux Libertine (title) and
  880. Linux Biolinum (annotations). Uncomment the appropriate lines in
  881. the script to make a \PS-file with outlined fonts or to convert to
  882. a PDF-file.
  883. \GMTexample{31}{Using non-default fonts in \PS.}
  884. \index{Example!Using non-default fonts in \PS|)}
  885. \section{Draping an image over topography}
  886. \index{Example!Draping an image over topography|(}
  887. In some cases, it is nice to ``drape'' an arbitrary image over a topographic map.
  888. We have already seen how to use \GMTprog{psimage} to plot an image anywhere in out plot.
  889. But here are aim is different, we want to manipulate an image to shade it and plot it in 3-D over topography.
  890. This example was originally created by Stephan Eickschen for a flyer emphasizing the historical economical and cultural
  891. bond between Brussels, Maastricht and Bonn. Obviously, the flag of the European Union came to mind as a good
  892. ``background''.
  893. To avoid adding large files to this example, some steps have been already done. First we get the EU flag
  894. directly from the web and convert it to a grid with values ranging from 0 to 255, where the higher values will become
  895. yellow and the lower values blue. This use of \GMTprog{grdreformat} requires GDAL support. \GMTprog{grdedit} then adds
  896. the right grid dimension.
  897. The second step is to reformat the GTOPO30 DEM file to a netCDF grid as well and then subsample it at the same pixels
  898. as the EU flag. We then illuminate the topography grid so we can use it later to emphasize the topography.
  899. The colors that we will use are those of the proper flag. Lower values will become blue and the upper values yellow.
  900. The call the \GMTprog{grdview} plots a topography map of northwest continental Europe, with the flagged draped over
  901. it and with shading to show the little topography there is.
  902. \GMTprog{pscoast} is used in conjunction with \GMTprog{grdtrack} and \GMT{psxyz} to plot borders ``at altitude''.
  903. Something similar is done at the end to plot some symbols and names for cities.
  904. \script{example_32}
  905. The script produces the plot in Figure~\ref{fig:GMT_example_32}. Note that the PNG image of the flag can be
  906. downloaded directly in the call the \GMTprog{grdreformat}, but we have commented that out in the example because
  907. it requires compilation with GDAL support. You will also see the \GMTprog{grdcut} command commented out because
  908. we did not want to store the 58 MB DEM file, whose location is mentioned in the script.
  909. \GMTexample[width=\textwidth]{32}{Draping an image over topography}
  910. \index{Example!Draping an image over topography|)}
Tip!

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

Comments

Loading...