Created
February 21, 2018 23:46
-
-
Save pwolfram/832f2eb1ca5b711b88f03afba5a93b53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Populating the interactive namespace from numpy and matplotlib\n", | |
"mkdir: figures: File exists\r\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/Users/pwolfram/miniconda2/lib/python2.7/site-packages/xarray/core/formatting.py:16: FutureWarning: The pandas.tslib module is deprecated and will be removed in a future version.\n", | |
" from pandas.tslib import OutOfBoundsDatetime\n", | |
"/Users/pwolfram/miniconda2/lib/python2.7/site-packages/IPython/core/magics/pylab.py:161: UserWarning: pylab import has clobbered these variables: ['table']\n", | |
"`%matplotlib` prevents importing * from pylab and numpy\n", | |
" \"\\n`%matplotlib` prevents importing * from pylab and numpy\"\n" | |
] | |
} | |
], | |
"source": [ | |
"import matplotlib.pyplot as plt\n", | |
"import matplotlib as mpl\n", | |
"import numpy as np\n", | |
"import xarray as xr\n", | |
"%pylab inline\n", | |
"rcParams['savefig.dpi'] = 150\n", | |
"plt.close('all')\n", | |
"%pwd\n", | |
"plotme= True\n", | |
"figuredir = './figures'\n", | |
"%mkdir figures\n", | |
"from tabulate import tabulate\n", | |
"def save_fig(name,dpi=300, *args, **kwargs):\n", | |
" plt.savefig(figuredir+name,dpi=dpi, bbox_inches='tight')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"ds = xr.open_dataset('transport.nc')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<xarray.Dataset>\n", | |
"Dimensions: (Time: 3720, nTransects: 15)\n", | |
"Coordinates:\n", | |
" * Time (Time) float64 0.04252 0.1233 0.2042 0.2877 0.3713 0.4549 ...\n", | |
"Dimensions without coordinates: nTransects\n", | |
"Data variables:\n", | |
" TransectNames (nTransects) |S64 'Drake Passage' 'Tasmania-Ant' ...\n", | |
" Transport (Time, nTransects) float64 146.8 162.7 152.9 -12.61 ..." | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ds" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<xarray.DataArray 'TransectNames' (nTransects: 15)>\n", | |
"array(['Drake Passage', 'Tasmania-Ant', 'Africa-Ant', 'Antilles Inflow',\n", | |
" 'Mona Passage', 'Windward Passage', 'Florida-Cuba', 'Florida-Bahamas',\n", | |
" 'Indonesian Throughflow', 'Agulhas', 'Mozambique Channel',\n", | |
" 'Bering Strait', 'Lancaster Sound', 'Fram Strait', 'Robeson Channel'],\n", | |
" dtype='|S64')\n", | |
"Dimensions without coordinates: nTransects" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ds.TransectNames" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# filter out unneeded data\n", | |
"\n", | |
"# observations (Positive values are north and eastward, see Ringler et al 2013)\n", | |
"obs = {'Drake Passage': {'mean': 134 , 'std dev': 14, 'ref': 'Nowlin and Klinck (1986)'}, \n", | |
" 'Tasmania-Ant': {'mean': 157, 'std dev': 10, 'ref': 'Ganachaud and Wunsch (2000)'},\n", | |
" 'Africa-Ant': {'mean': 150, 'std dev': 30, 'ref': 'Estimated from Drake and Tasmania-Ant passages from Ganachaud and Wunsch (2000) http://onlinelibrary.wiley.com/doi/10.1029/2002JC001565/full'},\n", | |
" 'Indonesian Throughflow': {'mean': -15, 'std dev': 4, 'ref': 'Sprintall et al. (2009)'},\n", | |
" 'Agulhas': {'mean': -70, 'std dev': 20, 'ref': 'unclear from Ringler et al (2013)' },\n", | |
" 'Mozambique Channel': {'mean': -16, 'std dev': 13, 'ref': ' van der Werf et al. (2010)'},\n", | |
" 'Antilles Inflow': {'mean': -18.4, 'std dev': 4.7, 'ref': 'Johns et al. (2002) and Roemmich (1981)'},\n", | |
" 'Mona Passage': {'mean': -2.6, 'std dev': 1.2, 'ref': 'Johns et al. (2002) and Roemmich (1981).'},\n", | |
" 'Windward Passage': {'mean': -7.0, 'std dev': np.nan, 'ref': 'Johns et al. (2002) and Roemmich (1981).'},\n", | |
" 'Florida-Cuba': {'mean': 31, 'std dev': 1.5, 'ref': 'Johns et al. (2002) and Roemmich (1981).'},\n", | |
" 'Florida-Bahamas': {'mean': 31.5, 'std dev': 1.5, 'ref': 'Johns et al. (2002) and Roemmich (1981).'},\n", | |
" 'Bering Strait': {'mean': 0.8, 'std dev': 0.3, 'ref': 'Roach et al (1995) http://onlinelibrary.wiley.com/doi/10.1029/95JC01673/full'},\n", | |
" 'Lancaster Sound': {'mean': 0.8 , 'std dev': 0.3, 'ref': 'Prisenberg and Hamilton (2005) http://www.tandfonline.com/doi/abs/10.3137/ao.430101'},\n", | |
" 'Fram Strait': {'mean': -3, 'std dev': 3, 'ref': 'Schauer et al (2004) http://onlinelibrary.wiley.com/doi/10.1029/2003JC001823/full'}, \n", | |
" 'Robeson Channel': {'mean': -0.7 , 'std dev': .2 , 'ref': 'Maltrud and McClean (2005) https://www.sciencedirect.com/science/article/pii/S1463500303000684#BIB16'}\n", | |
" }" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Note: Africa-Ant completely estimated from a heuristic control volume analysis and could be removed from the table!\n", | |
"Transect location Simulation (Sv) Observation (Sv) Observation reference Result in range?\n", | |
"---------------------- ----------------- ------------------ ----------------------- --------------------------------------------------------------------------------------------------------------------------------------------\n", | |
"Drake Passage 83.8 $\\pm$ 17.7 134.0 $\\pm$ 14.0 False Nowlin and Klinck (1986)\n", | |
"Tasmania-Ant 98.0 $\\pm$ 20.0 157.0 $\\pm$ 10.0 False Ganachaud and Wunsch (2000)\n", | |
"Africa-Ant 83.4 $\\pm$ 17.9 150.0 $\\pm$ 30.0 False Estimated from Drake and Tasmania-Ant passages from Ganachaud and Wunsch (2000) http://onlinelibrary.wiley.com/doi/10.1029/2002JC001565/full\n", | |
"Antilles Inflow -15.9 $\\pm$ 3.2 -18.4 $\\pm$ 4.7 True Johns et al. (2002) and Roemmich (1981)\n", | |
"Mona Passage -1.8 $\\pm$ 1.0 -2.6 $\\pm$ 1.2 True Johns et al. (2002) and Roemmich (1981).\n", | |
"Windward Passage 1.9 $\\pm$ 2.1 -7.0 $\\pm$ nan False Johns et al. (2002) and Roemmich (1981).\n", | |
"Florida-Cuba 15.7 $\\pm$ 1.6 31.0 $\\pm$ 1.5 False Johns et al. (2002) and Roemmich (1981).\n", | |
"Florida-Bahamas 15.4 $\\pm$ 1.1 31.5 $\\pm$ 1.5 False Johns et al. (2002) and Roemmich (1981).\n", | |
"Indonesian Throughflow -11.0 $\\pm$ 3.6 -15.0 $\\pm$ 4.0 True Sprintall et al. (2009)\n", | |
"Agulhas -68.5 $\\pm$ 5.8 -70.0 $\\pm$ 20.0 True unclear from Ringler et al (2013)\n", | |
"Mozambique Channel -18.7 $\\pm$ 6.8 -16.0 $\\pm$ 13.0 True van der Werf et al. (2010)\n", | |
"Bering Strait 0.9 $\\pm$ 0.5 0.8 $\\pm$ 0.3 False Roach et al (1995) http://onlinelibrary.wiley.com/doi/10.1029/95JC01673/full\n", | |
"Lancaster Sound 0.5 $\\pm$ 0.3 0.8 $\\pm$ 0.3 True Prisenberg and Hamilton (2005) http://www.tandfonline.com/doi/abs/10.3137/ao.430101\n", | |
"Fram Strait -2.1 $\\pm$ 1.1 -3.0 $\\pm$ 3.0 True Schauer et al (2004) http://onlinelibrary.wiley.com/doi/10.1029/2003JC001823/full\n", | |
"Robeson Channel 0.0 $\\pm$ 0.0 -0.7 $\\pm$ 0.2 False Maltrud and McClean (2005) https://www.sciencedirect.com/science/article/pii/S1463500303000684#BIB16\n" | |
] | |
} | |
], | |
"source": [ | |
"def check_in_range(amean, astddev, bmean, bstddev):\n", | |
" amax = amean + astddev\n", | |
" amin = amean - astddev\n", | |
" bmax = bmean + bstddev\n", | |
" bmin = bmean - bstddev\n", | |
" \n", | |
" inrange = ((amin < bmax) and (amin > bmin)) or ((amax < bmax) and (amax > bmin))\n", | |
" return inrange\n", | |
"\n", | |
"# build the headers \n", | |
"headers = []\n", | |
"headers.append('Transect location')\n", | |
"headers.append('Simulation (Sv)')\n", | |
"headers.append('Observation (Sv)')\n", | |
"headers.append('Observation reference')\n", | |
"headers.append('Result in range?')\n", | |
"#for atrans in ds.TransectNames:\n", | |
"# headers.append(atrans.values)\n", | |
" \n", | |
"table = []\n", | |
"# structure data into table format\n", | |
"for name, mean, stddev in zip(ds.TransectNames.values, ds.Transport.mean('Time').values, ds.Transport.std('Time').values):\n", | |
" newrow = []\n", | |
" newrow.append(str(name))\n", | |
" newrow.append('%0.1f $\\pm$ %0.1f'%(mean, stddev))\n", | |
" obsmean = obs[str(name)]['mean']\n", | |
" obsstd = obs[str(name)]['std dev']\n", | |
" newrow.append('%0.1f $\\pm$ %0.1f'%(obsmean,obsstd))\n", | |
" newrow.append(str(check_in_range(mean, stddev, obsmean, obsstd)))\n", | |
" newrow.append(str(obs[str(name)]['ref']))\n", | |
" table.append(newrow)\n", | |
"\n", | |
"print 'Note: Africa-Ant completely estimated from a heuristic control volume analysis and could be removed from the table!'\n", | |
"print tabulate(table, headers=headers, floatfmt=\"0.1f\", numalign=\"center\") " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\\begin{tabular}{lllll}\n", | |
"\\hline\n", | |
" Transect location & Simulation (Sv) & Observation (Sv) & Observation reference & Result in range? \\\\\n", | |
"\\hline\n", | |
" Drake Passage & 83.8 \\$\\textbackslash{}pm\\$ 17.7 & 134.0 \\$\\textbackslash{}pm\\$ 14.0 & False & Nowlin and Klinck (1986) \\\\\n", | |
" Tasmania-Ant & 98.0 \\$\\textbackslash{}pm\\$ 20.0 & 157.0 \\$\\textbackslash{}pm\\$ 10.0 & False & Ganachaud and Wunsch (2000) \\\\\n", | |
" Africa-Ant & 83.4 \\$\\textbackslash{}pm\\$ 17.9 & 150.0 \\$\\textbackslash{}pm\\$ 30.0 & False & Estimated from Drake and Tasmania-Ant passages from Ganachaud and Wunsch (2000) http://onlinelibrary.wiley.com/doi/10.1029/2002JC001565/full \\\\\n", | |
" Antilles Inflow & -15.9 \\$\\textbackslash{}pm\\$ 3.2 & -18.4 \\$\\textbackslash{}pm\\$ 4.7 & True & Johns et al. (2002) and Roemmich (1981) \\\\\n", | |
" Mona Passage & -1.8 \\$\\textbackslash{}pm\\$ 1.0 & -2.6 \\$\\textbackslash{}pm\\$ 1.2 & True & Johns et al. (2002) and Roemmich (1981). \\\\\n", | |
" Windward Passage & 1.9 \\$\\textbackslash{}pm\\$ 2.1 & -7.0 \\$\\textbackslash{}pm\\$ nan & False & Johns et al. (2002) and Roemmich (1981). \\\\\n", | |
" Florida-Cuba & 15.7 \\$\\textbackslash{}pm\\$ 1.6 & 31.0 \\$\\textbackslash{}pm\\$ 1.5 & False & Johns et al. (2002) and Roemmich (1981). \\\\\n", | |
" Florida-Bahamas & 15.4 \\$\\textbackslash{}pm\\$ 1.1 & 31.5 \\$\\textbackslash{}pm\\$ 1.5 & False & Johns et al. (2002) and Roemmich (1981). \\\\\n", | |
" Indonesian Throughflow & -11.0 \\$\\textbackslash{}pm\\$ 3.6 & -15.0 \\$\\textbackslash{}pm\\$ 4.0 & True & Sprintall et al. (2009) \\\\\n", | |
" Agulhas & -68.5 \\$\\textbackslash{}pm\\$ 5.8 & -70.0 \\$\\textbackslash{}pm\\$ 20.0 & True & unclear from Ringler et al (2013) \\\\\n", | |
" Mozambique Channel & -18.7 \\$\\textbackslash{}pm\\$ 6.8 & -16.0 \\$\\textbackslash{}pm\\$ 13.0 & True & van der Werf et al. (2010) \\\\\n", | |
" Bering Strait & 0.9 \\$\\textbackslash{}pm\\$ 0.5 & 0.8 \\$\\textbackslash{}pm\\$ 0.3 & False & Roach et al (1995) http://onlinelibrary.wiley.com/doi/10.1029/95JC01673/full \\\\\n", | |
" Lancaster Sound & 0.5 \\$\\textbackslash{}pm\\$ 0.3 & 0.8 \\$\\textbackslash{}pm\\$ 0.3 & True & Prisenberg and Hamilton (2005) http://www.tandfonline.com/doi/abs/10.3137/ao.430101 \\\\\n", | |
" Fram Strait & -2.1 \\$\\textbackslash{}pm\\$ 1.1 & -3.0 \\$\\textbackslash{}pm\\$ 3.0 & True & Schauer et al (2004) http://onlinelibrary.wiley.com/doi/10.1029/2003JC001823/full \\\\\n", | |
" Robeson Channel & 0.0 \\$\\textbackslash{}pm\\$ 0.0 & -0.7 \\$\\textbackslash{}pm\\$ 0.2 & False & Maltrud and McClean (2005) https://www.sciencedirect.com/science/article/pii/S1463500303000684\\#BIB16 \\\\\n", | |
"\\hline\n", | |
"\\end{tabular}\n" | |
] | |
} | |
], | |
"source": [ | |
"print tabulate(table, headers=headers, floatfmt=\".2f\", numalign=\"center\", tablefmt=\"latex\") " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.13" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment