from IPython.core.display import Image
Use software tools to keep a running record of 1 or more files.
Data differencing
Unix diff
and patch
utilities
Given a file, and a complete set of diffs between one state and another, any intermediate state for which there is a diff can be reconstructed.
http://en.wikipedia.org/wiki/Revision_control
thesis2.tex
, JFM-21mar.doc
, pooh.txt
, ...
http://en.wikipedia.org/wiki/Revision_control
Bazaar
stuff1.txt
, stuff2.f90
, stuff4.m
probably isn't a good enough systemhttp://git-scm.com/documentation
Pro Git book: http://git-scm.com/book
$ git help
$ git init myproject
$ cd myproject
add/create some files
$ git add
$ git commit -m"Initial commit."
Print revision history of files or whole repository:
$ git log
Show differences between revisions:
$ git diff
Show status of files (e.g. modified, added, removed, missing, not tracked)
$ git status
N.B. There are lots of options for each command. See git help command
Tags are symbolic names for specific revisions in the repository. Most often you assign a tag to the current revision (HEAD) to mark a significant event.
Tag the current revision as jgr_1
:
$ git tag --anotate -m"1st submission to JGR." jgr_1
Print a list of the tags in the repository:
$ git tag --list
$ git clone project_repo
$ cd project
edit some files
$ git add file1 file2 file3
$ git commit -m"My changes."
$ git push
project_repo
can be a path, or a URL (http
, https
, ssh
)
Based on the argparse standard library module
SOG run
- Runs model from 1 or more parameter value filesSOG batch
- Execute a series of runs, possibly concurrently
Based on the cliff command line tool package
salishsea run tides.yaml iodef.xml ../results/tides3
salishsea prepare
- Create a NEMO run directory containing files and symlinks
salishsea combine
- Combine per-processor netCDF results files; optionally compress
salishsea gather
- combine
+ move run inputs, outputs & metadata to results directory
salishsea get_cgrf
manages CGRF atmospheric forcing file collectionSalishSeaTools
Packagebathy_tools
- Viewing and manipulation of netCDF bathymetry filesnc_tools
- Exploring and managing the attributes of netCDF filestidetools
- Analysis and plotting tidal harmonics results from NEMOstormtools
- Analysis of storm surge results from the Salish Sea Modelviz_tools
- Functions to do routine tasks associated with plotting and visualizationhg_commands
- API for Mercurial commands that other tools usenamelist
- Parse Fortran namelist files as Python dictionary data structures
Documentation at http://salishsea-meopar-tools.readthedocs.org/en/latest/SalishSeaTools/salishsea-tools.html
Daily, quasi-operational forecast of the 1st spring phytoplankton bloom in the Strait of Georgia:
Do all of that while we get on with other research!
import requests
url = 'http://climate.weather.gc.ca/climateData/bulkdata_e.html'
params = {
'stationID': 6831,
'format': 'xml',
'Year': 2014,
'Month': 6,
'Day': 1,
'timeframe': 1,
}
response = requests.get(url, params=params)
print(response.text[:1000])
<?xml version="1.0" encoding="utf-8"?><climatedata xmlns:xsd="http://www.w3.org/TR/xmlschema-1/" xsd:schemaLocation="http://www.climate.weatheroffice.gc.ca/climateData/bulkxml/bulkschema.xsd"><lang>ENG</lang><legend> <flag> <symbol>M</symbol> <description>Missing</description> </flag> <flag> <symbol>E</symbol> <description>Estimated</description> </flag> <flag> <symbol>NA</symbol> <description>Not Available</description> </flag> <flag> <symbol>**</symbol> <description>Partner data that is not subject to review by the National Climate Archives</description> </flag> </legend> <stationinformation><name>SANDHEADS CS</name><province>BRITISH COLU
with requests.session() as s:
s.post(disclaimer_url, data='I Agree')
time.sleep(5)
response = s.get(data_url, params=params)
import subprocess
cmd = 'nice -n 19 SOG < infile > outfile 2>&1'
proc = subprocess.Proc(cmd, shell=True)
while True:
if proc.poll() is None:
time.sleep(30)
else:
print('Done!)
break
import matplotlib.pyplot as plt
fig, ax_left = matplotlib.pyplot.subplots(1, 1)
ax_right = ax_left.twinx()
ax_left.plot(nitrate.time, nitrate.values, color='blue')
ax_right.plot(diatoms.time, diatoms.values, color='green')
ax_left.set_ytitle('Nitrate Concentration [uM N]')
ax_right.set_ytitle('Diatom Biomass [uM N]')
ax_left.set_xtitle('Year Day in 2014')
fig.savefig('nitrate_diatoms_timeseries.svg')
page_tmpl = """
<h1>Strait of Georgia Spring Bloom Prediction</h1>
<p>
The median bloom date calculate from a
{member_count} ensemble forecast is
{bloom_dates['median']:%Y-%m-%d}
...
</p>
"""
page = page_tmpl.format(
member_count=len(members),
bloom_dates=bloom_dates,
...
)
with open('page.html', 'rt') as f:
f.write(page)
rsync
, scp
, sftp
, hg
, git
, ...
cmd = [
'rsync',
'-Rtvhz',
'{}/./{}'.format(html_path, results_page),
'shelob:/www/salishsea/data/'
]
subprocess.check_call(cmd)
Daily, quasi-operational forecast of the 1st spring phytoplankton bloom in the Strait of Georgia:
Do all of that while we get on with other research!
Shell script to run SoG-bloomcast:
# cron script to run SoG-bloomcast
#
# make sure that this file has mode 744
# and that MAILTO is set in crontab
VENV=/data/dlatorne/.virtualenvs/bloomcast
RUN_DIR=/data/dlatorne/SOG-projects/SoG-bloomcast/run
. $VENV/bin/activate && cd $RUN_DIR && $VENV/bin/bloomcast config.yaml
Cron entry to trigger the script daily:
MAILTO=dlatornell@eos.ubc.ca
BLOOMCAST_DIR=/data/dlatorne/SOG-projects/SoG-bloomcast
# m h dom mon dow command
0 9 * * * $BLOOMCAST_DIR/cronjob.sh
In support of the Salish Sea NEMO project we are developing a collection of IPython Notebooks that provide discussion, examples, and best practices for plotting various kinds of model results from netCDF files. They include:
salishsea_tools
packageThe notebooks so far:
The links are to static renderings of the notebooks provided by the nbviewer.ipython.org service.
The notebook sources are in the analysis_tools
directory of the public https://bitbucket.org/salishsea/tools/ repo.