In [ ]:
from ecoop.prov import *
from datetime import datetime as dt

In [ ]:
prov = initProv()

In [ ]:
prov['http://www.w3.org/ns/prov#startedAtTime'] = provStartedAtTime(dt.utcnow().toordinal())

In [ ]:
import os
import time
from ecoop.ecooputil import shareUtil
from ecoop.cf import cfData, cfPlot
from ecoop.ecooprovdict import ecooProvDict
from ecoop.printer import openDocument, closeDocument, addSection, addSubSection, addFigure
from ecoop.splashtemplate import makeSplash
from ecoop.splashdict import splash
from ecoop.epimagic import *

In [ ]:
try :
    from os import environ
    ecoop_username = environ['ecoop_username']
except :
    print "no username provided"
    ecoop_username = "anonymous"
# note : 
# when no username is provided we can still assign the username to the current unix user with :
# import getpass
# ecoop_username = getpass.getuser()

In [ ]:
%matplotlib inline

In [ ]:
util = shareUtil()
cfd = cfData()
cfp = cfPlot()

Document


In [ ]:
ID = util.get_id('test/Climate-forcing_pdf')
document = openDocument()

Section 1


In [ ]:
%%writefileref {ID}/climate_forcing.txt {ecoop_username}
Climate patterns over the North Atlantic are important drivers of oceanographic conditions and ecosystem states. 
Steadily increasing atmospheric carbon dioxide levels can not only affect climate on global and regional scales 
but alter critical aspects of ocean chemistry. Here, we describe the atmospheric forcing mechanisms related 
to climate in this region including large-scale atmospheric pressure systems, natural ocean temperature cycles in the North Atlantic, 
components of the large-scale circulation of the Atlantic Ocean, and issues related to ocean acidification.

In [ ]:
section = addSection(name='Climate Forcing', data=os.path.join(ID,'climate_forcing.txt'))

Sub Section 1


In [ ]:
%%writefileref {ID}/nao.txt {ecoop_username}
Climate and weather over the North Atlantic are strongly influenced by the relative strengths 
of two large-scale atmospheric pressure cells -- the Icelandic Low and the Azores High [4]. 
As the relative strengths of these two pressure systems vary, characteristic patterns of temperature, precipitation, and wind fields are observed. 
An index of this dipole pattern has been developed based on the standardized difference in sea level pressure between Lisbon, Portugal and Reykjavík, 
Iceland in the winter (December-February; see Glossary for a description of methods used to create standardized indicators). 
This North Atlantic Oscillation (NAO) index has been related to key oceanographic and ecological processes in the North Atlantic basin [5].  
When the NAO index is high (positive NAO state), the westerly winds shift northward and increase in strength. 
Additionally, there is an increase in precipitation over southeastern Canada, the eastern seaboard of the United States, 
and northwestern Europe. Water temperatures are cool off Labrador and northern Newfoundland, influencing the formation of Deep Labrador Slope water, 
but warm off the United States. 
Conversely, when the NAO index is low (negative NAO state), there is a southward shift and decrease in westerly winds, decreased storminess, 
and drier conditions over southeastern Canada, the eastern United States, and northwestern Europe. 
Water temperatures are warmer off Labrador and Newfoundland, but cooler off the eastern United States. 
Since 1972, the NAO has primarily been in a positive state (Figure 1), although notable short-term reversals to a negative state have been observed during this period. 
Changes in the NAO have been linked to changes in plankton community composition in the North Atlantic, reflecting changes in both the distribution 
and abundance of warm and cold-temperate species.

In [ ]:
naodata = cfd.nao_get(save=ID, csvout="nao.csv", prov=True)

In [ ]:
# NAO
naodata = cfd.nao_get(save=ID, csvout="nao.csv")
cfp.plot_index(name='NAO_lowess', xticks=10, xticks_fontsize=10, 
               data=naodata, nb='y', scategory='lowess', frac=1./6, it=6, 
               output=ID, dateformat=True, figsave="nao.png", prov=True)

In [ ]:
#from bokeh import pyplot

In [ ]:
time.sleep(1)
nb_name = 'ESR_Test_rdf.ipynb'
util.save_notebook(ID, nb_name)
time.sleep(1)

!rm -rf splash_nao.ipynb

nao_datafile = os.path.join(ID,'nao.csv')
naodatalink = util.gistit(filename=nao_datafile, jist='/usr/local/bin/gist', type='text')
nbviewerlink = util.gistit(filename=nb_name, jist='/usr/local/bin/gist', type='notebook')

splash['NAO']['nbviewer'] = nbviewerlink
splash['NAO']['repository'] = 'https://github.com/epifanio/ecoop'
splash['NAO']['download'] = 'http://144.76.93.231/shared/%s' % ID

f = open('splash_nao.ipynb', 'w')
f.write(makeSplash(splash, 'NAO'))
f.close()
naosplashlink = util.gistit(filename='splash_nao.ipynb', jist='/usr/local/bin/gist', type='notebook')

naofig = addFigure(img=os.path.join(ID,'nao.png'), name='North Atlantic Oscillation', metadata=naosplashlink)

In [ ]:
naosubsection = addSubSection(name='North Atlantic Oscillation Index', data=os.path.join(ID,'nao.txt'), fig=naofig)

Sub Section 2


In [ ]:
%%writefileref {ID}/amo.txt {ecoop_username}
Multidecadal patterns in sea surface temperature (SST) in the North Atlantic are represented by the Atlantic Multidecadal Oscillation (AMO) index. 
The AMO signal is based on spatial patterns in SST variability after removing the effects of anthropogenic forcing on temperature, 
revealing natural long term cycles in SST.
The AMO is characterized by warm and cool phases [6] with periods of approximately 20-40 years. 
The AMO index is related to air temperatures and rainfall over North America and Europe and is associated 
with changes in the frequency of droughts in North America and the frequency of severe hurricane events. 
The AMO is thought to be related to the North Atlantic branch of the deep thermohaline circulation 
(for more see The Gulf Stream below) which is in turn directly related to dynamics of the Gulf Stream.
The AMO index shows a relatively cool period starting in the early 1960s, extending through the mid 1990s. 
Since 1997, the AMO has been in a warm phase (Figure 2). 
If past patterns continue to hold, the warm phase will potentially continue for the next several decades.

In [ ]:
# AMO
amodata = cfd.amo_get(save=ID, csvout="amo.csv")
cfp.plot_index(name='AMO_lowess', xticks=10, xticks_fontsize=10, 
               data=amodata, nb='y', scategory='lowess', frac=1./6, it=6, 
               output=ID, dateformat=True, figsave="amo.png", prov=True)

In [ ]:
time.sleep(1)
nb_name = 'ESR_Test_rdf.ipynb'
util.save_notebook(ID, nb_name)
time.sleep(1)

amo_datafile = os.path.join(ID,'amo.csv')
amodatalink = util.gistit(filename=amo_datafile, jist='/usr/local/bin/gist', type='text')
nbviewerlink2 = util.gistit(filename=nb_name, jist='/usr/local/bin/gist', type='notebook')

splash['AMO']['nbviewer'] = nbviewerlink
splash['AMO']['repository'] = 'https://github.com/epifanio/ecoop'
splash['AMO']['download'] = 'http://144.76.93.231/shared/%s' % ID

f = open('splash_amo.ipynb', 'w')
f.write(makeSplash(splash, 'AMO'))
f.close()
amosplashlink = util.gistit(filename='splash_amo.ipynb', jist='/usr/local/bin/gist', type='notebook')

amofig = addFigure(img=os.path.join(ID,'amo.png'), name='Atlantic Multidecadal Oscillation', metadata=amosplashlink)

In [ ]:
amosubsection = addSubSection(name='Atlantic Multidecadal Oscillation', data=os.path.join(ID,'amo.txt'), fig=amofig)

Write Document


In [ ]:
closedDocument = closeDocument()

In [ ]:
texfile=''
texfile += document
texfile += section
texfile += naosubsection
texfile += amosubsection
texfile += closedDocument

In [ ]:
#print texfile

In [ ]:
pdf = os.path.join(ID,'test.tex')
f = open(pdf,'w')
f.write(texfile)
f.close()

In [ ]:
!pdflatex -output-directory={ID} {pdf}

In [ ]:
!rm -rf /var/www/shared/test.pdf

In [ ]:
!cp {ID}/test.pdf /var/www/html/shared/test.pdf

or via QR code :


In [ ]:
from IPython.core.display import Image
!rm -rf pdf.png
import qrcode
img = qrcode.make("http://144.76.93.231/shared/test.pdf")
img.save("pdf.png")
Image('pdf.png')

Upload to SFTP :

from secret import username, password, hostname, port
inputfile = ID
outputfile = '/var/www/shared/%s.zip' % ID
util.uploadfile(username=username, 
                password=password, 
                hostname=hostname, 
                port=port, 
                inputfile=inputfile,
                outputfile=outputfile, 
                zip=True, link=True, qr=True, apacheroot='/var/www/')
  • User and Version Info

In [ ]:
prov['http://www.w3.org/ns/prov#endedAtTime'] = provStartedAtTime(dt.utcnow().toordinal())

In [ ]:
prov["http://www.w3.org/ns/prov#wasAssociatedWith"] = provWasAssociatedWith("massimo patrick")

In [ ]:
prov["http://www.w3.org/ns/prov#used"] = provWasAssociatedWith("ecoop_software ipython_software")

In [ ]:
prov

In [ ]:
from IPython.core.display import Javascript

In [ ]:
Javascript("IPython.notebook.metadata['ecoop_prov'] = %s" % prov)

INSTALLATION:

  • Download and install the ecoop code and its dependencies

      git clone https://github.com/epifanio/ecoop-1
      cd ecoop-1/pyecoop
      pip install -r requirement.txt
      python setup.py install
  • pdflatex

     apt-get install texlive texlive-latex-extra
  • gist utility:

      apt-get install rubygems
      gem install gist