Searching the USGS Earthquake Catalog with Mathematica

This note documents a simple in-class activity that I use in my GEOSC 109H earthquakes and society class. In class I describe the Gutenberg-Richter Relation that represents the distribution of earthquakes as a function of magnitude (a nice paper-based activity is available from SCEC). I show the students a plot from the GCMT catalog in class, in this activity, they use Mathematica to download data for a few randomly chosen years and see if the pattern I showed in class holds up.

The Mathematica notebook begins with a few utility functions that allow students to use web services to acquire seismicity data and a few functions to list some events (which is partly a check to see that things are working). Below is a listing of the search script (an example usage is provided below).

comcatRectangularSearchPath[start_, end_, minlat_, maxlat_, minlon_, maxlon_] := Module[{},
  "http://earthquake.usgs.gov/fdsnws/event/1/query?format=csv&starttime=" <> 
   DateString[start, "ISODateTime"] <> "&endtime=" <> 
   DateString[end, "ISODateTime"] <> 
   "&minmagnitude=4.0&minlatitude=" <> 
   ToString[Round[minlat, 0.001]] <>
   "&maxlatitude=" <> 
   ToString[Round[maxlat, 0.001]] <>
   "&minlongitude=" <> 
   ToString[Round[minlon, 0.001]] <> "&maxlongitude=" <> 
   ToString[Round[maxlon, 0.001]] <> "&orderby=time-asc"
  ]

comcatRectangularSearch[start_, end_, minlat_: - 90, maxlat_: 90, 
  minlon_: - 180, maxlon_: 180] := Module[{path},
   path = comcatRectangularSearchPath[start, end, minlat, maxlat, minlon, maxlon];
  {path, Import[path, "CSV"]}
  ]

The scripts are simplistic, and to avoid errors for some of the more active years, I limit the magnitude range of the analysis to events greater than or equal to magnitude 4.0. The code below is a function to list the largest events in the search results.

Continue reading

Elevation Profiles with Mathematica

Introduction

One of the activities that I use in my 100-level earthquakes and society class is an exploration of Earth’s topography using Mathematica. Mathematica provides easy access to elevation data and has some relatively simple to use commands for making rudimentary maps. They are not competitive with a nice GMT (Generic Mapping Tools) product, but they are useful for exploring concepts. I keep things simple and have students simply execute the notebook commands to produce topographic profiles along the paths following a constant latitude (e.g. 30N and 30S are interesting). This keeps the commands short and limits their focus on the code. For this note I will use a profile along the latitude of Penn State, which is located near the geographic center of Pennsylvania (latitude is 40.795N).

The Code

We start by creating a reference map that shows the location of the latitudinal profile using a red line. Here’s the Mathematica code:

(* create a map and show where the latitude "slide" is *)
latitude = 40.795;
p0 = Framed[
  GeoGraphics[GeoRange -> "World", GeoProjection -> "CylindricalEquidistant",
  GeoZoomLevel -> 2, GeoBackground -> "ReliefMap", ImageSize -> Full,
  GeoGridLinesStyle -> Directive[Red, Thick], 
  GeoGridLines -> {{latitude}, None}]]

and here is the map:

Mathematica world map with a red reference line at a latitude equal to 40.795N, the latitude University Park, PA.

Continue reading

Word Clouds with Mathematica

One of the examples in my introductory classes is to create a word cloud from a text file containing the text of one of their reading assignments. A word cloud is a graphical representation of the frequency with which words occur in a section of text. The underlying assumption is that the more often a word is used, the more important it is to the topic. To meet that  assumption, we have to remove common words such as “the”, “and”, “a”, etc. as well as combine different forms of a word such as plurals and singular versions – at least for the important terms.

The example used below includes the text from an introductory chapter on Plate Tectonics, that is assigned early in the course. The overall goal is to show students a use of computational thinking (and computing) that helps in the analysis of something other than mathematical computations.

Before making the word cloud we have to scrub the text to remove non-words such as numbers, and to remove words that carry little information about the topic such as “the” – Mathematica calls these terms stop words. I use the following code to make a word cloud and then adapts some of the scrubbing functions to better clean the specific text that I am processing.

Import the text file

I created the text file using the scanned images of the textbook and the Mac OSX tool pdfPenPro. I copied and pasted the text into an editor and saved the file. We start by reading
the text into a string variable called d0, which we can use to manipulate the text.

(* you will have to replace the path to the text file using 
   the the menu command: Insert->File Path...
   We load and store the text into an item we'll call d0 *)
d0 = Import["Chapter02.txt"];

Continue reading

Working with Slab Model 1.0 in Mathematica

The GeoGraphics features in Mathematica that were introduced some time around Version 9 and later allow some useful exploration of geophysical data, models, etc. In this note I illustrate how to read and display (in a simple form) the tectonic Slab 1.0 Model of Hayes et al [2012].

Slab Model 1.0 is available at https://earthquake.usgs.gov/data/slab/, and was constructed to be able to compare earthquake locations and faulting geometry with historical spatial patterns of seismicity, which are believed to outline the shapes of recently subducted lithospheric slabs.

You can read about the model in Hayes, G. P., D. J. Wald, and R. L. Johnson (2012), Slab1.0: A three-dimensional model of global subduction zone geometries, J. Geophys. Res., 117, B01302, doi:10.1029/2011JB008524, and if you use the model, be sure to cite that paper.

Parsing the Slab 1.0 kmz File

The simplest way to import the model is to parse the kmz file available from the US Geological Survey’s site (see the link above). You can read about the kmz file format here. Essentially kmz is a compressed form of kml, which is short for keyhole markup language.

KMZ files can contain a number of constructs and in this case, the slab contours are stored in graphics primitives for drawing lines. What we ultimately want to extract from the file are the latitudes and longitudes of contours of slab depth. The contours are stored in increments of 20 km, starting at 20 km beneath sea level.

The information can be imported into Mathematica using the standard Import command. We can see what’s in the kmz file by asking Import for the elements of the file.

Import["/usr/local/data/slab_model_1.0.kmz", "Elements"]

Out[97]= {"Data", "Graphics", "GraphicsList", "ImageOverlays", "LayerNames", 
    "LayerTypes", "SpatialRange"}

We can import the kmz data using

slabkmzdata = Import["/usr/local/data/slab_model_1.0.kmz","Data"];

where you will of course have to change the path name to match that of your kmz file.

The list slabkmzdata contains a list of the graphics primitatives in the kml file. We need to unpack the list and pull the graphics commands apart. I’ll do it with some short simple functions to extract what we need in a way that makes it easy to display (to check it correct) and the manipulate.

Continue reading