kernels.linearclip

kernels.linearclip(
    arr,
    *,
    mask=None,
    low_scale=1.0,
    low=0.0,
    upp_scale=1.0,
    upp=0.0,
    maxiters=1,
    nkeep=1,
    maxrej=None,
    cenfunc='median',
    revert_on_nkeep=True,
    grow=None,
    validate=True,
)

Center-relative linear clipping (low + low_scale * center <= value <= upp + upp_scale * center).

Parameters

arr : (ndarray, shape(N, *spatial))

Image stack. Accepted dtypes are uint8, uint16, int16, int32, float32, and float64. Integer inputs are promoted to the package’s floating workspace when validate is True. Inputs with more than 3 dimensions are flattened internally; output shapes match the trailing spatial dimensions of the input.

mask : ndarray of bool = None

Input mask; True means already masked. Must have the same shape as arr before any internal flattening.

low_scale : float = 1.0

Multiplier for the per-pixel center used in the lower retained bound.

low : float = 0.0

Non-negative margin subtracted from low_scale * center.

upp_scale : float = 1.0

Multiplier for the per-pixel center used in the upper retained bound.

upp : float = 0.0

Non-negative margin added to upp_scale * center.

maxiters : int = 1

Maximum number of clipping iterations per pixel. 1 preserves the historical single-pass behavior.

nkeep : int = 1

Minimum number of unmasked values to preserve at each pixel.

maxrej : int or None = None

Maximum number of values that may be rejected at each pixel. None means no limit.

cenfunc : ('median', 'lmedian', 'mean') = "median"

Center estimator used each iteration. lmedian accepts the alias lmed and uses the lower of the two middle samples for even valid counts.

revert_on_nkeep : bool = True

If True, an iteration that would leave fewer than nkeep usable samples at a pixel is reverted in full for that pixel.

grow : float or None = None

Optional radius in pixels used to grow mask_rej spatially after rejection. Axis 0 is the stack axis and is never grown across. None disables growth and skips the extra calculation.

validate : bool = True

If True, check dimensionality and normalize dtype/contiguity before entering the Rust kernel. If False, callers must provide inputs that satisfy the compiled kernel assumptions.

Returns

mask_rej : ndarray of bool, shape (N, *spatial)

True where a value was rejected by this kernel. mask_rej.sum(axis=0) is the per-output rejected count.

std : (ndarray, shape(*spatial) or None)

Per-pixel spread used by sigma/CCD clipping. None for rejection algorithms without a spread diagnostic.

low : (ndarray, shape(*spatial))

Lower retained-value bound. Bounds are inclusive: values equal to low are retained.

upp : (ndarray, shape(*spatial))

Upper retained-value bound. Bounds are inclusive: values equal to upp are retained.

nit : ndarray of uint8, shape (*spatial)

Iteration-count map.

output_flags : ndarray of uint8, shape (*spatial)

Bit-coded status. 0 means normal completion; bit 1 means at least one pre-masked sample at this output element; bit 16 means grow added at least one rejected sample at this output element. Iterative kernels also use bit 2 for maxiters, bit 4 for nkeep, and bit 8 for maxrej. Bits are OR-ed. output_flags is a per-output diagnostic; use mask_rej.sum(axis=0) to count samples rejected by this step.

Notes

Values survive when low_scale * center - low <= value <= upp_scale * center + upp. Each iteration recomputes the center from finite, unmasked survivors and stops when no new samples are rejected or maxiters is reached. The default bounds (1, 0, 1, 0) are a no-op.