phenotypic.refine.ResidualOutlierRemover#
- class phenotypic.refine.ResidualOutlierRemover(axis: int | None = None, stddev_multiplier=1.5, max_coeff_variance: int = 1)[source]#
Bases:
GridObjectRefinerRemove objects with large regression residuals in noisy grid rows/columns.
- Intuition:
In grid assays, colony centroids should align along near-linear trends within each row/column. Rows or columns with high variability suggest mis-detections or artifacts. Within such noisy lines, this operation removes objects whose positional residuals exceed a robust cutoff.
- Why this is useful for agar plates:
Condensation, glare, and debris can produce off-grid detections that inflate row/column variance and break gridding assumptions. Pruning residual outliers restores alignment and improves subsequent measures.
- Use cases:
Cleaning rows with multiple off-line blobs before measuring growth.
Stabilizing grid registration when a subset of positions is noisy.
- Caveats:
If true colonies deviate due to warping or growth spreading, strict cutoffs may remove real data.
Depends on reasonable initial grid fit; with severe misregistration it may prune valid colonies.
- axis#
Axis to analyze for outliers.
Noneanalyzes both rows and columns;0analyzes rows;1analyzes columns. Restricting the axis can speed up processing or focus on suspected directions of error.- Type:
Optional[int]
- cutoff_multiplier#
Multiplier applied to a robust dispersion estimate (IQR-based in implementation) to set the outlier cutoff. Higher values are more permissive (fewer removals) and preserve edge cases; lower values prune more aggressively.
- Type:
- max_coeff_variance#
Maximum coefficient of variance (std/mean) allowed for a row/column before it is considered for outlier pruning. Smaller values trigger cleaning sooner; larger values only clean severely noisy lines.
- Type:
Examples
Remove objects with large regression residuals
>>> from phenotypic.refine import ResidualOutlierRemover >>> op = ResidualOutlierRemover(axis=None, stddev_multiplier=1.5, max_coeff_variance=1) >>> image = op.apply(image, inplace=True)
Methods
Initialize the remover.
Applies the operation to an image, either in-place or on a copy.
Drop references to the UI widgets.
Push internal state into widgets.
Return (and optionally display) the root widget.
- __init__(axis: int | None = None, stddev_multiplier=1.5, max_coeff_variance: int = 1)[source]#
Initialize the remover.
- Parameters:
axis (Optional[int]) – Axis selection for analysis.
Noneruns both directions;0rows;1columns. Limiting the axis reduces runtime and targets known problem directions.stddev_multiplier (float) – Robust residual cutoff multiplier. Lower values remove more outliers (stronger cleanup) but risk dropping valid off-center colonies; higher values are conservative.
max_coeff_variance (int) – Threshold for row/column variability (std/mean) to trigger outlier analysis. Lower values clean more lines; higher values only address extremely noisy lines.
- Raises:
ValueError – If parameters are not consistent with the operation (e.g., invalid types). Errors may arise during execution when measuring grid statistics.
- __del__()#
Automatically stop tracemalloc when the object is deleted.
- __getstate__()#
Prepare the object for pickling by disposing of any widgets.
This ensures that UI components (which may contain unpickleable objects like input functions or thread locks) are cleaned up before serialization.
Note
This method modifies the object state by calling dispose_widgets(). Any active widgets will be detached from the object.
- apply(image, inplace=False)#
Applies the operation to an image, either in-place or on a copy.
- widget(image: Image | None = None, show: bool = False) Widget#
Return (and optionally display) the root widget.
- Parameters:
- Returns:
The root widget.
- Return type:
ipywidgets.Widget
- Raises:
ImportError – If ipywidgets or IPython are not installed.