-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathearthquake.py
More file actions
52 lines (44 loc) · 1.52 KB
/
earthquake.py
File metadata and controls
52 lines (44 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# --- Process Data ---
data_file = open('datasets/earthquake_data.csv')
lats, lons = [], []
magnitudes = []
timestrings = []
for index, line in enumerate(data_file.readlines()):
if index > 0:
lats.append(float(line.split(',')[6]))
lons.append(float(line.split(',')[7]))
magnitudes.append(float(line.split(',')[8]))
timestrings.append(' '.join(line.split(',')[4:6]).strip('"'))
# --- Build Map ---
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0,
lat_0=0, lon_0=-130)
map.drawcoastlines()
map.drawcountries()
#map.fillcontinents(color = 'gray')
map.bluemarble()
map.drawmapboundary()
map.drawmeridians(np.arange(0, 360, 30))
map.drawparallels(np.arange(-90, 90, 30))
def get_marker_color(magnitude):
if magnitude < 3.0:
return ('go')
elif magnitude < 5.0:
return ('yo')
else:
return ('ro')
# Variable size dots:
# go through each lat, lon, plot it individually, calculating size dynamically
# magnitude 1.0 = min dot size; larger quakes scaled by magnitude
min_marker_size = 4
for lon, lat, mag in zip(lons, lats, magnitudes):
x,y = map(lon, lat)
msize = mag * min_marker_size
marker_string = get_marker_color(mag)
map.plot(x, y, marker_string, markersize=msize)
title_string = "Earthquakes of Magnitude 1.0 or Greater\n"
title_string += "%s through %s" % (timestrings[-1], timestrings[0])
plt.title(title_string)
plt.show()