Skip to content

CopickTiltSeries

copick.models.CopickTiltSeries

Encapsulates a tilt series: a stack of 2D images (section, y, x) stored as a multiscale OME-Zarr image, and its metadata (see CopickTiltSeriesMetadata).

The images are stored like on the CryoET Data Portal: chunks of one image, levels binned by 2 along y and x only. The metadata is read lazily from the Zarr group, so listing tilt series does not open their stores.

Attributes:

  • run (CopickRun) –

    Reference to the run this tilt series belongs to.

  • meta (CopickTiltSeriesMeta) –

    Identity of this tilt series.

  • ts_type (str) –

    Type of the tilt series.

cets_id

cets_id: str

Identifier of this tilt series in stored CETS metadata, unique within its run.

metadata

metadata: Optional[CopickTiltSeriesMetadata]

The metadata of this tilt series, or None if it holds no images yet.

pixel_size

pixel_size: Optional[float]

Pixel size of the full-size images in Angstrom, or None if the tilt series holds no images.

shape

shape: Optional[Tuple[int, int, int]]

Shape (section, y, x) of the full-size images, or None if the tilt series holds no images.

n_sections

n_sections: int

Number of images in the tilt series.

alignments

alignments: List[CopickAlignment]

All alignments of this tilt series in its run, best first (see CopickRun.get_alignments).

valid_alignments

valid_alignments: List[CopickAlignment]

The alignments of this tilt series from their authors, best first; placeholders are left out.

default_alignment

default_alignment: Optional[CopickAlignment]

The best valid alignment of this tilt series, or None if there is none.

__init__

__init__(run: CopickRun, meta: CopickTiltSeriesMeta)

Parameters:

store_metadata

store_metadata(metadata: Optional[CopickTiltSeriesMetadata] = None) -> None

Store metadata in the Zarr group of this tilt series.

Parameters:

  • metadata (Optional[CopickTiltSeriesMetadata], default: None ) –

    The metadata to store. Default: the current metadata (e.g. after editing it in place).

Raises:

  • ValueError –

    If the tilt series holds no images, or the metadata does not fit them.

zarr

zarr() -> MutableMapping

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

numpy

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

Return images of the tilt series as a numpy array (section, y, x).

Parameters:

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

    Multiscale level to read.

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

    Slice of sections.

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

    Slice along y.

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

    Slice along x.

Returns:

  • ndarray –

    np.ndarray: The images.

section

section(index: int, zarr_group: str = '0') -> np.ndarray

Return one image of the tilt series.

Parameters:

  • index (int) –

    Section of the image.

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

    Multiscale level to read.

Returns:

  • ndarray –

    np.ndarray: The image (y, x).

from_numpy

from_numpy(data: Any, pixel_size: Optional[float] = None, levels: int = TILT_SERIES_LEVELS, dtype: Optional[dtype] = np.float32, chunks: Tuple[int, int, int] = TILT_SERIES_CHUNKS, metadata: Optional[CopickTiltSeriesMetadata] = None) -> None

Write the images of the tilt series and their multiscale pyramid, replacing any stored images.

The images are written one section at a time, so data may be any array-like indexable per section, e.g. a memory-mapped MRC file. The stored metadata is kept if it still fits the images; otherwise it is replaced by metadata holding only the image geometry.

Parameters:

  • data (Any) –

    The images, shape (section, y, x).

  • pixel_size (Optional[float], default: None ) –

    Pixel size in Angstrom. Default: that of metadata or of the stored metadata.

  • levels (int, default: TILT_SERIES_LEVELS ) –

    Number of levels in the pyramid.

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

    Data type of the stored images; None keeps the type of data.

  • chunks (Tuple[int, int, int], default: TILT_SERIES_CHUNKS ) –

    Chunk shape of every level.

  • metadata (Optional[CopickTiltSeriesMetadata], default: None ) –

    Metadata to store with the images.

Raises:

  • ValueError –

    If no pixel size is known, or the metadata does not fit the images.

set_region

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

Overwrite a region of one multiscale level. The other levels are not updated.

Parameters:

  • data (ndarray) –

    The region's new content, shape (section, y, x).

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

    Multiscale level to write.

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

    Slice of sections.

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

    Slice along y.

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

    Slice along x.

refresh

refresh() -> None

Re-read the metadata on next access.

delete

delete() -> None

Delete the tilt series.