photon_mosaic.core.baserois#

Classes

BaseRois(sampling_frequency, shape, roi_ids)

Base class for rois extractors.

class photon_mosaic.core.baserois.BaseRois(sampling_frequency, shape, roi_ids)[source]#

Base class for rois extractors.

Attributes:
imaging

Get the registered imaging.

num_planes

Number of planes for ROI masks.

roi_ids

Get the ROI IDs.

sampling_frequency
segmentation_info
shape

Get the shape of the ROIs (height, width, planes).

Methods

get_num_planes()

Get the number of planes.

get_num_rois()

Get the total number of ROIs.

get_roi_image_masks([roi_ids])

Get the image mask for a specific ROI.

get_roi_pixel_masks([roi_ids])

Get the pixel coordinates for a specific ROI.

has_imaging()

Check if an imaging is registered.

register_imaging(imaging)

Register an imaging to the ROIs.

save([format])

Save a BaseRois object to a specified format:

select_rois(roi_ids)

Select a subset of ROIs.

set_segmentation_info

property imaging#

Get the registered imaging.

Returns:

The registered imaging or None if not registered.

Return type:

BaseImaging | None

property segmentation_info#
set_segmentation_info(imaging_dict, params_dict, log_dict)[source]#
has_imaging()[source]#

Check if an imaging is registered.

Returns:

True if an imaging is registered, False otherwise.

Return type:

bool

property shape#

Get the shape of the ROIs (height, width, planes).

Returns:

The shape of the ROIs as (height, width, planes).

Return type:

tuple

property sampling_frequency#
property roi_ids: ndarray#

Get the ROI IDs.

Returns:

The ROI IDs.

Return type:

np.ndarray

get_num_planes()[source]#

Get the number of planes.

Returns:

The number of planes.

Return type:

int

property num_planes: int#

Number of planes for ROI masks.

This is a convenience alias for get_num_planes().

get_num_rois()[source]#

Get the total number of ROIs.

Returns:

The total number of ROIs.

Return type:

int

get_roi_image_masks(roi_ids=None)[source]#

Get the image mask for a specific ROI. The image mask can be binary or weighted and 2D (single plane) or 3D (multi-plane).

Subclasses may return either a dense np.ndarray or a sparse pydata/sparse array (e.g. sparse.GCXS). Each ROI typically occupies only a tiny fraction of the full imaging volume, so a sparse representation avoids the out-of-memory errors a dense array would cause once there are many ROIs over a large (e.g. volumetric) field of view – see photon-mosaic#103. Callers that need actual pixel values (e.g. for plotting) should call .todense() explicitly rather than assume a dense array.

Parameters:

roi_ids (list[int | str] | None) – The IDs of the ROIs.

Returns:

The image mask for the specified ROIs.

Return type:

ndarray | SparseArray

get_roi_pixel_masks(roi_ids=None)[source]#

Get the pixel coordinates for a specific ROI.

Parameters:

roi_ids (list[int | str] | None) – The IDs of the ROIs.

Returns:

The pixel coordinates for the specified ROIs (y, x, [z,] weight).

Return type:

list[ndarray]

select_rois(roi_ids)[source]#

Select a subset of ROIs.

Parameters:

roi_ids (ArrayLike) – The IDs of the ROIs to select.

Returns:

A new BaseRois object containing only the selected ROIs.

Return type:

BaseRois

register_imaging(imaging)[source]#

Register an imaging to the ROIs. If the ROIs and imaging both contain time information, the imaging’s time information will be used.

Parameters:

imaging (BaseImaging) – Imaging with the same number of planes as the ROIs. Assigned to self._imaging.

save(format='binary', **save_kwargs)[source]#

Save a BaseRois object to a specified format:

  • “binary”

  • “zarr”

Parameters:
  • format (str, default: "binary") –

    The format to save the ROIs in. Options are:

    • ”binary”: Saves the ROIs in binary format.

    • ”zarr”: Saves the ROIs in Zarr format.

  • verbose (bool, default: False) – If True, prints additional information during the save process.

  • **save_kwargs (dict) –

    Additional keyword arguments specific to the chosen format. All formats support job_kwargs for parallel processing (see si.get_global_job_kwargs() for default values).

    • ”binary” format:
      • folderstr or Path

        The folder where the binary files will be saved.

      • overwritebool, default: False

        If True, existing files in the folder will be overwritten.

    • ”zarr” format:
      • folderstr or Path

        The folder where the Zarr files will be saved.

      • overwrite: bool, default: False

        If True, the folder is removed if it already exists

      • storage_options: dict or None, default: None

        Storage options for zarr store. E.g., if “s3://” or “gcs://” they can provide authentication methods, etc. For cloud storage locations, this should not be None (in case of default values, use an empty dict)

      • compressor: numcodecs.Codec or None, default: None

        Compressor for the ROI mask datasets. If None, zarr’s default is used

      • filters: list[numcodecs.Codec] or None, default: None

        Filters for the ROI mask datasets

      • chunks: tuple or None, default: None

        Chunk shape for the ROI mask datasets. If None, an automatic per-ROI chunking is applied

Returns:

The on-disk representation.

Return type:

BinaryFolderRois or ZarrRois