spateo.tdr.models.models_individual#

Submodules#

Package Contents#

Functions#

construct_cells(pc, cell_size[, geometry, xyz_scale, ...])

Reconstructing cells from point clouds.

construct_surface(→ Tuple[Union[pyvista.PolyData, ...)

Surface mesh reconstruction based on 3D point cloud model.

construct_pc(→ Tuple[pyvista.PolyData, Optional[str]])

Construct a point cloud model based on 3D coordinate information.

voxelize_mesh(→ Tuple[Union[pyvista.UnstructuredGrid, ...)

Construct a volumetric mesh based on surface mesh.

voxelize_pc(→ pyvista.UnstructuredGrid)

Voxelize the point cloud.

spateo.tdr.models.models_individual.construct_cells(pc: pyvista.PolyData, cell_size: numpy.ndarray, geometry: Literal[cube, sphere, ellipsoid] = 'cube', xyz_scale: tuple = (1, 1, 1), n_scale: tuple = (1, 1), factor: float = 0.5)[source]#

Reconstructing cells from point clouds.

Parameters:
pc

A point cloud object, including pc.point_data["obs_index"].

geometry

The geometry of generating cells. Available geometry are:

  • geometry = 'cube'

  • geometry = 'sphere'

  • geometry = 'ellipsoid'

cell_size

A numpy.ndarray object including the relative radius/length size of each cell.

xyz_scale

The scale factor for the x-axis, y-axis and z-axis.

n_scale

The squareness parameter in the x-y plane adn z axis. Only works if geometry = 'ellipsoid'.

factor

Scale factor applied to scaling array.

Returns:

A cells mesh including ds_glyph.point_data[“cell_size”], ds_glyph.point_data[“cell_centroid”] and the data contained in the pc.

Return type:

ds_glyph

spateo.tdr.models.models_individual.construct_surface(pc: pyvista.PolyData, key_added: str = 'groups', label: str = 'surface', color: str | None = 'gainsboro', alpha: float | int = 1.0, uniform_pc: bool = False, uniform_pc_alpha: float | int = 0, cs_method: Literal[pyvista, alpha_shape, ball_pivoting, poisson, marching_cube] = 'marching_cube', cs_args: dict | None = None, nsub: int | None = 3, nclus: int = 20000, smooth: int | None = 3000, scale_distance: float | int | list | tuple = None, scale_factor: float | int | list | tuple = None) Tuple[pyvista.PolyData | pyvista.UnstructuredGrid | None, pyvista.PolyData, str | None][source]#

Surface mesh reconstruction based on 3D point cloud model.

Parameters:
pc

A point cloud model.

key_added

The key under which to add the labels.

label

The label of reconstructed surface mesh model.

color

Color to use for plotting mesh. The default color is 'gainsboro'.

alpha

The opacity of the color to use for plotting mesh. The default alpha is 0.8.

uniform_pc

Generates a uniform point cloud with a larger number of points.

uniform_pc_alpha

Specify alpha (or distance) value to control output of this filter.

cs_method

The methods of generating a surface mesh. Available cs_method are:

  • 'pyvista': Generate a 3D tetrahedral mesh based on pyvista.

  • 'alpha_shape': Computes a triangle mesh on the alpha shape algorithm.

  • 'ball_pivoting': Computes a triangle mesh based on the Ball Pivoting algorithm.

  • 'poisson': Computes a triangle mesh based on thee Screened Poisson Reconstruction.

  • 'marching_cube': Computes a triangle mesh based on the marching cube algorithm.

cs_args

Parameters for various surface reconstruction methods. Available cs_args are: * 'pyvista': {‘alpha’: 0} * 'alpha_shape': {‘alpha’: 2.0} * 'ball_pivoting': {‘radii’: [1]} * 'poisson': {‘depth’: 8, ‘width’=0, ‘scale’=1.1, ‘linear_fit’: False, ‘density_threshold’: 0.01} * 'marching_cube': {‘levelset’: 0, ‘mc_scale_factor’: 1, ‘dist_sample_num’: 100}

nsub

Number of subdivisions. Each subdivision creates 4 new triangles, so the number of resulting triangles is nface*4**nsub where nface is the current number of faces.

nclus

Number of voronoi clustering.

smooth

Number of iterations for Laplacian smoothing.

scale_distance

The distance by which the model is scaled. If scale_distance is float, the model is scaled same distance along the xyz axis; when the scale factor is list, the model is scaled along the xyz axis at different distance. If scale_distance is None, there will be no scaling based on distance.

scale_factor

The scale by which the model is scaled. If scale factor is float, the model is scaled along the xyz axis at the same scale; when the scale factor is list, the model is scaled along the xyz axis at different scales. If scale_factor is None, there will be no scaling based on scale factor.

Returns:

A reconstructed surface mesh, which contains the following properties:

uniform_surf.cell_data[key_added], the label array; uniform_surf.cell_data[f'{key_added}_rgba'], the rgba colors of the label array.

inside_pc: A point cloud, which contains the following properties:

inside_pc.point_data['obs_index'], the obs_index of each coordinate in the original adata. inside_pc.point_data[key_added], the groupby information. inside_pc.point_data[f'{key_added}_rgba'], the rgba colors of the groupby information.

plot_cmap: Recommended colormap parameter values for plotting.

Return type:

uniform_surf

spateo.tdr.models.models_individual.construct_pc(adata: anndata.AnnData, layer: str = 'X', spatial_key: str = 'spatial', groupby: str | tuple = None, key_added: str = 'groups', mask: str | int | float | list = None, colormap: str | list | dict = 'rainbow', alphamap: float | list | dict = 1.0) Tuple[pyvista.PolyData, str | None][source]#

Construct a point cloud model based on 3D coordinate information.

Parameters:
adata

AnnData object.

layer

If 'X', uses .X, otherwise uses the representation given by .layers[layer].

spatial_key

The key in .obsm that corresponds to the spatial coordinate of each bucket.

groupby

The key that stores clustering or annotation information in .obs, a gene name or a list of gene names in .var.

key_added

The key under which to add the labels.

mask

The part that you don’t want to be displayed.

colormap

Colors to use for plotting pc. The default colormap is 'rainbow'.

alphamap

The opacity of the colors to use for plotting pc. The default alphamap is 1.0.

Returns:

A point cloud, which contains the following properties:

pc.point_data[key_added], the groupby information. pc.point_data[f'{key_added}_rgba'], the rgba colors of the groupby information. pc.point_data['obs_index'], the obs_index of each coordinate in the original adata.

plot_cmap: Recommended colormap parameter values for plotting.

Return type:

pc

spateo.tdr.models.models_individual.voxelize_mesh(mesh: pyvista.PolyData | pyvista.UnstructuredGrid, voxel_pc: pyvista.PolyData | pyvista.UnstructuredGrid = None, key_added: str = 'groups', label: str = 'voxel', color: str | None = 'gainsboro', alpha: float | int = 1.0, smooth: int | None = 200) Tuple[pyvista.UnstructuredGrid | Any, str | None][source]#

Construct a volumetric mesh based on surface mesh.

Parameters:
mesh

A surface mesh model.

voxel_pc

A voxel model which contains the voxel_pc.cell_data['obs_index'] and voxel_pc.cell_data[key_added].

key_added

The key under which to add the labels.

label

The label of reconstructed voxel model.

color

Color to use for plotting mesh. The default color is 'gainsboro'.

alpha

The opacity of the color to use for plotting model. The default alpha is 0.8.

smooth

The smoothness of the voxel model.

Returns:

A reconstructed voxel model, which contains the following properties:

voxel_model.cell_data[key_added], the label array; voxel_model.cell_data[f’{key_added}_rgba’], the rgba colors of the label array. voxel_model.cell_data[‘obs_index’], the cell labels if not (voxel_pc is None).

plot_cmap: Recommended colormap parameter values for plotting.

Return type:

voxel_model

spateo.tdr.models.models_individual.voxelize_pc(pc: pyvista.PolyData, voxel_size: numpy.ndarray | None = None) pyvista.UnstructuredGrid[source]#

Voxelize the point cloud.

Parameters:
pc

A point cloud model.

voxel_size

The size of the voxelized points. The shape of voxel_size is (pc.n_points, 3).

Returns:

A voxel model.

Return type:

voxel