In [1]:
cd ../dev/ecoop/trunk/python/
/home/epy/dev/ecoop/trunk/python

- Update the software library to the latest version

In [2]:
from esrutil import svnup
svnup()
Code updated to version number 7790

- Import the ESR library and get an unique ID where to save the session products

In [3]:
from esrutil import getID, getResults, makeQrCode, GUI
from driver import Driver as d
from driver import Driver as d
d = d()
ID = getID('epitest')
your session ID is :  epitest_Wednesday_07_November_2012_09_10_00_PM

In [4]:
%pylab inline

Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

- Get and plot the North Atlantic Oscillation (NAO)

In [35]:
nao = d.getnao(output=ID, web=True)
d.plotDriver(nao, ptype='bar', name='nao', nb='y', xticks=20, xticks_fontsize=20, dateformat=True, 
              figsize=(5,3), xmargin=True, ymargin=True, legend=True, output=ID, dpi=600, 
              grid=True, ylabel='Mean anomaly', title='North Atlantic Oscillation', web=True)
NAO data saved in :  epitest_Wednesday_07_November_2012_09_10_00_PM
graph saved in:  epitest_Wednesday_07_November_2012_09_10_00_PM/nao_bar.png
web is true  nao_bar.png epitest_Wednesday_07_November_2012_09_10_00_PM

In [36]:
amo = d.getamo(output=ID, web=True)
d.plotDriver(amo, ptype='bar', name='amo', nb='y', xticks=20, xticks_fontsize=20, dateformat=True, 
              figsize=(5,3), xmargin=True, ymargin=True, legend=True, output=ID, dpi=600, 
              grid=True, ylabel='Mean anomaly', title='Atlantic Multidecadal Oscillation', web=True)
AMO data saved in :  epitest_Wednesday_07_November_2012_09_10_00_PM
graph saved in:  epitest_Wednesday_07_November_2012_09_10_00_PM/amo_bar.png
web is true  amo_bar.png epitest_Wednesday_07_November_2012_09_10_00_PM

- Get and plot the phytoplankton abundance anomaly dataset (Dinoflagellates)

In [37]:
phytoplancton = d.getPhitoplancton()
diatom = phytoplancton['diatom']
dino = phytoplancton['dino']
d.plotDriver(dino, ptype='point', nb='y', datarange=(1960,2008), xticks=5, xticks_fontsize=20, dateformat=True, 
              figsize=(5,3), xmargin=True, ymargin=True, legend=True, smooth=(0.2,3), output=ID, dpi=600, 
              grid=True, xlabel='Year', ylabel='Abundance anomaly', title='Dinoflagellates (1960 - 2008)', web=True)
graph saved in:  epitest_Wednesday_07_November_2012_09_10_00_PM/driver_point.png
web is true  driver_point.png epitest_Wednesday_07_November_2012_09_10_00_PM
driver smothed data saved in :  epitest_Wednesday_07_November_2012_09_10_00_PM/driver_smooth.csv

- Plot the NAO and phytoplancton Data (Dinoflaggellates and Diatom)

In [8]:
d.plotOverlay(data1=nao, data3=dino, data2=diatom, 
                 label2='Diatom', label3='Dinoflagellates', label1='North Atlantic Oscillation', 
                 datarange=(1960,2008), smooth=(0.25,3), aligny=True, grid=True)
-1.5 2.0

- Geospatial Information plot example

Use a system call to GDAL to reproject the HDF file, convert to a GTiff format and warp it to "North-UP" representation (input hdf was flipped)

In [9]:
import os
os.system('gdal_translate -a_srs "+proj=lcc +lat_1=36.1667 +lat_2=43.8333 +lat_0=40 +lon_0=-70 +x_0=0 +y_0=0 +mo_defs +a=6378206.4 +rf=294.9786982 +to_meter=1" -a_ullr -640000 -640000 640000 640000 -of GTiff -ot Float64 /home/epy/notebook/clh-a.hdf clh-a.tif')
Out[9]:
0
In [10]:
os.system('gdalwarp clh-a.tif clh-a-nup.tif')
Out[10]:
0

Import the GRASS GIS environment and set its location settings

In [11]:
import sys
import grass.script as grass
import grass.script.setup as gsetup

gisbase = os.environ['GISBASE'] = "/usr/local/grass-7.0.svn/" 
gisdbase = os.path.join(os.environ['HOME'], "grass7data")
location = "modis"
mapset   = "PERMANENT" 
sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "python"))
gsetup.init(gisbase, gisdbase, location, mapset)
print grass.gisenv()
{'MAPSET': 'PERMANENT', 'GISDBASE': '/home/epy/grass7data', 'LOCATION_NAME': 'modis'}

Import the GTiff file into the GRASS Location

In [12]:
grass.run_command('r.in.gdal', input='clh-a-nup.tif', output='clha', flags='oe', overwrite=True)
Out[12]:
0

Set to 'null' the value 'inf'

In [13]:
grass.run_command('r.null', map='clha', setnull='inf')
Out[13]:
0

Generate a file used as "color table rules"

In [14]:
color_rules = '''0.03 128:0:133 
0.1 19:0:243
0.3 16:175:255
1 34:255:0
3 255:244:0
10 253:71:0
30 253:0:252'''
color = open("color.txt", "wb")
color.write( color_rules);
color.close()

Assign the colortable

In [15]:
grass.run_command('r.colors', map='clha', rules='color.txt')
Out[15]:
0

Export the map to png

In [16]:
grass.run_command('r.out.png', input='clha', output='clha-nup.png', flags='w', compression = 9,   overwrite=True)
Out[16]:
0

Display the map

In [17]:
from IPython.core.display import Image 
Image(filename='clha-nup.png')
Out[17]: