@@ -132,8 +132,12 @@ It is now possible to safely compute the difference ``other - interpolated``.
132
132
Interpolation methods
133
133
---------------------
134
134
135
- We use :py:class: `scipy.interpolate.interp1d ` for 1-dimensional interpolation and
136
- :py:func: `scipy.interpolate.interpn ` for multi-dimensional interpolation.
135
+ We use :py:class: `scipy.interpolate.interp1d ` for 1-dimensional interpolation.
136
+ For multi-dimensional interpolation, an attempt is first made to decompose the
137
+ interpolation in a series of 1-dimensional interpolations, in which case
138
+ :py:class: `scipy.interpolate.interp1d ` is used. If a decomposition cannot be
139
+ made (e.g. with advanced interpolation), :py:func: `scipy.interpolate.interpn ` is
140
+ used.
137
141
138
142
The interpolation method can be specified by the optional ``method `` argument.
139
143
@@ -165,7 +169,7 @@ Additional keyword arguments can be passed to scipy's functions.
165
169
[(" time" , np.arange(4 )), (" space" , [0.1 , 0.2 , 0.3 ])],
166
170
)
167
171
168
- da.interp(time = 4 , space = np.linspace(- 0.1 , 0.5 , 10 ), kwargs = {" fill_value" : None })
172
+ da.interp(time = 4 , space = np.linspace(- 0.1 , 0.5 , 10 ), kwargs = {" fill_value" : " extrapolate " })
169
173
170
174
171
175
Advanced Interpolation
@@ -198,23 +202,26 @@ For example:
198
202
y = xr.DataArray([0.1 , 0.2 , 0.3 ], dims = " z" )
199
203
da.sel(x = x, y = y)
200
204
201
- # advanced interpolation
202
- x = xr.DataArray([0.5 , 1.5 , 2.5 ], dims = " z" )
203
- y = xr.DataArray([0.15 , 0.25 , 0.35 ], dims = " z" )
205
+ # advanced interpolation, without extrapolation
206
+ x = xr.DataArray([0.5 , 1.5 , 2.5 , 3.5 ], dims = " z" )
207
+ y = xr.DataArray([0.15 , 0.25 , 0.35 , 0.45 ], dims = " z" )
204
208
da.interp(x = x, y = y)
205
209
206
210
where values on the original coordinates
207
- ``(x, y) = ((0.5, 0.15), (1.5, 0.25), (2.5, 0.35)) `` are obtained by the
208
- 2-dimensional interpolation and mapped along a new dimension ``z ``.
211
+ ``(x, y) = ((0.5, 0.15), (1.5, 0.25), (2.5, 0.35), (3.5, 0.45)) `` are obtained
212
+ by the 2-dimensional interpolation and mapped along a new dimension ``z ``. Since
213
+ no keyword arguments are passed to the interpolation routine, no extrapolation
214
+ is performed resulting in a ``nan `` value.
209
215
210
216
If you want to add a coordinate to the new dimension ``z ``, you can supply
211
- :py:class: `~xarray.DataArray ` s with a coordinate,
217
+ :py:class: `~xarray.DataArray ` s with a coordinate. Extrapolation can be achieved
218
+ by passing additional arguments to SciPy's ``interpnd `` function,
212
219
213
220
.. ipython :: python
214
221
215
- x = xr.DataArray([0.5 , 1.5 , 2.5 ], dims = " z" , coords = {" z" : [" a" , " b" , " c" ]})
216
- y = xr.DataArray([0.15 , 0.25 , 0.35 ], dims = " z" , coords = {" z" : [" a" , " b" , " c" ]})
217
- da.interp(x = x, y = y)
222
+ x = xr.DataArray([0.5 , 1.5 , 2.5 , 3.5 ], dims = " z" , coords = {" z" : [" a" , " b" , " c" , " d " ]})
223
+ y = xr.DataArray([0.15 , 0.25 , 0.35 , 0.45 ], dims = " z" , coords = {" z" : [" a" , " b" , " c" , " d " ]})
224
+ da.interp(x = x, y = y, kwargs = { " fill_value " : None } )
218
225
219
226
For the details of the advanced indexing,
220
227
see :ref: `more advanced indexing <more_advanced_indexing >`.
0 commit comments