Skip to content

Commit 184ea44

Browse files
committed
fix(denoise): bypass xarray/dask quantile — compute eagerly via numpy
Both the xarray→nanquantile and xarray→dask→map_blocks quantile paths in dask 2024.12.x pass the removed 'interpolation' kwarg to numpy 2.x. Bypass the entire xarray/dask quantile dispatch and compute eagerly with np.nanquantile(method='linear') on materialised values.
1 parent 7720c1d commit 184ea44

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

oceanstream/echodata/denoise/background_noise.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,21 @@ def background_noise_mask(
190190
if depth_stat == "min":
191191
noise_1d_db = binned_db.min(dim=range_dim, skipna=True)
192192
elif depth_stat == "quantile":
193-
# Use skipna=False to avoid the xarray → dask → np.nanquantile
194-
# code path where dask 2024.12.x passes the removed 'interpolation'
195-
# kwarg to numpy 2.x's nanquantile. We drop NaN slices ourselves
196-
# before computing the quantile.
197-
_binned = binned_db.fillna(0.0) if binned_db.isnull().any() else binned_db
198-
noise_1d_db = _binned.quantile(
199-
depth_quantile, dim=range_dim, method="linear", skipna=False
200-
)
201-
if "quantile" in noise_1d_db.dims:
202-
noise_1d_db = noise_1d_db.squeeze("quantile", drop=True)
193+
# Bypass xarray/dask quantile entirely — dask 2024.12.x passes the
194+
# removed 'interpolation' kwarg to numpy 2.x in both the nanquantile
195+
# and map_blocks/quantile code paths. Compute eagerly via numpy.
196+
import numpy as _np
197+
198+
_vals = binned_db.values if hasattr(binned_db, 'values') else binned_db
199+
_vals = _np.asarray(_vals, dtype=_np.float64)
200+
axis = binned_db.dims.index(range_dim)
201+
noise_arr = _np.nanquantile(_vals, depth_quantile, axis=axis, method="linear")
202+
remaining_dims = [d for d in binned_db.dims if d != range_dim]
203+
remaining_coords = {
204+
k: v for k, v in binned_db.coords.items()
205+
if k in remaining_dims
206+
}
207+
noise_1d_db = xr.DataArray(noise_arr, dims=remaining_dims, coords=remaining_coords)
203208
else:
204209
raise ValueError("depth_stat must be 'min' or 'quantile'.")
205210

0 commit comments

Comments
 (0)