spateo.alignment.methods.morpho_mesh_correction

Classes

Mesh_correction

A class to perform 3D reconstruction correction from slices using a mesh.

Module Contents

class spateo.alignment.methods.morpho_mesh_correction.Mesh_correction(slices: List[anndata.AnnData], z_heights: List | numpy.ndarray, mesh: pyvista.PolyData, spatial_key: str = 'spatial', key_added: str = 'align_spatial', normalize_spatial: bool = False, init_rotation: numpy.ndarray | None = np.array([0.0, 0.0, 0.0]), init_translation: numpy.ndarray | None = 0.0, init_scaling: numpy.ndarray | None = 1.0, max_rotation_angle: float = 180, max_translation_scale: float = 0.5, max_scaling: float = 1.5, min_rotation_angle: float = 10, min_translation_scale: float = 1, min_scaling: float = 1.1, label_num: int = 15, fastpd_iter: int = 100, max_iter: int = 10, anneal_rate: float = 0.7, multi_processing: bool = False, subsample_slices: int | None = None, verbose: bool = False)[source]

A class to perform 3D reconstruction correction from slices using a mesh.

slices

A list of aligned slices by Spateo or other methods.

Type:

List[AnnData]

z_heights[source]

The z-coordinates for each slice.

Type:

Union[List, np.ndarray]

mesh[source]

The mesh used for correction.

Type:

PolyData

spatial_key

The key to access spatial coordinates in the AnnData objects. The spatial coordinates under this key should be pre-aligned.

Type:

str

key_added[source]

The key under which the corrected spatial coordinates will be added.

Type:

str

normalize_spatial[source]

Flag indicating if spatial coordinates will be normalized.

Type:

bool

init_rotation

Initial rotation angles (in degrees) for the correction.

Type:

np.ndarray

init_translation

Initial translation vector for the correction.

Type:

np.ndarray

init_scaling

Initial scaling factor for the correction.

Type:

np.ndarray

max_rotation_angle[source]

Maximum rotation angle allowed during the correction process.

Type:

float

max_translation_scale[source]

Maximum translation scale allowed during the correction process.

Type:

float

max_scaling[source]

Maximum scaling factor allowed during the correction process.

Type:

float

label_num[source]

Number of labels used for optimization.

Type:

int

fastpd_iter[source]

Number of iterations for the fastPD algorithm.

Type:

int

max_iter[source]

Maximum number of iterations for the correction process.

Type:

int

anneal_rate[source]

Annealing rate for the optimization process.

Type:

float

multi_processing[source]

Flag indicating if multiprocessing will be used for the correction process.

Type:

bool

n_slices[source]
slices_spatial[source]
z_heights[source]
mesh[source]
key_added[source]
normalize_spatial[source]
max_rotation_angle[source]
max_translation_scale[source]
max_scaling[source]
min_rotation_angle[source]
min_translation_scale[source]
min_scaling[source]
label_num[source]
fastpd_iter[source]
max_iter[source]
anneal_rate[source]
multi_processing[source]
subsample_slices[source]
verbose[source]
contours[source]
set_init_parameters(init_rotation: numpy.ndarray | None = np.array([0.0, 0.0, 0.0]), init_translation: numpy.ndarray | None = 0.0, init_scaling: numpy.ndarray | None = 1.0)[source]

Sets the initial transformation parameters for the mesh.

Parameters:
init_rotation Optional[np.ndarray], optional

Initial rotation angles (in degrees) for the mesh. Defaults to np.array([0., 0., 0.]).

init_translation Optional[np.ndarray], optional

Initial translation vector for the mesh. Defaults to 0.

init_scaling Optional[np.ndarray], optional

Initial scaling factor for the mesh. Defaults to 1.

normalize_mesh_spatial_coordinates()[source]

Normalizes the spatial coordinates of the mesh to align with the slices’ spatial scale.

This method calculates the scaling factor based on the maximum spatial extent of the slices and the z-height range, then applies this scaling to the mesh points. It also centers the mesh points along the z-axis to match the mean z-height of the slices.

extract_contours(method: Literal['opencv', 'alpha_shape'] = 'alpha_shape', n_sampling: int | None = None, smoothing: bool = True, window_size: int = 5, filter_contours: bool = True, contour_filter_threshold: int = 20, opencv_kwargs: Dict | None = None, alpha_shape_kwargs: Dict | None = None)[source]

Extracts contours of slices using the specified method.

Parameters:
method Literal["opencv", "alpha_shape"], optional

Method to extract contours. Defaults to “alpha_shape”.

n_sampling Optional[int], optional

Number of points to sample from each slice. Defaults to None.

smoothing bool, optional

Whether to smooth the contours. Defaults to True.

window_size int, optional

Window size for contour smoothing. Defaults to 5.

filter_contours bool, optional

Whether to filter the contours based on the threshold. Defaults to True.

contour_filter_threshold int, optional

Threshold for filtering contours based on the number of points. Defaults to 20.

opencv_kwargs Optional[Dict], optional

Additional arguments for the OpenCV method. Defaults to None.

alpha_shape_kwargs Optional[Dict], optional

Additional arguments for the alpha shape method. Defaults to None.

run_discrete_optimization() None[source]

Runs the discrete optimization process to find the best transformation parameters.

discrete_optimization_step() Tuple[float, numpy.ndarray][source]

Performs a discrete optimization step to find the best transformation.

Returns:

The loss and the best transformation found.

Return type:

Tuple[float, np.ndarray]

generate_labels() numpy.ndarray[source]

Generates discrete labels for rotation, translation, and scaling.

Returns:

An array of discrete transformation labels.

Return type:

np.ndarray

perform_correction()[source]

Performs the correction using the best transformation found.