0% found this document useful (0 votes)
263 views28 pages

GMT Uno

The document describes GMT (Generic Mapping Tools), a software package used to create maps and graphs. GMT includes over 50 programs that each perform specific tasks related to mapping and plotting. Common GMT commands allow users to create basemaps with coastlines, political boundaries, and annotation. Scripts can be used to automate GMT commands and create customized maps and figures.

Uploaded by

melomanozalo
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
263 views28 pages

GMT Uno

The document describes GMT (Generic Mapping Tools), a software package used to create maps and graphs. GMT includes over 50 programs that each perform specific tasks related to mapping and plotting. Common GMT commands allow users to create basemaps with coastlines, political boundaries, and annotation. Scripts can be used to automate GMT commands and create customized maps and figures.

Uploaded by

melomanozalo
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

GMT: The Generic Mapping Tools

Example output

GMT = a software package to create high-quality postscript maps

and graphs in various projections.

Output includes standard x-y-plots as well as complicated maps

combined with other geographical referenced data.

Around 6000 scientists and engineers worldwide are using GMT in

their work

GMT is a highly effective way for creating customized, professional

looking maps or graphs.

More information and on-line manual: http://gmt.soest.hawaii.edu/


Your rst GMT map

GMT: The Generic Mapping Tools

At the command prompt, type:

GMT comes as a set of more than 50 programs and tools, each of

pscoast -R0/360/-70/70 -Jm1.2e-2i -Ba60f30/a30f15 -Dc -G240 -W1/0 -P > GMT_mercator.ps


To display the resulting map, type: gv GMT mercator.ps

them performing a specic 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

Figure 1: My rst GMT map!

What did we just type? Displaying postscript


There are several standard tools to display postscript, usually available
on most unix systems: ghostview: gs ghostscript: gv ImageMagick: display

A GMT command to plot coastlines: pscoast

Followed by a series of arguments in the form -...:

-R0/360/-70/70 = select frame between longitudes 0/360 and

latitudes -70/70

-Jm1.2e-2i = use Mercator projection (m) and a scale of 0.012

degree per inch

-Ba60f30/a30f15 = annotate longitude borders every 60 degrees,

latitude border every 30 degrees, ll longitude borders every 30 degrees,

Note that GMT commands can be directly piped into gv for instance:
pscoast -R0/360/-70/70 -Jm1.2e-2i -Ba60f30/a30f15 -Dc -G240 -W1/0 -P | gv | (vertical bar) means that the output of GMT is directly fed into (=
piped into) gv.

latitude border every 15 degree.

-Dc = use a crude resolution for plotting coastlines

-G240 = color landmasses in light grey (0=black, 255=white)

-W1/0 = draw coastlines with a 1 point-wide line (i.e. extra thin) in black

-P = plot in portrait mode (GMT default is landscape)

Unix: basic commands

Unix

login, logout, work environment Current directory? pwd Creating a new directory: mkdir directory Changing directory:
Go to home directory:

UNIX is an operating system, i.e. it manages the way the computer

work by driving the processor, the on-board memory, the disk drives,

keyboards, video monitors, etc. and by performing useful tasks for the

users

cd or cd user name
Go to directory /home/users/ecalais/work:

UNIX was created in the late 1960s as a multiuser, multitasking

cd /home/users/ecalais/work
Go to directory one level below:

system for use by programmers.

The philosophy behind the design of UNIX was to provide simple, yet

cd ..

powerful utilities that could be pieced together in a exible manner to

List the content of a directory: ls


List all les (includind those starting with a .):

perform a wide variety of tasks.

ls -a

Show details (ownership, date, etc):

ls -l

Unix: basic commands


Connect to remote computer: ssh [email protected] Transfer les between computers by ftp:
Establish connection with: ftp computername.domain For secure connection use: sftp computername.domain Anonymous ftp: ftp computername.domain, username =

Unix: basic commands

Create empty le: touch file1

Copying a le: cp file1 file2

Moving (= renamimg) a le: mv file2 file3

Removing a le: rm file3


anonymous, password your email address
Change directory on the server: cd directory Change directory on the host: lcd directory Transfer in binary mode: binary Download a le: get file

Viewing les:

cat file name

more file name

Editing les:

vi file name, emacs file name Upload a le: put file

edit file name (opens a new window)

Manual pages: man unix command

Unix: variables

set day = 1 echo $day echo $day > junk echo $day > /dev/null @ day = $day + 1 echo $day >> junk cat junk

Unix: if

Note that:

set day = 2 if ($day == 2) then echo you win else echo you loose endif
Try with day = 1 ...

> redirects the output of a command to a le. If the le did not exist, it

is created. If the le already existed, it is overwritten!

>> appends the output of a command to a le. If the le did not exist, it

is created. If the le already existed, the output is appended.

Unix: awk
echo echo echo echo echo 1234567 | awk {print substr($1,1,4))} echo 1234567 | awk {print substr($1,5,3))} set a = echo 1234567 | awk {print substr($1,1,4))} set b = echo 1234567 | awk {print substr($1,5,3))} set c = $a$b echo $c 3 3 3 4 2 2 2 | | awk {print $1,$2} | awk {print $1/$2} | awk {print int($1/$2}} awk {print sqrt($1)}

Unix: while / foreach

set day = 1 while ($day < 10) echo This is file $day > file.$day @ day ++ end

foreach f (*) echo This is file: $f end

Unix: background/foreground processes, kill


gv C (control-C) gv Z (control-Z) bg jobs -l kill job_number gv & jobs -l kill job_number

Unix: grep

echo TOTO > junk echo TATA >> junk echo TITI >> junk cat junk

grep TATA junk grep TATA junk | awk {print substr($1,1,2)} set TA = grep TATA junk | awk {print substr($1,1,2)} echo $TA

CSH scripts

Scripts are programs written in Unix, with different possible avors: sh,
csh, bash, ksh, etc...

Unix: background/foreground processes, kill


We will be using csh. Write a le with the following content, save it as my script.csh:
#!/bin/csh -f echo n What is your name? set name = $< if ($name == eric) then echo Hello $name else echo I dont know you, bye. endif

gv & ps -elf ps -elf | more ps -elf | grep ecalais ps -elf | grep gv kill job_number

Running CSH scripts

Your rst GMT script


Create a script le gmt1.csh with the following content:
pscoast -R0/360/-70/70 -Jm1.2e-2i -Ba60f30/a30f15 -Dc -G240 -W1/0 -P > GMT_mercator.ps gv GMT_mercator.ps &

Run your script: csh my script.csh

Make your script executable and run it:

Run it using: csh gmt1.csh Or make it executable rst: chmod +x gmt1.csh And then run it: gmt1.csh

ls -al my_script.csh chmod +x my_script.csh ls -al my_script.csh my_script.csh

Your second GMT script Your second GMT script


Note that:

Lets plot the same map as before twice on the same page, shifted

vertically by 4 inches. You GMT script gmt2.csh looks like:

The contents of -R and -J do not need to be repeated The rst line creates le GMT mercator.ps (with >), the second line appends to that le (with >>) -K means that more code will be added later: therefore, every GMT command, except the last one, must have -K -O means overlay on top of previous command: therefore, every GMT command, except the rst one, must have -O -P (for portrait mode) does not need to be repeated

pscoast -R0/360/-70/70 -Jm1.2e-2i -Ba60f30/a30f15 -Dc -G240 -W1/0 -P -K > GMT_mercator.ps pscoast -R -Jm -Ba60f30/a30f15 -Dc -G240 -W1/0 -O >> GMT_mercator.ps gv GMT_mercator.ps &

Run your script using: csh gmt2.csh

Or make it executable rst: chmod +x gmt2.csh

And then run it: gmt2.csh

Assignment

Using a csh script, create on the same page 4 maps of North America

Assignment

(20<lat<65 and -140<lon<-50) using:

A Mercator projection, grey land masses, white oceans, black

coastline with crude resolution, lat/lon borders annotated every 20

degrees and lled every 5 degrees

Same as above, but light brown land masses, light blue oceans,

intermediate resolution coastlines, a 1500 km long map scale located

in the bottom right corner of the map

Same as above, with all major rivers in blue pen, state boundaries in
Figure 2: Your output should look like this...

dashed solid black, country borders in solid red, coastline in dark blue.

Same as above, using a Lambert projection, without the map scale,


with a title, and the lat/lon annotations along the S and E sides only.

Command-line arguments Standardized arguments (1/2)


Among the many possible arguments in GMT, 13 have the same meaning for all programs:

Each program requires certain arguments to dene its operation.

Arguments are explained in the manual pages and in the usage

messages.

-B Denes tickmarks, annotations, and labels for basemaps and axes -H Species that input tables have header record(s) -J Selects a map projection or one of several non-map projections -P Selects Portrait plot orientation [Default is landscape] -R Denes the min. and max. coordinates of the map/plot region -U Plots a time-stamp, by default in the lower left corner of page

Each argument specication begins with a hyphen, followed by a

letter, and sometimes a number or character string immediately after

the letter.

Do not space between the hyphen, letter, and number or string.

Do space between options. -V Verbose operation

Example: pscoast -R0/20/0/20 -G200 -JM6i -W0.25p

-B5 -V > map.ps

Standardized arguments: exercises


pscoast -R0/360/-70/70 -JM6.5i -Ba60f30 -G0 -Dc -P -V > GMT mercator.ps

Verbose:

Standardized arguments (2/2)

-X Sets the x-coordinate for the plot origin on the page

-Y Sets the y-coordinate for the plot origin on the page

Time tag:
pscoast -R0/360/-70/70 -JM6.5i -Ba60f30 -G0 -Dc -P -U > GMT mercator.ps

-c Species the number of plot copies

-: Input geographic data are (lat,lon) rather than (lon,lat)

Landscape:
pscoast -R0/360/-70/70 -JM6.5i -Ba60f30 -G0 -Dc -U > GMT mercator.ps

-K Allows more plot code to be appended to this plot later

-O Allows this plot code to be appended to an existing plot

Shift by 4 inches verticall:


pscoast -R0/360/-70/70 -JM6.5i -Ba60f30 -G0 -Dc -P -Y4i > GMT mercator.ps

Overlay and Continue modes


GMT allows you to use color and grey scales for drawing lines or lling
polygons (landmasses, symbols, etc.)

Colors in GMT

If a GMT command is NOT THE LAST (in a script for instance), then it For instance:

must contain -K, meaning more postscript code will be appended

later.
landmasses)

If a GMT command is NOT THE FIRST, then it must contain -O,

Many GMT commands use -G to dene the ll color (e.g., pscoast for

meaning this postscript code is an overlay on top of previous code.


coastlines

Many GMT commands use -W to dene the pen color (and width) for

Therefore, in a GMT script:

The rst command contains -K only

pscoast uses -I to dene the pen color (and width) for rivers pscoast uses -S to dene the ll color for oceans and lakes.

The last command contains -O only

All commands in between contain -O -K

Colors are dened with numbers from 0 to 255 that give their intensity

Grey scale in GMT

White is coded as 0 - Black is coded as 255

Colors in GMT
Colors in GMT are dened as a mixture of 3 primary colors: Red /
Green / Blue (or R/G/B in short).

Anything between 0 and 255 is grey

Example of black landmasses and grey coastlines:

pscoast -R0/360/-70/70 -JM6.5i -Ba60f30 -Dc -G0

The intensity of each of those 3 primary colors ranges from 0 (lowest


intensity) to 255 (highest intensity).

-W4/200 -P > GMT mercator.ps

For instance:
Red is coded as 255/0/0 (full red, no green, no blue). Yellow is a mixture of red and green, therefore dened as 255/255/0.

The web link below provides a wide range of RGB color denitions:
http://stommel.tamu.edu/ baum/GMT/colors/colors.html

Other pen attributes

A pen in GMT has three attributes: width, color, and texture, specied for instance with: -Wwidth[/color][ttexture][p]

Width: measured in units of the current device resolution. Append p


to specify pen width in points (1/72 of an inch).

Color: see above, gray shade or RGB. Texture:


to = dotted line ta = dashed line tstring:offset = string = length gap length gap, offset from origin

Example: pscoast -R-140/-50/20/65 -JM6.5i -Ba20f5


-N1/2/255/0/0t20 10 5 10:10 -N2/2/0/to

-W1/0/0/255 -P > GMT mercator.ps

Plotting text strings

GMT command is pstext

Plotting text strings: input data


As an external le: 1. Create or edit le with text data, for instance:

Input data to pstext must contain:

x y size angle fontno justify text

x y = location, in plot units

size = font size in points (e.g. 12)

echo "-86 40 14 0 0 CM Purdue" >!

mytext.txt
2. Call pstext, for instance after a pscoast command:

angle = angle CCW from horizontal

fontno = font number (e.g. 0 for Helvetica)

justify = combination of LCM and TMB:

pscoast -R-140/-50/20/65 -JM6.5i -Ba20f5 -N1/2/255/0/0ta -N2/2/0/to -W1/0/0/255 -P -K > GMT_mercator.ps pstext mytext.txt -R -JM -O >> GMT_mercator.ps

Plotting text strings: input data Plotting text strings: input data
Directly: 1. By piping text into pstext:

echo "-86 40 14 0 0 CM Purdue" | pstext mytext.txt -R -JM -O >> GMT_mercator.ps


2. Using <<:

pstext << eof -R -JM -O >> GMT_mercator.ps -86 40 14 0 0 CM Purdue eof

Exercise

Map projections
distorsion of directions, distances, areas.

Plot a map of the continental US with the name of each state capital

3-dimensional Earths surface represented in 2-dimensions Scale: ratio of a distance on a map and that same distance on Earth. Projections attemps to minimize distorsions:
Conformal: scale is the same in all directions meridians and parallel intersect at right angles. Equidistant: distances from the center of the projection to points at equal distancea appear equal on the map. Equi-direction: azimuths are correctly portrayed on the map in all directions. Equal-area: proportional relationship between areas is preserved

shown at its geographic location. Use le state capitals, awk,

pscoast,and pstext.

on the map.

Map projections
Straight meridians and parallels that intersect at right angles. Scale is true at the equator or at two standard parallels equidistant
from the equator.

A cylindrical projection: Mercator

Cylindrical: projection of a spherical surface on a cylinder

Conic: projection of a spherical surface on a cone

Planar or Azimuthal: projection of a spherical surface on a plane


constant azimuth.

Often used for marine navigation because all straight lines are lines of In GMT:
-Jmscale or -JMwidth Give scale along equator (1:xxxx or UNIT/degree) -Jmlon0/lat0/scale or -JMlon0/lat0/width Give central meridian, standard latitude and scale along parallel (1:xxxx or UNIT/degree)

A cylindrical projection: Mercator

pscoast -R-180/180/-70/70 -JM6i -B30g30 -W1/0

A conic projection: Lambert


Lambert Conformal Conic Area and shape are distorted away from standard parallels. Directions are true in limited areas. Used for maps of North America.
-Jblon0/lat0/lat1/lat2/scale -JBlon0/lat0/lat1/lat2/width Give projection center,two standard parallels, and scale (1:xxxx or UNIT/degree).

-G240 -Dc -P > mercator.ps

A conic projection: Lambert An azimuthal projection: Stereographic


Used for navigation in polar regions. Directions are true from the center point and scale increases away
from the center point as does distortion in area and shape.

pscoast -R-20/90/15/65 -JL35/40/32/45/6i -B10g10

-W1/0 -G240 -Dc -P > lambertc.ps

-Jslon0/lat0/scale or -JSlon0/lat0/width lon0/lat0 specifies the projection center. Give scale as 1:xxxx (true at pole) or slat/1:xxxx (true at standard parallel slat) or radius/lat (radius in UNIT from origin to the oblique latitude lat).

An azimuthal projection: Stereographic

An azimuthal projection: Lambert

pscoast -R-180/180/-90/-60 -Js0/-90/3i/-60 -B10g5

pscoast -R-140/-50/20/65 -JA-95/44/6i -W1/O -G240 -Bg10 -Di -A5000 -P > lamberta.ps

-W1/0 -G240 -Dc -P > stereo.ps

Choosing a projection Choosing a projection

gmtset BASEMAP_TYPE plain pscoast -R-140/-50/20/65 -JM6i -W1/255/0/0 -Bg10 -Di -A5000 -K >! noam_proj.ps pscoast -R-140/-50/20/65 -JL-95/44/20/65/6i -W1/0/255/0 -Bg10 -Di -A5000 -O >> noam_proj.ps

Rule of thumb:

A country in the tropics asks for a cylindrical projection.

A country in the temperate zone asks for a conical projection.

A polar area asks for an azimuthal projection.

Goal = minimize distortion:

Cylindricals are true at the equator and distortion increases toward the

poles.

Conics are true along some parallel somewhere between the equator and

a pole and distortion increases away from this standard.

Azimuthals are true only at their center point, but generally distortion is

worst at the edge of the map.

Working with data les

psxy for plotting symbols


psxy uses argument -S to plot symbols For instance: -Sc will plot circles, -St triangles (type man psxy for
the entire list of available symbols)

One of the purposes of making maps is to be able to superimpose

geographically referenced data.

This data can be:

Discrete points that you want to plot with a given symbol (square,

triangle, circle, etc)

-S is followed by the scale of the symbol (e.g., 0.1) Symbol color and outline are dened with -G and -W arguments, like
in pscoast.

Continuous lines or polygons

This is commonly done with psxy

psxy for plotting symbols psxy for plotting symbols


To plot the earthquake catalog we just downloaded on a map, rst
extract the useful information (latitude, longitude) with awk:
awk NR>24 {print $7,$6} all_gt_6.neic >! tmp.sis

Log on to http://neic.usgs.gov/

Click on Earthquake Catalog Search

Choose Global Then plot the map:

Select Screen File Format, database USGS/NEIC (PDE) 1973 -

Present

pscoast -R-60/300/-70/70 -Ba30 -G230 -W1/0 -JM9i -P -K > eq1.ps

Choose minimum magnitude 6 maximum magnitude 10 and submit And add the seismicity in red circles:
psxy tmp.sis -R -JM -Sc0.09 -W1/255/0/0 -G255 -O >> eq1.ps

search

Save the resulting le in your working directory as a text le (not


html) and name it all gt 6.neic

psxy for plotting symbols


Note that the input data can also be specied as follows:
psxy << end -R -JM -Sc0.09 -W1/255/0/0 -G255 -O >> eq1.ps 166.50 -12.09 123.93 -0.12 -103.00 18.48 139.23 28.21 ... etc end

Or you can also pipe awk into psxy:


awk NR>24 {print $7,$6} all_gt_6.neic | psxy -R -JM -Sc0.09 -W1/255/0/0 -G255 -O >> eq1.ps

psxy for plotting symbols

psxy can also plot symbol color or size according to other

information, for instance earthquake depth and magnitude

Try this:

set mm = 0; set mM = 9; set dm = 0; set dM = 700 awk NR>24 {lon=$7; lat=$6; mag=$9; dep=$8; \ if (dep>dm && dep<dM && mag>mm && mag<mM) \ {print lon,lat,-dep,mag*mag/300}} \ dm=$dm dM=$dM mm=$mm mM=$mM all_gt_6.neic >! tmp.sis makecpt -T-700/0/50 -Z -Crainbow >! depth.cpt pscoast -R-60/300/-70/70 -G230 -Ba30 -W1/0 -JM9i -K > eq2.ps psxy tmp.sis -R -JM -Sc -W1/0 -Cdepth.cpt -O -K >> eq2.ps psscale -D4.5i/6.3i/9i/0.15ih -Ba50:"Earthquake Depth": \ -Cdepth.cpt -L -O >> eq2.ps

With:

set mm = 8; set mM = 9; set dm = 0; set dM = 30}

psxy for plotting symbols


Now plot volcanoes! Find data at http://www.ngdc.noaa.gov/seg/hazard/vol srch.shtml Select all volcanoes and save as world volcanoes Plot volcanoes as red triangles

psxy for plotting lines


psxy can also be used to plot lines or polygones The syntax is the same as for symbols, but you do not specify -G As usual, the color, width, and type of the line are given with -W psxy will draw continuous line until it reaches > > means pen up, start drawing a new line

psxy for plotting lines

File nuvel1 plates mod contains the trace of major plate

boundary faults

Plot map with plate boundary traces:

pscoast -R-60/300/-70/70 -Ba30 -G230 -W1/0 -JM9i -K > pbf.ps psxy nuvel1_plates_mod -R -JM -: -M -W4/255/0/0 -O >> pbf.ps


lon=strtonum(lon); lat=strtonum(lat); mag=strtonum(mag); dep=strtonum(dep); \ if (dep>dm && dep<dM && mag>mm && mag<mM) {print lon,lat,-dep,mag*mag/800}} \ dm=$dm dM=$dM mm=$mm mM=$mM $sis_file >! tmp.sis echo "Plotting seismicity..." makecpt -T-700/0/50 -Z -Crainbow >! depth.cpt psxy tmp.sis $frame $proj -Sc -W1/0 -Cdepth.cpt -O -K >> $plot psscale -D4.5/6.3/9/0.15h -Ba50:"Earthquake Depth": -Cdepth.cpt -L -O -K >> $plot echo "Sorting volcanoes..." awk NR>14 {lon=substr($0,70,8); lat=substr($0,62,7); \ lon=strtonum(lon); lat=strtonum(lat); \ print lon,lat} $vol_file >! tmp.vol echo "Plotting volcanoes..." psxy tmp.vol $frame $proj -St0.10 -G255/255/0 -W1/0 -O -K >> $plot echo "Plotting plate boundaries..." psxy $plt_file -: $frame $proj -M -W4/0 -O >> $plot

psxy for plotting symbols

#!/bin/csh -f

set set set set set set set set set set set set

plot = global_seismicity.ps sis_file = all_gt_6.neic vol_file = world_volcanoes plt_file = nuvel1_plates_mod latm = -70.0; set latM=70.0; set lonm=-60.0; set lonM=300.0 mm = 5; set mM = 9; set dm = 0; set dM = 700 proj = -JM9i grid = -B10a20::EWNS rivers = -I1/0/0/255; set resol = "-Dc -A4" LAND = -G255/228/196 WET = -S240/248/255 COAST = -W1/0/0/255

set frame=-R$lonm/$lonM/$latm/$latM

echo "Plotting basemap and coastlines..." psbasemap $proj $frame $grid -K >! $plot pscoast $frame $proj $resol $rivers -N1/1ta $COAST $LAND $WET -K -O >> $plot

echo "Sorting seismicity..." # Symbol color according to depth, size according to magnitude awk NR>24 { \ lon=substr($0,38,7); lat=substr($0,31,6); \ mag=substr($0,50,4); dep=substr($0,46,3); \

Shows your study area

Non geographic plots with psxy

GMT can be used to polt xy graphs

Lets plot y = 3sin(x)

First, lets create a data le with awk:

echo 3 | awk {for(i=1;i<=360;i++) \ {r=i*3.14/180;print r,$1*sin(r)}} > tmp.sin

Then plot the data with psxy, using -Jx:

psxy tmp.sin -JX6.5i -R0/6.28/-3/3 -W2/0 -P \ -Bg0.2a1:"x (meters)":/g0.5a1:"sin(x)":WSne:."y = 3 sin(x)": \ > sin.ps

GMT knows maths...

gmtmath can also be used to create the data le

gmtmath is a Reverse Polish Calculator

Use man gmtmath to get the (long) list of operators and functions

available

Then plot as triangles using psxy on top of previous graph

gmtmath -T0/360/1 T 3.14 MUL 180 DIV SIN 3 MUL = tmp.sin gmtmath -T0/360/10 T 3.14 MUL 180 DIV SIN 3 MUL = tmp2.sin psxy tmp.sin -JX6.5i -R0/360/-3/3 -W2/0 -P \ -Bg10a30:"x (degrees)":/g1a1:"sin(x)":WSne:."y = 3 sin(x)": -K \ > sin.ps psxy tmp2.sin -JX -R -St0.1 -G0 -O >> sin.ps

Plotting histograms

Download socal.sis: lon lat magnitude for southern California

Use pshistogram to plot the number of earthquakes per bin of 0.5

magnitude:

awk {print $3} socal.sis | \ pshistogram -JX6.5i -W0.5 \ -G240 -L1/0 -R2/8/0/10000 \ -Ba1:Magnitude:/a3000:"Number of earthquakes":WSne \ -P > socal.ps

Plotting histograms

Use pshistogram to output the binned data:

awk {print $3} socal.sis | pshistogram -W0.5 -Io

Save output for M>3 in socal.bin

Plot the number of earthquakes as a function of magnitude:

psxy socal.bin -JX6.5i -R2.5/9.5/0/10000 \ -Ba1:Magnitude:/a1000:"Number of earthquakes":WSne \ -Ss0.15 -G0 -P > socal2.ps

Same thing, using a semi-log scale:

psxy socal.bin -JX6.5i/6.5il -R2.5/9.5/1/10000 \ -Ba1:Magnitude:/a1000:"Number of earthquakes":WSne \ -Ss0.15 -G0 -P > socal2.ps

The Gutemberg relation:

Log(N) = a - b M

Get Log of number of earthquakes per bin using gmtmath

Use trend1d to t a straight line through the data

Use psxy to plot the data and the model

gmtmath -C1 socal.bin LOG10 = socal.log trend1d socal.log -Fxm -N2 -V > socal.trend psxy socal.log -JX6.5 -R2.5/9.5/0/4.5 \ -Ba1:Magnitude:/a1:"LOG(number of earthquakes)":WSne \ -Ss0.1 -W2/0 -K > socal2.ps psxy socal.trend -JX6.5i -R -W3ta -O >> socal2.ps

A word on GMT defaults...

GMT uses a number of defaults for the annotation font, angle,

A word on GMT defaults...


Defaults are stored in your working directory in le .gmtdefaults You can edit that le to change your defaults Useful defaults to changes, sometimes:
BASEMAP TYPE DEGREE FORMAT ANOT LABEL HEADER MEASURE UNIT PAPER MEDIA

basemap frame, ellipsoid for maps, etc.

Type man gmtdefaults for a list of defaults

If you are not happy with some of these defaults, you can change them

with the command gmtset

For instance:

gmtset gmtset gmtset gmtset gmtset gmtset

ANOT_FONT 29 ANOT_FONT_SIZE 16 LABEL_FONT 29 LABEL_FONT_SIZE 20 HEADER_FONT 29 HEADER_FONT_SIZE 28

Plotting a time series


Find the data range: minmax
set RE = minmax -I0.1/1 DRMC.E set RN = minmax -I0.1/1 DRMC.N

Plotting a time series

Lets plot an xy graph that shows the position of a GPS station as a Then plot:

function of time, with errors bars

Go to http://www.eas.purdue.edu/ ecalais/projects/denali/time series/

and download les DRMC.N and DRMC.E


psxy DRMC.E $RE -JX6.5/2.0 \ -Ba0.5f0.1:"Dec. year":/a20f5:"EW (mm)":WSen:."DRMC": \ -Ey0.02/2/255/0/0 -Sc0.03 -G255/0/0 -K -P -Y7i > drmc.ps

Data le DRMC.N contains the north-south component, DRMC.E the

east-west component

Data format is as follows: date (in decimal year) - position (in mm) -

uncertainty

psxy DRMC.N $RN -JX6.5/2.0 \ -Ba0.5f0.1:"Decimal year":/a20f5:"NS (mm)":WSen \ -Ey0.02/2/255/0/0 -Sc0.03 -G255/0/0 -O -Y-3.3i >> drmc.ps

GMT and gridded data sets


GMT can be used to calculate and display gridded data sets A gridded data set is an array of regularly spaced points in space You can think of it as a matrix (or as a spreadsheet):
Rows and columns correspond to y and x axis (for instance latitude and longitude) The value in each cell represents the measured quantify (for instance elevation)

GMT and gridded data sets Contouring gridded data sets


Gridded data sets can be displayed as contour maps For instance:
grdcontour etopo5.grd -R0/360/-70/70 -JM7i \ -C500 -P -B30 > etopo5_cont.ps

Gridded data sets in GMT are stored in net-CDF format: a binary

format with a header followed by the data

grdinfo allows you to check the contents of a GMT grid le Download etopo5.grd from the class web site and type grdinfo

etopo5.grd to get:

etopo5.grd: etopo5.grd: etopo5.grd: etopo5.grd: etopo5.grd: etopo5.grd: etopo5.grd: etopo5.grd: etopo5.grd:

Title: TOPO world Command: grdmath etopo5.grd 1000 x = etopo5km.grd Remark: Normal node registration used grdfile format # 0 x_min: 0 x_max: 360 x_inc: 0.0833333 units: degree nx: 4321 y_min: -90 y_max: 90 y_inc: 0.0833333 units: degree ny: 2161 z_min: -10741 z_max: 7833 units: km scale_factor: 1 add_offset: 0

This le contains the world topography and bathymetry with a grid step

of 5 minutes (about 10 km)

Contouring gridded data sets

Contouring gridded data sets


Customize your contours:

Other contouring options:

Create a contour le (cont.lev), with for instance the following 5


contour levels (note that contour 0 will be annotated):

Annotate contours with -A2000 (every 2000 unit)

Add smoothing with -S4

Tick highs and lows with -T

-8000 -3000 -2000 0 3000

C C C A C

Skip small features with -Q100 (skip if contour dened by less than

Use -Ccont.lev to plot those contours:


grdcontour etopo5.grd -R0/360/-70/70 -JM7i \ -Ccont.lev -P -B30 > etopo5_cont.ps

100 points)

Color image of gridded data sets

Contouring gridded data sets


need to creat a color map = a table that links your data range (e.g., elevation) with colors

Before you can display your gridded data set as a color image, you

There are two ways to create a color map:

119 162 243 243 176 163 214 232 249 252 217 230 207 133 134 179 142 202 245 250 makecpt -Ctopo -T-12000/8000/2000 -Z > etopo5.cpt -12000 -10000 -8000 -6000 -4000 -2000 0 2000 4000 6000 B F N 201 138 138 189 240 116 220 246 255 255 236 255 128 119 162 243 243 176 163 214 232 249 252 140 255 128 217 230 207 133 134 179 142 202 245 250 255 255 128 -10000 -8000 -6000 -4000 -2000 0 2000 4000 6000 8000 201 138 138 189 240 116 220 246 255 255

grd2cpt etopo5.grd -Cglobe -Z > etopo5.cpt

Color image of gridded data sets

Once you have a color map (etopo5.cpt), plot the image with grdimage:

Add illumination
Illumination (= shading) can be added to the color image But a grd le that contains the illumination data must be created rst Illumination will be a function of the spatial gradient of the elevation in the direction of illumination use grdgradient Then illumination needs to be normalized between -1 and +1 use
grdhisteq and grdmath

grdimage etopo5.grd -R0/360/-70/70 -JM7i \ -Cetopo5.cpt -P -B30 > etopo5_map.ps

The recipe is:


grdgradient etopo5.grd -A300 -Getopo5.grad -Nt grdhisteq etopo5.grad -Getopo5.hist -N grdinfo etopo5.hist grdmath etopo5.hist 4.41977 / = etopo5.norm

Add illumination Try different color maps


Download rob2.cpt from the class web site and produce:

Add illumination with -I:

grdimage etopo5.grd -Ietopo5.norm -R0/360/-70/70 \ -JM7i -Cetopo5.cpt -P -B30 > etopo5_map.ps

Global Digital Elevation Models


(about 10 km)

Try different color maps

ETOPO5: global bathymetry and topography, grid spacing = 5 minutes GTOPO30: global topography only
Horizontal grid spacing = 30 arc seconds (approximately 1 km). http://edcdaac.usgs.gov/gtopo30/gtopo30.html

Download myglobe.cpt from the class web site and produce:

SRTM: global topography only


Horizontal grid spacing = 1 arc second (30 m) for continental U.S., 3 arc seconds (90 m) for rest of the world http://www2.jpl.nasa.gov/srtm/ http://edc.usgs.gov/products/elevation.html

http://edcsgs9.cr.usgs.gov/pub/data/srtm/

Converting a DEM into GMT grd format

Global Digital Elevation Models


Most DEMs do not come in GMT format: they need to be converted
into netCDF format before they can be used and displayed with GMT

Log on to grdraster performs this conversion from any binary format to


netCDF

http://edcdaac.usgs.gov/gtopo30/gtopo30.html

Download north-east Africa: E020N40.tar.gz


the format of the le to be converted

Uncompress with gunzip E020N40.tar.gz

grdraster reads a le called grdraster.info that describes By default, GMT looks for grdraster.info in directory
$GMTHOME/share/dbase

Untar with tar xvf E020N40.tar

Keep E020N40.DEM but delete E020N40.tar and the all other

archive les (to save space)

If you do not have write permissions in $GMTHOME/share/dbase

Reminder: to monitor your disk quota: quota -v username


(which is most likely), then you need to set an environement variable to the directory that contain your grdraster.info le:

setenv GMT_GRIDDIR my_directory

Converting a DEM into GMT grd format

grdraster.info le contains one line per le to be converted, for

Converting a DEM into GMT grd format


Convert E020N40.DEM into GMT format using:
grdraster 17 -R20/60/-10/40 -Gne_africa.grd

instance:

17 "GTOPO30 NE AFRICA" "m" -R20/60/-10/40 -I0.5m P i 1 0 -9999 E020N40.DEM B 18 "SRTM LEVEL 3" "m" -R38/39/7/8 -I3c G i 1 0 -9999 N07E038.hgt B

Format of grdraster.info is (for le 17):

17 = le number

GTOPO30 NE AFRICA = comment

To produce a smaller le, center on the Afar depression:


grdcut ne_africa.grd -Gne_africa_sub.grd -R40/44/10/13

m = unit (meters)

-R20/60/-10/40 = boundaries of binary data le

-I0.5m = horizontal sampling in binary le

Or directly from the grdraster command:


grdraster 17 -R40/44/10/13 -Gne_africa_sub.grd

P/G = pixel versus grid registration

1 = scale to apply to binary le in conversion

0 = offset to apply to binary le in conversion

Then plot:
grdimage ne_africa_sub.grd -Ine_africa_sub.norm -R40/44/10/13 -JM7i -Cmyglobe.cpt -P -B1 > ne_africa_sub.ps

-9999 = values to use if data is NaN

E020N40.DEM = binary le name

B/L = big/little endian computer

More on displaying gridded les

Lets resample the grd les every 0.1 minutes:


grdsample ne_africa_sub.grd -Gne_africa_sub_resampled.grd -I0.1m grdsample ne_africa_sub.norm -Gne_africa_sub_resampled.norm -I0.1m grdimage ne_africa_sub_resampled.grd -Ine_africa_sub_resampled.norm \ -R40/44/10/13 -JM7i -Cmyglobe.cpt -P -B1 > ne_africa_sub.ps

It starts to show pixels...

Merging bathymetry and topography from different les

Plot bathymetry rst:

grdimage -R35/60/0/20 -JM7i etopo5.grd -Cmyglobe.cpt -P -K -Y1.5 >! all.ps

Cut the topography grid over land:

pscoast -R -JM -Dh -Gc -K -O >> all.ps grdimage -R -JM ne_africa.grd -Cmyglobe.cpt -K -O >> all.ps pscoast -Q -O -K >> all.ps

Plot coastlines:

pscoast -R -JM -B5 -Di -W2/0 -A100 -O -K >> all.ps

Note that your could grdcut etopo5.grd and resample the resulting

le at a higher resolution with grdsample

Add a color scale:


psscale -D3.5/-0.5/7/0.15h -Ba1000:Elevation:/:m: -Cmyglobe.cpt -O >> all.ps

Grid les in 3D A 3D view of the NE Caribbean plate boundary

First, lets cut the large etopo grid into a smaller subset:

grdcut etopo5.grd -R-76/-55/9/23 -Gnecar.grd grdcut etopo5.norm -R-76/-55/9/23 -Gnecar.norm

Then, lets use grdview to plot:

grdview necar.grd -JM8.5i -Cmyglobe.cpt -Qs -JZ1i -E70/20 -Wc -B1a2 -Inecar.norm > necar.ps

-Qm/s/i: plot mesh, surface, or image

-JZ: vertical scale

-E: view point azimuth/elevation

Passing arguments to csh scripts


#!/bin/csh -f # DEFINE DEFAULTS set plot_topo = n set area = 1

Building a command-driven shell-script to plot your maps

I like to be able to make nice maps of my study areas quickly without

having to edit my scripts.

To achieve that, I use the same script for every map I draw, but call it

with command-line options

For instance, to plot a map of Western North America with seismicity ranging from 4 < magnitude < 9 and 0 < depth < 100km I

# USAGE: if ($#argv < 1) then echo "Usage: run.map -a area" exit endif

use:

run.noam -a 7 -s 1 4 9 0 100

To plot a map of Central and Easter US with seismicity ranging from 6 < magnitude < 9 and 0 < depth < 100km and with

# READ USER INPUT foreach a ($argv) switch ($a) case -a: set area = $argv[2] breaksw endsw shift end echo PLOTTING AREA $area

topography I use:

run.noam -a 1 -s 1 6 9 0 100 -t y

Passing arguments to csh scripts Passing arguments to csh scripts


Download script run.map from the class web site Make sure it is executable: chmod +x run.map Try it, you get:
Usage: run.noam -a area [-s plot_sismi mm mM dm dM] [-t plot_topo] -a geographic area to plot: 1 --> Central + Eastern US 2 --> Western US -s plot seismicity: 1 => size = f(mag) 2 => equal size [n] then give limits: magmin, magmax, depthmin, depthmax -p plot topo, y/n [n]

Now pass arguments to dene display of seismicity: type magmin magmax depthmin depthmax

# READ USER INPUT foreach a ($argv) switch ($a) case -a: set area = $argv[2] breaksw case -s: set plot_sismi = $argv[2] set mm = $argv[3]; set mM = $argv[4] set dm = $argv[5]; set dM = $argv[6] breaksw endsw shift end

Now lets look at whats inside...


Make sure that you are passing the correct arguments to your script!

You might also like