MCPcopy
hub / github.com/pydata/xarray / _localize

Function _localize

xarray/core/missing.py:579–594  ·  view source on GitHub ↗

Speed up for linear and nearest neighbor method. Only consider a subspace that is needed for the interpolation

(obj: T, indexes_coords: SourceDest)

Source from the content-addressed store, hash-verified

577
578
579def _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
597def _floatize_x(

Callers 1

_interpndFunction · 0.85

Calls 4

is_chunked_arrayFunction · 0.90
itemsMethod · 0.80
to_indexMethod · 0.45
iselMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…