ngff_zarr.methods._dask

Module Contents

Functions

_bin_shrink

Local mean over axes windows, remainder trimmed, integers rounded half up.

_bin_shrink_wide_integers

Half-up window mean of 64-bit integers in integer arithmetic.

_mode

Most frequent value over axes windows, remainder trimmed, the smallest on a tie.

_block_mode

dask.array.coarsen’s reduction for a label map.

_reaches_target

Whether shrinking previous_image by dim_factors hits the level size.

_downsample_dask_bin_shrink

_downsample_dask_mode

_downsample_dask_coarsen

The levels of ngff_image, each window of each level reduced by reduce.

API

ngff_zarr.methods._dask._bin_shrink(data: dask.array.Array, axes: dict[int, int]) → dask.array.Array

Local mean over axes windows, remainder trimmed, integers rounded half up.

The mean accumulates in float64, which is exact for integers of up to 32 bits; 64-bit integers take the integer path. Rounding half up on integer input gives the same samples as ITK’s BinShrinkImageFilter.

ngff_zarr.methods._dask._bin_shrink_wide_integers(
data: dask.array.Array,
axes: dict[int, int],
) → dask.array.Array

Half-up window mean of 64-bit integers in integer arithmetic.

float64 carries 53 bits, so a 64-bit sample converted to it can lose low bits. Each sample is split by the window size into a quotient and a remainder; the quotient sum stays within the dtype and the remainder sum is small, so the mean is exact.

ngff_zarr.methods._dask._mode(data: dask.array.Array, axes: dict[int, int]) → dask.array.Array

Most frequent value over axes windows, remainder trimmed, the smallest on a tie.

ngff_zarr.methods._dask._block_mode(
block: numpy.ndarray,
axis: tuple[int, ...] | None = None,
) → numpy.ndarray

dask.array.coarsen’s reduction for a label map.

Sorted, a window holds its equal values in runs and the first longest run is its mode, so the cost follows the window size whatever the number of labels.

ngff_zarr.methods._dask._reaches_target(ngff_image, previous_image, scale_factor, dim_factors) → bool

Whether shrinking previous_image by dim_factors hits the level size.

ngff_zarr.methods._dask._downsample_dask_bin_shrink(
ngff_image: ngff_zarr.ngff_image.NgffImage,
default_chunks,
out_chunks,
scale_factors,
)
ngff_zarr.methods._dask._downsample_dask_mode(
ngff_image: ngff_zarr.ngff_image.NgffImage,
default_chunks,
out_chunks,
scale_factors,
)
ngff_zarr.methods._dask._downsample_dask_coarsen(
ngff_image: ngff_zarr.ngff_image.NgffImage,
out_chunks,
scale_factors,
reduce,
)

The levels of ngff_image, each window of each level reduced by reduce.