@@ -2228,16 +2228,13 @@ def interp(
2228
2228
kwargs : Mapping [str , Any ] | None = None ,
2229
2229
** coords_kwargs : Any ,
2230
2230
) -> Self :
2231
- """Interpolate a DataArray onto new coordinates
2231
+ """
2232
+ Interpolate a DataArray onto new coordinates.
2233
+
2234
+ Performs univariate or multivariate interpolation of a Dataset onto new coordinates,
2235
+ utilizing either NumPy or SciPy interpolation routines.
2232
2236
2233
- Performs univariate or multivariate interpolation of a DataArray onto
2234
- new coordinates using scipy's interpolation routines. If interpolating
2235
- along an existing dimension, either :py:class:`scipy.interpolate.interp1d`
2236
- or a 1-dimensional scipy interpolator (e.g. :py:class:`scipy.interpolate.KroghInterpolator`)
2237
- is called. When interpolating along multiple existing dimensions, an
2238
- attempt is made to decompose the interpolation into multiple
2239
- 1-dimensional interpolations. If this is possible, the 1-dimensional interpolator is called.
2240
- Otherwise, :py:func:`scipy.interpolate.interpn` is called.
2237
+ Out-of-range values are filled with NaN, unless specified otherwise via `kwargs` to the numpy/scipy interpolant.
2241
2238
2242
2239
Parameters
2243
2240
----------
@@ -2246,16 +2243,9 @@ def interp(
2246
2243
New coordinate can be a scalar, array-like or DataArray.
2247
2244
If DataArrays are passed as new coordinates, their dimensions are
2248
2245
used for the broadcasting. Missing values are skipped.
2249
- method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial"}, default: "linear"
2250
- The method used to interpolate. The method should be supported by
2251
- the scipy interpolator:
2252
-
2253
- - ``interp1d``: {"linear", "nearest", "zero", "slinear",
2254
- "quadratic", "cubic", "polynomial"}
2255
- - ``interpn``: {"linear", "nearest"}
2256
-
2257
- If ``"polynomial"`` is passed, the ``order`` keyword argument must
2258
- also be provided.
2246
+ method : { "linear", "nearest", "zero", "slinear", "quadratic", "cubic", \
2247
+ "quintic", "polynomial", "pchip", "barycentric", "krogh", "akima", "makima" }
2248
+ Interpolation method to use (see descriptions above).
2259
2249
assume_sorted : bool, default: False
2260
2250
If False, values of x can be in any order and they are sorted
2261
2251
first. If True, x has to be an array of monotonically increasing
@@ -2275,12 +2265,37 @@ def interp(
2275
2265
2276
2266
Notes
2277
2267
-----
2278
- scipy is required.
2268
+ - SciPy is required for certain interpolation methods.
2269
+ - When interpolating along multiple dimensions with methods `linear` and `nearest`,
2270
+ the process attempts to decompose the interpolation into independent interpolations
2271
+ along one dimension at a time.
2272
+ - The specific interpolation method and dimensionality determine which
2273
+ interpolant is used:
2274
+
2275
+ 1. **Interpolation along one dimension of 1D data (`method='linear'`)**
2276
+ - Uses :py:func:`numpy.interp`, unless `fill_value='extrapolate'` is provided via `kwargs`.
2277
+
2278
+ 2. **Interpolation along one dimension of N-dimensional data (N ≥ 1)**
2279
+ - Methods {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "quintic", "polynomial"}
2280
+ use :py:func:`scipy.interpolate.interp1d`, unless conditions permit the use of :py:func:`numpy.interp`
2281
+ (as in the case of `method='linear'` for 1D data).
2282
+ - If `method='polynomial'`, the `order` keyword argument must also be provided.
2283
+
2284
+ 3. **Special interpolants for interpolation along one dimension of N-dimensional data (N ≥ 1)**
2285
+ - Depending on the `method`, the following interpolants from :py:class:`scipy.interpolate` are used:
2286
+ - `"pchip"`: :py:class:`scipy.interpolate.PchipInterpolator`
2287
+ - `"barycentric"`: :py:class:`scipy.interpolate.BarycentricInterpolator`
2288
+ - `"krogh"`: :py:class:`scipy.interpolate.KroghInterpolator`
2289
+ - `"akima"` or `"makima"`: :py:class:`scipy.interpolate.Akima1dInterpolator`
2290
+ (`makima` is handled by passing the `makima` flag).
2291
+
2292
+ 4. **Interpolation along multiple dimensions of multi-dimensional data**
2293
+ - Uses :py:func:`scipy.interpolate.interpn` for methods {"linear", "nearest", "slinear",
2294
+ "cubic", "quintic", "pchip"}.
2279
2295
2280
2296
See Also
2281
2297
--------
2282
- scipy.interpolate.interp1d
2283
- scipy.interpolate.interpn
2298
+ :mod:`scipy.interpolate`
2284
2299
2285
2300
:doc:`xarray-tutorial:fundamentals/02.2_manipulating_dimensions`
2286
2301
Tutorial material on manipulating data resolution using :py:func:`~xarray.DataArray.interp`
@@ -2376,43 +2391,67 @@ def interp_like(
2376
2391
"""Interpolate this object onto the coordinates of another object,
2377
2392
filling out of range values with NaN.
2378
2393
2379
- If interpolating along a single existing dimension,
2380
- :py:class:`scipy.interpolate.interp1d` is called. When interpolating
2381
- along multiple existing dimensions, an attempt is made to decompose the
2382
- interpolation into multiple 1-dimensional interpolations. If this is
2383
- possible, :py:class:`scipy.interpolate.interp1d` is called. Otherwise,
2384
- :py:func:`scipy.interpolate.interpn` is called.
2385
-
2386
2394
Parameters
2387
2395
----------
2388
2396
other : Dataset or DataArray
2389
2397
Object with an 'indexes' attribute giving a mapping from dimension
2390
2398
names to an 1d array-like, which provides coordinates upon
2391
2399
which to index the variables in this dataset. Missing values are skipped.
2392
- method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial"}, default: "linear"
2393
- The method used to interpolate. The method should be supported by
2394
- the scipy interpolator:
2395
-
2396
- - {"linear", "nearest", "zero", "slinear", "quadratic", "cubic",
2397
- "polynomial"} when ``interp1d`` is called.
2398
- - {"linear", "nearest"} when ``interpn`` is called.
2399
-
2400
- If ``"polynomial"`` is passed, the ``order`` keyword argument must
2401
- also be provided.
2400
+ method : { "linear", "nearest", "zero", "slinear", "quadratic", "cubic", \
2401
+ "quintic", "polynomial", "pchip", "barycentric", "krogh", "akima", "makima" }
2402
+ Interpolation method to use (see descriptions above).
2402
2403
assume_sorted : bool, default: False
2403
2404
If False, values of coordinates that are interpolated over can be
2404
2405
in any order and they are sorted first. If True, interpolated
2405
2406
coordinates are assumed to be an array of monotonically increasing
2406
2407
values.
2407
2408
kwargs : dict, optional
2408
- Additional keyword passed to scipy's interpolator .
2409
+ Additional keyword arguments passed to the interpolant .
2409
2410
2410
2411
Returns
2411
2412
-------
2412
2413
interpolated : DataArray
2413
2414
Another dataarray by interpolating this dataarray's data along the
2414
2415
coordinates of the other object.
2415
2416
2417
+ Notes
2418
+ -----
2419
+ - scipy is required.
2420
+ - If the dataarray has object-type coordinates, reindex is used for these
2421
+ coordinates instead of the interpolation.
2422
+ - When interpolating along multiple dimensions with methods `linear` and `nearest`,
2423
+ the process attempts to decompose the interpolation into independent interpolations
2424
+ along one dimension at a time.
2425
+ - The specific interpolation method and dimensionality determine which
2426
+ interpolant is used:
2427
+
2428
+ 1. **Interpolation along one dimension of 1D data (`method='linear'`)**
2429
+ - Uses :py:func:`numpy.interp`, unless `fill_value='extrapolate'` is provided via `kwargs`.
2430
+
2431
+ 2. **Interpolation along one dimension of N-dimensional data (N ≥ 1)**
2432
+ - Methods {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "quintic", "polynomial"}
2433
+ use :py:func:`scipy.interpolate.interp1d`, unless conditions permit the use of :py:func:`numpy.interp`
2434
+ (as in the case of `method='linear'` for 1D data).
2435
+ - If `method='polynomial'`, the `order` keyword argument must also be provided.
2436
+
2437
+ 3. **Special interpolants for interpolation along one dimension of N-dimensional data (N ≥ 1)**
2438
+ - Depending on the `method`, the following interpolants from :py:class:`scipy.interpolate` are used:
2439
+ - `"pchip"`: :py:class:`scipy.interpolate.PchipInterpolator`
2440
+ - `"barycentric"`: :py:class:`scipy.interpolate.BarycentricInterpolator`
2441
+ - `"krogh"`: :py:class:`scipy.interpolate.KroghInterpolator`
2442
+ - `"akima"` or `"makima"`: :py:class:`scipy.interpolate.Akima1dInterpolator`
2443
+ (`makima` is handled by passing the `makima` flag).
2444
+
2445
+ 4. **Interpolation along multiple dimensions of multi-dimensional data**
2446
+ - Uses :py:func:`scipy.interpolate.interpn` for methods {"linear", "nearest", "slinear",
2447
+ "cubic", "quintic", "pchip"}.
2448
+
2449
+ See Also
2450
+ --------
2451
+ :func:`DataArray.interp`
2452
+ :func:`DataArray.reindex_like`
2453
+ :mod:`scipy.interpolate`
2454
+
2416
2455
Examples
2417
2456
--------
2418
2457
>>> data = np.arange(12).reshape(4, 3)
@@ -2468,18 +2507,8 @@ def interp_like(
2468
2507
Coordinates:
2469
2508
* x (x) int64 32B 10 20 30 40
2470
2509
* y (y) int64 24B 70 80 90
2471
-
2472
- Notes
2473
- -----
2474
- scipy is required.
2475
- If the dataarray has object-type coordinates, reindex is used for these
2476
- coordinates instead of the interpolation.
2477
-
2478
- See Also
2479
- --------
2480
- DataArray.interp
2481
- DataArray.reindex_like
2482
2510
"""
2511
+
2483
2512
if self .dtype .kind not in "uifc" :
2484
2513
raise TypeError (
2485
2514
f"interp only works for a numeric type array. Given { self .dtype } ."
0 commit comments