Skip to content

Commit 994b36d

Browse files
committed
Added chekc installation script
1 parent bbe9f32 commit 994b36d

File tree

7 files changed

+75
-17
lines changed

7 files changed

+75
-17
lines changed

figures/grid.png

324 Bytes
Loading

figures/imshow.png

2.01 KB
Loading

scripts/check-installation.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright (c) 2016, Nicolas P. Rougier. All Rights Reserved.
3+
# Distributed under the (new) BSD License.
4+
# -----------------------------------------------------------------------------
5+
from distutils.version import LooseVersion
6+
7+
# Check for python
8+
import sys
9+
if sys.version_info <= (3,0):
10+
print("This tutorial requires Python 3\n")
11+
sys.exit()
12+
13+
# Check for numpy
14+
try:
15+
import numpy as np
16+
except:
17+
print("This tutorial requires numpy\n")
18+
sys.exit()
19+
print("Check for numpy: ", end="")
20+
if LooseVersion(np.__version__) < LooseVersion("1.0"):
21+
print("numpy too old (< 1.0)\n")
22+
sys.exit()
23+
else:
24+
print("ok")
25+
26+
27+
# Check for matplotlib
28+
try:
29+
import matplotlib as mpl
30+
except:
31+
print("This tutorial requires matplotib\n")
32+
sys.exit()
33+
print("Check for matplotlib: ", end="")
34+
if LooseVersion(mpl.__version__) < LooseVersion("1.5"):
35+
print("matplotlib too old (< 1.5)\n")
36+
sys.exit()
37+
else:
38+
print("ok")
39+
40+
# Check for basemap
41+
try:
42+
import mpl_toolkits.basemap as basemap
43+
except:
44+
print("This tutorial requires basemap\n")
45+
sys.exit()
46+
print("Check for basemap: ", end="")
47+
if LooseVersion(basemap.__version__) < LooseVersion("1.0"):
48+
print("basemape is too old (< 1.0) \n")
49+
sys.exit()
50+
else:
51+
print("ok")
52+
53+
# Check for urllib
54+
try:
55+
import urllib
56+
except:
57+
print("This tutorial requires urllib")
58+
else:
59+
print("Check for urllib: ok")

scripts/earthquakes.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2015, Nicolas P. Rougier. All Rights Reserved.
2+
# Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
33
# Distributed under the (new) BSD License.
44
# -----------------------------------------------------------------------------
55
# Based on : https://peak5390.wordpress.com
@@ -23,7 +23,7 @@
2323
# url = urllib.urlopen(feed + "significant_month.csv")
2424

2525
# Earthquakes of magnitude > 4.5 in the past 30 days
26-
url = urllib.urlopen(feed + "4.5_month.csv")
26+
url = urllib.request.urlopen(feed + "4.5_month.csv")
2727

2828
# Earthquakes of magnitude > 2.5 in the past 30 days
2929
# url = urllib.urlopen(feed + "2.5_month.csv")
@@ -32,26 +32,27 @@
3232
# url = urllib.urlopen(feed + "1.0_month.csv")
3333

3434
# Set earthquake data
35-
data = url.read().split('\n')[+1:-1]
35+
data = url.read()
36+
data = data.split(b'\n')[+1:-1]
3637
E = np.zeros(len(data), dtype=[('position', float, 2),
3738
('magnitude', float, 1)])
3839
for i in range(len(data)):
39-
row = data[i].split(',')
40+
row = data[i].split(b',')
4041
E['position'][i] = float(row[2]),float(row[1])
4142
E['magnitude'][i] = float(row[4])
4243

4344

44-
fig = plt.figure(figsize=(10,8))
45+
fig = plt.figure(figsize=(14,10))
4546
ax = plt.subplot(1,1,1)
4647
P = np.zeros(50, dtype=[('position', float, 2),
4748
('size', float, 1),
4849
('growth', float, 1),
4950
('color', float, 4)])
5051

5152
# Basemap projection
52-
earth = Basemap(projection='mill')
53-
earth.drawcoastlines(color='0.50', linewidth=0.25)
54-
earth.fillcontinents(color='0.95')
53+
map = Basemap(projection='mill')
54+
map.drawcoastlines(color='0.50', linewidth=0.25)
55+
map.fillcontinents(color='0.95')
5556
scat = ax.scatter(P['position'][:,0], P['position'][:,1], P['size'], lw=0.5,
5657
edgecolors = P['color'], facecolors='None', zorder=10)
5758

@@ -64,7 +65,7 @@ def update(frame):
6465
P['size'] += P['growth']
6566

6667
magnitude = E['magnitude'][current]
67-
P['position'][i] = earth(*E['position'][current])
68+
P['position'][i] = map(*E['position'][current])
6869
P['size'][i] = 5
6970
P['growth'][i]= np.exp(magnitude) * 0.1
7071

@@ -76,9 +77,7 @@ def update(frame):
7677
scat.set_facecolors(P['color']*(1,1,1,0.25))
7778
scat.set_sizes(P['size'])
7879
scat.set_offsets(P['position'])
79-
return scat,
8080

81-
82-
plt.title("Earthquakes > 4.5 in the last 30 days (18/08/2015)")
81+
plt.title("Earthquakes > 4.5 in the last 30 days")
8382
animation = FuncAnimation(fig, update, interval=10)
8483
plt.show()

scripts/imshow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
2525
size='medium',
2626
transform = gca().transAxes)
2727

28-
plt.savefig('../figures/imshow.png', dpi=64)
29-
28+
#plt.savefig('../figures/imshow.png', dpi=64)
29+
plt.show()

scripts/imshow_ex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def f(x,y):
1515
Z = f(X,Y)
1616

1717
plt.axes([0.025,0.025,0.95,0.95])
18-
plt.imshow(Z,interpolation='nearest', cmap='bone', origin='lower')
18+
plt.imshow(Z,interpolation='bicubic', cmap='bone', origin='lower')
1919
plt.colorbar(shrink=.92)
2020

2121
plt.xticks([]), plt.yticks([])

scripts/subplot-vertical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
subplot(1,2,1)
44
xticks([]), yticks([])
5-
text(0.5,0.5, 'subplot(1,2,1)',ha='center',va='center',size=24,alpha=.5)
5+
text(0.5,0.5, 'subplot(2,2,1)',ha='center',va='center',size=24,alpha=.5)
66

77
subplot(1,2,2)
88
xticks([]), yticks([])
9-
text(0.5,0.5, 'subplot(1,2,2)',ha='center',va='center',size=24,alpha=.5)
9+
text(0.5,0.5, 'subplot(2,2,2)',ha='center',va='center',size=24,alpha=.5)
1010

1111
# plt.savefig('../figures/subplot-vertical.png', dpi=64)
1212
show()

0 commit comments

Comments
 (0)