acryo.loader package

Module contents

class acryo.loader.BatchLoader(order: int = 3, scale: float = 1.0, output_shape: int | tuple[int, int, int] | acryo.loader._base.Unset = Unset, corner_safe: bool = False)[source]

Bases: acryo.loader._base.LoaderBase

Collection of tomograms and their molecules.

A BatchLoader is similar to a list of SubtomogramLoader objects, but with better consistency in loader parameters and more convenient access to the molecules. This class is useful for processing many tomograms at once, especially when you want to get the average of all the molecules available.

add_loader(loader: SubtomogramLoader | BatchLoader) Self[source]

Add a subtomogram loader or a batch loader to the collection.

add_tomogram(image: np.ndarray | da.Array, molecules: Molecules, image_id: Hashable | None = None) Self[source]

Add a tomogram and its molecules to the collection.

Parameters
  • image (np.ndarray or da.Array) – Tomogram image. This argument is passed directly to the SubtomogramLoader constructor.

  • molecules (Molecules) – Molecules in the tomogram (corresponding to the image argument). This argument is passed directly to the SubtomogramLoader constructor.

  • image_id (Hashable, optional) – Identifier for the tomogram. If not provided, a unique identifier will be generated. This identifier is used to tag molecules with the tomogram they reside in.

binning(binsize: int, *, compute: bool = False) Self[source]

Return a new instance with binned images.

construct_loading_tasks(output_shape: _ShapeType = None, backend: Backend | None = None) DaskArrayList[source]

Construct batch loading tasks.

classmethod from_loaders(loaders: Iterable[SubtomogramLoader], order: int = 3, scale: nm = 1.0, output_shape: pixel | tuple[pixel, pixel, pixel] | Unset = Unset, corner_safe: bool = False) Self[source]

Construct a loader from a list of loaders.

property images: mappingproxy

All the images in the collection.

property loaders: acryo.loader._batch.LoaderAccessor

Interface to access the subtomogram loaders.

property molecules: acryo.molecules.core.Molecules

Collect all the molecules from all the loaders

replace(molecules: Molecules | None = None, output_shape: _ShapeType | Unset = None, order: int | None = None, scale: float | None = None, corner_safe: bool | None = None) Self[source]

Return a new instance with different parameter(s).

class acryo.loader.MockLoader(template: numpy.ndarray[Any, numpy.dtype[numpy.float32]] | acryo.pipe._classes.ImageProvider, molecules: acryo.molecules.core.Molecules, noise: float = 0.0, degrees: Optional[Union[Sequence[float], numpy.ndarray[Any, numpy.dtype[numpy.float32]]]] = None, central_axis: tuple[float, float, float] = (0.0, 1.0, 0.0), order: int = 3, scale: float = 1.0, corner_safe: bool = False)[source]

Bases: acryo.loader._base.LoaderBase

A subtomogram loader from a virtual tomogram.

This loader is for testing purpose only. The tomogram does not actually exist but subtomograms are generated on the fly based on the template image. The true center of the molecules is always at (0, 0, 0) and the true rotation is always the identity rotation. Thus, given molecule positions/rotations will directly be the values to be tested.

Parameters
  • template (3D array, ImageProvider) – The template image.

  • molecules (Molecules) – The molecules to be loaded. Note that the true center/rotation is always (0, 0, 0) and the identity rotation, respectively.

  • noise (float, optional) – Standard deviation of the Gaussian noise to be added to the subtomograms projection slices.

  • degrees (array-like, optional) – The rotation angles in degrees. If not provided, projection/back-projection will not be simulated.

  • central_axis (tuple, default is (0.0, 1.0, 0.0)) – The central axis of the rotation during tomogram acquisition.

construct_loading_tasks(output_shape: _ShapeType = None, backend: Backend | None = None) DaskArrayList[source]
property molecules: acryo.molecules.core.Molecules

All the molecules

replace(molecules: Molecules | None = None, output_shape: None = None, order: int | None = None, scale: float | None = None, corner_safe: bool | None = None) Self[source]
class acryo.loader.SubtomogramLoader(image: numpy.ndarray | dask.array.core.Array, molecules: acryo.molecules.core.Molecules, order: int = 3, scale: float = 1.0, output_shape: int | tuple[int, int, int] | acryo.loader._base.Unset = Unset, corner_safe: bool = False)[source]

Bases: acryo.loader._base.LoaderBase

A class for efficient loading of subtomograms.

A SubtomogramLoader instance is basically composed of two elements, an image and a Molecules object. A subtomogram is loaded by creating a local rotated Cartesian coordinate at a molecule and calculating mapping from the image to the subtomogram.

Parameters
  • image (np.ndarray or da.Array) – Tomogram image. Must be 3-D.

  • molecules (Molecules) – Molecules object that represents positions and orientations of subtomograms.

  • order (int, default is 3) – Interpolation order of subtomogram sampling. - 0 = Nearest neighbor - 1 = Linear interpolation - 3 = Cubic interpolation

  • scale (float, default is 1.0) – Physical scale of pixel, such as nm. This value does not affect averaging/alignment results but molecule coordinates are multiplied by this value. This parameter is useful when another loader with binned image is created.

  • output_shape (int or tuple of int, optional) – Shape of output subtomogram in pixel. This parameter is not required if template (or mask) image is available immediately.

  • corner_safe (bool, default is False) – If true, regions around molecules will be cropped at a volume larger than output_shape so that densities at the corners will not be lost due to rotation. If target density is globular, this parameter should be set false to save computation time.

binning(binsize: pixel = 2, *, compute: bool = True) Self[source]

Return a new instance with binned image.

This method also properly translates the molecule coordinates.

Parameters
  • binsize (int, default is 2) – Bin size.

  • compute (bool, default is True) – If true, the image is computed immediately to a numpy array.

Returns

A new instance with binned image.

Return type

SubtomogramLoader

construct_loading_tasks(output_shape: Optional[Union[int, tuple[int, ...]]] = None, backend: acryo.backend._api.Backend | None = None) acryo._dask.DaskArrayList[source]

Construct a list of subtomogram lazy loader.

Returns

Each object returns a subtomogram on execution by da.compute.

Return type

list of Delayed object

property image: NDArray[np.float32] | da.Array

Return tomogram image.

classmethod imread(path: str, molecules: acryo.molecules.core.Molecules, order: int = 3, scale: float | None = None, output_shape: int | tuple[int, int, int] | acryo.loader._base.Unset = Unset, corner_safe: bool = False, chunks: Any = 'auto')[source]
property molecules: acryo.molecules.core.Molecules

Return the molecules of the subtomogram loader.

replace(molecules: Molecules | None = None, output_shape: pixel | tuple[pixel, pixel, pixel] | Unset | None = None, order: int | None = None, scale: float | None = None, corner_safe: bool | None = None) Self[source]

Return a new instance with different parameter(s).