Skip to content

Commit

Permalink
Verify notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 committed Sep 13, 2019
1 parent 0658797 commit 1089db7
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 1,583 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,4 @@ setup/jlab/start-jlab
.vscode/
data/*.nc
data/*.csv
*.zarr
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:

# - repo: https://github.com/kynan/nbstripout
# rev: master
# hooks:
# - id: nbstripout
# files: ".ipynb"
- repo: https://github.com/kynan/nbstripout
rev: master
hooks:
- id: nbstripout
files: ".ipynb"

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
Expand Down
278 changes: 23 additions & 255 deletions notebooks/bytopic/xarray/01_getting_started_with_xarray.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -89,38 +89,9 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[[ 4.43508091, 2.15124776, 2.10558373, 19.94490096],\n",
" [ 2.60872261, 3.52042546, 18.63140782, 13.72228345],\n",
" [27.30081072, 5.96095059, 2.91805875, 17.6037812 ]],\n",
"\n",
" [[ 8.74433669, 8.27582507, 7.03698317, 3.31496248],\n",
" [ 4.87882522, 4.70457746, 3.64326797, 2.7801325 ],\n",
" [ 8.78350864, 2.13838567, 2.85726807, 3.9849055 ]],\n",
"\n",
" [[ 8.6100285 , 3.51406472, 18.56975917, 3.39210852],\n",
" [ 3.36315056, 5.33039337, 6.57733997, 5.73891663],\n",
" [14.24651928, 2.14877667, 16.73808201, 15.76765027]],\n",
"\n",
" [[ 5.64740648, 17.38358732, 6.21165503, 17.54573517],\n",
" [12.23201627, 2.88654703, 2.78561898, 2.13348846],\n",
" [ 2.38664008, 5.1335385 , 24.82225676, 7.95046948]],\n",
"\n",
" [[ 8.41788254, 16.13446971, 4.76249737, 3.26780217],\n",
" [16.20042451, 6.25651099, 11.77345362, 2.22748438],\n",
" [11.94589889, 3.79870376, 10.81441387, 8.1399644 ]]])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Create some sample data\n",
"data = 2 + 6 * np.random.exponential(size=(5, 3, 4))\n",
Expand All @@ -136,40 +107,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<xarray.DataArray (dim_0: 5, dim_1: 3, dim_2: 4)>\n",
"array([[[ 4.435081, 2.151248, 2.105584, 19.944901],\n",
" [ 2.608723, 3.520425, 18.631408, 13.722283],\n",
" [27.300811, 5.960951, 2.918059, 17.603781]],\n",
"\n",
" [[ 8.744337, 8.275825, 7.036983, 3.314962],\n",
" [ 4.878825, 4.704577, 3.643268, 2.780133],\n",
" [ 8.783509, 2.138386, 2.857268, 3.984906]],\n",
"\n",
" [[ 8.610028, 3.514065, 18.569759, 3.392109],\n",
" [ 3.363151, 5.330393, 6.57734 , 5.738917],\n",
" [14.246519, 2.148777, 16.738082, 15.76765 ]],\n",
"\n",
" [[ 5.647406, 17.383587, 6.211655, 17.545735],\n",
" [12.232016, 2.886547, 2.785619, 2.133488],\n",
" [ 2.38664 , 5.133539, 24.822257, 7.950469]],\n",
"\n",
" [[ 8.417883, 16.13447 , 4.762497, 3.267802],\n",
" [16.200425, 6.256511, 11.773454, 2.227484],\n",
" [11.945899, 3.798704, 10.814414, 8.139964]]])\n",
"Dimensions without coordinates: dim_0, dim_1, dim_2"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"prec = xr.DataArray(data)\n",
"prec"
Expand All @@ -190,22 +130,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DatetimeIndex(['2019-04-01', '2019-04-02', '2019-04-03', '2019-04-04',\n",
" '2019-04-05'],\n",
" dtype='datetime64[ns]', freq='D')"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Use pandas to create an array of datetimes\n",
"import pandas as pd\n",
Expand All @@ -215,20 +142,9 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([-150., -120., -90., -60.]), array([10., 45., 80.]))"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Use numpy to create array of longitude and latitude values\n",
"lons = np.linspace(-150, -60, 4)\n",
Expand All @@ -238,7 +154,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -248,43 +164,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<xarray.DataArray 'prec' (time: 5, lat: 3, lon: 4)>\n",
"array([[[ 4.435081, 2.151248, 2.105584, 19.944901],\n",
" [ 2.608723, 3.520425, 18.631408, 13.722283],\n",
" [27.300811, 5.960951, 2.918059, 17.603781]],\n",
"\n",
" [[ 8.744337, 8.275825, 7.036983, 3.314962],\n",
" [ 4.878825, 4.704577, 3.643268, 2.780133],\n",
" [ 8.783509, 2.138386, 2.857268, 3.984906]],\n",
"\n",
" [[ 8.610028, 3.514065, 18.569759, 3.392109],\n",
" [ 3.363151, 5.330393, 6.57734 , 5.738917],\n",
" [14.246519, 2.148777, 16.738082, 15.76765 ]],\n",
"\n",
" [[ 5.647406, 17.383587, 6.211655, 17.545735],\n",
" [12.232016, 2.886547, 2.785619, 2.133488],\n",
" [ 2.38664 , 5.133539, 24.822257, 7.950469]],\n",
"\n",
" [[ 8.417883, 16.13447 , 4.762497, 3.267802],\n",
" [16.200425, 6.256511, 11.773454, 2.227484],\n",
" [11.945899, 3.798704, 10.814414, 8.139964]]])\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2019-04-01 2019-04-02 ... 2019-04-05\n",
" * lat (lat) float64 10.0 45.0 80.0\n",
" * lon (lon) float64 -150.0 -120.0 -90.0 -60.0"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Add name, coords, dims to our data\n",
"prec = xr.DataArray(data, dims=dims, coords=coords, name='prec')\n",
Expand All @@ -302,46 +184,9 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<xarray.DataArray 'prec' (time: 5, lat: 3, lon: 4)>\n",
"array([[[ 4.435081, 2.151248, 2.105584, 19.944901],\n",
" [ 2.608723, 3.520425, 18.631408, 13.722283],\n",
" [27.300811, 5.960951, 2.918059, 17.603781]],\n",
"\n",
" [[ 8.744337, 8.275825, 7.036983, 3.314962],\n",
" [ 4.878825, 4.704577, 3.643268, 2.780133],\n",
" [ 8.783509, 2.138386, 2.857268, 3.984906]],\n",
"\n",
" [[ 8.610028, 3.514065, 18.569759, 3.392109],\n",
" [ 3.363151, 5.330393, 6.57734 , 5.738917],\n",
" [14.246519, 2.148777, 16.738082, 15.76765 ]],\n",
"\n",
" [[ 5.647406, 17.383587, 6.211655, 17.545735],\n",
" [12.232016, 2.886547, 2.785619, 2.133488],\n",
" [ 2.38664 , 5.133539, 24.822257, 7.950469]],\n",
"\n",
" [[ 8.417883, 16.13447 , 4.762497, 3.267802],\n",
" [16.200425, 6.256511, 11.773454, 2.227484],\n",
" [11.945899, 3.798704, 10.814414, 8.139964]]])\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2019-04-01 2019-04-02 ... 2019-04-05\n",
" * lat (lat) float64 10.0 45.0 80.0\n",
" * lon (lon) float64 -150.0 -120.0 -90.0 -60.0\n",
"Attributes:\n",
" units: mm\n",
" standard_name: precipitation"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"prec.attrs['units'] = 'mm'\n",
"prec.attrs['standard_name'] = 'precipitation'\n",
Expand Down Expand Up @@ -380,27 +225,9 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<xarray.Dataset>\n",
"Dimensions: (lat: 3, lon: 4, time: 5)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2019-04-01 2019-04-02 ... 2019-04-05\n",
" * lat (lat) float64 10.0 45.0 80.0\n",
" * lon (lon) float64 -150.0 -120.0 -90.0 -60.0\n",
"Data variables:\n",
" precipitation (time, lat, lon) float64 4.435 2.151 2.106 ... 10.81 8.14"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"dset = xr.Dataset({'precipitation' : prec})\n",
"dset"
Expand All @@ -415,49 +242,12 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<xarray.DataArray 'temp' (time: 5, lat: 3, lon: 4)>\n",
"array([[[291.067308, 282.59583 , 286.514387, 279.784996],\n",
" [280.69826 , 277.181048, 276.998507, 283.234755],\n",
" [288.075202, 288.162201, 282.123016, 279.179585]],\n",
"\n",
" [[284.365503, 285.320669, 277.804468, 292.489392],\n",
" [281.912137, 271.326958, 275.402304, 283.102304],\n",
" [283.385009, 285.068898, 282.416826, 286.847279]],\n",
"\n",
" [[284.225161, 286.364076, 279.136546, 283.171794],\n",
" [288.33622 , 286.568405, 283.427888, 287.146929],\n",
" [283.232354, 284.007581, 282.913762, 284.85474 ]],\n",
"\n",
" [[282.210031, 278.921674, 295.395575, 282.505313],\n",
" [280.417009, 279.191678, 278.279562, 281.70787 ],\n",
" [281.791588, 283.762458, 287.691885, 282.041789]],\n",
"\n",
" [[280.795983, 282.317272, 289.734355, 286.826475],\n",
" [284.127492, 294.012677, 286.166998, 281.696582],\n",
" [288.024786, 280.485435, 275.519706, 282.380892]]])\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2019-04-01 2019-04-02 ... 2019-04-05\n",
" * lat (lat) float64 10.0 45.0 80.0\n",
" * lon (lon) float64 -150.0 -120.0 -90.0 -60.0\n",
"Attributes:\n",
" standard_name: air_temperature\n",
" units: kelvin"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"temp_data = 283 + 5 * np.random.randn(5, 3, 4)\n",
"temp = xr.DataArray(data=temp_data, dims=['time', 'lat', 'lon'], \n",
"temp = xr.DataArray(data=temp_data, dims=['time', 'lat', 'lon'],\n",
" coords={'time': times, 'lat': lats, 'lon': lons},\n",
" name='temp',\n",
" attrs={'standard_name': 'air_temperature', 'units': 'kelvin'})\n",
Expand All @@ -466,31 +256,9 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<xarray.Dataset>\n",
"Dimensions: (lat: 3, lon: 4, time: 5)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2019-04-01 2019-04-02 ... 2019-04-05\n",
" * lat (lat) float64 10.0 45.0 80.0\n",
" * lon (lon) float64 -150.0 -120.0 -90.0 -60.0\n",
"Data variables:\n",
" precipitation (time, lat, lon) float64 4.435 2.151 2.106 ... 10.81 8.14\n",
" temperature (time, lat, lon) float64 291.1 282.6 286.5 ... 275.5 282.4\n",
"Attributes:\n",
" history: Created for the xarray tutorial\n",
" author: foo and bar"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Now add this data array to our existing dataset\n",
"dset['temperature'] = temp\n",
Expand Down Expand Up @@ -521,9 +289,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python [conda env:python-tutorial]",
"language": "python",
"name": "python3"
"name": "conda-env-python-tutorial-py"
},
"language_info": {
"codemirror_mode": {
Expand Down
Loading

0 comments on commit 1089db7

Please sign in to comment.