Make an interpolation of Variable Parameters ---------- var : Variable indexes_coords Mapping from dimension name to a pair of original and new coordinates. Original coordinates should be sorted in strictly ascending order. Note that all the coordinates shoul
(
var: Variable,
indexes_coords: SourceDest,
method: InterpOptions,
**kwargs,
)
| 614 | |
| 615 | |
| 616 | def interp( |
| 617 | var: Variable, |
| 618 | indexes_coords: SourceDest, |
| 619 | method: InterpOptions, |
| 620 | **kwargs, |
| 621 | ) -> Variable: |
| 622 | """Make an interpolation of Variable |
| 623 | |
| 624 | Parameters |
| 625 | ---------- |
| 626 | var : Variable |
| 627 | indexes_coords |
| 628 | Mapping from dimension name to a pair of original and new coordinates. |
| 629 | Original coordinates should be sorted in strictly ascending order. |
| 630 | Note that all the coordinates should be Variable objects. |
| 631 | method : string |
| 632 | One of {'linear', 'nearest', 'zero', 'slinear', 'quadratic', |
| 633 | 'cubic'}. For multidimensional interpolation, only |
| 634 | {'linear', 'nearest'} can be used. |
| 635 | **kwargs |
| 636 | keyword arguments to be passed to scipy.interpolate |
| 637 | |
| 638 | Returns |
| 639 | ------- |
| 640 | Interpolated Variable |
| 641 | |
| 642 | See Also |
| 643 | -------- |
| 644 | DataArray.interp |
| 645 | Dataset.interp |
| 646 | """ |
| 647 | if not indexes_coords: |
| 648 | return var.copy() |
| 649 | |
| 650 | result = var |
| 651 | |
| 652 | if method in ["linear", "nearest", "slinear"]: |
| 653 | # decompose the interpolation into a succession of independent interpolation. |
| 654 | iter_indexes_coords = decompose_interp(indexes_coords) |
| 655 | else: |
| 656 | iter_indexes_coords = (_ for _ in [indexes_coords]) |
| 657 | |
| 658 | for indep_indexes_coords in iter_indexes_coords: |
| 659 | var = result |
| 660 | |
| 661 | # target dimensions |
| 662 | dims = list(indep_indexes_coords) |
| 663 | |
| 664 | # transpose to make the interpolated axis to the last position |
| 665 | broadcast_dims = [d for d in var.dims if d not in dims] |
| 666 | original_dims = broadcast_dims + dims |
| 667 | result = interpolate_variable( |
| 668 | var.transpose(*original_dims), |
| 669 | {k: indep_indexes_coords[k] for k in dims}, |
| 670 | method=method, |
| 671 | kwargs=kwargs, |
| 672 | ) |
| 673 |
nothing calls this directly
no test coverage detected
searching dependent graphs…