Lesson 1


Goals


The goal of this lesson is to familiarize you with GMT, display (image magik), and ghostview. You will run some standard gmt examples and plot the results using the program ghostview. You will learn to generate a simple location map using GMT and the high resolution coastline data base.


What is GMT?

GMT stands for Generic Mapping Tools. This is a program developed by two graduate students at Columbia University - Paul Wessel and Walter Smith. Although they are long done with graduate school, their program is following them around. Lesson 1 - never write a computer program that other people will find useful! You will spend a great deal of time improving it. Lesson 2 - if someone else writes a useful program - USE IT! GMT continues to evolve into an incredibly useful mapping tool for geologists and geophysicists. GMT is used to create location maps, plot data in numerous formats (xy plots, contour maps) and do simple data processing. Some of the geophysics tools in GMT are quite sophisticated. You can think of GMT as a geographic information system - like Grass, ArcView and similar products - only tailored to suit the needs of people who plot and present geological and geophysical data on maps. An important difference between GMT and GIS software is that the output from GMT is postscript. Postscript is a language that is used and interpreted by other programs (like ghostview) to plot images on the computer screen and print them. One important thing about postscript is that you will not be able to manipulate images easily, once the postscript is created. Also, unlike true GIS software, you cannot query maps once the postscript is created. Occasionally this is a disadvantage, but for the great majority of applications in geology, this is no great issue. Another important difference between GMT and many software products is that GMT is freely available to use and abuse. You can download it onto any computer you wish.

Check out the GMT website for much more detail: gmt website

Why do you want to learn GMT?

Learning any new software package is an investment. GMT asks for a substantial investment, particularly if you are not already familiar with UNIX operating system and writing scripts in UNIX shells. Why am I asking you to make this investment in this course? There are two reasons: 1) in geophysical analysis it is crucial to be able to plot and view various types of data on graphs and maps. It is a huge advantage to be able to quickly create these maps using computer software. GMT is nearly ideal for this task; 2) I am convinced that you can quickly overcome the steep part of the GMT learning curve, and find GMT to be quite useful in all aspects of your education and post-graduate experience. Even if in the long run you are not using GMT (no software hangs around forever!) you will be using some type of computer mapping technique. Consider this your introduction!


Examples of GMT output

A simple graph: this graph show the vertical magnetic field, measured at 23 kHz, over the Santiago crater a Masaya caldera, Nicaragua. The vertical lines show the width of the crater. The magnetic anomaly over the crater is caused by magma (high electrical conductivity) about 300 m beneath the crater rim.



A more complicated graph: This graph shows vlf data, again from Santiago Crater but collected with a different vlf transmitter station, and an interpretation of this VLF data. Note that the electical conductivity section is plotted exactly under the data, a best fit curve is plotted through the data, and the electrical conductivity section is contoured and shaded. A scale (color bar) is used to show variation in electrical conductivity as a function of depth and distance.



a simple basemap: GMT provides a complete, reasonably high resolution, database of coastlines, national boundaries, rivers, etc., and allows you to create simple maps in different geographic projections (map projections) using this data base. This is a location map created using just one line of "code": pscoast -R-90/-80/5/15 -JM6i -W -N1 -Df -P -B2g1 -G180/120/60 -V > map.ps



a more sophisticated map: this comes directly from the GMT cookbook examples. You can go directly to the gmt website for many more examples like this one!



Displaying Output from GMT

as you can see from the examples, GMT is an excellent resource for showing geologic and geophysical data on maps. GMT normally produces postscript output. In order to see this output, you need to run a program that is a postscript viewer. By convention, a postscript file usually ends in ".ps", so map.ps is an example of a file that is a postscript file. One program that is a postscript viewer is ghostview. Ghostview is a Unix utility (also available free for windows).

In you xterm, on the command line, type: gv map.ps &

ghostview should launch and the simple location map from the above example should be displayed. "gv" launches ghostview, "map.ps" is the postscript file that is displayed by ghostview, and "&" means that ghostview is running in background - you can still type other commands on the command line in your xterm.

if gv map.ps & did not work, there can be a couple of reasons. Check to make sure the spelling is absolutely correct (or simply copy the statement onto the command line using the mouse). You may get a message like:

gv: Cannot open file map.ps (No such file or directory)

This may mean that the file "map.ps" is not in your directory. To check, list the contents of the directory by typing: ls -ll, and search for the file name. If it is not present in your directory then ask for help.

If "gv" did not launch ghostview then you may need to type a slightly different command (depending on the computer system and installation running. Try ghostview map.ps or gsview map.ps

if you forget to type the "&" then you will need to quit ghostview (exit under file) before you can type on the command line again.

Assuming you are on the right track, move the mouse back into the xterm window, and type: more map.ps

You should see the contents of the file "map.ps" listed in the xterm window. "more" lists the contents of any ascii file. In this case, map.ps contains the postscript that is interpreted by ghostview and rendered into an image. If you touch the spacebar, more of the file is listed. Since the file is long, you may not want to list the whole file, so type: q for "quit", and you will get the command line back. Note that the cursor (mouse) still needs to be in the xterm window for these commands to work! "more" will list the contents of the file, but will not allow you to change the file contents

take a minute to get the feel for the ghostview program - poke around!

in the command window type: ls *.ps to list all the postscript files in the directory. View these files in ghostview



Another Postscript viewer

Postscript is a great way to store images - it excellent for particularly high resolution output. Nevertheless, there are many other image formats that are quite useful. If you want to embed your image in a microsoft document or on a webpage, postscript will not work. So it is handy to convert postscript files to other formats. One way to do this is using another program "display". To launch display and view one of your postscript files, like "map.ps", type: display map.ps"

If all is well, the example location map should appear in a box on the screen. If not, make sure you have typed everything correctly, have the file "map.ps" in your directory, and that the command "display" actually launched the program (if it did not, try running a different image viewing program like: xview map.ps , or xv map.ps,or ggv map.ps

Assuming you are in "display", now move the mouse over the image, and press (click and hold) the right mouse button. A new window should appear. Scroll down to the "save..." button in this window. Note that you can save the map using many different file formats. Try saving the image as a jpeg - now calling the file "test1.jpg". Files in this format can be imported into many applications (e.g., MS Word), although some resolution is often lost. Other file formats that are often good to try are "gif" and "pdf"

Click the "Quit" button on the xv control window to bail out.



Generating a Location Map with GMT

GMT comes with extensive documentation. For example, you can read and print the GMT tutorial by launching ghostview and opening gmt_tutorial.ps

On the command line type (or copy and paste using the mouse) the following command line

pscoast -R-90/-80/5/15 -JM6i -B2g1 -G180/180/180 > location_map1.ps

then type: gv location_map1.ps and a simple location map should pop-up in ghostview. You just used GMT to generate a simple location map! Syntax is very important, so look at the command line carefully. Here are the basic elements:

pscoast : this is a gmt command that indicates you are going to generate a postscript file with gmt showing coastlines and similar geographic (or political) boundaries. All gmt commands begin with "ps" presumably to indicate that postscript is generated by the command.

-R-90/-80/5/15 : indicates the region that will be plotted. This region is shown and outlined in degrees, which makes sense for such a large map area. The units of R can be any number that you want (but only some numbers make sense!). Note that the nomenclature (syntax) is -R min x value/ maximum x value / minimum y value / maximum y value. Note that in the western hemisphere the degrees west are given as negative numbers.

-JM6i : controls the map projection. In this case a Mercator projection is used and the total width of the map is six inches. Note that the scale is controlled by setting the region and the map size. Many other projections are available.

-B2g1 : labels the axes every 2 dgrees of latitude and longitude, draws a grid every 1 degree of latitute and longitude

-G180/180/180 controls the shading of the continents and other land areas. The numbers are in the red/green/blue (rgb) scheme. If the colors are equal, you get a shade of gray. The larger the number (up to 255) the darker the shade of gray.

> : create the following file and write to it. This > symbol directs the output generated by gmt to the following file (in this case location_map1.ps). The contents of the previous file with this name will be blown away! You will also find that you can add to the contents of the file using a ">>" symbol (more on that later)

location_map1.ps : the name of the location map (file) that the command line creates.

-R, -J, -B, -G are arguments (options) that you specify when generating a map using gmt. Some arguments (like -R) are required in order to generate the map at all, and others are not required. For a complete list of arguments for "pscoast", move the mouse into the xterm window and simply type pscoast . Too much info? Try typing pscoast | more then use the spacebar to page through

Experiment with the command line we have already used. Change the color of the land area:

pscoast -R-90/-80/5/15 -JM6i -B2g1 -G180/0/0 > location_map1.ps

and view the results

change the size (scale) of the map:

pscoast -R-90/-80/5/15 -JM3i -B2g1 -G70/180/180 > location_map1.ps

and view the results

change the annotation and grid spacing:

pscoast -R-90/-80/5/15 -JM6i -B5g5 -G180/180/180 > location_map1.ps

and view the results

change the map projection to an orthographic projection:

pscoast -R-90/-80/5/15 -JG-90/10/6i -B5g5 -G180/180/180 > location_map1.ps

and view the results



Add Detail to the Location Map

It helps to add detail to the location map. Here we will use a higher resolution coastline database by adding the "-Df" option. We will outline the coastlines more clearly using the " -W" option, we will add national boundaries using the "-N1" option. We will also plot the map using the "-P" option for portait mode - instead of landscape mode.

pscoast -R-90/-80/5/15 -JM6i -B2g4 -N1 -Df -W -G180/180/180 -P > location_map1.ps

and view the results



Assignment #1

Choose any area in the world you wish and draw a simple base map of the area (it will help you in the long run if you choose an area you are interested in! Or, I do not mind if you choose an area that is your thesis area, etc). Make at least two of these base maps - one on a very regional (or global) scale, the other zooming in on the area of interest. Print the two maps and turn them in as hard copies. In addition, youwant to save these files for your own use. Try inserting thenm in "Word" by cutting from gv and pasting into a word.doc.


Chuck Connor
Last modified: Fri Dec 30 15:39:19 EST 2005