#!/usr/bin/python # Earthquake Plotting Program # "earth.png" is from NASA's "Blue Marble Next Generation"; the full-size version is accessible # at NASA's website: http://veimages.gsfc.nasa.gov/7105/world.topo.bathy.200406.3x5400x2700.jpg # Earthquake information is from the USGS's live earthquake feed, accessible at # http://earthquake.usgs.gov/eqcenter/catalogs/ # Thanks also go out to mom, dad, the designers of Quartz, the creators of Python, and, of course, # plate tectonics and hotspots for making this program possible. # This work is protected under the GNU General Public License version 3, available at: # http://www.gnu.org/licenses/gpl-3.0.txt # This particular variation is intended to map the earthquakes in the last $godknowshowlong using # a color scale from green-yellow-red for 0.0-4.0-8.0. Mw > 8.0 will be white. from CoreGraphics import * import httplib, time, sys, os, re from math import pi def mag_sort(a,b): return cmp(a[4],b[4]) eqdata = [] maxdepth = 0.0 cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB) c = CGBitmapContextCreateWithColor(2700,1350,cs,(0,0,0,0)) i = CGImageImport(CGDataProviderCreateWithFilename(os.environ['HOME'] + "/.eq-map/earth.png")) imageRect = CGRectMake(0,0,2700,1350) c.drawImage(imageRect,i) eqfile = file("earthquakes","r") data = eqfile.read() data = data.replace("\n\n","\n") data = data.split("\n") eqdata = [] del data[-1] for entry in data: info = re.split('^(.+?):(.+?:.+?:.+?):(.+?):(.+?):(.+?):(.+?)$',entry) del info[-1] del info[0] eqid,otime,lat,lon,mag,depth = info lat,lon,mag,depth = float(lat),float(lon),float(mag),float(depth) eqdata.append([eqid,otime,lat,lon,mag,depth]) eqdata.sort(mag_sort) for entry in eqdata: eqid,otime,lat,lon,mag,depth = entry x = int((lon + 180) * 7.5 + 0.5) y = int((90 - (-1 * lat)) * 7.5 + 0.5) color = [0.0,0.0,0.0,1.0] if mag <= 4.0: color[0] = 1.0 * (mag / 4.0) color[1] = 1.0 color[2] = 0.0 elif mag <= 8.0: color[0] = 1.0 color[1] = 1.0 - ((mag - 4.0) / 4.0) color[2] = 0.0 elif mag > 8.0: color[0] = 1.0 color[1] = 1.0 color[2] = 1.0 color[3] = 1.0 c.setRGBFillColor(color[0],color[1],color[2],color[3]) c.addArc(x,y,2,0,2*pi,0) c.fillPath() c.writeToFile("earthquakes-by-magnitude.png",kCGImageFormatPNG)