acryo.pipe package
Module contents
- class acryo.pipe.ImageConverter(converter: Callable[[numpy.ndarray[Any, numpy.dtype[numpy.float32]], float], numpy.ndarray[Any, numpy.dtype[numpy.float32]]])[source]
Bases:
acryo.pipe._classes._Pipeline
Functionthat convert an image.
- compose(other: acryo.pipe._classes.ImageProvider) acryo.pipe._classes.ImageProvider [source]
- compose(other: acryo.pipe._classes.ImageConverter) acryo.pipe._classes.ImageConverter
Function composition
- class acryo.pipe.ImageProvider(provider: Callable[[float], acryo.pipe._classes._R])[source]
Bases:
acryo.pipe._classes._Pipeline
,Generic
[acryo.pipe._classes._R
]Function that provides an image at a given scale.
- acryo.pipe.center_by_mass(*args, **kwargs) NDArray[np.float32] [source]
Centering an image by its center of mass.
- acryo.pipe.closing(*args, **kwargs) NDArray[np.bool_] [source]
Pipe operation that close (or open) a binary image using a circular structure.
- Parameters
radius (float) – Radius of the structure element in nanometer. If negative, opening is applied.
- acryo.pipe.converter_function(fn: Callable[[Concatenate[numpy.ndarray, float, _P]], numpy.ndarray]) Callable[[_P], acryo.pipe._classes.ImageConverter] [source]
Convert a function into a curried function that returns a image converter.
Input function must accept fn(img, scale).
Examples
>>> from scipy import ndimage as ndi >>> @converter_function ... def gaussian_filter(img, scale, sigma): ... return ndi.gaussian_filter(img, sigma / scale) >>> converter = gaussian_filter(1.5) >>> converter(arr) # return a Gaussian filtered `arr`
- acryo.pipe.dilation(*args, **kwargs) NDArray[np.bool_] [source]
Pipe operation that dilate (or erode) a binary image using a circular structure.
- Parameters
radius (float) – Radius of the structure element in nanometer. If negative, erosion is applied.
- acryo.pipe.from_array(*args, **kwargs) NDArray[np.float32] [source]
An image provider function using existing image array.
This function will provide a subtomogram loader with a resized image from an array. Will be used for the template images or the mask images.
>>> loader.align( ... template=from_array(img, original_scale=0.28), ... mask=from_file("path/to/mask.mrc"), ... )
- Parameters
img (np.ndarray) – Input image array. Must be 3D.
original_scale (float, optional) – If given, this value will be used as the image scale (nm/pixel) instead of the scale extracted from the image metadata.
tol (float) – Tolerance of the scale difference. If the relative difference is smaller than this, the image will not be resized.
- acryo.pipe.from_atoms(*args, **kwargs) NDArray[np.float32] [source]
An image provider function using a point cloud.
Given an array of atoms, such as data extracted from a PDB file, this function can generate a 3D image of the atoms by simply building a histogram.
- Parameters
atoms ((N, 3) array) – Atoms coordinates in nanometer.
weights (np.ndarray, optional) – weights of the atoms.
center (tuple of float, optional) – Coordinates of the image center. If not given, the geometric center of the atoms will be used.
- acryo.pipe.from_file(*args, **kwargs) NDArray[np.float32] [source]
An image provider function with rescaling.
This function will provide a subtomogram loader with a resized image from a file. Will be used for the template images or the mask images.
>>> loader.align( ... template=from_file("path/to/template.mrc"), ... mask=from_file("path/to/mask.mrc"), ... )
- Parameters
path (path-like) – Path to the image.
original_scale (float, optional) – If given, this value will be used as the image scale (nm/pixel) instead of the scale extracted from the image metadata.
tol (float) – Tolerance of the scale difference. If the relative difference is smaller than this, the image will not be resized.
- acryo.pipe.from_files(*args, **kwargs) list[NDArray[np.float32]] [source]
Batch image provider function with rescaling.
This function will provide a subtomogram loader with resized images from files. Will be used for the template images.
>>> from glob import glob >>> loader.align( ... template=from_files(glob("path/to/template_*.mrc")), ... mask=from_file("path/to/mask.mrc"), ... )
- Parameters
paths (iterable of path-like) – Paths to the image.
original_scale (float, optional) – If given, this value will be used as the image scale (nm/pixel) instead of the scale extracted from the image metadata.
tol (float) – Tolerance of the scale difference. If the relative difference is smaller than this, the image will not be resized.
- acryo.pipe.from_gaussian(*args, **kwargs) NDArray[np.float32] [source]
An image provider function by a Gaussian function.
This function will provide a Gaussian particle with given shape, sigma and shift from the center.
>>> loader.align( ... template=from_gaussian(shape=(4.8, 4.8, 4.8), sigma=1.2), ... mask=from_file("path/to/mask.mrc"), ... )
- Parameters
shape (float or tuple of float) – Shape of the output image in nm.
sigma (float or tuple of float) – Standard deviation of the Gaussian particle in nm.
shift (tuple of float, optional) – Shift of the Gaussian particle from the center in nm.
- acryo.pipe.gaussian_filter(*args, **kwargs) NDArray[np.float32] [source]
Gaussian filtering an image.
- acryo.pipe.gaussian_smooth(*args, **kwargs) NDArray[np.float32] [source]
Pipe operation that smooth a binary image using a Gaussian kernel.
- Parameters
sigma (float) – Standard deviation of the Gaussian kernel.
- acryo.pipe.provider_function(fn: Callable[[Concatenate[float, _P]], acryo.pipe._curry._R]) Callable[[_P], acryo.pipe._classes.ImageProvider[acryo.pipe._curry._R]] [source]
Convert a function into a curried function that returns a image provider.
Examples
>>> @provider_function ... def provide_random_image(scale, shape): ... return np.random.random(shape) >>> provider = provide_random_image((10, 20, 30)) >>> provider(0.18) # return a (10, 20, 30) array
- acryo.pipe.soft_otsu(sigma: float = 1.0, radius: float = 1.0, bins: int = 256)[source]
Pipe operation of soft Otsu thresholding.
This operation binarize an image using Otsu’s method, dilate the edges and smooth the image using a Gaussian kernel.
>>> from acryo.pipe import reader, soft_otsu >>> loader.align( ... template=reader("path/to/template.mrc"), ... mask=soft_otsu(2.0, 2.0), ... )
- Parameters
sigma (float, default is 1.0) – Standard deviation of the Gaussian kernel.
radius (float, default is 1.0) – Radius of the structure element. If negative, erosion is applied.
bins (int, default is 256) – Number of bins to build histogram.