# how to check whether we are running on picloud
notebook_dir = !pwd
print notebook_dir
['/home/picloud/notebook']
import os
if os.getcwd() == '/home/picloud/notebook':
print 'on picloud'
on picloud
import os
os.path.exists('/home/picloud/working-open-data'), os.path.exists('/home/picloud/working-open-data')
(True, True)
!ls /home/picloud/*
/home/picloud/notebook_watcher.py /home/picloud/notebook: Day_02_class_starter.ipynb Day_02_completed.ipynb Day_04_completed.ipynb Day_04_starter.ipynb Day_05_plotting.ipynb Day_07_array_len_and_multiply.ipynb Day_08_basemap_globe_example.ipynb Day_08_completed.ipynb Day_08_freebase_intro.ipynb Day_08_starter.ipynb Day_10_A_fixed_width_parsing_completed.ipynb Day_10_freebase_cursor_completed.ipynb Day_10_requests_lxml.ipynb Day_14_PfDA_starter.ipynb Day_14_basemap_redux.ipynb Day_14_date_time.ipynb Day_15_Sample_Python_Questions.ipynb Primer.ipynb Untitled0.ipynb Untitled1.ipynb my_starter.ipynb notebook_javascript_examples.ipynb vtk_example.ipynb /home/picloud/pydata-book: ch02 ch03 ch06 ch07 ch08 ch09 ch11 ch13 /home/picloud/working-open-data: README.md data lectures notebooks pydata-book
!ls /home/picloud/working-open-data/notebooks/*.ipynb
/home/picloud/working-open-data/notebooks/Day_02_class_starter.ipynb /home/picloud/working-open-data/notebooks/Day_02_completed.ipynb /home/picloud/working-open-data/notebooks/Day_04_completed.ipynb /home/picloud/working-open-data/notebooks/Day_04_starter.ipynb /home/picloud/working-open-data/notebooks/Day_05_plotting.ipynb /home/picloud/working-open-data/notebooks/Day_07_array_len_and_multiply.ipynb /home/picloud/working-open-data/notebooks/Day_08_basemap_globe_example.ipynb /home/picloud/working-open-data/notebooks/Day_08_completed.ipynb /home/picloud/working-open-data/notebooks/Day_08_freebase_intro.ipynb /home/picloud/working-open-data/notebooks/Day_08_starter.ipynb /home/picloud/working-open-data/notebooks/Day_10_A_fixed_width_parsing_completed.ipynb /home/picloud/working-open-data/notebooks/Day_10_freebase_cursor_completed.ipynb /home/picloud/working-open-data/notebooks/Day_10_requests_lxml.ipynb /home/picloud/working-open-data/notebooks/Day_14_PfDA_starter.ipynb /home/picloud/working-open-data/notebooks/Day_14_basemap_redux.ipynb /home/picloud/working-open-data/notebooks/Day_14_date_time.ipynb /home/picloud/working-open-data/notebooks/Day_15_Sample_Python_Questions.ipynb /home/picloud/working-open-data/notebooks/notebook_javascript_examples.ipynb /home/picloud/working-open-data/notebooks/vtk_example.ipynb
plot(arange(10))
[<matplotlib.lines.Line2D at 0x376a410>]
!ls
Primer.ipynb Untitled0.ipynb my_starter.ipynb
!pwd
/home/picloud/notebook
# http://matplotlib.org/basemap/users/examples.html
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
# set up orthographic map projection with
# perspective of satellite looking down at 50N, 100W.
# use low resolution coastlines.
map = Basemap(projection='ortho',lat_0=45,lon_0=-100,resolution='l')
# draw coastlines, country boundaries, fill continents.
map.drawcoastlines(linewidth=0.25)
map.drawcountries(linewidth=0.25)
map.fillcontinents(color='coral',lake_color='aqua')
# draw the edge of the map projection region (the projection limb)
map.drawmapboundary(fill_color='aqua')
# draw lat/lon grid lines every 30 degrees.
map.drawmeridians(np.arange(0,360,30))
map.drawparallels(np.arange(-90,90,30))
# make up some data on a regular lat/lon grid.
nlats = 73; nlons = 145; delta = 2.*np.pi/(nlons-1)
lats = (0.5*np.pi-delta*np.indices((nlats,nlons))[0,:,:])
lons = (delta*np.indices((nlats,nlons))[1,:,:])
wave = 0.75*(np.sin(2.*lats)**8*np.cos(4.*lons))
mean = 0.5*np.cos(2.*lats)*((np.sin(2.*lats))**2 + 2.)
# compute native map projection coordinates of lat/lon grid.
x, y = map(lons*180./np.pi, lats*180./np.pi)
# contour data over the map.
cs = map.contour(x,y,wave+mean,15,linewidths=1.5)
plt.title('contour lines over filled continent background')
plt.show()
# http://matplotlib.org/basemap/users/merc.html
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
# llcrnrlat,llcrnrlon,urcrnrlat,urcrnrlon
# are the lat/lon values of the lower left and upper right corners
# of the map.
# lat_ts is the latitude of true scale.
# resolution = 'c' means use crude resolution coastlines.
m = Basemap(projection='merc',llcrnrlat=-80,urcrnrlat=80,\
llcrnrlon=-180,urcrnrlon=180,lat_ts=20,resolution='c')
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(-180.,181.,60.))
m.drawmapboundary(fill_color='aqua')
plt.title("Mercator Projection")
plt.show()
# http://matplotlib.org/basemap/users/laea.html
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
# setup lambert azimuthal equal area basemap.
# lat_ts is latitude of true scale.
# lon_0,lat_0 is central point.
m = Basemap(width=12000000,height=8000000,
resolution='l',projection='laea',\
lat_ts=50,lat_0=50,lon_0=-107.)
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-80.,81.,20.))
m.drawmeridians(np.arange(-180.,181.,20.))
m.drawmapboundary(fill_color='aqua')
# draw tissot's indicatrix to show distortion.
ax = plt.gca()
for y in np.linspace(m.ymax/20,19*m.ymax/20,9):
for x in np.linspace(m.xmax/20,19*m.xmax/20,12):
lon, lat = m(x,y,inverse=True)
poly = m.tissot(lon,lat,1.5,100,\
facecolor='green',zorder=10,alpha=0.5)
plt.title("Lambert Azimuthal Equal Area Projection")
plt.show()
# http://matplotlib.org/basemap/users/lcc.html
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
# setup lambert conformal basemap.
# lat_1 is first standard parallel.
# lat_2 is second standard parallel (defaults to lat_1).
# lon_0,lat_0 is central point.
# rsphere=(6378137.00,6356752.3142) specifies WGS4 ellipsoid
# area_thresh=1000 means don't plot coastline features less
# than 1000 km^2 in area.
m = Basemap(width=12000000,height=9000000,
rsphere=(6378137.00,6356752.3142),\
resolution='l',area_thresh=1000.,projection='lcc',\
lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-80.,81.,20.))
m.drawmeridians(np.arange(-180.,181.,20.))
m.drawmapboundary(fill_color='aqua')
# draw tissot's indicatrix to show distortion.
ax = plt.gca()
for y in np.linspace(m.ymax/20,19*m.ymax/20,9):
for x in np.linspace(m.xmax/20,19*m.xmax/20,12):
lon, lat = m(x,y,inverse=True)
poly = m.tissot(lon,lat,1.5,100,\
facecolor='green',zorder=10,alpha=0.5)
plt.title("Lambert Conformal Projection")
plt.show()
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
# setup lambert azimuthal equal area basemap.
# lat_ts is latitude of true scale.
# lon_0,lat_0 is central point.
m = Basemap(width=16200000,height=19500000,
resolution='l',projection='laea',\
lat_ts=0, lat_0=0,lon_0=0.)
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-80.,81.,20.))
m.drawmeridians(np.arange(-180.,181.,20.))
m.drawmapboundary(fill_color='aqua')
# draw tissot's indicatrix to show distortion.
ax = plt.gca()
for y in np.linspace(m.ymax/20,19*m.ymax/20,9):
for x in np.linspace(m.xmax/20,19*m.xmax/20,12):
lon, lat = m(x,y,inverse=True)
poly = m.tissot(lon,lat,1.5,100,\
facecolor='green',zorder=10,alpha=0.5)
plt.title("Lambert Azimuthal Equal Area Projection")
plt.show()
# http://matplotlib.org/basemap/users/geography.html
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# setup Lambert Conformal basemap.
m = Basemap(width=12000000,height=9000000,projection='lcc',
resolution='c',lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
# draw coastlines.
m.drawcoastlines()
# draw a boundary around the map, fill the background.
# this background will end up being the ocean color, since
# the continents will be drawn on top.
m.drawmapboundary(fill_color='aqua')
# fill continents, set lake color same as ocean color.
m.fillcontinents(color='coral',lake_color='aqua')
plt.show()
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# setup Lambert Conformal basemap.
# set resolution=None to skip processing of boundary datasets.
#m = Basemap(width=12000000,height=9000000,projection='lcc',
# resolution=None,lat_1=45.,lat_2=55.,lat_0=45.,lon_0=-107.)
m = Basemap(width=12000000,height=9000000,projection='lcc',
resolution='c',lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
m.bluemarble()
plt.show()