Interpolating data¶
xarray offers flexible interpolation routines, which have a similar interface to our indexing.
Note
interp
requires scipy installed.
Scalar and 1-dimensional interpolation¶
Interpolating a DataArray
works mostly like labeled
indexing of a DataArray
,
In [1]: da = xr.DataArray(np.sin(0.3 * np.arange(12).reshape(4, 3)),
...: [('time', np.arange(4)),
...: ('space', [0.1, 0.2, 0.3])])
...:
# label lookup
In [2]: da.sel(time=3)
Out[2]:
<xarray.DataArray (space: 3)>
array([ 0.42738 , 0.14112 , -0.157746])
Coordinates:
time int64 3
* space (space) float64 0.1 0.2 0.3
# interpolation
In [3]: da.interp(time=2.5)