photon_mosaic.segmentation.basesegmentation#

Functions

get_available_segmentation_methods()

Return the names of all built-in and registered segmentation methods.

get_segmentation_class(method)

Return the BaseSegmentation subclass implementing method.

register_segmentation_class(segmentation_class)

Register a BaseSegmentation subclass under its method_name.

Classes

BaseSegmentation()

Base class for ROI segmentation backends.

photon_mosaic.segmentation.basesegmentation.register_segmentation_class(segmentation_class)[source]#

Register a BaseSegmentation subclass under its method_name.

Backend modules call this at import time so that run_segmentation(..., method=...) can find them. Third-party backends can call it too, which is what makes the set of methods extensible.

Parameters:

segmentation_class (type[BaseSegmentation]) – Subclass defining method_name (and usually settings_class).

Returns:

The class, unchanged, so this can be used as a decorator.

Return type:

type[BaseSegmentation]

photon_mosaic.segmentation.basesegmentation.get_segmentation_class(method)[source]#

Return the BaseSegmentation subclass implementing method.

Built-in backends are imported lazily on first use, so an optional dependency is only required when its method is actually requested.

Return type:

type[BaseSegmentation]

photon_mosaic.segmentation.basesegmentation.get_available_segmentation_methods()[source]#

Return the names of all built-in and registered segmentation methods.

Return type:

list[str]

class photon_mosaic.segmentation.basesegmentation.BaseSegmentation[source]#

Base class for ROI segmentation backends.

Modelled on SpikeInterface’s BaseSorter: subclasses are never instantiated, they only provide classmethods that photon_mosaic.segmentation.run_segmentation() calls in order:

  1. initialize_folder() / set_params_to_folder() (provided here)

  2. run() – detect ROIs on one contiguous span of epochs and return them as a BaseRois

Subclasses declare method_name (the string users pass as method) and settings_class (their pydantic settings model), and register themselves with register_segmentation_class().

Attributes:
method_name
settings_class

Methods

default_params()

Return the default value of every setting of settings_class.

get_method_version()

Return the version of the underlying segmentation library.

initialize_folder(folder[, ...])

Create the output folder, refusing to overwrite unless asked.

is_installed()

Return whether the backend's dependencies are importable.

params_description()

Return the description of every setting of settings_class.

run(imaging, yrange, xrange, badframes, settings)

Detect ROIs on the concatenation of all epochs of imaging and return them.

set_params_to_folder(folder, settings, ...)

Write the validated settings and the run arguments to segmentation_params.json.

method_name: str | None = None#
settings_class: type[BaseSettings] | None = None#
support_multi_plane = False#
classmethod is_installed()[source]#

Return whether the backend’s dependencies are importable.

Return type:

bool

classmethod get_method_version()[source]#

Return the version of the underlying segmentation library.

Return type:

str

classmethod default_params()[source]#

Return the default value of every setting of settings_class.

Return type:

dict[str, Any]

classmethod params_description()[source]#

Return the description of every setting of settings_class.

Return type:

dict[str, str | None]

classmethod initialize_folder(folder, remove_existing_folder=False)[source]#

Create the output folder, refusing to overwrite unless asked.

Return type:

Path

classmethod set_params_to_folder(folder, settings, run_kwargs)[source]#

Write the validated settings and the run arguments to segmentation_params.json.

Return type:

None

classmethod run(imaging, yrange, xrange, badframes, settings)[source]#

Detect ROIs on the concatenation of all epochs of imaging and return them.

Parameters:
  • imaging (BaseImaging) – Motion-corrected imaging object.

  • yrange (Sequence[int]) – Valid pixel range [lo, hi].

  • xrange (Sequence[int]) – Valid pixel range [lo, hi].

  • badframes (NDArray[bool] | None) – Frames to exclude, shaped (total_frames_in_epochs,).

  • settings (Any) – Validated settings_class instance.

Returns:

rois – Detected ROIs for the concatenated epochs.

Return type:

BaseRois