Skip to content

Commit 3486e5c

Browse files
authored
Add a tutorial version in Julia (#6103)
* Add a tutorial version in Julia * Add installing/consulting links.
1 parent 049acea commit 3486e5c

File tree

7 files changed

+1444
-0
lines changed

7 files changed

+1444
-0
lines changed

doc/rst/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Quick links
4545
gallery
4646
animations
4747
tutorial
48+
tutorial_jl
4849

4950
---
5051

doc/rst/source/tutorial/intro_jl.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Introduction
2+
============
3+
4+
Historical highlights
5+
---------------------
6+
7+
The GMT system was initiated in late 1987 at Lamont-Doherty Earth Observatory, Columbia University by graduate students
8+
Paul Wessel and Walter H. F. Smith. Version 1 was officially introduced to Lamont scientists in July 1988. GMT 1
9+
migrated by word of mouth (and tape) to other institutions in the United States, UK, Japan, and France and attracted
10+
a small following. Paul took a Post-doctoral position at SOEST in December 1989 and continued the GMT development.
11+
Version 2.0 was released with an article in EOS, October 1991, and quickly spread worldwide. Version 3.0 in 1993
12+
which was released with another article in EOS on August 15, 1995. A major upgrade to GMT 4.0 took place in Oct 2004.
13+
Finally, in 2013 we released the new GMT 5 series and we have updated this tutorial to reflect the changes in style
14+
and syntax. However, GMT 5 is generally backwards compatible with GMT 4 syntax. In October 2019 we released the current
15+
version GMT 6. GMT is used by tens of thousands of users worldwide in a broad range of disciplines.
16+
17+
Philosophy
18+
----------
19+
20+
GMT is written in the ANSI C programming language (very portable), is POSIX compliant, and is independent of hardware
21+
constraints (e.g., memory). GMT was deliberately written for command-line usage, not a windows environment, in order
22+
to maximize flexibility. We standardized early on to use PostScript output instead of other graphics formats. Apart
23+
from the built-in support for coastlines, GMT completely decouples data retrieval from the main GMT modules. GMT uses
24+
architecture-independent file formats.
25+
26+
GMT installation considerations
27+
-------------------------------
28+
29+
See the `install guide <https://github.com/GenericMappingTools/gmt/blob/master/INSTALL.md>`_
30+
for instructions and to make sure you have all required dependencies installed.
31+
Alternatively, you can build GMT from source by following the
32+
`building guide <https://github.com/GenericMappingTools/gmt/blob/master/BUILDING.md>`_.
33+
34+
See also the general information about `Julia https://julialang.org/learning/getting-started/`_
35+
as well as the introduction to the Julia wrapper at
36+
https://www.generic-mapping-tools.org/GMT.jl/dev/usage/ and the very recomendable
37+
`Quick Learn https://www.generic-mapping-tools.org/GMT.jl/dev/quick_learn/`_. Complement with the instructions on how to
38+
install `GMT.jl https://github.com/GenericMappingTools/GMT.jl#install`_
Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
Session One
2+
===========
3+
4+
Tutorial setup
5+
--------------
6+
7+
#. GMT man pages, documentation, and gallery example scripts are available from the GMT.jl documentation web page
8+
available from https://www.generic-mapping-tools.org/GMT.jl/dev/.
9+
10+
#. We recommend you create a sub-directory called *tutorial*,
11+
cd into that directory, and run the commands there to keep things tidy.
12+
13+
#. As we discuss GMT principles it may be a good idea to consult :doc:`the GMT Cookbook </cookbook>`
14+
for more detailed explanations (but the CookBook is not translated into the GMT.jl syntax).
15+
16+
#. The tutorial data sets are distributed via the GMT cache server.
17+
You will therefore find that all the data files have a "@" prepended to
18+
their names. This will ensure the file is copied from the server
19+
before being used, hence you do not need to download any of the
20+
data manually. The only downside is that you will need an Internet
21+
connection to run the examples by cut and paste.
22+
23+
#. Please cd into the directory *tutorial*. We are now ready to start.
24+
25+
26+
Input data
27+
~~~~~~~~~~
28+
29+
A GMT module may or may not take input data/files. Four different
30+
types of input are recognized (more details can be found in :doc:`/cookbook/file-formats`):
31+
32+
#. Data tables.
33+
These are rectangular tables with a fixed number of columns and
34+
unlimited number of rows. We distinguish between two groups:
35+
36+
* ASCII (Preferred unless files are huge)
37+
38+
* Binary (to speed up input/output)
39+
40+
* In memory GMTdataset or plain Julia matrices.
41+
42+
Such tables may have segment headers and can therefore hold any number of
43+
subsets such as individual line segments or polygons.
44+
45+
#. Gridded dated sets.
46+
These are data matrices (evenly spaced in two coordinates) that come in two flavors:
47+
48+
* Grid-line registration
49+
50+
* Pixel registration
51+
52+
You may choose among several file formats (even define your own format),
53+
but the GMT default is the architecture-independent netCDF format.
54+
55+
The other alternative is to use Julia in-memory data in the form of GMTgrids.
56+
57+
#. Color palette table (For imaging, color plots, and contour maps). We will discuss these later.
58+
59+
60+
Job Control
61+
~~~~~~~~~~~
62+
63+
GMT modules may get operational parameters from several places:
64+
65+
#. Supplied command line options/switches or module defaults.
66+
67+
#. Short-hand notation to select previously used option arguments.
68+
69+
#. Implicitly using GMT defaults for a variety of parameters (stored in :doc:`/gmt.conf`).
70+
71+
#. May use hidden support data like coastlines or PostScript patterns.
72+
73+
Output data
74+
~~~~~~~~~~~
75+
76+
There are 5 general categories of output produced by GMT:
77+
78+
#. PostScript plot commands.
79+
80+
#. Data Table(s).
81+
82+
#. Gridded data set(s).
83+
84+
#. Statistics & Summaries.
85+
86+
#. Warnings and Errors, written to the REPL
87+
88+
89+
Laboratory Exercises
90+
--------------------
91+
92+
We will begin our adventure by making some simple plot axes and coastline basemaps. We will do this in order
93+
to introduce the all-important common options **frame**, **proj**, and **region** and to familiarize ourselves
94+
with a few selected GMT projections. The GMT modules we will utilize are :doc:`/basemap` and
95+
`basemap <https://www.generic-mapping-tools.org/GMT.jl/dev/coast/>`_.
96+
Please consult their manual pages for reference.
97+
98+
Linear projection
99+
~~~~~~~~~~~~~~~~~
100+
101+
We start by making the basemap frame for a linear *x-y* plot. We want it to go from 10 to 70 in *x* and from
102+
-3 to 8 in *y*, with automatic annotation intervals. Finally, we let the canvas be painted light red and have
103+
dimensions of 10 by 7.5 centimeters. Here's how we do it:
104+
105+
::
106+
107+
basemap(region=(10,70,-3,8), proj=:linear, figsize=(10,7.5),
108+
frame=(fill=:lightred, title="My first plot"), show=true)
109+
110+
This script will open the result in a PNG viewer and it should look like :ref:`our example 1 below <gmt_tut_1_jl>`.
111+
Examine the :doc:`/basemap` documentation so you understand what each option means.
112+
113+
.. _gmt_tut_1_jl:
114+
115+
.. figure:: /_images/GMT_tut_1.*
116+
:width: 400 px
117+
:align: center
118+
119+
Result of GMT Tutorial example 1.
120+
121+
Exercises:
122+
123+
#. Try change the **proj=:linear** values.
124+
125+
#. Try change the **frame** values.
126+
127+
#. Change title and canvas color.
128+
129+
130+
Logarithmic projection
131+
~~~~~~~~~~~~~~~~~~~~~~
132+
133+
We next will show how to do a basemap for a log–log plot. We have no data set yet but we will imagine that the
134+
raw *x* data range from 3 to 9613 and that *y* ranges from 10^20 to 10^24. One possibility is
135+
136+
::
137+
138+
basemap(region=(1,10000,1e20,1e25), proj=:loglog, figsize=(12,8), xaxis=(annot=2, label="Wavelength (m)"),
139+
yaxis=(annot=1, ticks=3, scale=:pow, label="Power (W)"), frame=(axes=:WS,), show=true)
140+
141+
Make sure your plot looks like :ref:`our example 2 below <gmt_tut_2_jl>`
142+
143+
.. _gmt_tut_2_jl:
144+
145+
.. figure:: /_images/GMT_tut_2.*
146+
:width: 400 px
147+
:align: center
148+
149+
Result of GMT Tutorial example 2.
150+
151+
Exercises:
152+
153+
#. Do not use **proj**\ =:loglog the axes lengths.
154+
155+
#. Leave the **scale**\ =:pow out of the **frame** string.
156+
157+
#. Add **grid**\ =3 to **xaxis** and **yaxis** settings.
158+
159+
Mercator projection
160+
~~~~~~~~~~~~~~~~~~~
161+
162+
Despite the problems of extreme horizontal exaggeration at high latitudes, the conformal Mercator projection
163+
(**proj=:merc**) remains the stalwart of location maps used by scientists. It is one of several cylindrical
164+
projections offered by GMT; here we will only have time to focus on one such projection. The complete syntax is simply
165+
166+
**proj=:merc**
167+
168+
To make coastline maps we use `basemap <https://www.generic-mapping-tools.org/GMT.jl/dev/coast/>`_ which automatically
169+
will access the GMT coastline, river and border data base derived from the GSHHG database [See *Wessel and Smith*, 1996].
170+
In addition to the common switches we may need to use some of several coast-specific options:
171+
172+
============== ================================================================================================
173+
Option Purpose
174+
============== ================================================================================================
175+
**area** Exclude small features or those of high hierarchical levels (see `GSHHG <https://github.com/GenericMappingTools/gshhg-gmt#readme>`_.)
176+
**resolution** Select data resolution (**f**\ ull, **h**\ igh, **i**\ ntermediate, **l**\ ow, or **c**\ rude)
177+
**land** Set color of dry areas (default does not paint)
178+
**rivers** Draw rivers (chose features from one or more hierarchical categories)
179+
**map_scale** Plot map scale (length scale can be km, miles, or nautical miles)
180+
**borders** Draw political borders (including US state borders)
181+
**ocean** Set color for wet areas (default does not paint)
182+
**shore** Draw coastlines and set pen thickness
183+
============== ================================================================================================
184+
185+
One of **shore**, **land**, **ocean** must be selected. Our first coastline example is from Latin America:
186+
187+
::
188+
189+
coast(region=(-90,-70,0,20), proj=:merc, land=:chocolate, show=true)
190+
191+
Your plot should look like :ref:`our example 3 below <gmt_tut_3_jl>`
192+
193+
.. _gmt_tut_3_jl:
194+
195+
.. figure:: /_images/GMT_tut_3.*
196+
:width: 400 px
197+
:align: center
198+
199+
Result of GMT Tutorial example 3.
200+
201+
Exercises:
202+
203+
#. Add the **verbose** option.
204+
#. Try **region=**\ (270,290,0,20) instead. What happens to the annotations?
205+
#. Edit your gmt.conf file, change :term:`FORMAT_GEO_MAP`
206+
to another setting (see the :doc:`/gmt.conf` documentation), and plot again.
207+
#. Pick another region and change land color.
208+
#. Pick a region that includes the north or south poles.
209+
#. Try **shore**\ ="0.25\ **p**" instead of (or in addition to) **land**.
210+
211+
Albers projection
212+
~~~~~~~~~~~~~~~~~
213+
214+
The Albers projection (**poj=:albers**) is an equal-area conical projection;
215+
its conformal cousin is the Lambert conic projection (**proj=:lambert**).
216+
Their usages are almost identical so we will only use the Albers here.
217+
The general syntax is
218+
219+
proj=(name=:albers, center=(lon_0,lat_0), parallels=(lat_1,lat_2))
220+
221+
where (*lon_0, lat_0*) is the map (projection) center and *lat_1, lat_2*
222+
are the two standard parallels where the cone intersects the Earth's surface.
223+
We try the following command:
224+
225+
::
226+
227+
coast(region=(-130,-70,24,52), proj=(name=:albers, center=(-100,35), parallels=(33,45)),
228+
title="Conic Projection", borders=((type=1, pen=:thicker), (type=2, pen=:thinnest)),
229+
area=500, land=:gray, coast=:thinnest, show=true)
230+
231+
Your plot should look like :ref:`our example 4 below <gmt_tut_4_jl>`
232+
233+
.. _gmt_tut_4_jl:
234+
235+
.. figure:: /_images/GMT_tut_4.*
236+
:width: 400 px
237+
:align: center
238+
239+
Result of GMT Tutorial example 4.
240+
241+
Exercises:
242+
243+
#. Change the parameter :term:`MAP_GRID_CROSS_SIZE_PRIMARY` to make grid crosses instead of gridlines.
244+
245+
#. Change **region** to a rectangular box specification instead of minimum and maximum values.
246+
247+
Orthographic projection
248+
~~~~~~~~~~~~~~~~~~~~~~~
249+
250+
The azimuthal orthographic projection (**proj=:ortho**) is one of several projections with similar syntax and
251+
behavior; the one we have chosen mimics viewing the Earth from space at an infinite distance; it is neither
252+
conformal nor equal-area. The syntax for this projection is
253+
254+
proj=(name=:ortho, center=(lon_0,lat_0))
255+
256+
where (*lon_0, lat_0*) is the center of the map (projection). As an example we will try
257+
258+
::
259+
260+
coast(region=:global360, proj=(name=:ortho, center=(280,30)), frame=(annot=:a, grid=:a),
261+
area=5000, land=:white, ocean=:DarkTurquoise, show=true)
262+
263+
Your plot should look like :ref:`our example 5 below <gmt_tut_5_jl>`
264+
265+
.. _gmt_tut_5_jl:
266+
267+
.. figure:: /_images/GMT_tut_5.*
268+
:width: 400 px
269+
:align: center
270+
271+
Result of GMT Tutorial example 5
272+
273+
Exercises:
274+
275+
#. Use the rectangular option in **region** to make a rectangular map showing the US only.
276+
277+
Eckert IV and VI projection
278+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
279+
280+
We conclude the survey of map projections with the Eckert IV and VI projections, two of several projections
281+
used for global thematic maps; They are both equal-area projections whose syntax is
282+
283+
proj=(name=:EckertIV, center=lon_0)
284+
proj=(name=:EckertVI, center=lon_0)
285+
286+
The *lon_0* is the central meridian (which takes precedence over the mid-value implied by the **region** setting).
287+
A simple Eckert VI world map is thus generated by
288+
289+
::
290+
291+
coast(region=:global360, proj=(name=:EckertVI, center=180), frame=(annot=:a, grid=:a), resolution=:crude,
292+
area=5000, land=:chocolate, shore=:thinnest, ocean=:DarkTurquoise, show=true)
293+
294+
Your plot should look like :ref:`our example 6 below <gmt_tut_6_jl>`
295+
296+
.. _gmt_tut_6_jl:
297+
298+
.. figure:: /_images/GMT_tut_6.*
299+
:width: 400 px
300+
:align: center
301+
302+
Result of GMT Tutorial example 6
303+
304+
Exercises:
305+
306+
#. Center the map on Greenwich.
307+
308+
#. Add a map scale with **map_scale**.

0 commit comments

Comments
 (0)