Last active
January 1, 2016 15:49
-
-
Save perrette/8166666 to your computer and use it in GitHub Desktop.
Dimarray notebooks
This file contains 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
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "heading", | |
"level": 1, | |
"metadata": {}, | |
"source": [ | |
"Introduction to dimarray" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Download dimarray at:\n", | |
"https://github.com/perrette/dimarray/\n", | |
"\n", | |
"Including the latest version of this notebook:\n", | |
"https://github.com/perrette/dimarray/blob/master/Tutorial.ipynb" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%pylab\n", | |
"%matplotlib inline\n", | |
"%load_ext autoreload\n", | |
"%autoreload 2" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"Using matplotlib backend: GTKAgg\n", | |
"Populating the interactive namespace from numpy and matplotlib\n" | |
] | |
} | |
], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import numpy as np\n", | |
"import dimarray as da\n", | |
"from dimarray import DimArray" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##Definition and attributes of a DimArray" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"A __`DimArray`__ can be defined just like a numpy array, with additional information about axis values (`axes=`) and axis names (`dims=`)." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a = DimArray(values=[[1,2,3],[4,5,6]], axes=[[\"a\",\"b\"], [0,1,2]], dims=['x0','x1']) \n", | |
"a" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 3, | |
"text": [ | |
"dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): a to b\n", | |
"1 / x1 (3): 0 to 2\n", | |
"array([[1, 2, 3],\n", | |
" [4, 5, 6]])" | |
] | |
} | |
], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Array data are stored in a `values` attribute:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a.values" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 4, | |
"text": [ | |
"array([[1, 2, 3],\n", | |
" [4, 5, 6]])" | |
] | |
} | |
], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"While dimensions are stored in an `axes` attribute, which is equivalent to a list of __`Axis`__ objects:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a.axes" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 5, | |
"text": [ | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): a to b\n", | |
"1 / x1 (3): 0 to 2" | |
] | |
} | |
], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"ax = a.axes[0] # by integer position\n", | |
"ax = a.axes['x0'] # by axis name\n", | |
"ax" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 6, | |
"text": [ | |
"x0 (2): a to b" | |
] | |
} | |
], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"An __`Axis`__ object itself has `name` and `values` attributes:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"ax.name" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 7, | |
"text": [ | |
"'x0'" | |
] | |
} | |
], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"ax.values" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 8, | |
"text": [ | |
"array(['a', 'b'], dtype=object)" | |
] | |
} | |
], | |
"prompt_number": 8 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"For convenience, axis names and values can be accessed directly via `dims` and `<axis name>`. " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a.x0, a.x1 # alias for a.axes['x0'].values, a.axes['x1'].values" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 9, | |
"text": [ | |
"(array(['a', 'b'], dtype=object), array([0, 1, 2]))" | |
] | |
} | |
], | |
"prompt_number": 9 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a.dims # `dims` is just an alias for axis names" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 10, | |
"text": [ | |
"('x0', 'x1')" | |
] | |
} | |
], | |
"prompt_number": 10 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Note that numpy-like attribute `shape` and `ndim`, among others, are also defined:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a.shape" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 11, | |
"text": [ | |
"(2, 3)" | |
] | |
} | |
], | |
"prompt_number": 11 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a.ndim" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 12, | |
"text": [ | |
"2" | |
] | |
} | |
], | |
"prompt_number": 12 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##Alternative definitions" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"For convenience, two other possibilities exist to define a DimArray, either with a list of tuples or with a dictionary of axes" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"b = DimArray([[1,2,3],[4,5,6]], axes = {'x0':[\"a\",\"b\"], 'x1':[0,1,2]}, dims=['x0','x1']) # dims could be omitted here\n", | |
"c = DimArray([[1,2,3],[4,5,6]], axes=[(\"x0\",[\"a\",\"b\"]), (\"x1\", [0,1,2])]) \n", | |
"np.all(a == b == c)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 13, | |
"text": [ | |
"True" | |
] | |
} | |
], | |
"prompt_number": 13 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Note the keyword argument form above is only valid for non-square arrays, and requires the additional parameter `dims=` if any two axes have the same size. \n", | |
"\n", | |
"The `array` function is also provided as a convenience, to define a DimArray from keyword arguments (this is an alias for DimArray.from_kw). In this form, no keyword argument is allowed (no metadata) except for axis names." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"d = DimArray.from_kw([[1,2,3],[4,5,6]], ['x0','x1'], x0=[\"a\",\"b\"], x1=[0,1,2]) \n", | |
"e = da.array([[1,2,3],[4,5,6]], ['x0','x1'], x0=[\"a\",\"b\"], x1=[0,1,2]) # ['x0','x1'] is guessed from array shape\n", | |
"f = da.array([[1,2,3],[4,5,6]], x0=[\"a\",\"b\"], x1=[0,1,2]) # ['x0','x1'] is guessed from array shape\n", | |
"np.all(a == b == c == d == e == f)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 14, | |
"text": [ | |
"True" | |
] | |
} | |
], | |
"prompt_number": 14 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"It is also possible to omit any of the first three arguments, and they will be automatically named following a default pattern of \"x0\", \"x1\" ... for axis names and [0, 1, ...] for axis values." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"DimArray([[1,2,3],[4,5,6]]) # automatic labelling" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 15, | |
"text": [ | |
"dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): 0 to 1\n", | |
"1 / x1 (3): 0 to 2\n", | |
"array([[1, 2, 3],\n", | |
" [4, 5, 6]])" | |
] | |
} | |
], | |
"prompt_number": 15 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"DimArray([[1,2,3],[4,5,6]], dims=['items','time']) # automatic axis labelling" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 16, | |
"text": [ | |
"dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'items', 'time'\n", | |
"0 / items (2): 0 to 1\n", | |
"1 / time (3): 0 to 2\n", | |
"array([[1, 2, 3],\n", | |
" [4, 5, 6]])" | |
] | |
} | |
], | |
"prompt_number": 16 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"DimArray([[1,2,3],[4,5,6]], axes=[list(\"ab\"), np.arange(1950,1953)]) # automatic dimension labelling" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 17, | |
"text": [ | |
"dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): a to b\n", | |
"1 / x1 (3): 1950 to 1952\n", | |
"array([[1, 2, 3],\n", | |
" [4, 5, 6]])" | |
] | |
} | |
], | |
"prompt_number": 17 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"As for `values`, an array of NaNs will be generated if this parameter (first argument) is left empty:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"DimArray(axes=[[\"a\",\"b\"], [0,1,2]], dims=['x0','x1']) # empty data, fill with NaNs (float only)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 18, | |
"text": [ | |
"dimarray: 0 non-null elements (6 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): a to b\n", | |
"1 / x1 (3): 0 to 2\n", | |
"array([[ nan, nan, nan],\n", | |
" [ nan, nan, nan]])" | |
] | |
} | |
], | |
"prompt_number": 18 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##Support for metadata" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"`DimArray` and `Axis` objects, support metadata. They can be passed by keyword arguments to DimArray (not via da.array or DimArray.from_kw !)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a = DimArray([[1,2,3],[4,5,6]], name='myname', units='myunits') \n", | |
"a.name, a.units" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 19, | |
"text": [ | |
"('myname', 'myunits')" | |
] | |
} | |
], | |
"prompt_number": 19 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"ax = a.axes[0]\n", | |
"ax.units = \"meters\"" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 20 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"metadata are conserved by slicing and along-axis transformation, but are lost with any other transformation" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a[:].units" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 21, | |
"text": [ | |
"'myunits'" | |
] | |
} | |
], | |
"prompt_number": 21 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"ax[:].units" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 22, | |
"text": [ | |
"'meters'" | |
] | |
} | |
], | |
"prompt_number": 22 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##Indexing" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### by axis values" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from dimarray import DimArray\n", | |
"v = DimArray([[1,2,3],[4,5,6]], axes=[[\"aa\",\"bb\"], [10.,20.,30.]], dims=['x0','x1'], dtype=float) \n", | |
"v" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 23, | |
"text": [ | |
"dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): aa to bb\n", | |
"1 / x1 (3): 10.0 to 30.0\n", | |
"array([[ 1., 2., 3.],\n", | |
" [ 4., 5., 6.]])" | |
] | |
} | |
], | |
"prompt_number": 23 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"### Single value\n", | |
"a = v[:,10]\n", | |
"b = v.take(10, axis=1)\n", | |
"c = v.take(10, axis='x1')\n", | |
"d = v.take({'x1':10}) # dict\n", | |
"assert a is not None\n", | |
"assert(a==b==c==d)\n", | |
"a" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 24, | |
"text": [ | |
"dimarray: 2 non-null elements (0 null)\n", | |
"dimensions: 'x0'\n", | |
"0 / x0 (2): aa to bb\n", | |
"array([ 1., 4.])" | |
] | |
} | |
], | |
"prompt_number": 24 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#string\n", | |
"v[\"aa\"]\n", | |
"v.take(\"aa\", axis=0)\n", | |
"v.take(\"aa\", axis=0, keepdims=1)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 25, | |
"text": [ | |
"dimarray: 3 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (1): aa to aa\n", | |
"1 / x1 (3): 10.0 to 30.0\n", | |
"array([[ 1., 2., 3.]])" | |
] | |
} | |
], | |
"prompt_number": 25 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"v['aa',10]\n", | |
"v[[\"aa\"]]\n", | |
"d = v.take({'x1':10}) # dict\n", | |
"v.take((\"aa\", 10), axis=0)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 26, | |
"text": [ | |
"1.0" | |
] | |
} | |
], | |
"prompt_number": 26 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"### List\n", | |
"a = v[:,[10,20]]\n", | |
"b = v.take([10,20], axis='x1')\n", | |
"assert np.all(a==b)\n", | |
"a" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 27, | |
"text": [ | |
"dimarray: 4 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): aa to bb\n", | |
"1 / x1 (2): 10.0 to 20.0\n", | |
"array([[ 1., 2.],\n", | |
" [ 4., 5.]])" | |
] | |
} | |
], | |
"prompt_number": 27 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"### Slice\n", | |
"c = v[:,10:20] # slice include last element\n", | |
"d = v.take(slice(10,20), axis='x1') # slice via tuple" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 28 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### by integer position" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"### Single values\n", | |
"v.ix[:,0] # WARNING: 'ix' stands for integer index, in contrast to pandas\n", | |
"v.take(0, axis=1, indexing='position')\n", | |
"v.take(0, axis='x1', indexing='position')\n", | |
"v.take({\"x1\":0},indexing='position') # keyword arguments: EXPERIMENTAL" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 29, | |
"text": [ | |
"dimarray: 2 non-null elements (0 null)\n", | |
"dimensions: 'x0'\n", | |
"0 / x0 (2): aa to bb\n", | |
"array([ 1., 4.])" | |
] | |
} | |
], | |
"prompt_number": 29 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"### list\n", | |
"a = v.ix[:,[0,1]]\n", | |
"b = v.take([0,1], axis='x1', indexing='position')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 30 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a = v.ix[:,0:1] # does NOT include last element\n", | |
"b = v.take(slice(0,1), axis='x1', indexing='position') # slice via tuple" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 31 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Reindex Axis" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#import dim\n", | |
"import dimarray.core._indexing as re; reload(re)\n", | |
"import dimarray as da\n", | |
"a = da.DimArray([1,2,3],[('x0', [1,2,3])])\n", | |
"b = da.DimArray([3,4],[('x0',[1,3])])\n", | |
"b.reindex_axis([1,2,3])" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 32, | |
"text": [ | |
"dimarray: 2 non-null elements (1 null)\n", | |
"dimensions: 'x0'\n", | |
"0 / x0 (3): 1 to 3\n", | |
"array([ 3., nan, 4.])" | |
] | |
} | |
], | |
"prompt_number": 32 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Can also reindex in \"interp\" mode\n", | |
"b.reindex_axis([0,1,2,3], method='interp')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 33, | |
"text": [ | |
"dimarray: 3 non-null elements (1 null)\n", | |
"dimensions: 'x0'\n", | |
"0 / x0 (4): 0 to 3\n", | |
"array([ nan, 3. , 3.5, 4. ])" | |
] | |
} | |
], | |
"prompt_number": 33 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Or like another array\n", | |
"c = da.DimArray([[1,2,3], [1,2,3]],[('x1',[\"a\",\"b\"]),('x0',[1, 2, 3])])\n", | |
"b.reindex_like(c, method='interp')\n", | |
"#b.reindex_axis([1,2,3], method='interp')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 34, | |
"text": [ | |
"dimarray: 3 non-null elements (0 null)\n", | |
"dimensions: 'x0'\n", | |
"0 / x0 (3): 1 to 3\n", | |
"array([ 3. , 3.5, 4. ])" | |
] | |
} | |
], | |
"prompt_number": 34 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##Modify dimensions: basic functionality" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Basic numpy methods to modify array dimensions are implemented in dimarray, with some additional functionality allowed by named dimensions." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"###Transpose" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Transpose, just like its numpy equivalent, permutes dimensions, but in dimarray it can be provided with axis names instead of just axis position." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a = DimArray([[1,2,3],[3,4,5]],dims=('x0','x1'))\n", | |
"a.transpose()\n", | |
"a.T" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 35, | |
"text": [ | |
"dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'x1', 'x0'\n", | |
"0 / x1 (3): 0 to 2\n", | |
"1 / x0 (2): 0 to 1\n", | |
"array([[1, 3],\n", | |
" [2, 4],\n", | |
" [3, 5]])" | |
] | |
} | |
], | |
"prompt_number": 35 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a = DimArray([[[1,2,3],[3,4,5]]],dims=('x2','x0','x1'))\n", | |
"a.transpose(('x1','x2','x0'))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 36, | |
"text": [ | |
"dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'x1', 'x2', 'x0'\n", | |
"0 / x1 (3): 0 to 2\n", | |
"1 / x2 (1): 0 to 0\n", | |
"2 / x0 (2): 0 to 1\n", | |
"array([[[1, 3]],\n", | |
"\n", | |
" [[2, 4]],\n", | |
"\n", | |
" [[3, 5]]])" | |
] | |
} | |
], | |
"prompt_number": 36 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"###Insert new axis" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Numpy provides a np.newaxis constant (equal to None), to augment the array dimensions with new singleton axes. In dimarray, newaxis has been implemented as an array method, which requires to indicate axis name and optionally axis position (`pos=`). Under the `repeat` section, you'll see it is also possible to input the values of the new axis in order to repeast the array along it." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a = DimArray([1,2])\n", | |
"a.newaxis('new', pos=1) # singleton" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 37, | |
"text": [ | |
"dimarray: 2 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'new'\n", | |
"0 / x0 (2): 0 to 1\n", | |
"1 / new (1): None to None\n", | |
"array([[1],\n", | |
" [2]])" | |
] | |
} | |
], | |
"prompt_number": 37 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"###Reshape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a = da.DimArray.from_kw(arange(2), lon=[30., 40.])\n", | |
"b = a.reshape(('time','lon'))\n", | |
"b" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 38, | |
"text": [ | |
"dimarray: 2 non-null elements (0 null)\n", | |
"dimensions: 'time', 'lon'\n", | |
"0 / time (1): None to None\n", | |
"1 / lon (2): 30.0 to 40.0\n", | |
"array([[0, 1]])" | |
] | |
} | |
], | |
"prompt_number": 38 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Repeat" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"### Single axis:\n", | |
">>> b.repeat(np.arange(1950,1955), axis=\"time\") # doctest: +ELLIPSIS" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 39, | |
"text": [ | |
"dimarray: 10 non-null elements (0 null)\n", | |
"dimensions: 'time', 'lon'\n", | |
"0 / time (5): 1950 to 1954\n", | |
"1 / lon (2): 30.0 to 40.0\n", | |
"array([[0, 1],\n", | |
" [0, 1],\n", | |
" [0, 1],\n", | |
" [0, 1],\n", | |
" [0, 1]])" | |
] | |
} | |
], | |
"prompt_number": 39 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"### Multi-axis\n", | |
"# ...create some dummy data:\n", | |
"lon = np.linspace(10, 30, 2)\n", | |
"lat = np.linspace(10, 50, 3)\n", | |
"time = np.arange(1950,1955)\n", | |
"ts = da.DimArray.from_kw(np.arange(5), time=time)\n", | |
"cube = da.DimArray.from_kw(np.zeros((3,2,5)), lon=lon, lat=lat, time=time) # lat x lon x time\n", | |
"cube.axes # doctest: +ELLIPSIS" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 40, | |
"text": [ | |
"dimensions: 'lat', 'lon', 'time'\n", | |
"0 / lat (3): 10.0 to 50.0\n", | |
"1 / lon (2): 10.0 to 30.0\n", | |
"2 / time (5): 1950 to 1954" | |
] | |
} | |
], | |
"prompt_number": 40 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"### In combination with repeat\n", | |
"a.newaxis('new', values=['a','b'],pos=1) # repeat 2 times along the first axis" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 41, | |
"text": [ | |
"dimarray: 4 non-null elements (0 null)\n", | |
"dimensions: 'lon', 'new'\n", | |
"0 / lon (2): 30.0 to 40.0\n", | |
"1 / new (2): a to b\n", | |
"array([[0, 0],\n", | |
" [1, 1]])" | |
] | |
} | |
], | |
"prompt_number": 41 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"###Broadcast" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# broadcast along new axes (reshape + repeat array)\n", | |
">>> ts3D = ts.broadcast(cube) # lat x lon x time\n", | |
"ts3D" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 42, | |
"text": [ | |
"dimarray: 30 non-null elements (0 null)\n", | |
"dimensions: 'lat', 'lon', 'time'\n", | |
"0 / lat (3): 10.0 to 50.0\n", | |
"1 / lon (2): 10.0 to 30.0\n", | |
"2 / time (5): 1950 to 1954\n", | |
"array([[[0, 1, 2, 3, 4],\n", | |
" [0, 1, 2, 3, 4]],\n", | |
"\n", | |
" [[0, 1, 2, 3, 4],\n", | |
" [0, 1, 2, 3, 4]],\n", | |
"\n", | |
" [[0, 1, 2, 3, 4],\n", | |
" [0, 1, 2, 3, 4]]])" | |
] | |
} | |
], | |
"prompt_number": 42 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##Align arrays" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"###Align dimensions" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Keep new axes as singleton dimensions\n", | |
"x = da.DimArray(np.arange(2), dims=('x0',))\n", | |
"y = da.DimArray(np.arange(3), dims=('x1',))\n", | |
"da.align_dims(x, y)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 43, | |
"text": [ | |
"[dimarray: 2 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): 0 to 1\n", | |
"1 / x1 (1): None to None\n", | |
"array([[0],\n", | |
" [1]]),\n", | |
" dimarray: 3 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (1): None to None\n", | |
"1 / x1 (3): 0 to 2\n", | |
"array([[0, 1, 2]])]" | |
] | |
} | |
], | |
"prompt_number": 43 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Broadcast arrays: all array have same size\n", | |
"da.broadcast_arrays(x, y)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 44, | |
"text": [ | |
"[dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): 0 to 1\n", | |
"1 / x1 (3): 0 to 2\n", | |
"array([[0, 0, 0],\n", | |
" [1, 1, 1]]),\n", | |
" dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): 0 to 1\n", | |
"1 / x1 (3): 0 to 2\n", | |
"array([[0, 1, 2],\n", | |
" [0, 1, 2]])]" | |
] | |
} | |
], | |
"prompt_number": 44 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Align axes" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a = da.DimArray([1,2,3],('x0',[1,2,3]))\n", | |
"b = da.DimArray([3,4],('x0',[2,4]))\n", | |
"da.align_axes(a, b)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 45, | |
"text": [ | |
"[dimarray: 3 non-null elements (1 null)\n", | |
"dimensions: 'x0'\n", | |
"0 / x0 (4): 1 to 4\n", | |
"array([ 1., 2., 3., nan]),\n", | |
" dimarray: 2 non-null elements (2 null)\n", | |
"dimensions: 'x0'\n", | |
"0 / x0 (4): 1 to 4\n", | |
"array([ nan, 3., nan, 4.])]" | |
] | |
} | |
], | |
"prompt_number": 45 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##Operations" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"###Basic Operations " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"a = da.DimArray([[1,2,3],[3,4,5]],dims=('x0','x1'))\n", | |
"assert all(a == a)\n", | |
"assert all(a+2 == a + np.ones(a.shape)*2)\n", | |
"assert all(a+a == a*2)\n", | |
"assert all(a*a == a**2)\n", | |
"assert all((a - a.values) == a - a)\n", | |
"a == a" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 46, | |
"text": [ | |
"dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): 0 to 1\n", | |
"1 / x1 (3): 0 to 2\n", | |
"array([[ True, True, True],\n", | |
" [ True, True, True]], dtype=bool)" | |
] | |
} | |
], | |
"prompt_number": 46 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Operation with data alignment " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# broadcasting\n", | |
"x = da.DimArray(np.arange(2), dims=('x0',))\n", | |
"y = da.DimArray(np.arange(3), dims=('x1',))\n", | |
"x+y" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 47, | |
"text": [ | |
"dimarray: 6 non-null elements (0 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (2): 0 to 1\n", | |
"1 / x1 (3): 0 to 2\n", | |
"array([[0, 1, 2],\n", | |
" [1, 2, 3]])" | |
] | |
} | |
], | |
"prompt_number": 47 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# axis alignment\n", | |
"z = da.DimArray([0,1,2],('x0',[0,1,2]))\n", | |
"x+z" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 48, | |
"text": [ | |
"dimarray: 2 non-null elements (1 null)\n", | |
"dimensions: 'x0'\n", | |
"0 / x0 (3): 0 to 2\n", | |
"array([ 0., 2., nan])" | |
] | |
} | |
], | |
"prompt_number": 48 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# or both\n", | |
"(x+y)+(x+z)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 49, | |
"text": [ | |
"dimarray: 6 non-null elements (3 null)\n", | |
"dimensions: 'x0', 'x1'\n", | |
"0 / x0 (3): 0 to 2\n", | |
"1 / x1 (3): 0 to 2\n", | |
"array([[ 0., 1., 2.],\n", | |
" [ 3., 4., 5.],\n", | |
" [ nan, nan, nan]])" | |
] | |
} | |
], | |
"prompt_number": 49 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##Numpy Transformations" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"np.random.seed(0)\n", | |
"v = da.DimArray(randn(5,7), {'time':arange(1950,1955), 'lat':linspace(-90,90,7)})" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 50 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Basic transforms: reduce axis" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"v.sum() # sum over all axes\n", | |
"v.sum(axis=0) # sum over first axis\n", | |
"v.sum(axis='time') # named axis\n", | |
"v.prod(axis='time') # named axis\n", | |
"v.mean(axis='time') # named axis\n", | |
"v.var(axis='time') # named axis\n", | |
"v.std(axis='time') # named axis\n", | |
"v.median(axis='time') # named axis\n", | |
"v.min(axis='time') # named axis\n", | |
"v.max(axis='time') # named axis\n", | |
"v.ptp(axis='time') # named axis\n", | |
"v.all(axis='time') # named axis\n", | |
"v.any(axis='time') # named axis" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 51, | |
"text": [ | |
"dimarray: 7 non-null elements (0 null)\n", | |
"dimensions: 'lat'\n", | |
"0 / lat (7): -90.0 to 90.0\n", | |
"array([ True, True, True, True, True, True, True], dtype=bool)" | |
] | |
} | |
], | |
"prompt_number": 51 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"locmin/locmax as dimarray equivalent of argmin/argmax: return axis value " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"v.locmin(axis='time') \n", | |
"v.locmin() # over all axes\n", | |
"v.locmax(axis='time') \n", | |
"v.locmax() # over all axes\n", | |
"v.locmax(axis='time')\n", | |
"assert v[v.locmax()] == v.max(), \"problem with locmax/max\"\n", | |
"assert v[v.locmin()] == v.min(), \"problem with locmin/min\"\n", | |
"res = np.array([v.ix[i][ix] for i, ix in enumerate(v.locmax(axis=1).values)])\n", | |
"assert np.all(res == v.max(axis=1)), \"problem with locmax/max\"\n", | |
"v.locmax()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 52, | |
"text": [ | |
"(1953, 0.0)" | |
] | |
} | |
], | |
"prompt_number": 52 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"cumulative transformation" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"v.cumsum() # last axis\n", | |
"v.cumsum(axis=None) # return numpy array\n", | |
"assert np.all(v.cumsum(axis=-1) == v.cumsum()), \"default last axis\"" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 53 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"new diff method" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"v.diff(axis='time', keepaxis=False)\n", | |
"v.diff(axis=0, keepaxis=False, scheme='centered')\n", | |
"v.diff(axis=0, keepaxis=False, scheme='backward')\n", | |
"v.diff(axis=0, keepaxis=False, scheme='forward')\n", | |
"v.diff(axis=0, keepaxis=True, scheme='backward')\n", | |
"v.diff(axis=0, keepaxis=True, scheme='forward')\n", | |
"v.diff(n=2,axis=('time'), scheme='centered')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 54, | |
"text": [ | |
"dimarray: 21 non-null elements (0 null)\n", | |
"dimensions: 'time', 'lat'\n", | |
"0 / time (3): 1951.0 to 1953.0\n", | |
"1 / lat (7): -90.0 to 90.0\n", | |
"array([[ 2.51063 , 0.94026924, 1.65162005, 1.74764779, -0.72792132,\n", | |
" -3.35344907, -1.84625143],\n", | |
" [-0.38546508, 0.09386869, -3.31972466, 2.82411472, -0.62622757,\n", | |
" 2.51498772, 5.0404708 ],\n", | |
" [ 0.66940526, 0.0741607 , 3.13335654, -4.36650499, 2.3340133 ,\n", | |
" -2.92640924, -2.52653427]])" | |
] | |
} | |
], | |
"prompt_number": 54 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# CHECK AGAINST PANDAS\n", | |
"assert np.all(v.std(ddof=1, axis=0).values==v.to_pandas().std().values), \"std vs pandas\"\n", | |
"assert np.sum((v.var(ddof=1, axis=0).values-v.to_pandas().var().values)**2)<1e-10, \"var vs pandas\"\n", | |
"assert np.all(v.cumsum(axis=0).values == v.to_pandas().cumsum().values), \"error against pandas\"\n", | |
"assert np.all(v.cumprod(axis=0).values == v.to_pandas().cumprod().values), \"error against pandas\"\n", | |
"assert np.nansum((v.diff(axis=0, keepaxis=True).cumsum(axis=0).values - v.to_pandas().diff().cumsum().values)**2) \\\n", | |
" < 1e-10, \"error against pandas\"" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 55 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##Dataset" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Aggregate several datasets to a Dataset object, it will automatically align the data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import dimarray as da\n", | |
"seed(0)\n", | |
"mymap = da.DimArray.from_kw(randn(50,7), lon=linspace(-180,180,50), lat=linspace(-90,90,7))\n", | |
"ts = da.DimArray(np.arange(5), ('time',arange(1950,1955)))\n", | |
"ts2 = da.DimArray(np.arange(10), ('time',arange(1950,1960)))\n", | |
"\n", | |
"# Define a Dataset made of several variables\n", | |
"data = da.Dataset({'ts':ts, 'ts2':ts2, 'mymap':mymap})\n", | |
"data = da.Dataset([ts, ts2, mymap], keys=['ts','ts2','mymap'])" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 56 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Data have been automatically aligned, while keeping the same shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"assert np.all(data['ts'].time == data['ts2'].time),\"Dataset: pb data alignment\" \n", | |
"data['ts']" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 57, | |
"text": [ | |
"dimarray: 5 non-null elements (5 null)\n", | |
"dimensions: 'time'\n", | |
"0 / time (10): 1950 to 1959\n", | |
"array([ 0., 1., 2., 3., 4., nan, nan, nan, nan, nan])" | |
] | |
} | |
], | |
"prompt_number": 57 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Can also add any other data as long as it is aligned with the dataset" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"data['test'] = da.DimArray([0],('source',['greenland'])) # new axis\n", | |
"try:\n", | |
" data['test2'] = da.DimArray([0,3],('source',['greenland','antarctica']))\n", | |
"except Exception, msg:\n", | |
" print msg\n", | |
"data\n", | |
"## TODO: \"expand\" Dataset (such as reindex_axis)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"axes values do not match, align data first.\t\t\t \n", | |
"Dataset: source(1)=greenland:greenland, \n", | |
"Got: source(2)=greenland:antarctica\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 58, | |
"text": [ | |
"Dataset of 4 variables\n", | |
"dimensions: 'time', 'lon', 'lat', 'source'\n", | |
"0 / time (10): 1950 to 1959\n", | |
"1 / lon (50): -180.0 to 180.0\n", | |
"2 / lat (7): -90.0 to 90.0\n", | |
"3 / source (1): greenland to greenland\n", | |
"ts: time\n", | |
"ts2: time\n", | |
"mymap: lon, lat\n", | |
"test: source" | |
] | |
} | |
], | |
"prompt_number": 58 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Export to a DimArray\n", | |
"print data.to_array()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"dimarray: 12250 non-null elements (1750 null)\n", | |
"dimensions: 'items', 'time', 'lon', 'lat', 'source'\n", | |
"0 / items (4): ts to test\n", | |
"1 / time (10): 1950 to 1959\n", | |
"2 / lon (50): -180.0 to 180.0\n", | |
"3 / lat (7): -90.0 to 90.0\n", | |
"4 / source (1): greenland to greenland\n", | |
"array(...)\n" | |
] | |
} | |
], | |
"prompt_number": 59 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##NetCDF I/O" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from dimarray import DimArray, summary_nc, read_nc\n", | |
"a = DimArray([1,2], dims='xx0')\n", | |
"b = DimArray([3,4,5], dims='xx1')\n", | |
"a.write_nc(\"test.nc\",\"a\", mode='w')\n", | |
"b.write_nc(\"test.nc\",\"b\", mode='a')\n", | |
"data = read_nc(\"test.nc\")\n", | |
"data" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"write to test.nc\n", | |
"write to" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
" test.nc\n", | |
"read from" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
" test.nc\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 60, | |
"text": [ | |
"Dataset of 2 variables\n", | |
"dimensions: u'xx0', u'xx1'\n", | |
"0 / xx0 (2): 0 to 1\n", | |
"1 / xx1 (3): 0 to 2\n", | |
"a: xx0\n", | |
"b: xx1" | |
] | |
} | |
], | |
"prompt_number": 60 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"A real-data example" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"path=\"/media/Data/Data/All/Etopo/Etopo5.cdf\"\n", | |
"import dimarray.io.nc as ncio; reload(ncio) \n", | |
"import dimarray as da\n", | |
"print da.summary_nc(path)\n", | |
"da.read_nc(path, \"elev\", indices={\"X\":slice(0.0,10), \"Y\":slice(80., 70)}, tol=0.1)\n", | |
"#da.read_nc(path, \"elev\", indices={\"X\":slice(10), \"Y\":slice(-10,None)}, numpy_indexing=True)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"/media/Data/Data/All/Etopo/Etopo5.cdf:\n", | |
"-------------------------------------\n", | |
"Dataset of 1 variable\n", | |
"dimensions: u'Y', u'X'\n", | |
"0 / Y (2160): 90.0 to -89.9166641235\n", | |
"1 / X (4320): 0.0 to 359.916656494\n", | |
"elev : Y, X\n", | |
"None\n", | |
"read from" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
" /media/Data/Data/All/Etopo/Etopo5.cdf\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 61, | |
"text": [ | |
"dimarray: 14641 non-null elements (0 null)\n", | |
"dimensions: u'Y', u'X'\n", | |
"0 / Y (121): 80.0 to 70.0\n", | |
"1 / X (121): 0.0 to 10.0\n", | |
"array(...)" | |
] | |
} | |
], | |
"prompt_number": 61 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### From a DimArray" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"seed(0)\n", | |
"v = da.DimArray(randn(5,7,2), [(\"time\",np.arange(1950,1955)), (\"lat\",np.linspace(-90,90,7)), (\"items\",np.array(['greenland','antarctica']))])\n", | |
"v" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 62, | |
"text": [ | |
"dimarray: 70 non-null elements (0 null)\n", | |
"dimensions: 'time', 'lat', 'items'\n", | |
"0 / time (5): 1950 to 1954\n", | |
"1 / lat (7): -90.0 to 90.0\n", | |
"2 / items (2): greenland to antarctica\n", | |
"array([[[ 1.76405235, 0.40015721],\n", | |
" [ 0.97873798, 2.2408932 ],\n", | |
" [ 1.86755799, -0.97727788],\n", | |
" [ 0.95008842, -0.15135721],\n", | |
" [-0.10321885, 0.4105985 ],\n", | |
" [ 0.14404357, 1.45427351],\n", | |
" [ 0.76103773, 0.12167502]],\n", | |
"\n", | |
" [[ 0.44386323, 0.33367433],\n", | |
" [ 1.49407907, -0.20515826],\n", | |
" [ 0.3130677 , -0.85409574],\n", | |
" [-2.55298982, 0.6536186 ],\n", | |
" [ 0.8644362 , -0.74216502],\n", | |
" [ 2.26975462, -1.45436567],\n", | |
" [ 0.04575852, -0.18718385]],\n", | |
"\n", | |
" [[ 1.53277921, 1.46935877],\n", | |
" [ 0.15494743, 0.37816252],\n", | |
" [-0.88778575, -1.98079647],\n", | |
" [-0.34791215, 0.15634897],\n", | |
" [ 1.23029068, 1.20237985],\n", | |
" [-0.38732682, -0.30230275],\n", | |
" [-1.04855297, -1.42001794]],\n", | |
"\n", | |
" [[-1.70627019, 1.9507754 ],\n", | |
" [-0.50965218, -0.4380743 ],\n", | |
" [-1.25279536, 0.77749036],\n", | |
" [-1.61389785, -0.21274028],\n", | |
" [-0.89546656, 0.3869025 ],\n", | |
" [-0.51080514, -1.18063218],\n", | |
" [-0.02818223, 0.42833187]],\n", | |
"\n", | |
" [[ 0.06651722, 0.3024719 ],\n", | |
" [-0.63432209, -0.36274117],\n", | |
" [-0.67246045, -0.35955316],\n", | |
" [-0.81314628, -1.7262826 ],\n", | |
" [ 0.17742614, -0.40178094],\n", | |
" [-1.63019835, 0.46278226],\n", | |
" [-0.90729836, 0.0519454 ]]])" | |
] | |
} | |
], | |
"prompt_number": 62 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# writing\n", | |
"v.write_nc(\"test2.nc\",\"myvarstr\", mode=\"w\")" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"write to test2.nc\n" | |
] | |
} | |
], | |
"prompt_number": 63 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# checking\n", | |
"da.summary_nc(\"test2.nc\")" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"test2.nc:\n", | |
"--------\n", | |
"Dataset of 1 variable\n", | |
"dimensions: u'time', u'lat', u'items'\n", | |
"0 / time (5): 1950 to 1954\n", | |
"1 / lat (7): -90.0 to 90.0\n", | |
"2 / items (2): greenland to antarctica\n", | |
"myvarstr : time, lat, items\n" | |
] | |
} | |
], | |
"prompt_number": 64 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# reading\n", | |
"w = da.read_nc(\"test2.nc\")\n", | |
"assert np.all(w['myvarstr'] == v), \"Problem when reading netcdf\"\n", | |
"w" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"read from test2.nc\n" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 65, | |
"text": [ | |
"Dataset of 1 variable\n", | |
"dimensions: u'time', u'lat', u'items'\n", | |
"0 / time (5): 1950 to 1954\n", | |
"1 / lat (7): -90.0 to 90.0\n", | |
"2 / items (2): greenland to antarctica\n", | |
"myvarstr: time, lat, items" | |
] | |
} | |
], | |
"prompt_number": 65 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### From/To Dataset" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"data.write('test3.nc')\n", | |
"da.summary_nc('test3.nc')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"write to test3.nc\n", | |
"test3.nc:\n", | |
"--------" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"Dataset of 6 variables\n", | |
"dimensions: u'time', u'lon', u'lat', u'source', u'xx0', u'xx1'\n", | |
"0 / time (10): 1950 to 1959\n", | |
"1 / lon (50): -180.0 to 180.0\n", | |
"2 / lat (7): -90.0 to 90.0\n", | |
"3 / source (1): greenland to greenland\n", | |
"4 / xx0 (2): 0 to 1\n", | |
"5 / xx1 (3): 0 to 2\n", | |
"ts : time\n", | |
"ts2 : time\n", | |
"mymap : lon, lat\n", | |
"test" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
" : source\n", | |
"a : xx0\n", | |
"b : xx1\n" | |
] | |
} | |
], | |
"prompt_number": 66 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##Experimental Features" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"###Group / Ungroup" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import dimarray as da" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 67 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
">>> np.random.seed(0)\n", | |
">>> v = da.DimArray.from_kw(randn(2,5,180), time=arange(1950,1955), lat=linspace(-90,90,180), items=array(['greenland','antarctica']))\n", | |
"#axes = v.axes[('time','lat')]\n", | |
"#ax.GroupedAxis(*[v.axes[k] for k in ('time','lat')])\n", | |
"print v\n", | |
"\n", | |
"# group time, lat\n", | |
">>> w = v.group(('time','lat'))\n", | |
"print \"\\nBasic grouping:\\n\\n\", w\n", | |
"\n", | |
"# group dimensions and insert as first dimension\n", | |
">>> w = v.group(('time','lat'), insert=0) \n", | |
"print \"\\nGroup + insert as first:\\n\\n\", w\n", | |
"\n", | |
"# group and ungroup\n", | |
">>> v2 = v.group(('time','items')).ungroup()\n", | |
"print \"\\ngroup/ungroup no reshaping:\", np.all(v2 == v)\n", | |
"print \"\\ngroup/ungroup with reshaping:\", np.all(v2.reshape(v.dims) == v)\n", | |
"\n", | |
"# grouping in transformations\n", | |
">>> res = v.mean(axis=('time','lat'))\n", | |
"print \"\\nmean with grouping time,lat grouping:\\n\\n\",res" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"dimarray: 1800 non-null elements (0 null)\n", | |
"dimensions: 'items', 'time', 'lat'\n", | |
"0 / items (2): greenland to antarctica\n", | |
"1 / time (5): 1950 to 1954\n", | |
"2 / lat (180): -90.0 to 90.0\n", | |
"array(...)\n", | |
"\n", | |
"Basic grouping:\n", | |
"\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"dimarray: 1800 non-null elements (0 null)\n", | |
"dimensions: 'items', 'time,lat'\n", | |
"0 / items (2): greenland to antarctica\n", | |
"1 / time,lat (900): (1950, -90.0) to (1954, 90.0)\n", | |
"array(...)\n", | |
"\n", | |
"Group + insert as first:\n", | |
"\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"dimarray: 1800 non-null elements (0 null)\n", | |
"dimensions: 'time,lat', 'items'\n", | |
"0 / time,lat (900): (1950, -90.0) to (1954, 90.0)\n", | |
"1 / items (2): greenland to antarctica\n", | |
"array(...)\n", | |
"\n", | |
"group/ungroup no reshaping:" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
" False\n", | |
"\n", | |
"group/ungroup with reshaping: True" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"\n", | |
"mean with grouping time,lat grouping:\n", | |
"\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"dimarray: 2 non-null elements (0 null)\n", | |
"dimensions: 'items'\n", | |
"0 / items (2): greenland to antarctica\n", | |
"array([-0.06849458, 0.04075616])\n" | |
] | |
} | |
], | |
"prompt_number": 68 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"###Weighted mean" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Each axis can have a `weights` attribute. If not None, it will be automatically used when computing mean, var, std" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
">>> np.random.seed(0)\n", | |
">>> data = da.DimArray(randn(7), ('lat',linspace(-90,90,7)))\n", | |
"\n", | |
">>> umean = data.mean(axis='lat')\n", | |
"print \"\\nunweighted zonal mean:\\n\\n\", umean\n", | |
"\n", | |
"# now add weights\n", | |
">>> data.axes['lat'].weights = lambda x: np.cos(np.radians(x))\n", | |
"\n", | |
">>> wmean = data.mean(axis='lat')\n", | |
"print \"\\nweighted zonal mean:\\n\", wmean\n", | |
"\n", | |
">>> wmean = data[:].mean(axis='lat')\n", | |
"print \"\\nweighted zonal mean after [:]:\\n\", wmean\n", | |
"\n", | |
">>> test = data.mean(axis='lat', weights=None) \n", | |
"print \"\\nCHECK:\", test == umean" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"unweighted zonal mean:\n", | |
"\n", | |
"1.03202989506\n", | |
"\n", | |
"weighted zonal mean:\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"1.18361129352\n", | |
"\n", | |
"weighted zonal mean after [:]:\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"1.18361129352\n", | |
"\n", | |
"CHECK:" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
" True\n" | |
] | |
} | |
], | |
"prompt_number": 69 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Weighted mean with grouping\n", | |
"#>>> mymap[mymap.lon > 0])\n", | |
"#lon=linspace(-180,180,50), \n", | |
"mymap = data.reshape(('lat','lon')).repeat(linspace(-180,180,5), axis='lon')\n", | |
"mymap.values[:,0] = np.nan\n", | |
"#>>> print mymap\n", | |
"#lon=linspace(-180,180,50)\n", | |
"wmean = mymap.mean()\n", | |
"print \"\\nNaN + flatten all:\\n\",umean\n", | |
"#>>> wmean = mymap.mean(axis=('lon','lat'))\n", | |
"wmean = mymap.mean(axis='lon').mean(axis='lat')\n", | |
"print \"\\nNaN + sequential:\\n\",wmean\n", | |
"cube = da.DimArray(randn(50,7,5), [('lon',linspace(-180,180,50)), (\"lat\",linspace(-90,90,7)), ('time',arange(1950,1955))])\n", | |
"cube.axes['lat'].weights = lambda x: np.cos(np.radians(x))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"NaN + flatten all:\n", | |
"1.03202989506\n", | |
"\n", | |
"NaN + sequential:\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"1.18361129352\n" | |
] | |
} | |
], | |
"prompt_number": 70 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"###Interpolation" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"time=np.linspace(1950,1955,8)\n", | |
"v = da.DimArray.from_kw(cos(time), time=time)\n", | |
"#w = v.reindex_axis(arange(1940,1960), axis='time') \n", | |
"w = da.interp1d(v, np.linspace(1948,1957,10), axis='time')\n", | |
"#%matplotlib inline\n", | |
"clf()\n", | |
"plot(v.time, v.values, label='original')\n", | |
"plot(w.time, w.values, label='interp')\n", | |
"legend()\n", | |
"show()\n", | |
"draw()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "display_data", | |
"png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAEICAYAAABRSj9aAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8TNf7wPHPJKLEGkpKQqO2UEFsUYRQxFailNjXlJRq\nUbX81FKqqNiq1F5U7SIhkloTu1hiqTVFiCDEVhEkmdzfH/MVQiKTZXInk+f9es2rycy5c5+5r8zj\n9DnnnqNRFEVBCCGEyTJTOwAhhBCGJYleCCFMnCR6IYQwcZLohRDCxEmiF0IIEyeJXgghTFyGE33f\nvn2xtrbGwcEhxTZDhgyhfPnyVKtWjZCQkIyeUgghRBpkONH36dOHgICAFF/fvn07//77L6GhoSxa\ntAhPT8+MnlIIIUQaZDjROzs7Y2VlleLrvr6+9OrVCwAnJycePXpEZGRkRk8rhBBCTwav0UdERFCq\nVKnE321tbbl586ahTyuEEOJ/cmXFSd5cZUGj0bzVJrnnhBBCpC61lWwM3qO3sbEhPDw88febN29i\nY2OTbFtFUeShKIwfP171GIzlIddCroWhrsW9ewq7dys8f67+58nIQx8GT/Rt27Zl5cqVABw5coTC\nhQtjbW1t6NMKIUQiRYHLl2H5cujfHypVgrJl4euvwdUVHj5UO0LDynDppkuXLgQFBREVFUWpUqWY\nOHEicXFxAAwYMIBWrVqxfft2ypU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Tw8PPDz8wOgY8eO3L9/HwsLC+bPn0/BggUBGDlyJKdO\nnUKj0VCmTBkWLlwI6Hr3YWFh1KhRA0VRKF68ON7e3ly4cIHhw4cnxjJmzJhUB4OTfAZZAkEIIUyb\nlG6EEMLESaIXQggTJ4leCCFMnCR6IYQwcZLohRDCxEmiF0IIE/f/bRYoSMtvvC0AAAAASUVORK5C\nYII=\n", | |
"text": [ | |
"<matplotlib.figure.Figure at 0xa28fd8c>" | |
] | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "display_data", | |
"text": [ | |
"<matplotlib.figure.Figure at 0xa21bc8c>" | |
] | |
} | |
], | |
"prompt_number": 71 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"###Export to other formats" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"#reload(da) # for dict\n", | |
"v = da.DimArray.from_kw(randn(2,5,7), time=arange(1950,1955), lat=linspace(-90,90,7), items=array(['greenland','antarctica']))\n", | |
"#reload(co) # for dict\n", | |
"\n", | |
"print \"\\nExport to pandas\\n\"\n", | |
"print v.to_pandas()\n", | |
"print \"\\nExport to larry\\n\"\n", | |
"print v.to_larry()\n", | |
"print \"\\nExport to Dataset\\n\"\n", | |
"print v.to_dict()\n", | |
"#v.to_MaskedArray() # to masked array" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"Export to pandas\n", | |
"\n", | |
"<class 'pandas.core.panel.Panel'>\n", | |
"Dimensions: 2 (items) x 5 (major_axis) x 7 (minor_axis)\n", | |
"Items axis: greenland to antarctica\n", | |
"Major_axis axis: 1950 to 1954\n", | |
"Minor_axis axis: -90.0 to 90.0" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"\n", | |
"Export to larry\n", | |
"\n", | |
"warning: dimension names have not been passed to larry" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"label_0\n", | |
" greenland\n", | |
" antarctica\n", | |
"label_1\n", | |
" 1950\n", | |
" 1951\n", | |
" 1952\n", | |
" 1953\n", | |
" 1954\n", | |
"label_2\n", | |
" -90.0\n", | |
" -60.0\n", | |
" -30.0\n", | |
" 0.0\n", | |
" 30.0\n", | |
" 60.0\n", | |
" 90.0\n", | |
"x\n", | |
"array([[[ 0.02429091, 1.27981202, -0.88596648, 0.40088568, -0.00965724,\n", | |
" -1.79716462, -0.80225317],\n", | |
" [ 0.19321355, 1.29734209, 1.00133102, 0.5972125 , -0.81527566,\n", | |
" 1.80121399, 0.21524047],\n", | |
" [-1.00636552, -0.18290498, 0.89624843, 0.0076175 , 0.88686469,\n", | |
" 1.10369396, 0.40053068],\n", | |
" [-0.85770262, 0.13545466, 0.04516586, 1.85934633, -1.62632194,\n", | |
" -0.13482245, -0.58409355],\n", | |
" [ 0.33510562, -2.43756436, 1.11492456, 0.01374849, -1.84470116,\n", | |
" -0.36111313, 0.60896234]],\n", | |
"\n", | |
" [[-1.59144788, 0.00322222, -1.05747365, -0.55598503, 0.02673838,\n", | |
" 0.18345025, -0.4707425 ],\n", | |
" [ 0.27279639, 0.81797761, -0.27891428, 1.43156776, 1.46221417,\n", | |
" -0.42870207, -0.63784056],\n", | |
" [-1.66417299, -0.12656933, -0.36343778, 0.77905122, -1.50966161,\n", | |
" -0.27739139, 0.96874439],\n", | |
" [-0.7303571 , -0.76236154, -1.44694033, 2.62057385, -0.74747318,\n", | |
" -1.30034683, -0.8038504 ],\n", | |
" [-0.77429508, -0.26938978, 0.82537223, -0.29832317, -0.92282331,\n", | |
" -1.4513385 , 0.02185736]]])\n", | |
"\n", | |
"Export to Dataset\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"Dataset of 2 variables\n", | |
"dimensions: 'time', 'lat'\n", | |
"0 / time (5): 1950 to 1954\n", | |
"1 / lat (7): -90.0 to 90.0\n", | |
"greenland: time, lat\n", | |
"antarctica: time, lat" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n" | |
] | |
} | |
], | |
"prompt_number": 72 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"##doctest framework" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from dimarray import testing\n", | |
"testing.test_all()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"\n", | |
"============================\n", | |
"TEST dimarray.core.metadata\n", | |
"============================\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"============================\n", | |
"TEST dimarray.core.core\n", | |
"============================\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"============================" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"TEST dimarray.core.axes\n", | |
"============================\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"============================" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"TEST dimarray.core._indexing\n", | |
"============================\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"============================" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"TEST dimarray.core._transform\n", | |
"============================\n", | |
"\n", | |
"\n", | |
"\n", | |
"\n", | |
"============================" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"\n", | |
"TEST dimarray.core._reshape\n", | |
"============================\n", | |
"\n", | |
"\n" | |
] | |
} | |
], | |
"prompt_number": 73 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment