cryolike.grids
cryolike.grids.cartesian_grid
- class cryolike.grids.cartesian_grid.CartesianGrid2D(n_pixels: int | list[int] | ndarray[tuple[int, ...], dtype[integer]], pixel_size: float | list[float] | ndarray[tuple[int, ...], dtype[floating]], endpoint: bool = False)
Bases:
objectClass implementing 2D Cartesian grid.
- n_pixels
Number of pixels on each dimension of the grid.
- Type:
IntArrayType
- pixel_size
Size of each pixel as [x, y].
- Type:
FloatArrayType
- box_size
Overall area of the grid (pixel size times number of pixels) in each dimension.
- Type:
FloatArrayType
- radius
Half the box size, i.e. multidimensional radius centered at the grid center.
- Type:
FloatArrayType
- x_axis
1-D array represetting X-coordinates of the grid
- Type:
FloatArrayType
- y_axis
1-D array represetting Y-coordinates of the grid
- Type:
FloatArrayType
- x_pixels
2-D array representing X-coordinates of each pixel on the grid
- Type:
FloatArrayType
- y_pixels
2-D array representing Y-coordinates of each pixel on the grid
- Type:
FloatArrayType
- class cryolike.grids.cartesian_grid.CartesianGrid3D(n_voxels: int | list[int] | ndarray[tuple[int, ...], dtype[integer]], voxel_size: float | list[float] | ndarray[tuple[int, ...], dtype[floating]], endpoint: bool = False)
Bases:
objectClass implementing 3D Cartesian grid.
- n_voxels
Number of voxels in each dimension of the grid.
- Type:
IntArrayType
- voxel_size
Size of each voxel as [x, y, z].
- Type:
FloatArrayType
- box_size
Overall area of the grid (voxel size times number of voxels) in each dimension.
- Type:
FloatArrayType
- radius
Half the box size, i.e. multidimensional radius centered at the grid center.
- Type:
FloatArrayType
- x_axis
X-axis positions of the grid, assuming 0 for the grid center
- Type:
FloatArrayType
- y_axis
Y-axis positions of the grid, assuming 0 for the grid center
- Type:
FloatArrayType
- z_axis
Z-axis positions of the grid, assuming 0 for the grid center
- Type:
FloatArrayType
- x_voxels
X-positions of each voxel
- Type:
FloatArrayType
- y_voxels
Y-positions of each voxel
- Type:
FloatArrayType
- z_voxels
Z-positions of each voxel
- Type:
FloatArrayType
cryolike.grids.polar_grid
- class cryolike.grids.polar_grid.ArbitraryPolarQuadrature(radius_shells: ndarray[tuple[int, ...], dtype[floating]], weight_shells: ndarray[tuple[int, ...], dtype[floating]] | None)
Bases:
objectData class to facilitate preselected quadrature points for polar grids.
- Parameters:
radius_shells (NDArray[np.floating]) – Radius of each radial shell.
weight_shells (NDArray[np.floating], optional) – Weight of each radial shell. Will be computed if unset.
- Raises:
ValueError – On inconsistency between radius_shells and weight_shells, which are required to have the same shape if both are set.
- class cryolike.grids.polar_grid.PolarGrid(radius_max: float = -1.0, dist_radii: float = -1.0, uniform: bool = True, quadrature: QuadratureType | ArbitraryPolarQuadrature = QuadratureType.GAUSS_JACOBI_BETA_1, n_inplanes: int | ndarray[tuple[int, ...], dtype[integer]] | None = None, dist_inplane: float = 0.15915494309189535, half_space: bool = False)
Bases:
objectClass implementing polar-coordinate grid.
- radius_shells
Radius of each radial shell
- Type:
FloatArrayType
- weight_shells
Weight of each radial shell
- Type:
FloatArrayType
- n_inplanes
Number of points in each radial shell. Only applicable to uniform grids; if the shells have different point counts, see n_inplane_shells.
- Type:
- n_inplane_shells
Number of points per each radial shell
- Type:
IntArrayType
- radius_points
Radius coordinate for each point in the list of points
- Type:
FloatArrayType
- theta_shell
For uniform grids, all shells have the same sets of angles. These are those angles.
- Type:
FloatArrayType
- theta_points
Theta coordinate for each point in the list of points
- Type:
FloatArrayType
- weight_points
Weight for each point in the list of points
- Type:
FloatArrayType
- integration_weight_points
Weight_points, but multiplied by 4pi^2 for use in integration. Pre-shaped to conform to [n_radius x n_inplane].
- Type:
FloatArrayType
- shell_indices
Index for the point lists, identifying which shell each point belongs to
- Type:
IntArrayType
- x_points
X-coordinate of each point on the quadrature grid
- Type:
FloatArrayType
- y_points
Y-coordinate of each point on the quadrature grid
- Type:
FloatArrayType
- mask_points
Integration mask weight for each point on the quadrature grid. User-settable, but defaults to 4 * sinc(2 * x_points) * sinc(2 * y_points).
- Type:
FloatArrayType
- mask_integral
Integral of the point masks. Used in computing integrated log likelihood.
- Type:
- get_fourier_translation_kernel(x_displacements_angstrom: Tensor, y_displacements_angstrom: Tensor, box_size_x: float = 2.0, box_size_y: float = 2.0, precision: Precision = Precision.DEFAULT, device: str | device = 'cuda') Tensor
Get a translation kernel that can pointwise-multiply a Fourier-space image representation to accomplish the equivalent of a translation (or set of translations) in Angstrom-denominated physical space. The resulting kernel will have dimensions of [n_displacements, n_radii, n_inplanes].
- Parameters:
x_displacements_angstrom (torch.Tensor) – X-displacement (or displacements) to apply
y_displacements_angstrom (torch.Tensor) – Y-displacement(s) to apply
box_size_x (float, optional) – Total width (in Angstrom) of viewing box. Defaults to 2.0.
box_size_y (float, optional) – Total height (in Angstrom) of viewing box. Defaults to 2.0.
precision (Precision, optional) – If set, target precision for the returned tensor. Defaults to Precision.DEFAULT.
device (str | torch.device, optional) – If set, target device for returned tensor. Defaults to “cuda”.
- Returns:
- A Tensor which can be used to displace a Fourier representation of
an image stack.
- Return type:
torch.Tensor
- set_mask_points(callback: Callable[[ndarray[tuple[int, ...], dtype[floating]], ndarray[tuple[int, ...], dtype[floating]]], ndarray[tuple[int, ...], dtype[floating]]] | None = None)
Sets the mask points (for integrated log likelihood computation) of this polar grid. These should be set by passing a callback function, which takes the x- and y-coordinates of every point in the grid and returns a float-type numpy array with the corresponding mask value at that point.
For example, the default callback performs:
4.0 * np.sinc(2.0 * x_pts) * np.sinc(2.0 * y_pts)
where x_pts and y_pts are the two parameters, the x- and y-coordinates (respectively) of every grid point on the polar grid.
- Parameters:
callback (Callable[[FloatArrayType, FloatArrayType], FloatArrayType] | None, optional) – A function mapping the Cartesian values of the polar grid points to the mask weight. Defaults to None, in which case a sinc-based default is used.
cryolike.grids.sphere_grid
- class cryolike.grids.sphere_grid.CartesianShell(x_points: ndarray[tuple[int, ...], dtype[floating]], y_points: ndarray[tuple[int, ...], dtype[floating]], z_points: ndarray[tuple[int, ...], dtype[floating]], xyz_points: ndarray[tuple[int, ...], dtype[floating]])
Bases:
NamedTupleCollection of Cartesian points for a sphere or spherical shell.
- x_points
x-positions of the points
- Type:
FloatArrayType
- y_points
y-positions of the points
- Type:
FloatArrayType
- z_points
z-positions of the points
- Type:
FloatArrayType
- xyz_points
arrays of x, y, z positions for each point
- Type:
FloatArrayType
- class cryolike.grids.sphere_grid.SphereGrid(radius_max: float = 1.0, dist_eq: float = 0.15915494309189535, azimuthal_sampling: SamplingStrategy = SamplingStrategy.UNIFORM, equal_shell: bool = False, dist_type: SamplingStrategy = SamplingStrategy.UNIFORM)
Bases:
objectClass to sample points on a spherical grid comprised of shells.
- dist_type
‘Uniform’ or ‘Adaptive’ distance between points for various shells
- Type:
- azimuthal_sampling
‘Uniform’ or ‘adaptive’ aziumthal sampling for polar circles
- Type:
- radius_shells
radius of each radial shell
- Type:
FloatArrayType
- weights_radius_shells
weight of each radial shell
- Type:
FloatArrayType
- radius_points
radius of each point
- Type:
FloatArrayType
- polar_points
polar angle of each point
- Type:
FloatArrayType
- azimu_points
azimuthal angle of each point
- Type:
FloatArrayType
- weight_points
weight of each point
- Type:
FloatArrayType
- shells
list of radial shells
- Type:
- point_shell_start_indices
start index of each shell within the point list
- Type:
IntArrayType
- cartesian_points
If set, a NamedTuple of four float arrays (x_points, y_points, z_points, xyz_points) defining cartesian coordinates of each point
- Type:
Optional[CartesianShell]
- class cryolike.grids.sphere_grid.SphereShell(radius: float = 1.0, dist_eq: float = 0.15915494309189535, azimuthal_sampling: SamplingStrategy = SamplingStrategy.UNIFORM, compute_cartesian: bool = True)
Bases:
objectClass to sample points on a sphere shell of known radius r.
- azimuthal_sampling
Whether the grid is uniform or adaptive.
- Type:
- polar_circles
polar angles at each polar circle
- Type:
FloatArrayType
- weights_polar
weight at each point
- Type:
FloatArrayType
- n_azimus_each_circle
number of azimuthal points at each polar circle
- Type:
IntArrayType
- azimu_points
azimuthal angles at each point
- Type:
FloatArrayType
- polar_points
polar angles at each point
- Type:
FloatArrayType
- weight_points
weight at each point
- Type:
FloatArrayType
- cartesian_points
If set, a NamedTuple of four float arrays (x_points, y_points, z_points, xyz_points) defining cartesian coordinates of each point.
- Type:
Optional[CartesianShell]
cryolike.grids.volume
- class cryolike.grids.volume.Volume(density_physical_data: PhysicalVolume | None = None, density_fourier_data: FourierVolume | None = None, box_size: float | ndarray[tuple[int, ...], dtype[floating]] | None = None)
Bases:
objectClass representing a volume in physical or Fourier space, with methods manipulating them.
- box_size
Size of the (Cartesian-space) viewing port.
- Type:
FloatArrayType
- voxel_grid
A grid describing the space in which physical images reside.
- Type:
- sphere_grid
A grid describing the space in which Fourier images reside.
- Type:
- density_physical
Cartesian-space density as a voxel-value array of [X-index x Y-index x Z-index].
- Type:
torch.Tensor
- density_fourier
Fourier-space density as a point-value array of [point-index].
- Type:
torch.Tensor
- classmethod from_mrc(filename: str, voxel_size: float | list[float] | ndarray[tuple[int, ...], dtype[floating]] | None = None, device: str | device = 'cpu')
Create a new physical density from an MRC file.
- Parameters:
filename (str) – Name of MRC file to load. Must end with a .mrc or .mrcs extension.
voxel_size (Optional[float | list[float] | FloatArrayType]) – Sizes of the volume voxels (Angstrom). If set, will override the values in the MRC file; if unset, the file values will be used.
device (str | torch.device, optional) – Device to use for the resulting image Tensor. Defaults to ‘cpu’.
- Raises:
ValueError – If a non-MRC file extension is passed.
ValueError – If the voxel_size is not set and the existing MRC file has non-positive pixel sizes.
- Returns:
An Images image collection, with the physical images and grid populated per the saved data.
- Return type:
- classmethod from_tensor_fourier(density_fourier: Tensor, sphere_grid: SphereGrid)
Create a new physical density from an MRC file.