Speed up for linear and nearest neighbor method. Only consider a subspace that is needed for the interpolation
(obj: T, indexes_coords: SourceDest)
| 577 | |
| 578 | |
| 579 | def _localize(obj: T, indexes_coords: SourceDest) -> tuple[T, SourceDest]: |
| 580 | """Speed up for linear and nearest neighbor method. |
| 581 | Only consider a subspace that is needed for the interpolation |
| 582 | """ |
| 583 | indexes = {} |
| 584 | for dim, [x, new_x] in indexes_coords.items(): |
| 585 | if is_chunked_array(new_x._data): |
| 586 | continue |
| 587 | new_x_loaded = new_x.data |
| 588 | minval = np.nanmin(new_x_loaded) |
| 589 | maxval = np.nanmax(new_x_loaded) |
| 590 | index = x.to_index() |
| 591 | imin, imax = index.get_indexer(pd.Index([minval, maxval]), method="nearest") |
| 592 | indexes[dim] = slice(max(imin - 2, 0), imax + 2) |
| 593 | indexes_coords[dim] = (x[indexes[dim]], new_x) |
| 594 | return obj.isel(indexes), indexes_coords # type: ignore[attr-defined] |
| 595 | |
| 596 | |
| 597 | def _floatize_x( |
no test coverage detected
searching dependent graphs…