IRIS Orientation GMT Script

advertisement
IRIS Orientation GMT Script
#!/bin/tcsh -f
#plot_socorro_topo.gmt
#a simple script to plot topography around socorrow, NM
#this follows a tutorial by Andy Goodliffe from the university of
Alabama and was altered by Rob Porritt from UC Berkeley.
#plots topography with some illumination, then adds an inset map,
and finishes with by adding a topographic profile to the top.
#This script is overly commented to work as a tutorial for beginners.
GMT is a paint by numbers toolkit which is powerful, but confusing.
#It is usually best to start with example scripts and edit as necessary
#Fundamentally gmt is a set of c tools which take options of the form
"-A" where the "A" is a letter corresponding to a mapping parameter
or option.
#The most important options are:
# -R (or region)
# -B (or boundaries)
# -J (or projection)
#The tools then write postscript information to standard out (stdout)
and are able to take in information from standard in (stdin)
#In order for the script to work, the suer must have socorro.grd and
socorro.cpt in the current directory.
#This is an example of how to set up gmt default parameters. There's
a big list so check the help for full information
gmtset PLOT_DEGREE_FORMAT -ddd:mm:ssF
gmtset PAPER_MEDIA letter
gmtset MEASURE_UNIT inch
gmtset ANNOT_FONT_SIZE 10p
gmtset LABEL_FONT_SIZE 10p
#The first two commands make new data files. grd2cpt takes a
gridded data file and generates a color scale. grdgradient creates a
gradient file for illumination from a gridded data file
grd2cpt socorro.grd -Chaxby >! socorro2.cpt #take the grid,
socorro.grd and make a color scale called socorro2.cpt using the
haxby color pattern. look at the help for full availability of pre-defined
color patterns. You can also create your own if you feel motivated.
grdgradient socorro.grd -A0 -M -Nt -Gsocorro.grad #creates a .grad
file from the grid file. This is essentially the spatial gradient of the data
file useful as a method for illuminating topography
#most gmt plot scripts set global map parameters in an early block
like this.
set region = "-R-107.45/-106.3/33.4/34.7"
#longmin/longmax/latmin/latmax - some people set this as a variable
called "R"
set boundaries = "-BSWnea0.2f10m"
#label South and West
side of the map. annotate every .2degrees with tick marks every 10
miles
set projection = "-JM5.5i"
#the projection is M
(mercator) with an X dimension of 5.5 inches (i)
set region_inset = "-R-130/-70/26/50"
#the region to be displayed
in the inset map - ie the entire united states
set projection_inset = "-JM2i"
#projection for the inset
map. Mercator projection in default gmt units.
set region_profile = "-R-107.45/-106.3/34.0/34.06" #This is for a
profile of topography through socorro
set projection_profile = "-JX5.5i/1i"
#we want a long skinny
profile, so a new projection is necessary
#often we use psfile or psname or PS for the post-script file name
variable. This is more informative. The final output will be a .ps file
with this name.
set post_script_name = socorro.ps
#####main region
#creating a basemap - make a new file and put boundary information
set misc = "-K -V -P -X2i" #misc is a variable I use generally for
incorporating many options. This time we have -K (more plot will be
appended later), -V (be verbose - ie write information to the screen), P (portrait mode), -X2 (move the base of the plot 2 default gmt units)
psbasemap $region $projection $boundaries $misc >!
$post_script_name #create a basemap. The >! means make a new
file and overwrite if needed. Starting with a basemap is usually good
practice to make sure you have boundary and background
information.
#Add the topography for a good background
set misc = "-Isocorro.grad -Csocorro2.cpt -K -V -O " #new additions
to misc: -Isocorro.grad (illuminate with file socorro.grad created
earlier), -Csocorro2.cpt (use the cpt file created earlier). -O (overlay
the previous plot)
grdimage socorro.grd $region $projection $misc >>
$post_script_name #grdimage makes a colored image for xyz data
display. >> means append to file
#overlay contours to better illustrate the topography
set misc = "-C200 -A1000 -O -K -V" #new additions to misc: -C200
contour interval is 200. -A1000 Annotated interval is 1000
grdcontour socorro.grd $region $projection $misc >>
$post_script_name #grdcontour makes a contour map with the data
contained in the grid file
#Add a star at the map location of socorro
set misc = "-O -K -Sa0.4i -W1p/0 -G255" #new additions: -Sa0.4
create a star (a) with a size of 0.4. -W1p/0: pen size is 1 point with a
color of black for the line. -G255 fill the star with white. The 0
correspondes to black and 255 to white. Using a single number
between the two plots grayscale. You can use three numbers for
red/green/blue
psxy $region $projection $misc << END >> $post_script_name
-106.903 34.0633
END
#psxy is a great tool. It plots simple xy data. For this application we
plot a single point defined by standard input.
#add text so we know what the star means
set misc = "-O -K -G255"
pstext $region $projection $misc << END >> $post_script_name
-106.903 34.03 14 0 1 CM Socorro
END
#pstext is a difficult tool. The first entry in the data part is the location
(-106.903, 34.03). The next line is the font size, then the inclination (0
is horizontal, 90 is vertical), 1 is the font type (helvetica in this case),
CM is the location relative to the data point (CenterMiddle), and
Socorro is the text to plot
#add a scale bar
set misc = "-O -K -B500/:meters: -X1i"
psscale -Csocorro2.cpt -D1.25/-0.5/4/0.25h $misc >>
$post_script_name #psscale creates a scalebar to the location with
the size defined by the -D option.
#####now overly a single line to identify where a future profile is
set misc = "-O -W5/255/0/0 -V -K -X-1i"
psxy $region $projection $misc << END >> $post_script_name
-107.45 34.06
-106.3 34.06
END
#the two points defined in psxy are the end points of a line. Its
connected with a line of size 5 points and color red as designated by
the -W5/255/0/0
######inset map
set misc = "-O -K -G255 -Bnesw"
psbasemap $region_inset $projection_inset $misc -Y6.3i >>
$post_script_name #creates a new basemap over the original map
#inserting a star in the inset map to designate how the main map
shows socorro, NM
set misc = "-O -K -Sa0.2 -W1p/0 -G0"
psxy $region_inset $projection_inset $misc << END >>
$post_script_name
-106.903 34.0663
END
#pscoast draws state/country boundaries and lakes
set misc = "-Dl -Na -W1p/0 -O -K" #-N option is used to decide how
many features to plot. See the help for full info.
pscoast $region_inset $projection_inset $misc >> $post_script_name
###topographic profile
#first extract an xyz file from the grid file along the line of interest
#convert the grid file to an xyz file for the profile
grd2xyz socorro.grd $region_profile > socorro.xyz
#basemap for the profile above the map
set misc = "-K -O -G255 -Bnesw"
psbasemap $region_profile $projection_profile $misc -Y2.0i >>
$post_script_name
#Here we use awk to look for proper points in the xyz file and use the
| (pipe) option to send the information to psxy. Because the scale is in
longitude and depth, new region and boundary information is
necessary. Awk is a mini-programming language. This usage looks
for all values in the second column that are equal to 34.06 (the
latitude of interest). It then prints the longitude (column 1) and the
elevation (column 3) from the file socorro.xyz.
awk '{if ($2 == 34.06) print $1, $3}' socorro.xyz | psxy -R-107.45/106.3/1000/3200 -Ba.2f.2:"Longitude":/a500f500:"Elevation
(m)":nSeW $projection_profile -O -K >> $post_script_name
#add text to the profile to designated where socorro is
set misc = "-O -G0 -Y-.4i -K "
pstext $region_profile $projection_profile $misc << END >>
$post_script_name
-106.903 34.03 8 0 1 CM Socorro
END
#point to socorrow with an arrow
set misc = "-O -V -Si0.2 -G0 -Y-.2i"
psxy $region_profile $projection_profile $misc << END >>
$post_script_name
-106.903 34.06
END
#convert the 20+MB image file to a png
convert $post_script_name ${post_script_name}.png
#let the user know what happened.
echo "$post_script_name and ${post_script_name}.png graphic
objects created"
exit
Download