Lesson 7

Goals

All seismic hazard assessments rely to one degree or another on earthquake catalogs. The goal of this lesson is to plot earthquake data (e.g., epicenters shaded by depth or magnitude) derived from an on-line earthquake catalog. In this lesson, earthquake date will be plotted on a map. Perl scripts will be explored in more detail, and modified to filter the earthquake catalog data in various ways.



Earthquake Catalogs

Many earthquake catalogs are now on-line. Visit the following websites to obtain an earthquake catalog for some region of interest to you using the CNSS site:

CNSS worldwide earthquake catalog

Harvard CMT catalog

Southern California Earthquake Data Center

Plotting Catalog Data with GMT


The plot shows the distribution of earthquake focii between 1990 and 2001 plotted using the CNSS catalog data. Only earthquakes with magnitudes greater than Ms = 3.0 are shown. The earthquakes are color-coded by depth. Note the clear outline of the plate boundaries and the dipping slab, based on earthquake focii outlined from the Middle America Trench beneath the Caribbean Plate.
Steps used in making this plot were:
  • obtain the focii data from the CNSS website
  • edit the CNSS file of focii to eliminate the headers (there are various methods for accomplishing this step, of course. For example, you can open the file in emacs and delete the headers, or you can try running the perl script and modifying the GMT script.
  • write a perl script to filter the CNSS file and obtain x,y,z for earthquake focii only, in a form suitable for plotting in GMT
  • write a gmt script to plot the earthquake focii, and color code them by depth

  • The perl script used for filtering the CNSS file is equake_read.pl

    This perl script is called as part of script7.gmt, which is used to draw the entire map, using GMT commands.


    Extracting Data from Files using Perl

    Take another look at the perl script used to filter the catalog data: equake_read.pl. The key lines in the perl script used to filter the data are:



    while (< FILE1 >) {
    $line = $_;
    @parse = split(" ", $line); #parses on the white space


    print "$parse[3] $parse[2] $parse[4]\n";


    } # this is the end of the loop that started with "while ()"
    close (FILE1);

    Look at the structure carefully. The set of lines:

    while (< FILE1 >) {
    .
    .
    .
    } # this is the end of the loop that started with "while ()"
    close (FILE1);

    are a loop, called a while-loop. The loop structure begins with a statement "while (< FILE1 >)", that means everthing inside the loop will be executed repeatedly while there is more data in the input file called FILE1. FILE1 is just an alias for whatever input file name was specified earlier in the code. In this case, for every line in the file referred to as FILE1, the steps inside the while-loop are executed. The program exits the loop when there are no more data lines in FILE1. The brackets "{....}" delineate the section of the computer code that is part of the while-loop.

    Now look at the commands that are executed within the loop. The first pair of commands are:


    $line = $_;
    @parse = split(" ", $line); #parses on the white space

    In perl, the symbols "$_" refer to "everything on one line of the input file". So the command $line = $_, means that everything on one line of the file is assigned to a variable called $line. This variable contains all the information on the line. If you printed $line the first time through the while-loop, you would see the first line of the file duplicated exactly. The next step is to extract the information we need from the line. In this case, we only need the longitude, latitude, and depth of the earthquake focus. Perl is particularly good at extracting this kind of information with a simple command. The line:


    @parse = split(" ", $line); #parses on the white space

    creates a set of variables from the single line. Every time the computer code encounters a blank (white space) in the line, it creates a new variable. This set of variables is stored in the array called "parse". The "@" in front of "parse" tells indicates that "parse" is an array and will contain sets of variables, each extracted from the line. The array can be called anything you wish, but it helps to be informative. In this case the array is called parse because we are parsing information in the line.

    In the input CNSS earthquake catalog file, the lines look like:


    1980/01/08 00:54:24.20 12.6660 -88.6140 33.00 4.90 Mb 22 0.00 NEI 198001084002

    When the command:


    @parse = split(" ", $line); #parses on the white space

    is executed, the array "parse" is filled with information from the line. Different information is stored in elements of "parse" as follows:

    $parse[0] = 1980/01/08
    $parse[1] = 00:54:24.20
    $parse[2] = 12.6660
    $parse[3] = -88.6140
    $parse[4] = 33.00
    $parse[5] = 4.90
    $parse[6] = 22
    $parse[7] = 0.00
    $parse[8] = NEI
    $parse[9] = 198001084002

    After executing the command, subsequent lines can refer to elements of the array. The longitude is stored in the element $parse[3], the latitude is stored in $parse[2], and the depth is stored in $parse[4]. Now that the line is parsed, we only have to print the information that we actually need to make the map. The line:


    print "$parse[3] $parse[2] $parse[4]\n";

    prints the longitude, latitude, and depth. In this example, the output looks like:


    -88.6140 12.6660 33.00

    The symbols "\n" puts a carriage return at the end of the new line that is printed. If instead of "longitude latitude depth", the "longitude latitude magnitude" should be printed, the print statement would be modified to look like:



    print "$parse[3] $parse[2] $parse[5]\n";

    It is possible to parse lines that have other symbols, like commas, separating the information that needs to be parsed. For example, the input file might contain lines that look like:



    543708,1379400,1300

    In this case the command to do the parsing would look like:


    @parse = split(",", $line); #parses on the comma

    Perhaps a comma followed by a space separate data contained in the line:


    @parse = split(", ", $line); #parses on the comma followed by white space

    will successfully parse this line.


    Filtering Data Sets Using Perl

    An advantage of using perl and similar computer languages is that it is easy to filter data sets with a few commands. Suppose the earthquake catalog is searched for all earthquakes within a specific geographic region. Later, you want to make a plot of only magnitude 6.0 or greater earthquakes. One approach would be to re-search the catalog. It is much more efficient just to write a filter in perl. This can be accomplished by adding a "if...then" statement to the while-loop within the perl script:


    while (< FILE1 >) {
    $line = $_;
    @parse = split(" ", $line); #parses on the white space

    if ($parse[5] => 6.0) {
    print "$parse[3] $parse[2] $parse[5]\n";
    }


    } # this is the end of the loop that started with "while ()"
    close (FILE1);

    Now, only when the value of $parse[5] is greater than or equal to 6.0 will output be printed. Notice that brackets "{}" delineate the statements that are including in the "if ... then" statement, and "then" is implied. A common programming error is to forget to match brackets. Without matching brackets, the program normally will not run at all. Unfortunately, programs will occasionally run with brackets that do not match as the programmer intends, leading to very muddled output.


    Assignment 7

    Select some area of interest - for example the area of your location map. Go to the website of the CNSS catalog and download a dataset of earthquakes for this area. Plot the earthquakes on your location map. Color-code the earthquakes by depth and magnitude (2 maps). Then plot the largest magnitude earthquakes (e.g., greater than Ms=6.5) on your map. For extra credit, make the size of the earthquake symbol proportionate to the magnitude of the earthquake. Add these resulting maps to your Word file.
    Chuck Connor
    Last modified: Thu Jan 12 11:25:19 EST 2006