Skip to content

Commit

Permalink
Added chekc installation script
Browse files Browse the repository at this point in the history
  • Loading branch information
rougier committed Jun 19, 2016
1 parent bbe9f32 commit 994b36d
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 17 deletions.
Binary file modified figures/grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/imshow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions scripts/check-installation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2016, Nicolas P. Rougier. All Rights Reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
from distutils.version import LooseVersion

# Check for python
import sys
if sys.version_info <= (3,0):
print("This tutorial requires Python 3\n")
sys.exit()

# Check for numpy
try:
import numpy as np
except:
print("This tutorial requires numpy\n")
sys.exit()
print("Check for numpy: ", end="")
if LooseVersion(np.__version__) < LooseVersion("1.0"):
print("numpy too old (< 1.0)\n")
sys.exit()
else:
print("ok")


# Check for matplotlib
try:
import matplotlib as mpl
except:
print("This tutorial requires matplotib\n")
sys.exit()
print("Check for matplotlib: ", end="")
if LooseVersion(mpl.__version__) < LooseVersion("1.5"):
print("matplotlib too old (< 1.5)\n")
sys.exit()
else:
print("ok")

# Check for basemap
try:
import mpl_toolkits.basemap as basemap
except:
print("This tutorial requires basemap\n")
sys.exit()
print("Check for basemap: ", end="")
if LooseVersion(basemap.__version__) < LooseVersion("1.0"):
print("basemape is too old (< 1.0) \n")
sys.exit()
else:
print("ok")

# Check for urllib
try:
import urllib
except:
print("This tutorial requires urllib")
else:
print("Check for urllib: ok")
23 changes: 11 additions & 12 deletions scripts/earthquakes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2015, Nicolas P. Rougier. All Rights Reserved.
# Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
# Based on : https://peak5390.wordpress.com
Expand All @@ -23,7 +23,7 @@
# url = urllib.urlopen(feed + "significant_month.csv")

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

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

# Set earthquake data
data = url.read().split('\n')[+1:-1]
data = url.read()
data = data.split(b'\n')[+1:-1]
E = np.zeros(len(data), dtype=[('position', float, 2),
('magnitude', float, 1)])
for i in range(len(data)):
row = data[i].split(',')
row = data[i].split(b',')
E['position'][i] = float(row[2]),float(row[1])
E['magnitude'][i] = float(row[4])


fig = plt.figure(figsize=(10,8))
fig = plt.figure(figsize=(14,10))
ax = plt.subplot(1,1,1)
P = np.zeros(50, dtype=[('position', float, 2),
('size', float, 1),
('growth', float, 1),
('color', float, 4)])

# Basemap projection
earth = Basemap(projection='mill')
earth.drawcoastlines(color='0.50', linewidth=0.25)
earth.fillcontinents(color='0.95')
map = Basemap(projection='mill')
map.drawcoastlines(color='0.50', linewidth=0.25)
map.fillcontinents(color='0.95')
scat = ax.scatter(P['position'][:,0], P['position'][:,1], P['size'], lw=0.5,
edgecolors = P['color'], facecolors='None', zorder=10)

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

magnitude = E['magnitude'][current]
P['position'][i] = earth(*E['position'][current])
P['position'][i] = map(*E['position'][current])
P['size'][i] = 5
P['growth'][i]= np.exp(magnitude) * 0.1

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


plt.title("Earthquakes > 4.5 in the last 30 days (18/08/2015)")
plt.title("Earthquakes > 4.5 in the last 30 days")
animation = FuncAnimation(fig, update, interval=10)
plt.show()
4 changes: 2 additions & 2 deletions scripts/imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
size='medium',
transform = gca().transAxes)

plt.savefig('../figures/imshow.png', dpi=64)

#plt.savefig('../figures/imshow.png', dpi=64)
plt.show()
2 changes: 1 addition & 1 deletion scripts/imshow_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def f(x,y):
Z = f(X,Y)

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

plt.xticks([]), plt.yticks([])
Expand Down
4 changes: 2 additions & 2 deletions scripts/subplot-vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

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

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

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

0 comments on commit 994b36d

Please sign in to comment.