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
imagingwith the requested segmentationmethod.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. fromphoton_mosaic.core.select_planes().Mirrors SpikeInterface’s
run_sorter: the backend returns the ROIs and the input imaging is registered to them. Iffolderis given, it receivessegmentation_params.json(validated settings and run arguments),segmentation_log.json(versions, run time, error), the imaging provenance (imaging.json, elseimaging.pickle) and the ROIs saved as binary underrois/, whichphoton_mosaic.core.load(folder / "rois")loads back.- Parameters:
imaging (
BaseImaging) – Motion-corrected imaging object.method (
Union[Literal['suite2p'],str]) – Segmentation backend; seephoton_mosaic.segmentation.get_available_segmentation_methods().folder (
str|Path|None) – Output folder. Must not exist unlessremove_existing_folder=True.Noneruns in memory only and writes nothing.settings (
Any) – Backend settings. Dicts andNoneare coerced into the backend’ssettings_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.Noneuses 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.Noneuses 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,)).Noneuses the registration’s bad frames for a registered imaging.remove_existing_folder (
bool) – Deletefolderfirst if it already exists.raise_error (
bool) – Re-raise a backend error. If False, the error is only logged (and recorded insegmentation_log.jsonwhenfolderis given) andNoneis returned.**params (
Any) – Backend settings, overridingsettings.
- Returns:
The detected ROIs, with
imagingregistered;Noneif the method failed andraise_error=False.- Return type:
BaseRois|None