Skip to content

CopickSegmentation

copick.models.CopickSegmentation

Encapsulates all data pertaining to a specific segmentation. This includes the Zarr-store for the segmentation and other metadata.

Attributes:

  • run (CopickRun) –

    Reference to the run this segmentation belongs to.

  • meta (CopickSegmentationMeta) –

    Metadata for this segmentation.

  • zarr (MutableMapping) –

    Zarr store for this segmentation. Either populated from storage or lazily loaded when CopickSegmentation.zarr is accessed for the first time.

  • from_tool (bool) –

    Flag to indicate if this segmentation was generated by a tool.

  • from_user (bool) –

    Flag to indicate if this segmentation was generated by a user.

  • user_id (str) –

    Unique identifier for the user or tool name.

  • session_id (str) –

    Unique identifier for the segmentation session

  • is_multilabel (bool) –

    Flag to indicate if this is a multilabel segmentation. If False, it is a single label segmentation.

  • voxel_size (float) –

    Voxel size of the tomogram this segmentation belongs to.

  • name (str) –

    Pickable Object name or multilabel name of the segmentation.

  • color

    Color of the pickable object this segmentation belongs to.

__init__(run: CopickRun, meta: CopickSegmentationMeta)

Parameters:

zarr() -> MutableMapping

Override to return the Zarr store for this segmentation. Also needs to handle creating the store if it doesn't exist.

numpy(zarr_group: str = '0', x: slice = slice(None, None), y: slice = slice(None, None), z: slice = slice(None, None)) -> np.ndarray

Returns the content of the Zarr-File for this segmentation as a numpy array. Multiscale group and slices are supported.

Parameters:

  • zarr_group (str, default: '0' ) –

    Zarr group to access.

  • x (slice, default: slice(None, None) ) –

    Slice for the x-axis.

  • y (slice, default: slice(None, None) ) –

    Slice for the y-axis.

  • z (slice, default: slice(None, None) ) –

    Slice for the z-axis.

Returns:

  • ndarray

    np.ndarray: The segmentation as a numpy array.

from_numpy(data: np.ndarray, levels: int = 1, dtype: Optional[np.dtype] = np.uint8) -> None

Set the segmentation from a numpy array and compute multiscale pyramid. By default, no pyramid is computed for segmentations.

Parameters:

  • data (ndarray) –

    The segmentation as a numpy array.

  • levels (int, default: 1 ) –

    Number of levels in the multiscale pyramid.

  • dtype (Optional[dtype], default: uint8 ) –

    Data type of the segmentation. Default is np.uint8.

set_region(data: np.ndarray, zarr_group: str = '0', x: slice = slice(None, None), y: slice = slice(None, None), z: slice = slice(None, None)) -> None

Set a region of the segmentation from a numpy array.

Parameters:

  • data (ndarray) –

    The segmentation's subregion as a numpy array.

  • zarr_group (str, default: '0' ) –

    Zarr group to access.

  • x (slice, default: slice(None, None) ) –

    Slice for the x-axis.

  • y (slice, default: slice(None, None) ) –

    Slice for the y-axis.

  • z (slice, default: slice(None, None) ) –

    Slice for the z-axis.