photon_mosaic.segmentation.run_segmentation#

photon_mosaic.segmentation.run_segmentation(imaging, method='suite2p', folder='segmentation_folder', *, settings=None, yrange=None, xrange=None, badframes=None, remove_existing_folder=False, raise_error=True, **params)[source]#

Detect ROIs on imaging with the requested segmentation method.

The imaging is segmented once over all of its epochs, concatenated. To get one ROI set per epoch, split it first with photon_mosaic.core.split_imaging_by_epochs() and run each part. A method that does not support multi-plane imaging needs a single plane, e.g. from photon_mosaic.core.select_planes().

Mirrors SpikeInterface’s run_sorter: the backend returns the ROIs and the input imaging is registered to them. If folder is given, it receives segmentation_params.json (validated settings and run arguments), segmentation_log.json (versions, run time, error), the imaging provenance (imaging.json, else imaging.pickle) and the ROIs saved as binary under rois/, which photon_mosaic.core.load(folder / "rois") loads back.

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

  • method (Union[Literal['suite2p'], str]) – Segmentation backend; see photon_mosaic.segmentation.get_available_segmentation_methods().

  • folder (str | Path | None) – Output folder. Must not exist unless remove_existing_folder=True. None runs in memory only and writes nothing.

  • settings (Any) – Backend settings. Dicts and None are coerced into the backend’s settings_class.

  • yrange (Union[Sequence[int], Sequence[Sequence[int]], None]) – Valid pixel range [lo, hi]. May be a single 1D pair (broadcast to every epoch) or a 2D (n_epochs, 2) sequence with one pair per epoch, which must then be uniform. None uses the registration’s ranges for a registered imaging, else the full image extent.

  • xrange (Union[Sequence[int], Sequence[Sequence[int]], None]) – Valid pixel range [lo, hi]. May be a single 1D pair (broadcast to every epoch) or a 2D (n_epochs, 2) sequence with one pair per epoch, which must then be uniform. None uses the registration’s ranges for a registered imaging, else the full image extent.

  • badframes (Union[NDArray[bool], Sequence[NDArray[bool] | None], None]) – Frames to exclude. May be a single flat (total_frames,) boolean array or a per-epoch sequence (each shaped (n_frames_in_epoch,)). None uses the registration’s bad frames for a registered imaging.

  • remove_existing_folder (bool) – Delete folder first if it already exists.

  • raise_error (bool) – Re-raise a backend error. If False, the error is only logged (and recorded in segmentation_log.json when folder is given) and None is returned.

  • **params (Any) – Backend settings, overriding settings.

Returns:

The detected ROIs, with imaging registered; None if the method failed and raise_error=False.

Return type:

BaseRois | None