In [ ]:
import os
from ecoop.ecooputil import shareUtil
from ecoop.cf import cfData, cfPlot, cfPrint
from ecoop.ecooprovdict import ecooProvDict

In [ ]:
util = shareUtil()
cfd = cfData()
cfp = cfPlot()
cft = cfPrint()
from printer import openDocument, closeDocument, addSection, addSubSection, addFigure
from splashtemplate import makeSplash
from splashdict import splash

Document


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

Section 1


In [ ]:
%%file {ID}/climate_forcing.txt
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 [ ]:
%%file {ID}/nao.txt
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 [ ]:
# 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")

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

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 [ ]:
%%file {ID}/amo.txt
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")

In [ ]:
import time
time.sleep(1)
nb_name = 'ESR_Climate_Forcing_PDF.ipynb'
util.save_notebook(ID, nb_name)
import time
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 [ ]:
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/shared/test.pdf

In [ ]:
from secret import username, password, hostname, port
inputfile = ID
outputfile = '/var/www/shared/%s' % ID
util.uploadfile(username=username, password=password, hostname=hostname, port=port, inputfile=inputfile,outputfile=outputfile, zip=True, link=False, qr=False)

INSTALLATION:

  • Download and install the ecoop code and its dependencies

      wget http://udoo.whoi.edu/shared/ecoop-0.0.1.tar.gz
      tar -zxvf ecoop-0.0.1.tar.gz
      cd ecoop-0.0.1
      pip install -r requirement.txt
      python setup.py install
      cd ..
  • pdflatex

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

      apt-get install rubygems
      gem install gist