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_Tutorial.tex 69 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
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
  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. \documentclass{report}
  10. \newcommand{\GMTTITLE}{A Map-making Tutorial}
  11. \input{GMT_macros}
  12. \makeindex
  13. %--------------------------------------------------------------------------
  14. \begin{document}
  15. \pagenumbering{roman}
  16. \input{GMT_Cover}
  17. \addcontentsline{toc}{chapter}{Front page}
  18. \clearpage
  19. \thispagestyle{headings}
  20. \tableofcontents
  21. %\addcontentsline{toc}{chapter}{Contents}
  22. \chapter*{INTRODUCTION}
  23. \pagenumbering{arabic}
  24. \thispagestyle{headings}
  25. \addcontentsline{toc}{chapter}{INTRODUCTION}
  26. \index{Purpose of tutorial}
  27. The purpose of this tutorial is to introduce new users to \GMT,
  28. outline the \GMT\ environment, and enable you to make several
  29. forms of graphics without having to know too much about \UNIX\
  30. and \UNIX\ tools. We will not be able to cover all aspects of
  31. \GMT\ nor will we necessarily cover the selected topics in
  32. sufficient detail. Nevertheless, it is hoped that the exposure
  33. will prompt the users to improve their \GMT\ and \UNIX\ skills
  34. after completion of this short tutorial.
  35. \section*{\gmt\ overview: History, philosophy, and usage}
  36. \addcontentsline{toc}{section}{\gmt\ overview: History, philosophy, and usage}
  37. \subsection*{Historical highlights}
  38. \addcontentsline{toc}{subsection}{Historical highlights}
  39. \index{GMT@\GMT!history}
  40. The \GMT\ system was initiated in late 1987 at Lamont-Doherty
  41. Earth Observatory, Columbia University by graduate students Paul
  42. Wessel and Walter H. F. Smith. Version 1 was officially introduced
  43. to Lamont scientists in July 1988. \GMT\ 1 migrated by word of mouth
  44. (and tape) to other institutions in the United States, UK, Japan, and
  45. France and attracted a small following. Paul took a Post-doctoral
  46. position at SOEST in December 1989 and continued the \GMT\ development.
  47. Version 2.0 was released with an article in EOS, October 1991, and
  48. quickly spread worldwide. We obtained NSF-funding for \GMT\
  49. version 3.0 in 1993 which was released with another article in EOS
  50. on August 15, 1995. Significantly improved versions (3.1-3.3,
  51. 3.3.1--6), 3.4, 3.4.1--5, and 4.0--4.5.0 were released between November 1998 and
  52. July 2009, culminating in the \GMTDOCDATE\ introduction of \GMTDOCVERSION.
  53. \GMT\ now is used by $\sim$15,000 users worldwide in a broad range of disciplines.
  54. \subsection*{Philosophy}
  55. \addcontentsline{toc}{subsection}{Philosophy}
  56. \index{GMT@\GMT!philosophy}
  57. \GMT\ follows the \UNIX\ philosophy in which complex tasks are broken
  58. down into smaller and more manageable components. Individual \GMT\
  59. modules are small, easy to maintain, and can be used as any other
  60. \UNIX\ tool. \GMT\ is written in the ANSI C programming language
  61. (very portable), is POSIX compliant, and is independent of
  62. hardware constraints (e.g., memory). \GMT\ was deliberately written
  63. for command-line usage, not a windows environment, in order to
  64. maximize flexibility. We standardized early on to use \PS\ output
  65. instead of other graphics formats. Apart from the built-in support for
  66. coastlines, \GMT\ completely decouples data retrieval from the main
  67. \GMT\ programs. \GMT\ uses architecture-independent file formats.
  68. \subsection*{Why is \gmt\ so popular?}
  69. \addcontentsline{toc}{subsection}{Why is \gmt\ so popular?}
  70. \index{GMT@\GMT!popularity}
  71. The price is right! Also, \GMT\ offers unlimited flexibility since
  72. it can be called from the command line, inside scripts, and from user
  73. programs. \GMT\ has attracted many users because of its high quality
  74. \PS\ output. \GMT\ easily installs on almost any computer.
  75. \subsection*{\gmt\ installation considerations}
  76. \addcontentsline{toc}{subsection}{\gmt\ installation considerations}
  77. \index{GMT@\GMT!installation}
  78. \GMT\ has been installed on machines ranging from super-computers
  79. to lap-top PCs. \GMT\ only contains some 100,000 lines of code and
  80. has modest space/memory requirements. Minimum requirements are
  81. \index{GMT@\GMT!requirements}
  82. \begin{itemize}
  83. \item The netCDF library 3.4 or higher (free from www.unidata.edu).
  84. \item A C Compiler (free from www.gnu.org).
  85. \item About 100 Mb disk space (70 Mb additional for full- and
  86. high-resolution coast-lines).
  87. \item About 32 Mb memory.
  88. \end{itemize}
  89. In addition, we recommend access to a \PS\ printer or equivalent
  90. (e.g., \progname{ghostscript}), \PS\ previewer (e.g., \progname{ghostview}),
  91. any flavor of the \UNIX\ operating system, and more disk space and memory.
  92. \chapter{SESSION ONE}
  93. \thispagestyle{headings}
  94. \section{Tutorial setup}
  95. \begin{enumerate}
  96. \item We assume that \GMT\ has been properly and fully
  97. installed and that the \GMT\ executables are in your executable path
  98. described in the \GMT\ \filename{README} file.
  99. \item All \GMT\ man pages, documentation, and example scripts
  100. are available from the \GMT\ documentation web page. It is
  101. assumed these pages have been installed locally at your site;
  102. if not they are always available from the main
  103. \htmladdnormallinkfoot{GMT home page}{http://\GMTSITE}.
  104. \item We recommend you create a sub-directory called \filename{tutorial},
  105. cd into that directory, and copy all the tutorial files directly
  106. there. Depending on your installation the tutorial files are likely in \filename{/usr/share/doc/gmt/tutorial}.
  107. \item As we discuss \GMT\ principles it may be a good idea to
  108. consult the \GMT\ Technical Reference and Cookbook for more
  109. detailed explanations.
  110. \item The tutorial uses the supplemental \GMT\ program
  111. \GMTprog{grdraster} to extract subsets of global gridded data
  112. sets. For your convenience we also supply the subsets in the
  113. event you do not wish to install \GMTprog{grdraster} and the
  114. public data sets it can read. Thus, run the \GMTprog{grdraster}
  115. commands if you have made the installation or ignore them if
  116. you have not.
  117. \item For all but the simplest \GMT\ jobs it is recommended that
  118. you place all the \GMT\ (and \UNIX) commands in a shell script
  119. file and make it executable. To ensure that \UNIX\ recognizes
  120. your script as a shell script it is a good habit always to start
  121. the script with the line \#!/bin/sh or \#!/bin/csh, depending on the shell you prefer to use.
  122. All the examples in this tutorial assumes you are running the bourne shell, \progname{sh}; if you are using
  123. something different then you are on your own.
  124. \item Making a script executable is accomplished using the \texttt{chmod}
  125. command, e.g., the script \filename{figure\_1.sh} is made executable
  126. with ``\texttt{chmod +x figure\_1.sh}''.
  127. \item To view a \PS\ file (e.g., \filename{map.ps}) on a UNIX workstation
  128. we use \progname{ghostview} \filename{map.ps}. On some systems there
  129. will be similar commands, like \filename{imagetool} and \filename{pageview}
  130. on Sun workstations. In this text we will refer to
  131. \progname{ghostview}; please substitute the relevant \PS\ previewer
  132. on your system.
  133. \item Please cd into the directory \filename{tutorial}. We are
  134. now ready to start.
  135. \end{enumerate}
  136. \section{The \gmt\ environment: What happens when you run \gmt ?}
  137. \index{GMT@\GMT!environment}
  138. \index{Run-time environment}
  139. To get a good grasp on \GMT\ one must understand what is going on ``under
  140. the hood''. Figure~\ref{fig:GMT_Environment} illustrates the relationships
  141. you need to be aware of at run-time.
  142. \begin{figure}[h]
  143. \centering\includegraphics[width=0.8\textwidth]{GMT_Environment}
  144. \caption{The \gmt\ run-time environment.}
  145. \label{fig:GMT_Environment}
  146. \end{figure}
  147. \subsection{Input data}
  148. A \GMT\ program may or may not take input files. Three different
  149. types of input are recognized (more details can be found in Appendix
  150. B in the Technical Reference):
  151. \index{GMT@\GMT!input}
  152. \index{Input files}
  153. \begin{enumerate}
  154. \item Data tables.
  155. These are ``spreadsheet'' tables with a fixed number of columns and
  156. unlimited number of rows. We distinguish between two groups:
  157. \begin{itemize}
  158. \item ASCII (Preferred unless files are huge)
  159. \begin{itemize}
  160. \item Single segment [Default]
  161. \item Multi-segment with internal header records (\Opt{M})
  162. \end{itemize}
  163. \item Binary (to speed up input/output)
  164. \begin{itemize}
  165. \item Single segment [Default]
  166. \item Multi-segment (segment headers are all NaN fields) (\Opt{M})
  167. \end{itemize}
  168. \end{itemize}
  169. \item Gridded dated sets.
  170. These are data matrices (evenly spaced in two coordinates) that come
  171. in two flavors:
  172. \begin{itemize}
  173. \item Grid-line registration
  174. \item Pixel registration
  175. \end{itemize}
  176. You may choose among several file formats (even define your own format),
  177. but the \GMT\ default is the architecture-indenpendent netCDF format.
  178. \item Color palette table (For imaging, color plots, and contour maps).
  179. We will discuss these later.
  180. \end{enumerate}
  181. \subsection{Job Control}
  182. \GMT\ programs may get operational parameters from several places:
  183. \begin{enumerate}
  184. \item Supplied command line options/switches or program defaults.
  185. \item Short-hand notation to select previously used option arguments
  186. (stored in \filename{.gmtcommands}).
  187. \index{gmt.conf@\filename{gmt.conf}}
  188. \item Implicitly using \GMT\ defaults for a variety of parameters
  189. (stored in \filename{gmt.conf}).
  190. \item May use hidden support data like coastlines or \PS\ patterns.
  191. \end{enumerate}
  192. \subsection{Output data}
  193. There are 6 general categories of output produced by \GMT:
  194. \begin{enumerate}
  195. \item \PS\ plot commands.
  196. \item Data Table(s).
  197. \item Gridded data set(s).
  198. \item Statistics \& Summaries.
  199. \item Warnings and Errors, written to \emph{stderr}.
  200. \item Exit status (0 means success, otherwise failure).
  201. \end{enumerate}
  202. Note: \GMT\ automatically creates and updates a history of past
  203. \GMT\ command options for the common switches. This history
  204. file is called \filename{.gmtcommands} and one will be created in
  205. every directory from which \GMT\ programs are executed. Many
  206. initial problems with \GMT\ usage result from not fully appreciating
  207. the relationships shown in Figure~\ref{fig:GMT_Environment}.
  208. \section{The UNIX Environment: Entry Level Knowledge}
  209. \subsection{Redirection}
  210. \index{UNIX@\UNIX!redirection}
  211. \index{Redirection}
  212. Most \GMT\ programs read their input from the terminal (called
  213. \emph{stdin}) or from files, and write their output to the
  214. terminal (called \emph{stdout}). To use files instead one can
  215. use \UNIX\ redirection:
  216. {\small\begin{verbatim}
  217. GMTprogram input-file > output-file
  218. GMTprogram < input-file > output-file
  219. GMTprogram input-file >> output-file # Append to existing file
  220. \end{verbatim}
  221. }
  222. \noindent
  223. In this example, and in all those to follow, it is assumed that you do not have the shell
  224. variable \textbf{noclobber} set. If you do, it prevents accidental overwriting of existing files.
  225. That may be a noble cause, but it is extremely annoying. So please, \textbf{unset noclobber}.
  226. \subsection{Piping ($|$)}
  227. \index{UNIX@\UNIX!piping}
  228. \index{Piping}
  229. Sometimes we want to use the output from one program as input
  230. to another program. This is achieved with \UNIX\ pipes:
  231. {\small\begin{verbatim}
  232. Someprogram | GMTprogram1 | GMTprogram2 > Output-file (or | lp)
  233. \end{verbatim}
  234. }
  235. \subsection{Standard error (\emph{stderr})}
  236. \index{UNIX@\UNIX!stderr}
  237. \index{Standard error}
  238. Most \UNIX\ and \GMT\ programs will on occasion write error messages.
  239. These are typically written to a separate data stream called
  240. \emph{stderr} and can be redirected separately from the standard
  241. output (which goes to \emph{stdout}). To send the error messages to the same location
  242. as standard output we use
  243. {\small\begin{verbatim}
  244. UNIXprogram > errors.log 2>&1
  245. \end{verbatim}
  246. }
  247. When we want to save both program output and error messages to
  248. separate files we use the following syntax:
  249. {\small\begin{verbatim}
  250. GMTprogram > output.d 2> errors.log
  251. \end{verbatim}
  252. }
  253. \subsection{File name expansion or ``wild cards''}
  254. \index{Wild cards@``Wild cards''}
  255. \index{UNIX@\UNIX!``wild cards''}
  256. \UNIX\ provides several ways to select groups of files based
  257. on name patterns (Table~\ref{tbl:wildcard}):
  258. \begin{table}[h]
  259. \small
  260. \centering
  261. \begin{tabular}{|l|l|} \hline
  262. \multicolumn{1}{|c|}{\emph{Code}} & \multicolumn{1}{c|}{\emph{Meaning}} \\ \hline
  263. * & Matches anything \\ \hline
  264. ? & Matches any single character \\ \hline
  265. [\emph{list}] & Matches characters in the list \\ \hline
  266. [\emph{range}] & Matches characters in the given range \\ \hline
  267. \end{tabular}
  268. \caption{\UNIX\ wildcards.} \label{tbl:wildcard}
  269. \end{table}
  270. \noindent
  271. You can save much time by getting into the habit of selecting
  272. ``good'' filenames that make it easy to select subsets of all
  273. files using the \UNIX\ wild card notation.
  274. \subsubsection{Examples}
  275. \index{Examples|(}
  276. \begin{itemize}
  277. \item GMTprogram data\_*.d operates on all files starting with
  278. ``data\_'' and ending in ``.d''.
  279. \item GMTprogram line\_?.d works on all files starting with
  280. ``line\_'' followed by any single character and ending in ``.d''.
  281. \item GMTprogram section\_1[0-9]0.part\_[12] only processes data
  282. from sections 100 through 190, only using every 10th profile, and
  283. gets both part 1 and 2.
  284. \end{itemize}
  285. \index{Examples|)}
  286. \section{Laboratory Exercises}
  287. We will begin our adventure by making some simple plot axes and
  288. coastline basemaps. We will do this in order to introduce the all-%
  289. important \Opt{B}, \Opt{J}, and \Opt{R} switches and to familiarize
  290. ourselves with a few selected \GMT\ projections. The \GMT\ programs
  291. we will utilize are \GMTprog{psbasemap} and \GMTprog{pscoast}. Please
  292. consult their manual pages on the \GMT\ web site for reference.
  293. \subsection{Linear projection}
  294. \index{Linear projection \Opt{JX}}
  295. \index{Projection!linear}
  296. We start by making the basemap frame for a linear \emph{x-y} plot.
  297. We want it to go from 10 to 70 in \emph{x}, annotating every 10, and
  298. from -3 to 8 in \emph{y}, annotating every 1. The final plot should be
  299. 4 by 3 inches in size. Here's how we do it:
  300. {\small\begin{verbatim}
  301. psbasemap -R10/70/-3/8 -JX4i/3i -B10/1:."My first plot": -P > plot.ps
  302. \end{verbatim}
  303. }
  304. \noindent
  305. You can view the result with \progname{ghostview} \filename{plot.ps}.
  306. \subsubsection{Exercises}
  307. \index{Exercises|(}
  308. \begin{enumerate}
  309. \item Try change the \Opt{JX} values.
  310. \item Try change the \Opt{B} values.
  311. \item Omit the \Opt{P}.
  312. \end{enumerate}
  313. \index{Exercises|)}
  314. \subsection{Logarithmic projection}
  315. \index{Logarithmic projection}
  316. \index{Projection!logarithmic}
  317. We next will show how to do a basemap for a log--log plot. We will
  318. assume that the raw \emph{x} data range from 3 to 9613 and \emph{y}
  319. ranges from $3.2 \cdot 10^{20}$ to $6.8 \cdot 10^{24}$. One possibility is
  320. {\small\begin{verbatim}
  321. psbasemap -R1/10000/1e20/1e25 -JX9il/6il \
  322. -B2:"Wavelength (m)":/a1pf3:"Power (W)":WS > plot.ps
  323. \end{verbatim}
  324. }
  325. \noindent
  326. (The backslash $\backslash$ makes \UNIX\ ignore the carriage return that follows and treat the two lines as one long command).
  327. \subsubsection{Exercises}
  328. \index{Exercises|(}
  329. \begin{enumerate}
  330. \item Do not append \textbf{l} to the axes lengths.
  331. \item Leave the \textbf{p} modifier out of the \Opt{B} string.
  332. \item Add \textbf{g}3 to each side of the slash in \Opt{B}.
  333. \end{enumerate}
  334. \index{Exercises|)}
  335. \subsection{Mercator projection}
  336. \index{Mercator projection \Opt{JM}}
  337. \index{Projection!Mercator}
  338. Despite the problems of extreme horizontal exaggeration at high
  339. latitudes, the conformal Mercator projection (\Opt{JM}) remains
  340. the stalwart of location maps used by scientists. It is one
  341. of several cylindrical projections offered by \GMT; here we
  342. will only have time to focus on one such projection. The
  343. complete syntax is simply \\
  344. \Opt{JM}\emph{width} \\
  345. To make coastline maps we use \GMTprog{pscoast} which automatically will
  346. access the \GMT\ coastline data base derived from the GSHHS
  347. database\footnote{See \emph{Wessel and Smith} [1996].}. In addition
  348. to the common switches we may need to use some of several \GMTprog{pscoast}
  349. -specific options (see Table~\ref{tbl:pscoast}).
  350. \begin{table}[h]
  351. \small
  352. \centering
  353. \begin{tabular}{|l|l|} \hline
  354. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  355. \Opt{A} & Exclude small features or those of high hierarchical levels (see Appendix K)\\ \hline
  356. \Opt{D} & Select data resolution (\textbf{f}ull, \textbf{h}igh, \textbf{i}ntermediate, \textbf{l}ow, or \textbf{c}rude) \\ \hline
  357. \Opt{G} & Set color of dry areas (default does not paint) \\ \hline
  358. \Opt{I} & Draw rivers (chose features from one or more hierarchical categories) \\ \hline
  359. \Opt{L} & Plot map scale (length scale can be km, miles, or nautical miles) \\ \hline
  360. \Opt{N} & Draw political borders (including US state borders) \\ \hline
  361. \Opt{S} & Set color for wet areas (default does not paint) \\ \hline
  362. \Opt{W} & Draw coastlines and set pen thickness \\ \hline
  363. \end{tabular}
  364. \caption{Main options when making coastline plots or overlays.} \label{tbl:pscoast}
  365. \end{table}
  366. One of \Opt{W}, \Opt{G}, \Opt{S} must be selected. Our first coastline
  367. example is from Latin America:
  368. {\small\begin{verbatim}
  369. pscoast -R-90/-70/0/20 -JM6i -P -B5g5 -Gchocolate > map.ps
  370. \end{verbatim}
  371. }
  372. \subsubsection{Exercises}
  373. \index{Exercises|(}
  374. \begin{enumerate}
  375. \item Add the \Opt{V} option.
  376. \item Try \Opt{R}270/290/0/20 instead. What happens to the annotations?
  377. \item Edit your \filename{gmt.conf} file, change \textbf{FORMAT\_GEO\_MAP}
  378. to another setting (see the \GMTprog{gmt.conf} man page), and plot again.
  379. \item Pick another region and change land color.
  380. \item Pick a region that includes the north or south poles.
  381. %\item Try \Opt{W}0.25\textbf{p} instead of (or in addition to) \Opt{G}.
  382. \item Try \Opt[0.25{\textbf{p}}]{W} instead of (or in addition to) \Opt{G}.
  383. \end{enumerate}
  384. \index{Exercises|)}
  385. \subsection{Albers projection}
  386. \index{Albers projection \Opt{JB}}
  387. \index{Projection!Albers}
  388. The Albers projection (\Opt{JB}) is an equal-area conical projection;
  389. its conformal cousin is the Lambert conic projection (\Opt{JL}).
  390. Their usages are almost identical so we will only use the Albers here.
  391. The general syntax is \\
  392. %\Opt{JB}$lon_0/lat_0/lat_1/lat_2/width$ \\
  393. \Opt[$lon_0/lat_0/lat_1/lat_2/width$]{JB} \\
  394. \noindent
  395. where ($lon_0, lat_0$) is the map (projection) center and $lat_1, lat_2$
  396. are the two standard parallels where the cone intersects the Earth's surface.
  397. We try the following command:
  398. {\small\begin{verbatim}
  399. pscoast -R-130/-70/24/52 -JB-100/35/33/45/6i -B10g5:."Conic Projection": \
  400. -N1/thickest -N2/thinnest -A500 -Ggray -Wthinnest -P > map.ps
  401. \end{verbatim}
  402. }
  403. \subsubsection{Exercises}
  404. \index{Exercises|(}
  405. \begin{enumerate}
  406. \item Change the parameter \textbf{MAP\_GRID\_CROSS\_SIZE\_PRIMARY} to make grid crosses instead of gridlines.
  407. \item Change \Opt{R} to a rectangular box specification instead of
  408. minimum and maximum values.
  409. \end{enumerate}
  410. \index{Exercises|)}
  411. \subsection{Orthographic projection}
  412. \index{Orthographic projection \Opt{JG}}
  413. \index{Projection!orthographic}
  414. The azimuthal orthographic projection (\Opt{JG}) is one of several
  415. projections with similar syntax and behavior; the one we have
  416. chosen mimics viewing the Earth from space at an infinite distance;
  417. it is neither conformal nor equal-area.
  418. The syntax for this projection is \\
  419. \Opt{JG}$lon_0/lat_0/width$ \\
  420. \noindent
  421. where ($lon_0, lat_0$) is the center of the map (projection).
  422. As an example we will try
  423. {\small\begin{verbatim}
  424. pscoast -R0/360/-90/90 -JG280/30/6i -Bg30/g15 -Dc -A5000 -Gwhite \
  425. -SDarkTurquoise -P > map.ps
  426. \end{verbatim}
  427. }
  428. \subsubsection{Exercises}
  429. \index{Exercises|(}
  430. \begin{enumerate}
  431. \item Use the rectangular option in \Opt{R} to make a rectangular map
  432. showing the US only.
  433. \end{enumerate}
  434. \index{Exercises|)}
  435. \subsection{Eckert IV and VI projection}
  436. \index{Eckert IV and VI projection \Opt{JK}}
  437. \index{Projection!Eckert IV and VI}
  438. We conclude the survey of map projections with the Eckert IV and VI projections
  439. (\Opt{JK}), two of several projections used for global thematic maps; They
  440. are both equal-area projections whose syntax is \\
  441. %\Opt{JK}[\textbf{f$|$s}]$lon_0/width$ \\
  442. \Opt[{$[${\textbf{f\textbar s}}$]lon_0/width$}]{JK} \\
  443. \noindent
  444. where \textbf{f} gives Eckert IV (4) and \textbf{s} (Default) gives Eckert VI (6).
  445. The $lon_0$ is the central meridian (which takes precedence over
  446. the mid-value implied by the \Opt{R} setting). A simple Eckert VI world map
  447. is thus generated by
  448. {\small\begin{verbatim}
  449. pscoast -R0/360/-90/90 -JKs180/9i -B60g30/30g15 -Dc -A5000 \
  450. -Gchocolate -SDarkTurquoise -Wthinnest > map.ps
  451. \end{verbatim}
  452. }
  453. \subsubsection{Exercises}
  454. \index{Exercises|(}
  455. \begin{enumerate}
  456. \item Center the map on Greenwich.
  457. \item Add a map scale with \Opt{L}.
  458. \end{enumerate}
  459. \index{Exercises|)}
  460. \chapter{SESSION TWO}
  461. \thispagestyle{headings}
  462. \section{General Information}
  463. There are 18 \GMT\ programs that directly create (or add overlays to)
  464. plots (Table~\ref{tbl:plotprogs}); the remaining 45 are mostly concerned with data
  465. processing. This session will focus on the task of plotting
  466. lines, symbols, and text on maps. We will build on the skills
  467. we acquired while familiarizing ourselves with the various
  468. \GMT\ map projections as well as how to select a data domain
  469. and boundary annotations.
  470. \begin{table}[h]
  471. \small
  472. \centering
  473. \begin{tabular}{|l|l|} \hline
  474. \multicolumn{1}{|c|}{\emph{Program}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  475. \multicolumn{2}{|c|}{\emph{BASEMAPS}} \\ \hline
  476. \GMTprog{psbasemap} & Create an empty basemap frame with optional scale \\ \hline
  477. \GMTprog{pscoast} & Plot coastlines, filled continents, rivers, and political borders \\ \hline
  478. \GMTprog{pslegend} & Create legend overlay \\ \hline
  479. \multicolumn{2}{|c|}{\emph{POINTS AND LINES}} \\ \hline
  480. \GMTprog{pswiggle} & Draw spatial time-series along their $(x,y)$-tracks \\ \hline
  481. \GMTprog{psxy} & Plot symbols, polygons, and lines in 2-D \\ \hline
  482. \GMTprog{psxyz} & Plot symbols, polygons, and lines in 3-D \\ \hline
  483. \multicolumn{2}{|c|}{\emph{HISTOGRAMS}} \\ \hline
  484. \GMTprog{pshistogram} & Plot a rectangular histogram \\ \hline
  485. \GMTprog{psrose} & Plot a polar histogram(sector/rose diagram) \\ \hline
  486. \multicolumn{2}{|c|}{\emph{CONTOURS}} \\ \hline
  487. \GMTprog{grdcontour} & Contouring of 2-D gridded data sets \\ \hline
  488. \GMTprog{pscontour} & Direct contouring or imaging of $xyz$ data by optimal triangulation \\ \hline
  489. \multicolumn{2}{|c|}{\emph{SURFACES}} \\ \hline
  490. \GMTprog{grdimage} & Produce color images from 2-D gridded data \\ \hline
  491. \GMTprog{grdvector} & Plot vector fields from 2-D gridded data \\ \hline
  492. \GMTprog{grdview} & 3-D perspective imaging of 2-D gridded data \\ \hline
  493. \multicolumn{2}{|c|}{\emph{UTILITIES}} \\ \hline
  494. \GMTprog{psclip} & Use polygon files to initiate custom clipping paths \\ \hline
  495. \GMTprog{psimage} & Plot Sun raster files \\ \hline
  496. \GMTprog{psmask} & Create clipping paths or generate overlay to mask \\ \hline
  497. \GMTprog{psscale} & Plot gray scale or color scale bar \\ \hline
  498. \GMTprog{pstext} & Plot text strings on maps \\ \hline
  499. \end{tabular}
  500. \caption{List of all 1-D and 2-D plotting programs in \gmt.}
  501. \label{tbl:plotprogs}
  502. \end{table}
  503. Plotting lines and symbols, \GMTprog{psxy} is one of the most frequently
  504. used programs in \GMT. In addition to the common command line switches
  505. it has numerous specific options, and expects different file formats
  506. depending on what action has been selected. These circumstances make
  507. \GMTprog{psxy} harder to master than most \GMT\ tools. Table~\ref{tbl:psxy}
  508. shows a complete list of the options.
  509. \begin{table}[h]
  510. \small
  511. \centering
  512. \begin{tabular}{|l|l|} \hline
  513. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  514. \Opt{A} & Suppress line interpolation along great circles \\ \hline
  515. \Opt{C}\emph{CPT} & Let symbol color be determined from $z$-values and the \emph{CPT} file \\ \hline
  516. \Opt{E}[\textbf{x}$|$\textbf{X}][\textbf{y}$|$\textbf{Y}][\emph{cap}][/\emph{pen}] & Draw selected error bars with specified attributes \\ \hline
  517. \Opt{G}\emph{fill} & Set color for symbol or fill for polygons \\ \hline
  518. \Opt{L} & Explicitly close polygons \\ \hline
  519. \Opt{N} & Do Not clip symbols at map borders \\ \hline
  520. \Opt{S[symbol]}[\emph{size}] & Select one of several symbols (See Table~\ref{tbl:psxysymbols}) \\ \hline
  521. \Opt{W}\emph{pen} & Set \emph{pen} for line or symbol outline \\ \hline
  522. \end{tabular}
  523. \caption{Optional switches in the \protect\GMTprog{psxy} program.}
  524. \label{tbl:psxy}
  525. \end{table}
  526. The symbols can either be transparent (using \Opt{W} only, not \Opt{G})
  527. or solid (\Opt{G}, with optional outline using \Opt{W}). The \Opt{S}
  528. option takes the code for the desired symbol and optional size information.
  529. If no symbol is given it is expected to be given in the last column of each record in the input
  530. file. The \emph{size} is optional since individual sizes for
  531. symbols may also be provided by the input data. The main symbols available to
  532. us are shown in Table~\ref{tbl:psxysymbols}.
  533. \begin{table}[h]
  534. \index{Symbols, plot}
  535. \index{Plot!symbols}
  536. \small
  537. \centering
  538. \begin{tabular}{|l|l|} \hline
  539. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Symbol}} \\ \hline
  540. \Opt{S-}\emph{size} & horizontal dash; \emph{size} is length of dash \\ \hline
  541. \Opt{Sa}\emph{size} & st\textbf{a}r; \emph{size} is radius of circumscribing circle \\ \hline
  542. \Opt{Sb}\emph{size}[/\emph{base}][\textbf{u}] & \textbf{b}ar; \emph{size} is bar width, append \textbf{u} if \emph{size} is in
  543. \emph{x}-units \\
  544. & Bar extends from \emph{base} [0] to the \emph{y}-value \\ \hline
  545. \Opt{Sc}\emph{size} & \textbf{c}ircle; \emph{size} is the diameter \\ \hline
  546. \Opt{Sd}\emph{size} & \textbf{d}iamond; \emph{size} is its side \\ \hline
  547. \Opt{Se} & \textbf{e}llipse; \emph{direction} (CCW from horizontal), \emph{major}, and \emph{minor} axes in inches \\
  548. & are read from the input file \\ \hline
  549. \Opt{SE} & \textbf{e}llipse; \emph{azimuth} (CW from vertical), \emph{major}, and \emph{minor} axes in kilometers \\
  550. & are read from the input file\\ \hline
  551. \Opt{Sg}\emph{size} & octa\textbf{g}on; \emph{size} is its side \\ \hline
  552. \Opt{Sh}\emph{size} & \textbf{h}exagon; \emph{size} is its side \\ \hline
  553. \Opt{Si}\emph{size} & \textbf{i}nverted triangle; \emph{size} is its side \\ \hline
  554. \Opt{Sk}\emph{symbol}/\emph{size} & \textbf{k}ustom symbol; \emph{size} is its side \\ \hline
  555. \Opt{Sl}\emph{size}/\emph{string}[\%\emph{font}] & \textbf{l}etter; \emph{size} is fontsize. Append a letter or text string, and optionally a font \\ \hline
  556. \Opt{Sn}\emph{size} & pe\textbf{n}tagon; \emph{size} is its side \\ \hline
  557. \Opt{Sp} & \textbf{p}oint; no size needed (1 pixel at current resolution is used) \\ \hline
  558. \Opt{Sr}\emph{size} & \textbf{r}ect, \emph{width} and \emph{height} are read from input file \\ \hline
  559. \Opt{Ss}\emph{size} & \textbf{s}quare, \emph{size} is its side \\ \hline
  560. \Opt{St}\emph{size} & \textbf{t}riangle; \emph{size} is its side \\ \hline
  561. \Opt{Sv}[\emph{thick}/\emph{length}/\emph{width}][\textbf{n}\emph{norm}] & \textbf{v}ector; \emph{direction} (CCW from
  562. horizontal) and \emph{length} are read from input data \\
  563. & Optionally, append the thickness of the vector and the width and length of the \\
  564. & arrow-head. If the \textbf{n}\emph{norm} is appended, all vectors whose lengths are less than \\
  565. & \emph{norm} will have their attributes scaled by length/\emph{norm} \\ \hline
  566. \Opt{SV}[\emph{thick}/\emph{length}/\emph{width}][\textbf{n}\emph{norm}] & \textbf{v}ector, except \emph{azimuth} (degrees east
  567. of north) is expected instead of \emph{direction} \\
  568. & The angle on the map is calculated based on the chosen map projection \\ \hline
  569. \Opt{Sw}[\emph{size} & pie \textbf{w}edge; \emph{start} and \emph{stop} directions (CCW from horizontal) are read from \\
  570. & input data \\ \hline
  571. \Opt{Sx}\emph{size} & cross; \emph{size} is length of crossing lines \\ \hline
  572. \Opt{Sy}\emph{size} & vertical dash; \emph{size} is length of dash \\ \hline
  573. \end{tabular}
  574. \caption{The symbol option in \protect\GMTprog{psxy}. Lower case symbols (\textbf{a, c, d, g, h, i, n, s, t, x})
  575. will fit inside a circle of given diameter. Upper case symbols (\textbf{A, C, D, G, H, I, N, S, T, X}) will have area equal to that of a circle of given diameter.}
  576. \label{tbl:psxysymbols}
  577. \end{table}
  578. Because some symbols require more input data than others, and because the
  579. size of symbols as well as their color can be determined from the input data,
  580. the format of data can be confusing. The general format for the input data
  581. is (optional items are in brackets []): \\
  582. \index{psxy@\GMTprog{psxy} input format}
  583. $x\mbox{ } y$ [ $z$ ] [ $size$ ] [ $\sigma_x$ ] [ $\sigma_y$ ] [ $symbol$ ] \\
  584. Thus, the only required input columns are the first two which must contain the
  585. longitude and latitude (or \emph{x} and \emph{y}). The remaining items
  586. apply when one (or more) of the following conditions are met:
  587. \begin{enumerate}
  588. \item If you want the color of each symbol to be determined individually,
  589. supply a CPT file with the \Opt{C} option and let the 3rd data column
  590. contain the \emph{z}-values to be used with the CPT file.
  591. \item If you want the size of each symbol to be determined individually,
  592. append the size in a separate column.
  593. \item To draw error bars, use the \Opt{E} option and give one or two
  594. additional data columns with the \PM dx and \PM dy values; the form of
  595. \Opt{E} determines if one (\Opt{Ex} or \Opt{Ey}) or two (\Opt{Exy})
  596. columns are needed. If upper case flags \textbf{X} or \textbf{Y} are given then
  597. we will instead draw a ``box-and-whisker'' symbol and the $\sigma_x$ (or
  598. $\sigma_y$) must represent 4 columns containing the minimum, the 25 and 75\%
  599. quartiles, and the maximum value. The given $x$ (or $y$) coordinate is taken as the 50\%
  600. quartile (median).
  601. \index{Error bars}
  602. \item If you draw vectors with \Opt{Sv} (or \Opt{SV}) then \emph{size} is
  603. actually two columns containing the \emph{direction} (or \emph{azimuth})
  604. and \emph{length} of each vector.
  605. \index{Vectors}
  606. \item If you draw ellipses (\Opt{Se}) then \emph{size} is actually three
  607. columns containing the \emph{direction} and the \emph{major} and \emph{minor}
  608. axes in plot units (with \Opt{SE} we expect \emph{azimuth} instead and axes
  609. lengths in km).
  610. \index{Ellipses}
  611. \end{enumerate}
  612. Before we try some examples we need to review two key switches; they
  613. specify pen attributes and symbol or polygon fill. Please consult
  614. Chapter 4 in the \GMT\ Technical Reference and Cookbook before experimenting
  615. with the examples below.
  616. \subsection{Examples}
  617. \index{Examples|(}
  618. We will start off using the file \filename{data} in your directory.
  619. Using the \GMT\ utility \GMTprog{minmax} we find the extent of the
  620. data region:
  621. {\small\begin{verbatim}
  622. minmax data
  623. \end{verbatim}
  624. }
  625. \noindent
  626. which returns
  627. {\small\begin{verbatim}
  628. data: N = 7 <1/5> <1/5>
  629. \end{verbatim}
  630. }
  631. \noindent
  632. telling us that the file \filename{data} has 7 records and gives the
  633. minimum and maximum values for the first two columns. Given our
  634. knowledge of how to set up linear projections with \Opt{R} and \Opt{JX},
  635. try the following:
  636. \begin{enumerate}
  637. \item Plot the data as transparent circles of size 0.3 inches.
  638. \item Plot the data as solid white circles instead.
  639. \item Plot the data using 0.5" stars, making them red with a thick (width = 1.5p),
  640. dashed pen.
  641. \end{enumerate}
  642. To simply plot the data as a line we choose no symbol and specify a pen thickness instead:
  643. {\small\begin{verbatim}
  644. psxy data -R -J -P -B -Wthinner > plot.ps
  645. \end{verbatim}
  646. }
  647. \index{Examples|)}
  648. \subsection{Exercises}
  649. \index{Exercises|(}
  650. \begin{enumerate}
  651. \item Plot the data as a green-blue polygon instead.
  652. \item Try using a predefined pattern.
  653. \end{enumerate}
  654. \index{Exercises|)}
  655. A common question is : ``How can I plot symbols connected by a line
  656. with psxy?''. The surprising answer is that we must call \GMTprog{psxy} twice.
  657. While this sounds cumbersome there is a reason for this: Basically,
  658. polygons need to be kept in memory since they may need to be clipped,
  659. hence computer memory places a limit on how large polygons we may plot.
  660. Symbols, on the other hand, can be plotted one at the time so there
  661. is no limit to how many symbols one may plot. Therefore, to connect
  662. symbols with a line we must use the overlay approach:
  663. \index{Connected symbols}
  664. {\small\begin{verbatim}
  665. psxy data -R -J -B -P -K -Wthinner > plot.ps
  666. psxy data -R -J -O -W -Si0.2i >> plot.ps
  667. \end{verbatim}
  668. }
  669. Our final \GMTprog{psxy} example involves a more complicated scenario
  670. in which we want to plot the epicenters of several earthquakes over
  671. the background of a coastline basemap. We want the symbols to have a
  672. size that reflects the magnitude of the earthquakes, and that their
  673. color should reflect the depth of the hypocenter. You will find the
  674. two files \filename{quakes.ngdc} and \filename{quakes.cpt} in your
  675. directory. The first few lines in the \filename{quakes.ngdc} looks
  676. like this:\par
  677. {\small\begin{verbatim}
  678. Historical Tsunami Earthquakes from the NGDC Database
  679. Year Mo Da Lat+N Long+E Dep Mag
  680. 1987 01 04 49.77 149.29 489 4.1
  681. 1987 01 09 39.90 141.68 067 6.8
  682. \end{verbatim}
  683. }
  684. Thus the file has three header records (including the blank line),
  685. but we are only interested in columns 5, 4, 6, and 7. In addition to
  686. extract those columns we must also scale the magnitudes into symbols
  687. sizes in inches. Given their range it looks like multiplying the
  688. magnitude by 0.02 will work well. Reformatting this file to comply
  689. with the \GMTprog{psxy} input format can be done in a number of ways,
  690. including manual editing, using MATLAB, a spreadsheet program, or \UNIX\
  691. tools. Here, without further elaboration, we simply use the \UNIX\ tool
  692. \progname{awk} to do the job (\$5 refers to the 5'th column etc., and NR
  693. is the current record number):
  694. {\small\begin{verbatim}
  695. awk '{if (NR > 3) print $5, $4, $6, 0.02*$7}' quakes.ngdc > quakes.d
  696. \end{verbatim}
  697. }
  698. The \progname{awk} statement is automatically applied to each record,
  699. hence the output file \filename{quakes.d} should now look like this (try it!):
  700. {\small\begin{verbatim}
  701. 149.29 49.77 489 0.082
  702. 141.68 39.90 067 0.136
  703. ...etc etc
  704. \end{verbatim}
  705. }
  706. We will follow conventional color schemes for seismicity and assign red
  707. to shallow quakes (depth 0--100 km), green to intermediate quakes
  708. (100--300 km), and blue to deep earthquakes (depth $>$ 300 km). The
  709. \filename{quakes.cpt} file establishes the relationship between depth
  710. and color:
  711. {\small\begin{verbatim}
  712. # color palette for seismicity
  713. #z0 color z1 color
  714. 0 red 100 red
  715. 100 green 300 green
  716. 300 blue 1000 blue
  717. \end{verbatim}
  718. }
  719. Apart from comment lines (starting with \#), each record in the CPT file
  720. governs the color of a symbol whose \emph{z} value falls in the range between
  721. $z_0$ and $z_1$. If the colors for the lower and upper levels differ
  722. then an intermediate color will be linearly interpolated given the $z$
  723. value. Here, we have chosen constant color intervals.
  724. We may now complete our example using the Mercator projection; we throw in a
  725. map scale out of pure generosity:
  726. {\small\begin{verbatim}
  727. pscoast -R130/150/35/50 -JM6i -B5 -P -Ggray -Lf134/49/42.5/500 -K > map.ps
  728. psxy -R -J -O -Cquakes.cpt quakes.d -Sci -Wthinnest >> map.ps
  729. \end{verbatim}
  730. }
  731. \noindent
  732. where the \textbf{i} appended to the \Opt{Sc} option ensures that symbols
  733. sizes are interpreted to be in inches.
  734. \subsection{More exercises}
  735. \begin{enumerate}
  736. \item Select another symbol.
  737. \item Let the deep earthquakes be cyan instead of blue.
  738. \end{enumerate}
  739. \section{Plotting text strings}
  740. In many situations we need to annotate plots or maps with text strings;
  741. in \GMT\ this is done using \GMTprog{pstext}. Apart from the common
  742. switches, there are 8 options that are particularly useful (Table~\ref{tbl:pstext}).
  743. \begin{table}[h]
  744. \small
  745. \centering
  746. \begin{tabular}{|l|l|} \hline
  747. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  748. \Opt{C}\emph{dx}/\emph{dy} & Spacing between text and the text box (see \Opt{G} and \Opt{W}) \\ \hline
  749. \Opt{D}\emph{dx}/\emph{dy} & Offsets the projected location of the strings \\ \hline
  750. \Opt{G}\emph{fill} & Paint the text box (see \Opt{C} and \Opt{T}) \\ \hline
  751. \Opt{L} & Lists the font ids and exits \\ \hline
  752. \Opt{N} & Deactivates clipping at the borders \\ \hline
  753. \Opt{S}\emph{pen} & Selects outline font and sets pen attributes \\ \hline
  754. \Opt{T}\textbf{o}$|$\textbf{O}$|$\textbf{c}$|$\textbf{C} & Selects shape of text box rectangle (see \Opt{G} and \Opt{W}) \\ \hline
  755. \Opt{W}[\emph{pen}] & Draw the text box outline (see \Opt{C} and \Opt{T}) \\ \hline
  756. \end{tabular}
  757. \caption{Some of the most frequently used options in \protect\GMTprog{pstext}.}
  758. \label{tbl:pstext}
  759. \end{table}
  760. \GMTfig[h]{GMT_pstext_clearance}{Relationship between the text box and the extra clearance.}
  761. The input data to \GMTprog{pstext} is expected to contain the following
  762. information: \\
  763. \index{pstext@\GMTprog{pstext} input format}
  764. \emph{x y size angle fontno justify text} \\
  765. The \emph{size} argument is the font size in points, the \emph{angle} is the
  766. angle (measured counterclockwise) between the text's baseline and the
  767. horizontal, \emph{justify} indicates which point on the text-string should
  768. correspond to the given \emph{x, y} location, and \emph{text} is the text
  769. string or sentence to plot. Figure~\ref{fig:GMT_pstext_justify} illustrates these concepts and shows
  770. the relevant two-character codes used for justification.
  771. \index{Text justification}
  772. \index{Justification of text}
  773. \GMTfig[h]{GMT_pstext_justify}{Justification (and corresponding character codes) for text strings.}
  774. The text string can be one or several words and may include octal codes for
  775. special characters and escape-sequences used to select subscripts or symbol
  776. fonts. The escape sequences that are recognized by \GMT\ are given in Tables~\ref{tbl:escape}
  777. and ~\ref{tbl:scand}.
  778. \index{Escape sequences}
  779. \index{Special characters}
  780. \index{Superscript}
  781. \index{Subscript}
  782. \index{Symbol font}
  783. \index{Small caps}
  784. \index{Composite characters}
  785. \begin{table}[h]
  786. \small
  787. \centering
  788. \begin{tabular}{|l|l|} \hline
  789. \multicolumn{1}{|c|}{\emph{Code}} & \multicolumn{1}{c|}{\emph{Effect}} \\ \hline
  790. @\~ & Turns symbol font on or off \\ \hline
  791. @+ & Turns superscript on or off \\ \hline
  792. @- & Turns subscript on or off \\ \hline
  793. @\# & Turns small caps on or off \\ \hline
  794. @\_ & Turns underline on or off \\ \hline
  795. @\%\emph{fontno}\% & Switches to another font; @\%\% resets to previous font \\ \hline
  796. @:\emph{size}: & Switches to another font size; @:: resets to previous size \\ \hline
  797. @;\emph{color}; & Switches to another font color; @;; resets to previous color \\ \hline
  798. @! & Creates one composite character of the next two characters \\ \hline
  799. @@ & Prints the @ sign itself \\ \hline
  800. \end{tabular}
  801. \caption{\gmt\ text escape sequences.}
  802. \label{tbl:escape}
  803. \end{table}
  804. Note that these escape sequences (as well as octal codes) can be
  805. used anywhere in \GMT\, including in arguments to the \Opt{B} option.
  806. A chart of octal codes can be found in Appendix F in the \GMT\
  807. technical reference book. For accented European characters you must
  808. set \textbf{PS\_CHAR\_ENCODING} to ISOLatin1 in your \filename{gmt.conf} file.
  809. We will demonstrate \GMTprog{pstext} with the following script:
  810. {\small\begin{verbatim}
  811. cat << EOF | pstext -R0/7/0/5 -Jx1i -P -B1g1 -GDarkOrange | ghostview -
  812. 1 1 30 0 4 BL It's P@al, not Pal!
  813. 1 2 30 0 4 BL Try @%33%ZapfChancery@%% today
  814. 1 3 30 0 4 BL @~D@~g@-b@- = 2@~pr@~G@~D@~h.
  815. 1 4 30 0 4 BL University of Hawaii at M@!a\225noa
  816. EOF
  817. \end{verbatim}
  818. }
  819. \index{here document@``here document''}
  820. Here we have used the ``here document'' notation in \UNIX: The $<$$<$ EOF
  821. will treat the following lines as the input file until it detects the
  822. word EOF. We pipe the \PS\ directly through \progname{ghostview} (the -- tells
  823. \progname{ghostview} that piping is happening).
  824. \begin{table}[H]
  825. \centering
  826. \begin{tabular}{|l|l||l|l|} \hline
  827. \emph{Code} & \emph{Effect} & \emph{Code} & \emph{Effect} \\ \hline
  828. @E & \AE & @e & \ae \\ \hline
  829. @O & \O & @o & \o \\ \hline
  830. @A & \AA & @a & \aa \\ \hline
  831. @C & \c{C} & @c & \c{c} \\ \hline
  832. @N & \~{N} & @n & \~{n} \\ \hline
  833. @U & \"{U} & @u & \"{u} \\ \hline
  834. @s & \ss & & \\ \hline
  835. \end{tabular}
  836. \caption{Shortcuts for some European characters.}
  837. \label{tbl:scand}
  838. \end{table}
  839. \section{Exercises}
  840. \index{Exercises|(}
  841. \begin{enumerate}
  842. \item At $y = 5$, add the sentence ``$z^2 = x^2 + y^2$''.
  843. \item At $y = 6$, add the sentence ``It is 80\DS\ today''.
  844. \end{enumerate}
  845. \index{Exercises|)}
  846. \chapter{SESSION THREE}
  847. \thispagestyle{headings}
  848. \section{Contouring gridded data sets}
  849. \GMT\ comes with several utilities that can create gridded data
  850. sets; we will discuss two such programs later this session. First,
  851. we will assume that we already have gridded data sets. In the
  852. supplemental \GMT\ archive there is a program that serves as a data
  853. extractor from several public domain global gridded data sets.
  854. Among these data are ETOPO5, crustal ages, gravity and geoid,
  855. and DEM for the continental US. Here, we will use \GMTprog{grdraster}
  856. to extract a \GMT-ready grid that we will next use for contouring:
  857. {\small\begin{verbatim}
  858. grdraster 1 -R-66/-60/30/35 -Gbermuda.nc -V
  859. \end{verbatim}
  860. }
  861. Here we use the file extension \filename{.nc} instead of the generic \filename{.grd}
  862. to indicate that this is a netCDF file. It is good form, but not essential,
  863. to use \filename{.nc} for netCDF grids. Using that extension will help
  864. other programs installed on your system to recognize these files and might
  865. give it an identifiable icon in your file browser.
  866. Learn about other programs that read netCDF files at the
  867. \htmladdnormallinkfoot{netCDF website}{http://www.unidata.ucar.edu/software/netcdf/}
  868. You can find \filename{bermuda.nc} also in the \filename{tutorial} directory of you \GMT{}
  869. installation. Feel free to open it in any other program and compare results with \GMT.
  870. We first use the \GMT\ program \GMTprog{grdinfo} to see what's in this file:
  871. {\small\begin{verbatim}
  872. grdinfo bermuda.nc
  873. \end{verbatim}
  874. }
  875. The file contains bathymetry for the Bermuda region and has depth
  876. values from -5475 to -89 meters. We want to make a contour map of
  877. this data; this is a job for \GMTprog{grdcontour}. As with previous
  878. plot commands we need to set up the map projection with \Opt{J}.
  879. Here, however, we do not have to specify the region since that is by
  880. default assumed to be the extent of the grid file.
  881. To generate any plot we will in addition need to supply information
  882. about which contours to draw. Unfortunately, \GMTprog{grdcontour}
  883. is a complicated program with too many options. We put a positive
  884. spin on this situation by touting its flexibility. Here are the most
  885. useful options:
  886. \begin{table}[h]
  887. \small
  888. \centering
  889. \begin{tabular}{|l|l|} \hline
  890. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  891. \Opt{A}\emph{annot\_int} & Annotation interval and attributes \\ \hline
  892. \Opt{C}\emph{cont\_int} & Contour interval \\ \hline
  893. \Opt{G}\emph{gap} & Controls placement of contour annotations \\ \hline
  894. \Opt{L}\emph{low}/\emph{high} & Only draw contours within the \emph{low} to \emph{high} range \\ \hline
  895. \Opt{Q}\emph{cut} & Do not draw contours with fewer than \emph{cut} points \\ \hline
  896. \Opt{S}\emph{smooth} & Resample contours every \emph{x\_inc}/\emph{smooth} increment \\ \hline
  897. \Opt{T}[\textbf{+}$|$\textbf{-}][\emph{gap}/\emph{length}][:\emph{LH}] & Draw tick-marks in downhill direction for innermost closed contours \\ \hline
  898. & Add tick spacing and length, and characters to plot at the center of closed contours. \\ \hline
  899. \Opt{W}[\textbf{a}$|$\textbf{c}]\emph{pen} & Set contour and annotation pens \\ \hline
  900. \Opt{Z}\emph{factor}[/\emph{offset}] & [Subtract \emph{offset}] and multiply data by \emph{factor} prior to processing \\ \hline
  901. \end{tabular}
  902. \caption{The most useful options in \protect\GMTprog{grdcontour}.}
  903. \label{tbl:grdcontour}
  904. \end{table}
  905. We will first make a plain contour map using 1 km as annotation
  906. interval and 250 m as contour interval. We choose a 7-inch-wide
  907. Mercator plot and annotate the borders every 2\DS:
  908. {\small\begin{verbatim}
  909. grdcontour bermuda.nc -JM7i -C250 -A1000 -P -B2 | ghostview -
  910. \end{verbatim}
  911. }
  912. \subsection{Exercises}
  913. \index{Exercises|(}
  914. \begin{enumerate}
  915. \item Add smoothing with \Opt{S}4.
  916. \item Try tick all highs and lows with \Opt{T}.
  917. \item Skip small features with \Opt{Q}10.
  918. \item Override region using \Opt{R}-70/-60/25/35.
  919. \item Try another region that clips our data domain.
  920. \item Scale data to km and use the km unit in the annotations.
  921. \end{enumerate}
  922. \index{Exercises|)}
  923. \section{Gridding of arbitrarily spaced data}
  924. Except in the situation above when a grid file is available, we must
  925. convert our data to the right format readable by \GMT\ before we can
  926. make contour plots and color-coded images. We distinguish between
  927. two scenarios:
  928. \begin{enumerate}
  929. \item The (\emph{x}, \emph{y}, \emph{z}) data are available on a regular
  930. lattice grid.
  931. \item The (\emph{x}, \emph{y}, \emph{z}) data are distributed unevenly
  932. in the plane.
  933. \end{enumerate}
  934. The former situation may require a simple reformatting (using
  935. \GMTprog{xyz2grd}), while the latter must be interpolated onto a
  936. regular lattice; this process is known as gridding.
  937. \GMT\ supports three different approaches to gridding; here, we
  938. will briefly discuss the two most common techniques.
  939. All \GMT\ gridding programs have in common the requirement that the
  940. user must specify the grid domain and output filename: \\
  941. \begin{tabular}{ll}
  942. \Opt{R}\emph{xmin}/\emph{xmax}/\emph{ymin}/\emph{ymax} & The desired grid extent \\
  943. \Opt{I}\emph{xinc}[\textbf{m}$|$\textbf{c}][/\emph{yinc}[\textbf{m}$|$\textbf{c}]] & The grid spacing (append \textbf{m} or
  944. \textbf{c} for minutes or seconds of arc) \\
  945. \Opt{G}\emph{gridfile} & The output grid filename \\
  946. \end{tabular}
  947. \subsection{Nearest neighbor gridding}
  948. \GMTfig[h]{GMT_nearneighbor}{Search geometry for \protect\GMTprog{nearneighbor}.}
  949. The \GMT\ program \GMTprog{nearneighbor} implements a simple
  950. ``nearest neighbor'' averaging operation. It is the preferred
  951. way to grid data when the data density is high. \GMTprog{nearneighbor}
  952. is a local procedure which means it will only consider the control
  953. data that is close to the desired output grid node.
  954. Only data points inside a specified search radius will
  955. be used, and we may also impose the condition that each of the \emph{n}
  956. sectors must have at least one data point in order to assign the nodal
  957. value. The nodal value is computed as a weighted average of the nearest
  958. data point per sector inside the search radius, with each point weighted
  959. according to its distance from the node as follows:
  960. \[
  961. \bar{z} = \frac{\sum_{i=1}^{n} z_{i} w_{i}}{\sum_{i=1}^{n} w_{i}} \quad
  962. w_{i} =
  963. \left( 1 + \frac{9 r_{i}^{2}}{R^{2}} \right) ^{-1} \]
  964. \index{nearest neighbor}
  965. \noindent
  966. The most important switches are listed in Table~\ref{tbl:nearneighbor}.
  967. \begin{table}[h]
  968. \small
  969. \centering
  970. \begin{tabular}{|l|l|} \hline
  971. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  972. \Opt{S}\emph{radius}[\textbf{k}] & Sets search radius. Append \textbf{k} to indicate radius in kilometers [Default is \emph{x}-units] \\ \hline
  973. \Opt{E}\emph{empty} & Assign this value to unconstrained nodes [Default is NaN] \\ \hline
  974. \Opt{N}\emph{sectors} & Sector search, indicate number of sectors [Default is 4] \\ \hline
  975. \Opt{W} & Read relative weights from the 4th column of input data \\ \hline
  976. \end{tabular}
  977. \caption{Switches used with the \protect\GMTprog{nearneighbor} program.}
  978. \label{tbl:nearneighbor}
  979. \end{table}
  980. We will grid the data in the file \filename{ship.xyz} which contains
  981. ship observations of bathymetry off Baja California. You can find the
  982. file in the sub-directory for example 15.
  983. We desire to make a 5' by 5' grid. Running \GMTprog{minmax} on the file yields
  984. {\small\begin{verbatim}
  985. ship.xyz: N = 82970 <245/254.705> <20/29.99131> <-7708/-9>
  986. \end{verbatim}
  987. }
  988. so we choose the region accordingly:
  989. {\small\begin{verbatim}
  990. nearneighbor -R245/255/20/30 -I5m -S40k -Gship.nc -V ship.xyz
  991. \end{verbatim}
  992. }
  993. We may get a view of the contour map using
  994. {\small\begin{verbatim}
  995. grdcontour ship.nc -JM6i -P -B2 -C250 -A1000 | ghostview -
  996. \end{verbatim}
  997. }
  998. Since the grid \filename{ship.nc} is stored in netCDF format that is supported by a host of other programs,
  999. you can try one of those as well on the same grid.
  1000. \subsubsection{Exercises}
  1001. \index{Exercises|(}
  1002. \begin{enumerate}
  1003. \item Try using a 100 km search radius and a 10 minute grid spacing.
  1004. \end{enumerate}
  1005. \index{Exercises|)}
  1006. \subsection{Gridding with Splines in Tension}
  1007. As an alternative, we may use a global procedure to grid our data.
  1008. This approach, implemented in the program \GMTprog{surface}, represents
  1009. an improvement over standard minimum curvature algorithms by allowing
  1010. users to introduce some tension into the surface.
  1011. Physically, we are trying to force a thin elastic plate to go through
  1012. all our data points; the values of this surface at the grid points
  1013. become the gridded data. Mathematically, we want to find the function
  1014. $z(x, y)$ that satisfies the following constraints: \\
  1015. \index{Minimum curvature}
  1016. \( \begin{array}{ll}
  1017. z(x_k, y_k) = z_k, & \mbox{for all data $(x_k, y_k, z_k), k =1,n$} \\
  1018. (1-t)\nabla^4 z - t \nabla^2 z = 0 & \mbox{elsewhere}
  1019. \end{array} \) \\
  1020. \noindent
  1021. where $t$ is the ``tension'', $0 \leq t \leq 1$. Basically, as
  1022. $t \rightarrow 0$ we obtain the minimum curvature solution, while as
  1023. $t \rightarrow \infty$ we go towards a harmonic solution (which is linear
  1024. in cross-section). The theory behind all this is quite involved
  1025. and we do not have the time to explain it all here, please see
  1026. \emph{Smith and Wessel} [1990] for details. Some of the most important
  1027. switches for this program are indicated in Table~\ref{tbl:surface}\footnote{The
  1028. \Opt{A} option is necessary for geographic grids since \emph{x\_inc} shrinks with latitude. Rule of thumb: set \emph{aspect} = cosine of the average latitude.}.
  1029. \begin{table}[h]
  1030. \small
  1031. \centering
  1032. \begin{tabular}{|l|l|} \hline
  1033. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  1034. \Opt{A}\emph{aspect} & Sets aspect ratio for anisotropic grids. \\ \hline
  1035. \Opt{C}\emph{limit} & Sets convergence limit. Default is 1/1000 of data range. \\ \hline
  1036. \Opt{T}\emph{tension} & Sets the tension [Default is 0] \\ \hline
  1037. \end{tabular}
  1038. \caption{Some of the options in \protect\GMTprog{surface}.}
  1039. \label{tbl:surface}
  1040. \end{table}
  1041. \subsection{Preprocessing}
  1042. The \GMTprog{surface} program assumes that the data have been
  1043. preprocessed to eliminate aliasing, hence we must ensure that
  1044. this step is completed prior to gridding. \GMT\ comes with
  1045. three preprocessors, called \GMTprog{blockmean}, \GMTprog{blockmedian},
  1046. and \GMTprog{blockmode}. The first averages values inside the
  1047. grid-spacing boxes, the second returns median values, wile the
  1048. latter returns modal values. As a rule of thumb, we use means for
  1049. most smooth data (such as potential fields) and medians (or modes)
  1050. for rough, non-Gaussian data (such as topography). In addition
  1051. to the required \Opt{R} and \Opt{I} switches, these preprocessors
  1052. all take the same options (listed in Table~\ref{tbl:preprocess}).
  1053. \begin{table}[h]
  1054. \small
  1055. \centering
  1056. \begin{tabular}{|l|l|} \hline
  1057. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  1058. \Opt{N} & Choose pixel node registration [Default is gridline] \\ \hline
  1059. \Opt{W}[\textbf{i}$|$\textbf{o}] & Append \textbf{i} or \textbf{o} to read or write weights in the 4th column \\ \hline
  1060. \end{tabular}
  1061. \caption{Some of the preprocessing options.}
  1062. \label{tbl:preprocess}
  1063. \end{table}
  1064. With respect to our ship data we preprocess it using the median method:
  1065. {\small\begin{verbatim}
  1066. blockmedian -R245/255/20/30 -I5m -V ship.xyz > ship_5m.xyz
  1067. \end{verbatim}
  1068. }
  1069. The output data can now be used with surface:
  1070. {\small\begin{verbatim}
  1071. surface ship_5m.xyz -R245/255/20/30 -I5m -Gship.nc -V
  1072. \end{verbatim}
  1073. }
  1074. If you rerun \GMTprog{grdcontour} on the new grid file (try it!)
  1075. you will notice a big difference compared to the grid made by
  1076. \GMTprog{nearneighbor}: since \GMTprog{surface} is a global method
  1077. it will evaluate the solution at all nodes, even if there are no
  1078. data constraints. There are numerous options available to us at
  1079. this point:
  1080. \begin{enumerate}
  1081. \item We can reset all nodes too far from a data constraint to the
  1082. NaN value.
  1083. \item We can pour white paint over those regions where contours
  1084. are unreliable.
  1085. \item We can plot the landmass which will cover most (but not all)
  1086. of the unconstrained areas.
  1087. \item We can set up a clip path so that only the contours in the
  1088. constrained region will show.
  1089. \end{enumerate}
  1090. Here we have only time to explore the latter approach. The \GMTprog{psmask}
  1091. program can read the same preprocessed data and set up a contour mask
  1092. based on the data distribution. Once the clip path is activated we can
  1093. contour the final grid; we finally deactivate the clipping with a second
  1094. call to \GMTprog{psmask}. Here's the recipe:
  1095. {\small\begin{verbatim}
  1096. psmask -R245/255/20/30 -I5m ship_5m.xyz -JM6i -B2 -P -K -V > map.ps
  1097. grdcontour ship.nc -J -O -K -C250 -A1000 >> map.ps
  1098. psmask -C -O >> map.ps
  1099. \end{verbatim}
  1100. }
  1101. \section{Exercises}
  1102. \index{Exercises|(}
  1103. \begin{enumerate}
  1104. \item Add the continents using any color you want.
  1105. \item Color the clip path light gray (use \Opt{G} in the first
  1106. \GMTprog{psmask} call).
  1107. \end{enumerate}
  1108. \index{Exercises|)}
  1109. \chapter{SESSION FOUR}
  1110. \thispagestyle{headings}
  1111. In our final session we will concentrate on color images and
  1112. perspective views of gridded data sets. Before we start that
  1113. discussion we need to cover three important aspects of plotting
  1114. that must be understood. These are
  1115. \begin{enumerate}
  1116. \item Color tables and pseudo-colors in \GMT.
  1117. \item Artificial illumination and how it affects colors.
  1118. \item Multi-dimensional grids.
  1119. \end{enumerate}
  1120. \section{Cpt files}
  1121. \index{Color!tables}
  1122. The CPT file is discussed in detail in the \GMT\ Technical Reference
  1123. and Cookbook, Chapter 4. Please review the format before experimenting
  1124. further.
  1125. Cpt files can be created in any number of ways. \GMT\ provides
  1126. two mechanisms:\
  1127. \begin{enumerate}
  1128. \item Create simple, linear color tables given a master color table
  1129. (several are built-in) and the desired $z$-values at color boundaries
  1130. (\GMTprog{makecpt})
  1131. \item Create color tables based on a master CPT color table and the
  1132. histogram-equalized distribution of $z$-values in a gridded data file (\GMTprog{grd2cpt})
  1133. \end{enumerate}
  1134. \noindent
  1135. One can also make these files manually or with \progname{awk}
  1136. or other tools. Here we will limit our discussion to \GMTprog{makecpt}.
  1137. Its main argument is the name of the master color table (a list is
  1138. shown if you run the program with no arguments) and the equidistant
  1139. $z$-values to go with it. The main options are given below.
  1140. \begin{table}[h]
  1141. \small
  1142. \centering
  1143. \begin{tabular}{|l|l|} \hline
  1144. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  1145. \Opt{C} & Set the name of the master CPT file to use \\ \hline
  1146. \Opt{I} & Reverse the sense of the color progression \\ \hline
  1147. \Opt{V} & Run in verbose mode \\ \hline
  1148. \Opt{Z} & Make a continuous rather than discrete table \\ \hline
  1149. \end{tabular}
  1150. \caption{Prime options available in \protect\GMTprog{makecpt}.}
  1151. \label{tbl:makecpt}
  1152. \end{table}
  1153. To make discrete and continuous color CPT files for data that ranges
  1154. from -20 to 60, with color changes at every 10, try these two variants:
  1155. {\small\begin{verbatim}
  1156. makecpt -Crainbow -T-20/60/10 > disc.cpt
  1157. makecpt -Crainbow -T-20/60/10 -Z > cont.cpt
  1158. \end{verbatim}
  1159. }
  1160. \noindent
  1161. We can plot these color tables with \GMTprog{psscale}; the options
  1162. worth mentioning here are listed in Table~\ref{tbl:psscale}.
  1163. In addition, the \Opt{B} option can be used to set the title
  1164. and unit label (and optionally to set the annotation-, tick-,
  1165. and grid-line intervals for the colorbars.)
  1166. \begin{table}[h]
  1167. \small
  1168. \centering
  1169. \begin{tabular}{|l|l|} \hline
  1170. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  1171. \Opt{C}\emph{CPT file} & The required CPT file \\ \hline
  1172. \Opt{D}\emph{xpos}/\emph{ypos}/\emph{length}/\emph{width}[\textbf{h}] & Sets the position of the center/left and dimensions of scale bar. \\ \hline
  1173. & Append \textbf{h} to get horizontal bar and give center/top instead \\ \hline
  1174. \Opt{I}\emph{max\_intensity} & Add illumination effects \\ \hline
  1175. \end{tabular}
  1176. \caption{The main switches and options in \protect\GMTprog{psscale}.}
  1177. \label{tbl:psscale}
  1178. \end{table}
  1179. {\small\begin{verbatim}
  1180. psbasemap -R0/8.5/0/11 -Jx1i -P -B0 -K > bar.ps
  1181. psscale -D3i/3i/4i/0.5ih -Cdisc.cpt -B:discrete: -O -K >> bar.ps
  1182. psscale -D3i/5i/4i/0.5ih -Ccont.cpt -B:continuous: -O -K >> bar.ps
  1183. psscale -D3i/7i/4i/0.5ih -Cdisc.cpt -B:discrete: -I0.5 -O -K >> bar.ps
  1184. psscale -D3i/9i/4i/0.5ih -Ccont.cpt -B:continuous: -I0.5 -O >> bar.ps
  1185. \end{verbatim}
  1186. }
  1187. \subsection{Exercises}
  1188. \index{Exercises|(}
  1189. \begin{enumerate}
  1190. \item Redo the \GMTprog{makecpt} exercise using the master table
  1191. \emph{hot} and redo the bar plot.
  1192. \item Try specifying \Opt{B}10g5.
  1193. \end{enumerate}
  1194. \index{Exercises|)}
  1195. \section{Illumination and intensities}
  1196. \GMT\ allows for artificial illumination and shading. What this
  1197. means is that we imagine an artificial sun placed at infinity in
  1198. some azimuth and elevation position illuminating our surface.
  1199. The parts of the surface that slope toward the sun should brighten
  1200. while those sides facing away should become darker; no shadows are
  1201. cast as a result of topographic undulations.
  1202. While it is clear that the actual slopes of the surface and the
  1203. orientation of the sun enter into these calculations, there is
  1204. clearly an arbitrary element when the surface is not topographic
  1205. relief but some other quantity. For instance, what does the slope
  1206. toward the sun mean if we are plotting a grid of heat flow anomalies?
  1207. While there are many ways to accomplish what we want, \GMT\ offers
  1208. a relatively simple way: We may calculate the gradient of the surface
  1209. in the direction of the sun and normalize these values to fall in
  1210. the \PM 1 range; +1 means maximum sun exposure and -1 means complete
  1211. shade. Although we will not show it here, it should be added that
  1212. \GMT\ treats the intensities as a separate data set. Thus, while
  1213. these values are often derived from the relief surface we want to
  1214. image they could be separately observed quantities such as back-scatter
  1215. information.
  1216. \index{Color!RGB system}
  1217. \index{Color!HSV system}
  1218. \index{Color!CMYK system}
  1219. Colors in \GMT\ are specified in the RGB system used for computer
  1220. screens; it mixes red, green, and blue light to achieve other colors.
  1221. The RGB system is a Cartesian coordinate system and produces a color cube.
  1222. For reasons better explained in Appendix I in the Reference book it is
  1223. difficult to darken and brighten a color based on its RGB values and an
  1224. alternative coordinate system is used instead; here we use the HSV system.
  1225. If you hold the color cube so that the black and white corners are along
  1226. a vertical axis, then the other 6 corners project onto the horizontal plane to
  1227. form a hexagon; the corners of this hexagon are the primary colors Red,
  1228. Yellow, Green, Cyan, Blue, and Magenta.
  1229. The CMY colors are the complimentary colors and are used when paints are
  1230. mixed to produce a new color (this is how printers operate; they also add
  1231. pure black (K) to avoid making gray from CMY). In this coordinate system the
  1232. angle 0--360\DS\ is the hue (H); the Saturation and Value are harder to
  1233. explain. Suffice it to say here that we intend to darken any pure color
  1234. (on the cube facets) by keeping H fixed and adding black and brighten it by adding white; for
  1235. interior points in the cube we will add or remove gray.
  1236. This operation is efficiently done in the HSV coordinate system; hence all
  1237. \GMT\ shading operations involve translating from RGB to HSV, do the
  1238. illumination effect, and transform back the modified RGB values.
  1239. \section{Color images}
  1240. \index{Color!images}
  1241. Once a CPT file has been made it is relatively straightforward to generate
  1242. a color image of a gridded data. Here, we will extract a subset of the
  1243. global 30" DEM (data id 9) from USGS:
  1244. {\small\begin{verbatim}
  1245. grdraster 9 -R-108/-103/35/40 -Gus.nc
  1246. \end{verbatim}
  1247. }
  1248. You can find the grid \filename{us.nc} also in the \filename{tutorial} directory
  1249. of your \GMT{} installation.
  1250. Using \GMTprog{grdinfo} we find that the data ranges from $\sim$1000m to
  1251. \noindent
  1252. $\sim$4300m so we make a CPT file accordingly:
  1253. {\small\begin{verbatim}
  1254. makecpt -Crainbow -T1000/5000/500 -Z > topo.cpt
  1255. \end{verbatim}
  1256. }
  1257. Color images are made with \GMTprog{grdimage} which takes the usual
  1258. common command options (by default the \Opt{R} is taken from the data set)
  1259. and a CPT file; the main other options are
  1260. \begin{table}[h]
  1261. \small
  1262. \centering
  1263. \begin{tabular}{|l|l|} \hline
  1264. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  1265. \Opt{E}\emph{dpi} & Sets the desired resolution of the image [Default is data resolution] \\ \hline
  1266. \Opt{I}\emph{intenfile} & Use artificial illumination using intensities from \emph{intensfile} \\ \hline
  1267. \Opt{M} & Force gray shade using the (television) YIQ conversion \\ \hline
  1268. \end{tabular}
  1269. \caption{The main options in \protect\GMTprog{grdimage}.}
  1270. \label{tbl:grdimage}
  1271. \end{table}
  1272. We want to make a plain color map with a color bar superimposed above
  1273. the plot. We try
  1274. {\small\begin{verbatim}
  1275. grdimage us.nc -JM6i -P -B2 -Ctopo.cpt -V -K > topo.ps
  1276. psscale -D3i/8.5i/5i/0.25ih -Ctopo.cpt -I0.4 -B/:m: -O >> topo.ps
  1277. \end{verbatim}
  1278. }
  1279. The plain color map lacks detail and fails to reveal the topographic
  1280. complexity of this Rocky Mountain region. What it needs is artificial
  1281. illumination. We want to simulate shading by a sun source in the east,
  1282. hence we derive the required intensities from the gradients of the
  1283. topography in the N90\DS E direction using \GMTprog{grdgradient}. Other than the
  1284. required input and output filenames, the available options are
  1285. \index{Artificial illumination}
  1286. \index{Illumination, artificial}
  1287. \begin{table}[h]
  1288. \small
  1289. \centering
  1290. \begin{tabular}{|l|l|} \hline
  1291. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  1292. \Opt{A}\emph{azimuth} & Azimuthal direction for gradients \\ \hline
  1293. \Opt{M} & Indicates that this is a geographic grid \\ \hline
  1294. \Opt{N}[\textbf{t}$|$\textbf{e}][\emph{norm}[/\emph{offset}]] & Normalize gradients by \emph{norm/offset} [= 1/0 by default]. \\
  1295. & Insert \textbf{t} to normalize by the $tan^{-1}$ transformation. \\
  1296. & Insert \textbf{e} to normalize by the cumulative Laplace distribution. \\ \hline
  1297. \end{tabular}
  1298. \caption{The \protect\GMTprog{grdgradient} options.}
  1299. \label{tbl:grdgradient}
  1300. \end{table}
  1301. Figure~\ref{fig:GMT_atan} shows that raw slopes from bathymetry tend to be
  1302. far from normally distributed (left). By using the inverse tangent
  1303. transformation we can ensure a more uniform distribution (right).
  1304. The inverse tangent transform simply takes the raw slope estimate
  1305. (the \emph{x} value at the arrow) and returns the corresponding inverse
  1306. tangent value (normalized to fall in the \PM 1 range; horizontal
  1307. arrow pointing to the \emph{y}-value).
  1308. \GMTfig[h]{GMT_atan}{How the inverse tangent operation works.}
  1309. Both \Opt{Ne} and \Opt{Nt} yield well behaved gradients. Personally,
  1310. we prefer to use the \Opt{Ne} option; the value of
  1311. \emph{norm} is subjective and you may experiment somewhat in the
  1312. 0.5--5 range. For our case we choose
  1313. {\small\begin{verbatim}
  1314. grdgradient us.nc -Ne0.8 -A100 -M -Gus_i.nc
  1315. \end{verbatim}
  1316. }
  1317. Given the CPT file and the two gridded data sets we can
  1318. create the shaded relief image:
  1319. {\small\begin{verbatim}
  1320. grdimage us.nc -Ius_i.nc -JM6i -P -B2 -Ctopo.cpt -K > topo.ps
  1321. psscale -D3i/8.5i/5i/0.25ih -Ctopo.cpt -I0.4 -B/:m: -O >> topo.ps
  1322. \end{verbatim}
  1323. }
  1324. \subsection{Exercises}
  1325. \index{Exercises|(}
  1326. \begin{enumerate}
  1327. \item Force a gray-shade image.
  1328. \item Rerun \GMTprog{grdgradient} with \Opt{N}1.
  1329. \end{enumerate}
  1330. \index{Exercises|)}
  1331. \section{Multi-dimensional maps}
  1332. \index{Multi-dimensional maps}
  1333. Climate data, like ocean temperatures or atmospheric pressure, are often provided as
  1334. multi-dimensional (3-D, 4-D or 5-D) grids in netCDF format. This section will demonstrate
  1335. that \GMT{} is able to plot ``horizonal''
  1336. slices (spanning latitude and longitude) of such grids without much effort.
  1337. As an example we will download the Seasonal Analysed Mean Temperature from the
  1338. \htmladdnormallinkfoot{World Ocean Atlas 1998}{http://www.cdc.noaa.gov/cdc/data.nodc.woa98.html}.
  1339. The file in question is named
  1340. \htmladdnormallinkfoot{\filename{otemp.anal1deg.nc}}{ftp://ftp.cdc.noaa.gov/Datasets/nodc.woa98/temperat/seasonal/otemp.anal1deg.nc}.
  1341. You can look at the information pertained in this file using the program \progname{ncdump} and
  1342. notice that the variable that we want to plot (otemp) is a four-dimensional variable of time,
  1343. level (i.e., depth), latitude and longitude.
  1344. {\small\begin{verbatim}
  1345. ncdump -h otemp.anal1deg.nc
  1346. \end{verbatim}
  1347. }
  1348. We will need to make an appropriate color scale, running from -2\DS C (freezing temperature of salt
  1349. water) to 30\DS C (highest likely ocean temperature). We do this as follows:
  1350. {\small\begin{verbatim}
  1351. makecpt -Cno_green -T-2/30/2 > otemp.cpt
  1352. \end{verbatim}
  1353. }
  1354. Let us focus on the temperatures in Summer (that is the third season, July through
  1355. September) at sea level (that is the first level). To plot these in a Mollweide projection we
  1356. use:
  1357. {\small\begin{verbatim}
  1358. grdimage -Rg -JW180/9i "otemp.anal1deg.nc?otemp[2,0]" -Cotemp.cpt -Bg30 \
  1359. > otemp.ps
  1360. \end{verbatim}
  1361. }
  1362. The addition \filename{?otemp[2,0]} indicates which variable to retrieve from the netCDF
  1363. file (otemp) and that we need the third time step and first level. The numbering of the
  1364. time steps and levels starts at zero, therefore \filename{[2,0]}. Make sure to put the
  1365. whole file name within quotes since the characters \verb|?|, \verb|[| and \verb|]| have
  1366. special meaning in Unix.
  1367. \subsection{Exercises}
  1368. \index{Exercises|(}
  1369. \begin{enumerate}
  1370. \item Plot the temperatures for Spring at 5000 m depth. (Hint: use \filename{ncdump -v level} to
  1371. figure out what level number that is).
  1372. \item Include a color scale at the bottom of the plot.
  1373. \end{enumerate}
  1374. \index{Exercises|)}
  1375. \section{Perspective views}
  1376. \index{Perspective views}
  1377. Our final undertaking in this tutorial is to examine three-dimensional
  1378. perspective views. \GMT\ is currently limited to vantage points at
  1379. infinity; thus we are unable to do fly-by's through canyons etc. The
  1380. \GMT\ module that produces perspective views of gridded data files is
  1381. \GMTprog{grdview}. It can make two kinds of plots:
  1382. \begin{enumerate}
  1383. \item Mesh or wire-frame plot (with or without superimposed contours)
  1384. \item Color-coded surface (with optional shading, contours, or draping).
  1385. \end{enumerate}
  1386. Regardless of plot type, some arguments must be specified; these are
  1387. \begin{enumerate}
  1388. \item \emph{relief\_file}; a gridded data set of the surface.
  1389. \item \Opt{J} for the desired map projection.
  1390. \item \Opt{JZ}\emph{height} for the vertical scaling.
  1391. \item \Opt{E}\emph{azimuth}/\emph{elevation} for vantage point.
  1392. \end{enumerate}
  1393. In addition, some options may be required:
  1394. \begin{table}[h]
  1395. \small
  1396. \centering
  1397. \begin{tabular}{|l|l|} \hline
  1398. \multicolumn{1}{|c|}{\emph{Option}} & \multicolumn{1}{c|}{\emph{Purpose}} \\ \hline
  1399. \Opt{C}\emph{CPT file} & The \emph{CPT file} is required for color -coded surfaces and for contoured mesh plots \\ \hline
  1400. \Opt{G}\emph{drape\_file} & Assign colors using \emph{drape\_file} instead of \emph{relief\_file} \\ \hline
  1401. \Opt{I}\emph{intens\_file} & File with illumination intensities \\ \hline
  1402. \Opt{Qm} & Selects mesh plot \\ \hline
  1403. \Opt{Qs}[\textbf{m}] & Surface plot using polygons; append \textbf{m} to show mesh. This option allows for \Opt{W} \\ \hline
  1404. \Opt{Qi}\emph{dpi}[\textbf{g}] & Image by scan-line conversion. Specify \emph{dpi}; append \textbf{g} to force gray-shade image. \\ \hline
  1405. \Opt{Qc}\emph{dpi}[\textbf{g}] & Same as \Opt{Qi} but using PostScript Level 3 to make NaN color transparent. \\ \hline
  1406. \Opt{W}\emph{pen} & Draw contours on top of surface (except with \Opt{Qi} or \Opt{Qc}) \\ \hline
  1407. \end{tabular}
  1408. \caption{The most useful options in \protect\GMTprog{grdview}.}
  1409. \label{tbl:grdview}
  1410. \end{table}
  1411. \subsection{Mesh-plot}
  1412. \index{Mesh plots}
  1413. Mesh plots work best on smaller data sets. We again use the small
  1414. subset of the ETOPO5 data over Bermuda and make a quick-and-dirty
  1415. CPT file:
  1416. {\small\begin{verbatim}
  1417. grd2cpt bermuda.nc -Cocean > bermuda.cpt
  1418. \end{verbatim}
  1419. }
  1420. A simple mesh plot can therefore be obtained with
  1421. {\small\begin{verbatim}
  1422. grdview bermuda.nc -JM5i -P -JZ2i -E135/30 -B2 -Cbermuda.cpt > map.ps
  1423. \end{verbatim}
  1424. }
  1425. \subsubsection{Exercises}
  1426. \index{Exercises|(}
  1427. \begin{enumerate}
  1428. \item Select another vantage point and vertical height.
  1429. \end{enumerate}
  1430. \index{Exercises|)}
  1431. \subsection{Color-coded view}
  1432. We will make a perspective, color-coded view of the US Rockies
  1433. from the southeast. This is done using
  1434. {\small\begin{verbatim}
  1435. grdview us.nc -JM6i -E135/35 -Qc50 -Ius_i.nc -Ctopo.cpt -V -B2 \
  1436. -JZ0.5i > view.ps
  1437. \end{verbatim}
  1438. }
  1439. \noindent
  1440. This plot is pretty crude since we selected 50 dpi but it is fast
  1441. to render and allows us to try alternate values for vantage point
  1442. and scaling. When we settle on the final values we select the
  1443. appropriate \emph{dpi} for the final output device and let it rip.
  1444. \subsubsection{Exercises}
  1445. \index{Exercises|(}
  1446. \begin{enumerate}
  1447. \item Choose another vantage point and scaling.
  1448. \item Redo \GMTprog{grdgradient} with another illumination direction and replot.
  1449. \item Select a higher \emph{dpi}, e.g., 200.
  1450. \end{enumerate}
  1451. \index{Exercises|)}
  1452. \chapter{References}
  1453. \thispagestyle{headings}
  1454. \begin{enumerate}
  1455. \item Smith, W.H.F., and P. Wessel, Gridding with continuous curvature
  1456. splines in tension, \emph{Geophysics}, \emph{55}, 293--305, 1990.
  1457. \item Wessel, P., and W.H.F. Smith, Free software helps map and
  1458. display data, \emph{EOS Trans. AGU}, \emph{72}, 441, 1991.
  1459. \item Wessel, P., and W.H.F. Smith, New version of the Generic
  1460. Mapping Tools released, \emph{EOS Trans. AGU}, \emph{76}, 329, 1995.
  1461. \item Wessel, P., and W.H.F. Smith, A global, self-consistent,
  1462. hierarchical, high-resolution shoreline database, \emph{J. Geophys. Res.},
  1463. \emph{101}, 8741--8743, 1996.
  1464. \item Wessel, P., and W.H.F. Smith, New, improved version of the Generic
  1465. Mapping Tools released, \emph{EOS Trans. AGU}, \emph{79}, 579, 1998.
  1466. \item Wessel, P., and W.H.F. Smith, The Generic Mapping Tools Technical Reference and Cookbook, \emph{Version 4.2.0}, pp. 155, 2007.
  1467. \end{enumerate}
  1468. \clearpage
  1469. \thispagestyle{headings}
  1470. %\addcontentsline{toc}{chapter}{INDEX}
  1471. \printindex
  1472. \end{document}
Tip!

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

Comments

Loading...