phenotypic.sdk_.mixin package#
Mixin classes for PhenoTypic operations.
This subpackage provides reusable mixin classes that add specific capabilities to ImageOperation subclasses and other PhenoTypic components.
Available mixins: - FootprintMixin: Generate morphological footprints (structuring elements) - GridInferenceMixin: Infer grid structure from binary masks using peak detection - LazyWidgetMixin: Generate interactive Jupyter widgets for parameter tuning - ClipControlMixin: Control output clipping behavior in composite operations - PointPickerMixin: Marker + shared plumbing for operations that take user-picked
(y, x)coordinates as a primary parameter
_GATSupportMixin: Optional Generalized Anscombe Transform variance stabilization for noise-driven enhancers and correctors
- class phenotypic.sdk_.mixin.ClipControlMixin[source]#
Bases:
objectMixin for operations that need to control clipping behavior of inner operations.
Provides a method to create copies of ImageEnhancer or ImagePipeline instances with clipping disabled. This is useful for composite operations where an inner enhancer operates on non-normalized data (e.g., variance-stabilized values from the Generalized Anscombe Transform, typically in the range ~1-32).
The mixin uses duck typing to check for a clip attribute on operations. If an operation has clip=True, the _disable_clipping method will create a shallow copy with clip=False. This preserves the original operation unchanged while allowing the copy to operate without output clipping.
Example
Creating a clip-disabled copy of an enhancer:
>>> from phenotypic.sdk_ import ClipControlMixin >>> from phenotypic.enhance import LocalEdgeDenoise >>> >>> enh = LocalEdgeDenoise(sigma_spatial=5, clip=True) >>> copied = ClipControlMixin._disable_clipping(enh) >>> # Original unchanged, copy has clip=False >>> enh.clip, copied.clip (True, False)
Creating a clip-disabled copy of a pipeline:
>>> from phenotypic import ImagePipeline >>> from phenotypic.enhance import GaussianBlur, LocalEdgeDenoise >>> >>> pipeline = ImagePipeline(pipe_cfgs=[ ... GaussianBlur(sigma=1.0), ... LocalEdgeDenoise(sigma_spatial=5, clip=True) ... ]) >>> copied_pipe = ClipControlMixin._disable_clipping(pipeline) >>> # Only LocalEdgeDenoise has clip attribute, so only it is affected >>> # _ops is a dict with operation names as keys >>> list(copied_pipe._ops.values())[1].clip False
- class phenotypic.sdk_.mixin.FootprintMixin[source]#
Bases:
objectProvides a mixin for creating morphological footprints for image processing.
The FootprintMixin class contains a static utility method to generate structuring elements (footprints) used in various image processing tasks. This functionality is particularly helpful in the context of analyzing microbial colonies on solid media agar plates. Morphological footprints are used to highlight specific features in images, such as colony edges, shapes, or connectivity, and can assist in segmentation, noise reduction, and feature extraction.
- None#
- class phenotypic.sdk_.mixin.GridInferenceMixin[source]#
Bases:
objectMixin providing grid inference capabilities from binary masks.
Provides static methods for inferring grid structure from colony patterns using peak detection on row/column projections. Used by detectors and refiners that work with gridded plate images (96-well, 384-well formats, pinned cultures).
All methods are static to support parallelization in pipeline operations.
This is an internal utility for advanced users creating custom grid-based operations. Most users should use RoundPeaksDetector for detection or GridAlignmentRefiner for post-detection refinement directly.
- class phenotypic.sdk_.mixin.LazyWidgetMixin[source]#
Bases:
objectMixin providing a lazy ipywidget interface.
This mixin allows ImageOperation classes to automatically generate a Jupyter widget interface for parameter tuning and visualization.
The six lazily-populated UI handles this mixin uses (
_ui,_param_widgets,_view_dropdown,_update_button,_output_widget,_image_ref) are declared asPrivateAttronImageOperationrather than here. A plain (non-BaseModel) mixin’sPrivateAttrdeclarations are not collected by pydantic, so this mixin stays a stateless methods-only class and the private attrs live on the pydantic model that mixes it in. This keeps the mixin safe to combine with anyBaseModelin any MRO position.- __getstate__()[source]#
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.
- widget(image: Image | None = None, show: bool = False) Widget[source]#
Return (and optionally display) the root widget.
- Parameters:
image (Image | None) – Optional image to visualize. If provided, visualization controls will be added to the widget.
show (bool) – Whether to display the widget immediately. Defaults to False.
- Returns:
The root widget.
- Return type:
ipywidgets.Widget
- Raises:
ImportError – If ipywidgets or IPython are not installed.
- class phenotypic.sdk_.mixin.PointPickerMixin[source]#
Bases:
objectShared plumbing for operations parameterised by user-picked
(y, x)points.Operations that take a list of point coordinates as a primary parameter (currently
ManualPointDetectorandManualRefine) inherit from this mixin to pick up two things at once:A blocking napari picker.
napari()opens a desktopPointPickerWidgetand writes the confirmed picks back to the operation. Closing the viewer without confirming is a no-op (existing centres are preserved).A GUI introspection hook. The
_point_picker_param_nameclass attribute tells the Dash builder which field to replace with an interactive picker button instead of a free-form text input.
Subclasses that store coordinates under a name other than
"centers"can override_point_picker_param_name;napari()uses that attribute.Coordinate coercion (list/tuple/
np.ndarray→ a canonical form) moves to afield_validatoron the coordinate field of each consuming operation as part of the pydantic migration — this mixin no longer overrides__setattr__(which would clash with pydantic’s).- _point_picker_param_name#
Name of the field holding the picked
(y, x)coordinates. Defaults to"centers".- Type:
ClassVar[str]
- napari(image: Image) _T[source]#
Interactively pick coordinates using a napari viewer.
Opens a blocking napari viewer displaying the plate image layers. Click points on the image, then click Confirm in the dock widget. The picked coordinates are stored in the attribute named by
_point_picker_param_name. If the viewer is closed without confirming any points, existing coordinates are preserved.- Parameters:
image (Image) – The Image to display for coordinate selection.
self (_T)
- Returns:
The mixin-bearing instance, for method chaining.
- Raises:
ImportError – If napari is not installed.
- Return type:
_T