GMT Uno
GMT Uno
Example output
their work
Most of the time, only 5-6 of these programs are used to plot maps or
simple graphs.
shell-scripts.
GMT commands can be called from you code (C, Fortran, etc.) or
from shell-scripts
latitudes -70/70
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.
-W1/0 = draw coastlines with a 1 point-wide line (i.e. extra thin) in black
Unix
login, logout, work environment Current directory? pwd Creating a new directory: mkdir directory Changing directory:
Go to home directory:
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:
cd /home/users/ecalais/work
Go to directory one level below:
The philosophy behind the design of UNIX was to provide simple, yet
cd ..
ls -a
Show details (ownership, date, etc):
ls -l
Viewing les:
Editing les:
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
>> appends the output of a command to a le. If the le did not exist, it
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)}
set day = 1 while ($day < 10) echo This is file $day > file.$day @ day ++ end
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...
gv & ps -elf ps -elf | more ps -elf | grep ecalais ps -elf | grep gv kill job_number
Run it using: csh gmt1.csh Or make it executable rst: chmod +x gmt1.csh And then run it: gmt1.csh
Lets plot the same map as before twice on the same page, shifted
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 &
Assignment
Using a csh script, create on the same page 4 maps of North America
Assignment
Same as above, but light brown land masses, light blue oceans,
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.
with a title, and the lat/lon annotations along the S and E sides only.
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
the letter.
Verbose:
Time tag:
pscoast -R0/360/-70/70 -JM6.5i -Ba60f30 -G0 -Dc -P -U > GMT mercator.ps
Landscape:
pscoast -R0/360/-70/70 -JM6.5i -Ba60f30 -G0 -Dc -U > GMT mercator.ps
Colors in GMT
If a GMT command is NOT THE LAST (in a script for instance), then it For instance:
later.
landmasses)
Many GMT commands use -G to dene the ll color (e.g., pscoast for
Many GMT commands use -W to dene the pen color (and width) for
pscoast uses -I to dene the pen color (and width) for rivers pscoast uses -S to dene the ll color for oceans and lakes.
Colors are dened with numbers from 0 to 255 that give their intensity
Colors in GMT
Colors in GMT are dened as a mixture of 3 primary colors: Red /
Green / Blue (or R/G/B in short).
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
A pen in GMT has three attributes: width, color, and texture, specied for instance with: -Wwidth[/color][ttexture][p]
to = dotted line ta = dashed line tstring:offset = string = length gap length gap, offset from origin
mytext.txt
2. Call pstext, for instance after a pscoast command:
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:
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
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.
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)
-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).
pscoast -R-140/-50/20/65 -JA-95/44/6i -W1/O -G240 -Bg10 -Di -A5000 -P > lamberta.ps
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:
Cylindricals are true at the equator and distortion increases toward the
poles.
Conics are true along some parallel somewhere between the equator and
Azimuthals are true only at their center point, but generally distortion is
Discrete points that you want to plot with a given symbol (square,
-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.
Log on to http://neic.usgs.gov/
Present
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
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:
boundary faults
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
#!/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); \
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
Use man gmtmath to get the (long) list of operators and functions
available
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
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
psxy socal.bin -JX6.5i -R2.5/9.5/0/10000 \ -Ba1:Magnitude:/a1000:"Number of earthquakes":WSne \ -Ss0.15 -G0 -P > socal2.ps
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
Log(N) = a - b M
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
If you are not happy with some of these defaults, you can change them
For instance:
Lets plot an xy graph that shows the position of a GPS station as a Then plot:
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
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:
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
C C C A C
Skip small features with -Q100 (skip if contour dened by less than
100 points)
Before you can display your gridded data set as a color image, you
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
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
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
http://edcsgs9.cr.usgs.gov/pub/data/srtm/
http://edcdaac.usgs.gov/gtopo30/gtopo30.html
grdraster reads a le called grdraster.info that describes By default, GMT looks for grdraster.info in directory
$GMTHOME/share/dbase
(which is most likely), then you need to set an environement variable to the directory that contain your grdraster.info le:
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
17 = le number
m = unit (meters)
Then plot:
grdimage ne_africa_sub.grd -Ine_africa_sub.norm -R40/44/10/13 -JM7i -Cmyglobe.cpt -P -B1 > ne_africa_sub.ps
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:
Note that your could grdcut etopo5.grd and resample the resulting
First, lets cut the large etopo grid into a smaller subset:
grdview necar.grd -JM8.5i -Cmyglobe.cpt -Qs -JZ1i -E70/20 -Wc -B1a2 -Inecar.norm > necar.ps
To achieve that, I use the same script for every map I draw, but call it
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
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
Make sure that you are passing the correct arguments to your script!