0% found this document useful (0 votes)
161 views

Intro To GMT

GMT is a widely used open-source software package for creating maps and graphs. It was developed in the late 1980s and allows scientists and engineers to produce high-quality, customized maps and graphs. GMT includes over 50 programs that can be used individually or combined to produce maps in various projections and styles. Common tasks like plotting coastlines, grids, and symbols can be accomplished with simple GMT scripts.

Uploaded by

Natacha DUROSE
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
161 views

Intro To GMT

GMT is a widely used open-source software package for creating maps and graphs. It was developed in the late 1980s and allows scientists and engineers to produce high-quality, customized maps and graphs. GMT includes over 50 programs that can be used individually or combined to produce maps in various projections and styles. Common tasks like plotting coastlines, grids, and symbols can be accomplished with simple GMT scripts.

Uploaded by

Natacha DUROSE
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

GMT: The Generic Mapping Tools

• GMT = a software package to create high-quality


postscript maps and graphs in various projections.
• The GMT system was initiated in late 1987 at Lamont-
Doherty Earth Observatory, Columbia University by
graduate students Paul Wessel and Walter H. F. Smith
• Output includes standard x-y-plots as well as complicated
maps combined with other geographical referenced
data.
• Now, tens of thousands scientists and engineers
worldwide are using GMT in their work”
GMT: The Generic Mapping Tools
• GMT is a highly effective way for creating customized,
professional looking maps or graphs.
• GMT follows the UNIX philosophy in which complex tasks are
broken down into smaller and more manageable components.
• Individual GMT modules are small, easy to maintain, and can
be used as any other UNIX tool. GMT is written in the ANSI C
programming language (very portable)
• GMT was deliberately written for command-line usage, not a
windows environment, in order to maximize flexibility.
• More information and on-line manual:
http://gmt.soest.hawaii.edu/
Example of Outputs
GMT: The Generic Mapping Tools
• GMT comes as a set of more than 50 programs and
tools, each of them performing a specific task.
• Most of the time, only 5-6 of these programs are used
to plot maps or simple graphs.
• GMT programs are either called from the command-
line or from shell-scripts.
• GMT commands can be called from you code (C,
Fortran, etc.) or from shell-scripts
Your first GMT map
Open a terminal
Then add these lines in a file name gmt_tut1.sh :
#!/usr/bin/env -S bash -e
# This script will create a basemap with two numerical axis with the title
# “My First Plot”. The output will be stored in 2 files named gmt_tut_1.png and gmt_tut_1.pdf
gmt begin gmt_tut_1 png
gmt basemap -R10/70/-3/8 -JX4i/3i -B -B+glightred+t"My First Plot"
gmt end show
Then type: sh gmt_tut_1.sh
The output should look like this:
Your first GMT map
Open a terminal
Then add these lines in a file name gmt_tut1.sh :
#!/usr/bin/env -S bash -e
# This script will create a basemap with two numerical axis with the title
# “My First Plot”. The output will be stored in 2 files named gmt_tut_1.png and gmt_tut_1.pdf
gmt begin gmt_tut_1 png
gmt basemap -R10/70/-3/8 -JX4i/3i -B -B+glightred+t"My First Plot"
gmt end show
Exercises:
1.Try change the -JX values.
2.Try change the -B values.
3.Change title and canvas color.
Mercator projection
• The conformal Mercator projection (-JM) remains the stalwart of location
maps used by scientists.
• Cons: extreme horizontal exaggeration at high latitudes
• The complete syntax is simply: -JMwidth
Option Purpose
-A Exclude small features or those of high hierarchical levels (see GSHHG)
-D Select data resolution (full, high, intermediate, low, or crude)
-G Set color of dry areas (default does not paint)
-I Draw rivers (chose features from one or more hierarchical categories)
-L Plot map scale (length scale can be km, miles, or nautical miles)
-N Draw political borders (including US state borders)
-S Set color for wet areas (default does not paint)
-W Draw coastlines and set pen thickness
One of -W, -G, -S must be selected.
Your second GMT map
Open a terminal
Then add these lines in a file name gmt_tut2.sh :
gmt begin GMT_tut_2 png
gmt coast -R-90/-70/0/20 -JM6i -B -Gchocolate
gmt end show
Exercises:
1. Add the -V option.
2. Try -R270/290/0/20 instead. What
happens to the annotations?
3. Edit your gmt.conf file,
change FORMAT_GEO_MAP to another
setting (see the gmt.conf documentation),
and plot again.
4. Pick another region and change land
color.
5. Pick a region that includes the north or
south poles.
6. Try -W0.25p instead of (or in addition
to) -G.
Your third GMT map
In the terminal
add these lines in a file name gmt_tut3.sh :
#!/usr/bin/env -S bash -e
# Purpose: Make our completed GMT map of Italy
gmt begin italy pdf,png # Starting our new gmt modern mode session, calling plot italy and
ask for pdf and png
# Lay down painted continent with national borders on a Mercator map
gmt coast -R5/20/35/50 -Wthin -Gwheat -EIT+gred -Df -Sazure -B -N1/thick,red -JM15c
# Show where Italy is in the world via a map inset
gmt inset begin -DjTR+w4c+o0.2c -M0 -F+gwhite+pthick
gmt coast -Rg -JG10E/25N/4c -Gwheat -Bg -EIT+gred
gmt inset end
gmt end show # end will finish the plots and open them in a viewer
Your second GMT map
Then type: sh gmt_tut_2.sh
The output should look like this:
What did we just type?
• A GMT script with commands to plot
coastlines:
• The script start with the command:
#!/usr/bin/env -S bash -e
This line set the environment to bash
• The other lines that starts with “#”are
comments, they are not executed with
the script
What did we just type?
• The man GMT commands used here to plot the map is:
gmt coast
• Followed by a series of arguments in the form -...:
• -R5/20/35/50 : select frame between longitudes 5/20
and latitudes 35/50
• -JM15c : use Mercator projection (M) and a scale of 15
degree per cm
• -B : annotate longitude borders every X degrees,
latitude border every Y degrees, fill longitude borders
every XX degrees, latitude border every YY degree (X, Y
are the default values).
• -Dc : use a full resolution for plotting coastlines
• -Gwheat : color landmasses in wheat (0=black,
255=white)
What did we just type?
• -Wthin : draw coastlines with a thin point-wide line (0 =
extra thin) in default black color
• -EIT+gred : select and fill Italy region in red
• -Sazure : fill oceans with azure color
• -N1/thick,red : draw national boundaries using thick red
lines
• Every commands between gmt inset begin and gmt
inset end are used to plot inset at the right top of map.
Albers projection
• The Albers projection (-JB) is an equal-area conical projection
• its conformal cousin is the Lambert conic projection (-JL).
• The complete syntax is simply: -JBlon_0/lat_0/lat_1/lat_2/width
- where (lon_0, lat_0) is the map (projection) center
- lat_1, lat_2 are the two standard parallels where the
cone intersects the Earth’s surface.
gmt begin GMT_tut_4 png
gmt coast -R-130/-70/24/52 -JB-100/35/33/45/6i -B -B+t"Conic Projection" -N1/thicker -N2/thinnest -A500 -Ggray -Wthinnest
gmt end show
Exercises:
1.Change the
parameter MAP_GRID_CROSS_SIZ
E_PRIMARY to make grid crosses
instead of gridlines.
2.Change -R to a rectangular box
specification instead of minimum
and maximum values.
Orthographic projection
• This orthographic projection (-JG) mimics viewing the Earth from space at an
infinite distance;
• it is neither conformal nor equal-area
• The complete syntax is simply: -JGlon_0/lat_0/width
- where (lon_0, lat_0) is the center of the map (projection).
gmt begin GMT_tut_5 png
gmt coast -Rg -JG280/30/6i -Bag -Dc -A5000 -Gwhite -SDarkTurquoise
gmt end show
Exercises:
1.Use the rectangular option in -R to
make a rectangular map showing the
US only.
Eckert IV and VI projection
• used for global thematic maps
• They are both equal-area projections
• The complete syntax is simply: -JK[f|s]lon_0/width
- f gives Eckert IV (4)
- s (Default) gives Eckert VI (6)
- lon_0 is the central meridian (which takes precedence over the mid-value implied by
the -R setting).
gmt begin GMT_tut_6
gmt coast -Rg -JKs180/9i -Bag -Dc -A5000 -Gchocolate -SDarkTurquoise -Wthinnest
gmt end show
Some more GMT commands
Program Purpose
BASEMAPS
basemap Create an empty basemap frame with optional scale
coast Plot coastlines, filled continents, rivers, and political borders
legend Create legend overlay
POINTS AND
LINES
wiggle Draw spatial time-series along their (x,y)-tracks
plot Plot symbols, polygons, and lines in 2-D
plot3d Plot symbols, polygons, and lines in 3-D
HISTOGRAMS
histogram Plot a rectangular histogram
rose Plot a polar histogram(sector/rose diagram)
Some more GMT commands
Program Purpose
CONTOURS
grdcontour Contouring of grids
contour Direct contouring/imaging of (x,y,z) data by optimal triangulation
CONTOURS
SURFACES
grdimage Project and plot grids or images
grdvector Plot vector fields from grids
grdview 3-D perspective imaging of grids
UTILITIES
clip Use polygon files to initiate custom clipping paths
image Plot Sun raster files
mask Create clipping paths or generate overlay to mask
colorbar Plot gray scale or color scale bar
text Plot text strings
The Plot command (symbols)
• Plotting lines and symbols, plot is one of the most frequently used modules in GMT.
• has numerous specific options
• expects different file formats depending on what action has been selected.
• plot is harder to master than most GMT tools.
#!/bin/bash
# Plot different type of symbols with plot command
gmt begin symbols png
echo 0 0 | gmt plot -R-1/6/-1/6 -JX15/15 -BWSen+t"Symbols & pens" -Ba2g1 -Ggreen -Sc0.75c
echo 1 0 | gmt plot -Ggreen -W1,black -Sc0.75c
echo 2 0 | gmt plot -Ggreen -W1,0/130/0 -Sc0.75c
echo 3 0 | gmt plot -Ggreen -W1,black,dashed -Sc0.75c
echo 4 0 | gmt plot -Ggreen -W1,black,-. -Sc0.75c
echo 5 0 | gmt plot -G- -W1,0/130/0 -Sc0.75c
echo 0 1 | gmt plot -Gred -W1,black -Sa0.75c
echo 1 1 | gmt plot -Gred -W1,black,dashed -Sc0.75c
echo 2 1 | gmt plot -Gred -Sd0.75c
echo 3 1 | gmt plot -Gred -W0.5,black -Sh0.75c
echo 4 1 | gmt plot -W2,red -S+0.75c
echo 5 1 | gmt plot -Gred -Ss0.75c
echo 0 3 | gmt plot -Gbrown -W1 -Skflash/1.5c
echo 1 3 | gmt plot -Gblue -W1 -Skhurricane/1.5c
echo 2 3 | gmt plot -Ggray -W1 -Skpacman/1.5c
echo 3 3 | gmt plot -Gbrown -W1 -Skstar3/1.5c
echo 4 3 | gmt plot -Gyellow -W1 -Sksun/1.5c
echo 5 3 | gmt plot -Gred -W1 -Skvolcano/1.5c
echo 1 5 | gmt plot -Sk@gallo/3.5c
echo 4 5 | gmt plot -Sk@sardinha/6c
gmt end show
Symbols
with Plot
command
The Plot command (lines)
• Plotting lines and symbols, plot is one of the most frequently used modules in GMT.
• has numerous specific options
• expects different file formats depending on what action has been selected.
• plot is harder to master than most GMT tools.
#!/bin/bash
# Plot different type of lines with plot command
gmt begin lines png
# Continous red line
echo 0 0 > t.dat
echo 10 1 >> t.dat
gmt plot t.dat -R-1/11/-1/11 -JX14 -Baf -BWSen -W1,red
# Continous thick green line
echo 0 1 > t.dat
echo 10 2 >> t.dat
gmt plot t.dat -W3,green
# Dashed thick blue line
echo 0 2 > t.dat
echo 10 3 >> t.dat
gmt plot t.dat -W3,blue,dashed
.
.
.
gmt end show
Lines with
Plot
command
The Plot command
Option Symbol
-S-size horizontal dash; size is length of dash
-Sasize star; size is radius of circumscribing circle
-
Sbsize[/base][u bar; size is bar width, set unit be u if size is in x-units
nit]
Bar extends from base [0] to the y-value
-Scsize circle; size is the diameter
-Sdsize diamond; size is its side
-Se ellipse; direction (CCW from horizontal), major, and minor axes
are read from the input file
-SE ellipse; azimuth (CW from vertical), major, and minor axes in kilometers
are read from the input file
-Sgsize octagon; size is its side
The Plot command
Option Symbol
-Shsize hexagon; size is its side
-Sisize inverted triangle; size is its side
-Sksymbol/size kustom symbol; size is its side
-Slsize+tstring letter; size is fontsize. The string can be a letter or a text string
Append +ffont to set font and +jjust for justification
-Snsize pentagon; size is its side
-Sp point; no size needed (1 pixel at current resolution is used)
-Srsize rect, width and height are read from input file
-Sssize square, size is its side
-Stsize triangle; size is its side
vector; direction (CCW from horizontal) and length are read from
-Svparams
input data
Etc …..
The Plot command
- Lower case symbols (a, c, d, g, h, i, n, s, t, x) will fit inside a circle of given diameter
- Upper case symbols (A, C, D, G, H, I, N, S, T, X) will have area equal to that of a
circle of given diameter.
- size of symbols as well as their color can be determined from the input data, the
format of data can be confusing
- general format for the input data is (optional items are in brackets []
x y [ z ] [ size ] [ sigma_x ] [ sigma_y ] [ symbol ]
- If you want the color of each symbol to be
determined individually, supply a CPT with
the -C option and let the 3rd data column
contain the z-values to be used with the CPT.
- To draw error bars, use the -E option
The Plot command (vectors)
#!/bin/bash
# Plot a vector with plot command
echo 0 0 1 1 1 0.2 0.2 > tmp.dat
JRB="-JX3/3 -R-1/2/-1/2 -Ba1f1g1"
gmt begin vec png
gmt velo tmp.dat $JRB -Se1.0/0.39/10 -W1p -A10p+ea+gblue+a90
gmt end show
gmt end show
Plot Focal Mechanisms with meca
- Focal mechanism describes the movement of the fault that generates the
seismic waves.
- Beachball is a graphic represention of focal mechanism.
- Syntax : gmt meca « file.dat » -J?? –R?? ….
We will use these three focal mechanisms as the example data.
# longitude latitude depth strike dip rake magnitude [event_title]
112 32 25 30 90 0 4 Strike-slip
115 34 15 30 60 90 5 Normal
118 32 45 30 60 -90 6 Reverse copy/paste the data and save it into a
plaintext file « meca.dat ».
#!/usr/bin/env bash
gmt begin beachball png
gmt meca meca.dat -JM10c -R110/120/30/35 -Sa1c -Baf
gmt end show
Plot Focal Mechanisms with meca
Plotting grids and images
• The main file format GMT uses for grids is called **netCDF**:
• The file contains information about:
Data values on the grid
Coordinates
Metadata: units, projections, etc
• All GMT commands that operate on grids start with `grd`: `grdimage`,
`grdsample`, `grdcontour`, etc.
- Use « grdinfo » to get information about a grid file:
gmt grdinfo @earth_relief_10m
- The option `-Cn` will print only numerical information about the grid
- Option `-o` can be combined with `-Cn` to select only one of the number printed
Plot with grdcontour
- The command for making contour plots from grids is: grdcontour
- By default, it will plot using black contours with a reasonable interval.
#!/usr/bin/env bash
# Make a contour plot of Earth relief in Antarctica
gmt begin contours png
# Create the map frame and set the region (-RAQ for Antarctica) and
# projection. The projection is stereographic (-JS) centered at the South
# pole (0/-90).
gmt basemap -RAQ -JS0/-90/15c -B
# Without any options will use the defaults.
gmt grdcontour @earth_relief_10m
gmt end show
Plot with grdimage
- The command for making color plots from grids is: grdimage
- add a shadow effect to the image based on the gradient of the data values with
grdgradient
#!/usr/bin/env bash
# Make a pseudo-color plot of Antarctica relief using the defaults
gmt begin images png
# Create the map frame and set the region (-RAQ for Antarctica) and
# projection. The projection is stereographic (-JS) centered at the South
# pole (0/-90).
gmt basemap -RAQ -JS0/-90/15c -B
# Plot Earth relief by mapping values to colors using the default CPT
# chosen by GMT.
gmt grdimage @earth_relief_10m
# Add a colorbar using the default placement and style.
gmt colorbar
gmt end show
Plot with grdimage
- The command for making color plots from grids is: grdimage
- Custom CPTs can be generated and configured with the `makecpt` command.
#!/usr/bin/env bash
# Make a pseudo-color plot of Antarctica relief using the defaults
gmt begin images png
# Create the map frame and set the region (-RAQ for Antarctica) and
# projection. The projection is stereographic (-JS) centered at the South
# pole (0/-90).
gmt basemap -RAQ -JS0/-90/15c -B
# Plot Earth relief by mapping values to colors using the default CPT
# chosen by GMT.
gmt grdimage @earth_relief_10m
# Add a colorbar using the default placement and style.
gmt colorbar
gmt end show

You might also like