The Global Earthquake Desktop

November 25, 2011
By

(This article was first published on rare earth, and kindly contributed to R-bloggers)

One of the first things I do over coffee each morning is scroll through the USGS earthquake RSS feeds.  In the era of free data and open source computing I asked myself, "Wouldn't it be better to visualize all of the earthquakes around the world rather than read a list?"  To that end I used the R maps package, some data mining, and a cron task to create a live desktop wall paper of global earthquakes.  Here's how.

Below is the final map to be used as the desktop wall paper (click to enlarge).  To create the image we'll need to pull a list of earthquake locations and magnitudes from the web, plot those earthquakes on the map, and save the output to an image file.  From there we can automate the task to update and display a new image on the desktop each day.


The U.S. Geological Survey (USGS) provides feeds and data catalogs of the latest earthquakes, which can be found here.  For our purposes we'll use the data for all earthquakes greater than magnitude 2.5 that have occurred over the last seven days.

The maps package in R is great for producing simple maps of data and coding up our earthquake map is pretty straightforward.  Here's the code.


From there you can simply set the image to your desktop wallpaper as you would any other image.  With a little extra work, however, you can setup you Mac to run the R script and update the map each day with the most recent earthquakes.  The first step is to create a shell command file in your favorite text editor and save the file with a name like "worldeq.command".


There's only three lines of code: The first line runs the R script to generate the global map of earthquakes. The second line of code sets the desktop background to the new image. The third line, killall Dock, refreshes the Dock to display the most recent image.

There you have it. Run the shell command anytime you'd like to update the desktop, add it to your login items to refresh the map each time you log in, or set up a cron task to update the image on an hourly basis.

To setup a cron task to refresh the map every four hours do the following (Thanks to Jason Mulcahy for help with this part):
  1. In terminal bring up the crontab file in the Vim editor by typing: sudo crontab -e
  2. Enter you password.
  3. Type i to modify the file.  You should see --INSERT-- at the bottom of the terminal. Enter everything below in line 4, making sure to correct the file path.
  4. * */4 * * * /Path/To/The/File/worldeq.command
  5. Type :w to write the above line of text to the file.
  6. Type :q to quit the editor.
  7. Verify that the changes were made by typing: sudo crontab -l

To leave a comment for the author, please follow the link and comment on his blog: rare earth.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , ,

Comments are closed.