Combiner
Combiner(arr, mask=None, *, copy=True, validate=True)Stateful pipeline holder for (scale/zero, reject, combine) workflows.
Use Standard Combiner with rejectors=... and diagnostics=None for production reductions. Use Chained Combiner calls when you need retained masks, rejection diagnostics, or step-by-step inspection.
Parameters
arr : (ndarray, shape(N, *spatial))-
Image stack. Accepted public input dtypes are
uint8,uint16,int16,int32,float32, andfloat64.uint8,uint16, andint16are promoted tofloat32;int32is promoted tofloat64;float32andfloat64are preserved. Other dtypes, includingint64andfloat128, are not silently cast.Combineris intended for workflows that may apply masking, rejection, zero, or scale. Inputs with more than 3 dimensions are flattened to(N, prod(spatial), 1)for internal processing; all outputs (from :meth:combineand :attr:last_reject) are reshaped back to the original trailing dimensions. mask : ndarray of bool = None-
Input mask with the same shape as
arr;True= masked.Nonemeans no mask. copy : bool = True-
If
True, copyarrandmaskinto owned workspace arrays. IfFalse, keep references to normalized inputs when possible. validate : bool = True-
If
True, validate shape, dtype, mask compatibility, and contiguity. IfFalse, callers must provide a 3-D contiguous stack with a dtype accepted by the compiled kernels and a same-shape boolean mask.
Attributes
arr : ndarray-
Working stack (after any
zero_scale), always 3-D internally. Owned, may be modified. mask : ndarray of bool or None-
Combined mask (union of input, threshold, and rejection masks), 3-D.
Noneuntil one is set. mask_thresh : ndarray of bool or None-
Threshold mask from :meth:
threshold, shaped like the original input stack.Noneuntil thresholding has been applied. last_reject : tuple or None-
(mask_rej, std, low, upp, nit, output_flags)from the most recent :meth:rejectcall, shaped to match the original trailing spatial dimensions. Ifgrowwas used,mask_rejis the grown rejection mask;low,upp,nit, andstdstill describe the underlying clipping calculation, andoutput_flagsbit16marks output elements where growth added at least one rejected sample.Noneuntil :meth:rejecthas been called. last_sample_flags : ndarray of uint8 or None-
Stack-shaped per-sample flags from the most recent :meth:
rejectcall made withdiagnostics="full". This is stage-local like :attr:last_reject; samples already masked before the rejection step are marked with sample bit32rather than replaying earlier-stage causes. Iterative sigma/CCD/linear clipping can also mark samples tentatively rejected and then restored bynkeepormaxrej.
Methods
| Name | Description |
|---|---|
| combine | Combine the (possibly masked) stack along axis 0 and return the result. |
| copy | Return an independent copy of this pipeline state. |
| reject | Apply a rejector, OR-merging its mask into self.mask. |
| threshold | Mask values outside inclusive threshold bounds. |
| variance | Return variance of final valid values along axis 0. |
| zero_scale | Apply per-image offset / scale: (arr - zero) / scale. |
combine
Combiner.combine(
method='mean',
*,
weight=None,
ddof=0,
zero=None,
scale=None,
zero_to_0th=True,
scale_to_0th=True,
zero_sigclip_kwargs=None,
scale_sigclip_kwargs=None,
thresholds=None,
rejectors=None,
full=False,
diagnostics=None,
)Combine the (possibly masked) stack along axis 0 and return the result.
Masked pixels are NaN-filled before combining so the kernels skip them. Passing combine-call thresholds or rejectors with diagnostics=None is the Standard Combiner style; supported single-rejector mean/median calls can use fused kernels without storing rejection diagnostics. Calling :meth:threshold, :meth:zero_scale, and :meth:reject before :meth:combine is the Chained Combiner style; it preserves masks and rejection diagnostics for inspection. Since Combiner works on its normalized workspace, lmedian here follows that workspace dtype. Integer-preserving pure lower median is available through :func:imcombiners.kernels.lmedian or pure :func:imcombiners.ndcombine calls.
Parameters
method : str = 'mean'-
Combine method. Supported aliases are
"mean","average","avg","median","med","lmedian","lmed","sum","min","max","variance","var","weighted_average"and"wvg". weight : ndarray of shape (N,) = None-
Required for
method="weighted_average". ddof : int = 0-
Delta degrees of freedom for
method="variance". Ignored by other combine methods. zero : array-like, str, callable, or None = None-
Per-plane values to subtract before scaling, after any thresholds passed to this
combinecall and before combine-call rejection. Accepts the same forms as :meth:zero_scale. scale : array-like, str, callable, or None = None-
Per-plane values used as divisors after zero subtraction. Accepts the same forms as :meth:
zero_scale. zero_to_0th : bool = True-
Whether per-plane zero or scale values are rebased to the zeroth frame before application, matching :meth:
zero_scaledefaults. scale_to_0th : bool = True-
Whether per-plane zero or scale values are rebased to the zeroth frame before application, matching :meth:
zero_scaledefaults. zero_sigclip_kwargs : dict or None = None-
Keyword arguments used only when
zeroorscaleis a sigma-clipped statistic alias. scale_sigclip_kwargs : dict or None = None-
Keyword arguments used only when
zeroorscaleis a sigma-clipped statistic alias. thresholds : tuple or sequence of tuple = None-
Inclusive threshold bounds to apply before any rejectors passed to this
combinecall. Passing these tocombinedoes not mutate the combiner unless a diagnostics level is requested. Combine-call zero/scale follows these thresholds. rejectors : Rejector or sequence of Rejector = None-
Rejection steps to apply as part of this
combinecall. Withdiagnostics=None, a single supported rejector may use a fused output-only kernel and no rejection diagnostics are stored. full : bool = False-
Legacy alias for
diagnostics="simple". diagnostics : (None, 'simple', 'full') = None-
Diagnostic level for this
combinecall.Nonereturns only the combined image without mutating state."simple"applies thresholds/rejectors to this combiner and retainslast_reject."full"also recordssample_flagsfor the most recent rejection step.
Returns
combined : (ndarray, shape(*spatial))-
Combined image, shaped to match the trailing spatial dimensions of the array passed to :meth:
__init__.
copy
Combiner.copy()Return an independent copy of this pipeline state.
Returns
combiner : Combiner-
New combiner with copied
arrandmask.last_rejectis shared by reference because it is diagnostic data from a completed step.
reject
Combiner.reject(rejector, *, grow=None, diagnostics='simple')Apply a rejector, OR-merging its mask into self.mask.
rejector is any :class:~imcombiners._rejectors.Rejector subclass (SigClip, CcdClip, LinearClip, MinMaxClip, PClip). If grow is not None, the rejection mask is grown spatially within each input plane before it is merged into the running mask. After a rejection step, self.mask_rej.sum(axis=0) is the number rejected by that step at each output element, including any grown samples. The number actually used by later combine calls is np.sum(np.isfinite(self.arr) & ~self.mask, axis=0) after all input and rejection masks have been merged.
Parameters
rejector : Rejector-
Rejection object to apply.
grow : float or None = None-
Non-negative radius in pixels used to grow this rejection mask over the original spatial axes. Axis 0 is the stack axis and is never grown across.
Nonedisables mask growth and avoids the extra calculation. diagnostics : (None, 'simple', 'full') = None-
Rejection diagnostic level.
Noneand"simple"keep the currentlast_rejectproducts."full"also records stack-shapedsample_flagsfor this rejection step.
Returns
combiner : Combiner-
This object, after updating
maskandlast_reject.
threshold
Combiner.threshold(low=-np.inf, upp=np.inf)Mask values outside inclusive threshold bounds.
Thresholding is a pre-rejection mask stage. Values survive when low <= value <= upp; values below low or above upp are recorded in :attr:mask_thresh and OR-merged into the running mask. Later zero_scale statistics, rejection, and combination ignore these thresholded pixels.
A common CCD-image pattern is low=0 to remove bad/cold pixels and upp=satlevel or upp=0.99 * satlevel to remove saturated or near-saturated pixels before they influence normalization or rejection.
Parameters
low : float = -np.inf-
Inclusive lower and upper retained-value bounds.
upp : float = -np.inf-
Inclusive lower and upper retained-value bounds.
Returns
combiner : Combiner-
This object, after updating
maskandmask_thresh.
variance
Combiner.variance(ddof=1, return_mean=False)Return variance of final valid values along axis 0.
Valid values are finite inputs not masked by the input mask and not rejected by previous :meth:reject calls. This is equivalent to::
arr_eff = np.where(mask | rejected, np.nan, stack)
var = np.nanvar(arr_eff, axis=0, ddof=ddof)
Parameters
ddof : int = 1-
Delta degrees of freedom. Pixels with
nvalid <= ddofreturnNaN. Default is1, i.e., Sample variance. Useddof=0for population variance. return_mean : bool = False-
If
True, also return the per-pixel mean computed from the same final valid values and the same Rust accumulation pass.
Returns
variance : (ndarray, shape(*spatial))-
Per-pixel variance. Use
np.sqrt(var)if an error or standard-deviation map is needed. mean : (ndarray, shape(*spatial))-
Returned only when
return_mean=True.
zero_scale
Combiner.zero_scale(
zero=None,
scale=None,
*,
zero_to_0th=True,
scale_to_0th=True,
zero_sigclip_kwargs=None,
scale_sigclip_kwargs=None,
)Apply per-image offset / scale: (arr - zero) / scale.
Either or both may be None. Modifies self.arr in place and returns self for chaining.
Parameters
zero : array-like, str, callable, or None = None-
Per-plane values to subtract before scaling. Array-like inputs must be scalar or length
N. Strings select a per-plane statistic: plain ("mean","median","sum","min","max"plus aliases) or sigma-clipped ("sigclip_mean"/"mean_sc"and"sigclip_median"/"median_sc"/"med_sc", usingsigma=3,maxiters=5by default). Callables are evaluated once per image plane and must return a scalar. Current masks, including threshold masks, are applied before string statistics are computed. scale : array-like, str, callable, or None = None-
Per-plane values used as divisors after zero subtraction. The same string and callable rules as
zeroapply, including the sigma-clipped variants. Scale values must be finite and non-zero when validation is enabled. zero_to_0th : bool = True-
If
True, subtract the first zero value from all zero values before applying them.Trueis the default behavior to follow IRAF. Setting this toTruemakes only a small subtraction happen, so real pixel values change only slightly and Poisson-noise calculations remain well behaved. scale_to_0th : bool = True-
If
True, divide all scale values by the first scale value before applying them.Trueis the default behavior to follow IRAF. Setting this toTruemakes only a small division happen, so real pixel values change only slightly and Poisson-noise calculations remain well behaved. zero_sigclip_kwargs : dict or None = None-
Keyword arguments used only when
zeroorscaleis a sigma-clipped statistic alias such as"mean_sc"or"med_sc". Supported keys aresigma,maxiters,cenfunc,clip_cen, andddof. scale_sigclip_kwargs : dict or None = None-
Keyword arguments used only when
zeroorscaleis a sigma-clipped statistic alias such as"mean_sc"or"med_sc". Supported keys aresigma,maxiters,cenfunc,clip_cen, andddof.
Returns
combiner : Combiner-
This object, after updating its working stack.