spateo.tdr.models

Subpackages

Functions

ElPiGraph_method(→ Tuple[numpy.ndarray, numpy.ndarray])

Generate a principal elastic tree.

PrinCurve_method(→ Tuple[numpy.ndarray, numpy.ndarray])

This is the global module that contains principal curve and nonlinear principal component analysis algorithms that

SimplePPT_method(→ Tuple[numpy.ndarray, numpy.ndarray])

Generate a simple principal tree.

backbone_scc(→ Optional[anndata.AnnData])

Spatially constrained clustering (scc) along the backbone.

construct_backbone(→ Tuple[pyvista.PolyData, float, ...)

Organ's backbone construction based on 3D point cloud model.

map_gene_to_backbone(model, tree, key[, nodes_key, ...])

Find the closest principal tree node to any point in the model through KDTree.

map_points_to_backbone(model, backbone_model[, ...])

Find the closest principal tree node to any point in the model through KDTree.

update_backbone(→ Union[pyvista.PolyData, ...)

Update the bakcbone through interaction or input of selected nodes.

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

Reconstructing cells from point clouds.

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

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

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

Surface mesh reconstruction based on 3D point cloud model.

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

Construct a volumetric mesh based on surface mesh.

voxelize_pc(→ pyvista.UnstructuredGrid)

Voxelize the point cloud.

construct_align_lines(→ Tuple[pyvista.PolyData, ...)

Construct alignment lines between models after model alignment.

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

Create a 3D arrow model.

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

Create multiple 3D arrows model.

construct_axis_line(→ Tuple[pyvista.PolyData, ...)

Construct axis line.

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

Create a 3D vector field arrows model.

construct_field_streams(model[, vf_key, ...])

Integrate a vector field to generate streamlines.

construct_genesis(→ Tuple[pyvista.MultiBlock, ...)

Reconstruction of cell-level cell developmental change model based on the cell fate prediction results. Here we only

construct_genesis_X(→ Tuple[pyvista.MultiBlock, ...)

Reconstruction of cell-level cell developmental change model based on the cell fate prediction results. Here we only

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

Create a 3D line model.

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

Create 3D lines model.

construct_trajectory(→ Tuple[Any, Optional[str]])

Reconstruction of cell developmental trajectory model based on cell fate prediction.

construct_trajectory_X(→ Tuple[Any, Optional[str]])

Reconstruction of cell developmental trajectory model.

add_model_labels(...)

Add rgba color to each point of model based on labels.

center_to_zero(model[, inplace])

Translate the center point of the model to the (0, 0, 0).

collect_models(→ pyvista.MultiBlock)

A composite class to hold many data sets which can be iterated over.

merge_models(→ PolyData or UnstructuredGrid)

Merge all models in the models list. The format of all models must be the same.

multiblock2model(model[, message])

Merge all models in MultiBlock into one model

read_model(filename)

Read any file type supported by vtk or meshio.

rotate_model(, rotate_center, tuple] = None, inplace, ...)

Rotate the model around the rotate_center.

save_model(model, filename[, binary, texture])

Save the pvvista/vtk model to vtk/vtm file.

scale_model(→ Union[pyvista.PolyData, ...)

Scale the model around the center of the model.

translate_model(, inplace, pyvista.UnstructuredGrid, None])

Translate the mesh.

Package Contents

spateo.tdr.models.ElPiGraph_method(X: numpy.ndarray, NumNodes: int = 50, topology: Literal['tree', 'circle', 'curve'] = 'curve', Lambda: float = 0.01, Mu: float = 0.1, alpha: float = 0.0, FinalEnergy: Literal['Base', 'Penalized'] = 'Penalized', **kwargs) Tuple[numpy.ndarray, numpy.ndarray][source]

Generate a principal elastic tree. Reference: Albergante et al. (2020), Robust and Scalable Learning of Complex Intrinsic Dataset Geometry via ElPiGraph.

Parameters:
X

DxN, data matrix list.

NumNodes

The number of nodes of the principal graph. Use a range of 10 to 100 for ElPiGraph approach.

topology

The appropriate topology used to fit a principal graph for each dataset.

Lambda

The attractive strength of edges between nodes (constrains edge lengths)

Mu

The repulsive strength of a node’s neighboring nodes (constrains angles to be close to harmonic)

alpha

Branching penalty (penalizes number of branches for the principal tree)

FinalEnergy

Indicating the final elastic emergy associated with the configuration. Currently it can be “Base” or “Penalized”

**kwargs

Other parameters used in elpigraph.computeElasticPrincipalTree. For details, please see: https://elpigraph-python.readthedocs.io/en/latest/basics.html

Returns:

The nodes in the principal tree. edges: The edges between nodes in the principal tree.

Return type:

nodes

spateo.tdr.models.PrinCurve_method(X: numpy.ndarray, NumNodes: int = 50, epochs: int = 500, lr: float = 0.01, scale_factor: int | float = 1, **kwargs) Tuple[numpy.ndarray, numpy.ndarray][source]

This is the global module that contains principal curve and nonlinear principal component analysis algorithms that work to optimize a line over an entire dataset. Reference: Chen et al. (2016), Constraint local principal curve: Concept, algorithms and applications.

Parameters:
X

DxN, data matrix list.

NumNodes

Number of nodes for the construction layers. Defaults to 50. The more complex the curve, the higher this number should be.

epochs

Number of epochs to train neural network, defaults to 500.

lr

Learning rate for backprop. Defaults to .01

scale_factor

**kwargs

Other parameters used in global algorithms. For details, please see: https://github.com/artusoma/prinPy/blob/master/prinpy/glob.py

Returns:

The nodes in the principal tree. edges: The edges between nodes in the principal tree.

Return type:

nodes

spateo.tdr.models.SimplePPT_method(X: numpy.ndarray, NumNodes: int = 50, sigma: float | int | None = 0.1, lam: float | int | None = 1, metric: str = 'euclidean', nsteps: int = 50, err_cut: float = 0.005, seed: int | None = 1, **kwargs) Tuple[numpy.ndarray, numpy.ndarray][source]

Generate a simple principal tree. Reference: Mao et al. (2015), SimplePPT: A simple principal tree algorithm, SIAM International Conference on Data Mining.

Parameters:
X

DxN, data matrix list.

NumNodes

The number of nodes of the principal graph. Use a range of 100 to 2000 for PPT approach.

sigma

Regularization parameter.

lam

Penalty for the tree length.

metric

The metric to use to compute distances in high dimensional space. For compatible metrics, check the documentation of sklearn.metrics.pairwise_distances.

nsteps

Number of steps for the optimisation process.

err_cut

Stop algorithm if proximity of principal points between iterations less than defined value.

seed

A numpy random seed.

**kwargs

Other parameters used in simpleppt.ppt. For details, please see: https://github.com/LouisFaure/simpleppt/blob/main/simpleppt/ppt.py

Returns:

The nodes in the principal tree. edges: The edges between nodes in the principal tree.

Return type:

nodes

spateo.tdr.models.backbone_scc(adata: anndata.AnnData, backbone: pyvista.PolyData, genes: list | None = None, adata_nodes_key: str = 'backbone_nodes', backbone_nodes_key: str = 'updated_nodes', key_added: str | None = 'backbone_scc', layer: str | None = None, e_neigh: int = 10, s_neigh: int = 6, cluster_method: Literal['leiden', 'louvain'] = 'leiden', resolution: float | None = None, inplace: bool = True) anndata.AnnData | None[source]

Spatially constrained clustering (scc) along the backbone.

Parameters:
adata

The anndata object.

backbone

The backbone model.

genes

The list of genes that will be used to subset the data for clustering. If genes = None, all genes will be used.

adata_nodes_key

The key that corresponds to the nodes in the adata.

backbone_nodes_key

The key that corresponds to the nodes in the backbone.

key_added

adata.obs key under which to add the cluster labels.

layer

The layer that will be used to retrieve data for dimension reduction and clustering. If layer = None, .X is used.

e_neigh

the number of nearest neighbor in gene expression space.

s_neigh

the number of nearest neighbor in physical space.

cluster_method

the method that will be used to cluster the cells.

resolution

the resolution parameter of the louvain clustering algorithm.

inplace

Whether to copy adata or modify it inplace.

Returns:

An AnnData object is updated/copied with the key_added in the .obs attribute, storing the clustering results.

spateo.tdr.models.construct_backbone(model: pyvista.PolyData | pyvista.UnstructuredGrid, spatial_key: str | None = None, nodes_key: str = 'nodes', rd_method: Literal['ElPiGraph', 'SimplePPT', 'PrinCurve'] = 'ElPiGraph', num_nodes: int = 50, color: str = 'gainsboro', **kwargs) Tuple[pyvista.PolyData, float, str | None][source]

Organ’s backbone construction based on 3D point cloud model.

Parameters:
model

A point cloud model.

spatial_key

If spatial_key is None, the spatial coordinates are in model.points, otherwise in model[spatial_key].

nodes_key

The key that corresponds to the coordinates of the nodes in the backbone.

rd_method

The method of constructing a backbone model. Available rd_method are:

  • 'ElPiGraph': Generate a principal elastic tree.

  • 'SimplePPT': Generate a simple principal tree.

  • 'PrinCurve': This is the global module that contains principal curve and nonlinear principal

    component analysis algorithms that work to optimize a line over an entire dataset.

num_nodes

Number of nodes for the backbone model.

color

Color to use for plotting backbone model.

**kwargs

Additional parameters that will be passed to ElPiGraph_method, SimplePPT_method or PrinCurve_method function.

Returns:

A three-dims backbone model. backbone_length: The length of the backbone model. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

backbone_model

spateo.tdr.models.map_gene_to_backbone(model: pyvista.PolyData | pyvista.UnstructuredGrid, tree: pyvista.PolyData, key: str | list, nodes_key: str | None = 'nodes', inplace: bool = False)[source]

Find the closest principal tree node to any point in the model through KDTree.

Parameters:
model

A reconstructed model contains the gene expression label.

tree

A three-dims principal tree model contains the nodes label.

key

The key that corresponds to the gene expression.

nodes_key

The key that corresponds to the coordinates of the nodes in the tree.

inplace

Updates tree model in-place.

Returns:

tree.point_data[key], the gene expression array.

Return type:

A tree, which contains the following properties

spateo.tdr.models.map_points_to_backbone(model: pyvista.PolyData | pyvista.UnstructuredGrid, backbone_model: pyvista.PolyData, nodes_key: str = 'nodes', key_added: str | None = 'nodes', inplace: bool = False, **kwargs)[source]

Find the closest principal tree node to any point in the model through KDTree.

Parameters:
model

The reconstructed model.

backbone_model

The constructed backbone model.

nodes_key

The key that corresponds to the coordinates of the nodes in the backbone.

key_added

The key under which to add the nodes labels.

inplace

Updates model in-place.

**kwargs

Additional parameters that will be passed to scipy.spatial.KDTree. function.

Returns:

model.point_data[key_added], the nodes labels array.

Return type:

A model, which contains the following properties

spateo.tdr.models.update_backbone(backbone: pyvista.PolyData, nodes_key: str = 'nodes', key_added: str = 'updated_nodes', select_nodes: list | numpy.ndarray | None = None, interactive: bool | None = True, model_size: float | list = 8.0, colormap: str = 'Spectral') pyvista.PolyData | pyvista.UnstructuredGrid[source]

Update the bakcbone through interaction or input of selected nodes.

Parameters:
backbone

The backbone model.

nodes_key

The key that corresponds to the coordinates of the nodes in the backbone.

key_added

The key under which to add the labels of new nodes.

select_nodes

Nodes that need to be retained.

interactive

Whether to delete useless nodes interactively. When interactive is True, select_nodes is invalid.

model_size

Thickness of backbone. When interactive is False, model_size is invalid.

colormap

Colormap of backbone. When interactive is False, colormap is invalid.

Returns:

The updated backbone model.

Return type:

updated_backbone

spateo.tdr.models.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.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.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.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.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

spateo.tdr.models.construct_align_lines(model1_points: numpy.ndarray, model2_points: numpy.ndarray, key_added: str = 'check_alignment', label: str | list | numpy.ndarray = 'align_mapping', color: str | list | dict | numpy.ndarray = 'gainsboro', alpha: float | int | list | dict | numpy.ndarray = 1.0) Tuple[pyvista.PolyData, str | None][source]

Construct alignment lines between models after model alignment.

Parameters:
model1_points

Start location in model1 of the line.

model2_points

End location in model2 of the line.

key_added

The key under which to add the labels.

label

The label of alignment lines model.

color

Color to use for plotting model.

alpha

The opacity of the color to use for plotting model.

Returns:

Alignment lines model. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

model

spateo.tdr.models.construct_arrow(start_point: list | tuple | numpy.ndarray, direction: list | tuple | numpy.ndarray, arrow_scale: int | float | None = None, key_added: str | None = 'arrow', label: str = 'arrow', color: str = 'gainsboro', alpha: float = 1.0, **kwargs) Tuple[pyvista.PolyData, str | None][source]

Create a 3D arrow model.

Parameters:
start_point

Start location in [x, y, z] of the arrow.

direction

Direction the arrow points to in [x, y, z].

arrow_scale

Scale factor of the entire object. ‘auto’ scales to length of direction array.

key_added

The key under which to add the labels.

label

The label of arrow model.

color

Color to use for plotting model.

alpha

The opacity of the color to use for plotting model.

**kwargs

Additional parameters that will be passed to _construct_arrow function.

Returns:

Arrow model. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

model

spateo.tdr.models.construct_arrows(start_points: numpy.ndarray, direction: numpy.ndarray = None, arrows_scale: numpy.ndarray | None = None, n_sampling: int | None = None, sampling_method: str = 'trn', factor: float = 1.0, key_added: str | None = 'arrow', label: str | list | numpy.ndarray = 'arrows', color: str | list | dict | numpy.ndarray = 'gainsboro', alpha: float | int | list | dict | numpy.ndarray = 1.0, **kwargs) Tuple[pyvista.PolyData, str | None][source]

Create multiple 3D arrows model.

Parameters:
start_points

List of Start location in [x, y, z] of the arrows.

direction

Direction the arrows points to in [x, y, z].

arrows_scale

Scale factor of the entire object.

n_sampling

n_sampling is the number of coordinates to keep after sampling. If there are too many coordinates in start_points, the generated arrows model will be too complex and unsightly, so sampling is used to reduce the number of coordinates.

sampling_method

The method to sample data points, can be one of ['trn', 'kmeans', 'random'].

factor

Scale factor applied to scaling array.

key_added

The key under which to add the labels.

label

The label of arrows models.

color

Color to use for plotting model.

alpha

The opacity of the color to use for plotting model.

**kwargs

Additional parameters that will be passed to _construct_arrow function.

Returns:

Arrows model. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

model

spateo.tdr.models.construct_axis_line(axis_points: numpy.ndarray, key_added: str = 'axis', label: str = 'axis_line', color: str = 'gainsboro', alpha: float | int | list | dict | numpy.ndarray = 1.0) Tuple[pyvista.PolyData, str | None][source]

Construct axis line.

Parameters:
axis_points

List of points defining an axis.

key_added

The key under which to add the labels.

label

The label of axis line model.

color

Color to use for plotting model.

alpha

The opacity of the color to use for plotting model.

Returns:

Axis line model. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

axis_line

spateo.tdr.models.construct_field(model: pyvista.PolyData, vf_key: str = 'VecFld_morpho', arrows_scale_key: str | None = None, n_sampling: int | None = None, sampling_method: str = 'trn', factor: float = 1.0, key_added: str = 'v_arrows', label: str | list | numpy.ndarray = 'vector field', color: str | list | dict | numpy.ndarray = 'gainsboro', alpha: float = 1.0, **kwargs) Tuple[pyvista.PolyData, str | None][source]

Create a 3D vector field arrows model.

Parameters:
model

A model that provides coordinate information and vector information for constructing vector field models.

vf_key

The key under which are the vector information.

arrows_scale_key

The key under which are scale factor of the entire object.

n_sampling

n_sampling is the number of coordinates to keep after sampling. If there are too many coordinates in start_points, the generated arrows model will be too complex and unsightly, so sampling is used to reduce the number of coordinates.

sampling_method

The method to sample data points, can be one of ['trn', 'kmeans', 'random'].

factor

Scale factor applied to scaling array.

key_added

The key under which to add the labels.

label

The label of arrows models.

color

Color to use for plotting model.

alpha

The opacity of the color to use for plotting model.

**kwargs

Additional parameters that will be passed to construct_arrows function.

Returns:

A 3D vector field arrows model. plot_cmap: Recommended colormap parameter values for plotting.

spateo.tdr.models.construct_field_streams(model: pyvista.PolyData, vf_key: str = 'VecFld_morpho', source_center: Tuple[float] | None = None, source_radius: float | None = None, tip_factor: int | float = 10, tip_radius: float = 0.2, key_added: str = 'v_streams', label: str | list | numpy.ndarray = 'vector field', stream_color: str = 'gainsboro', tip_color: str = 'orangered', alpha: float = 1.0, **kwargs)[source]

Integrate a vector field to generate streamlines.

Parameters:
model

A model that provides coordinate information and vector information for constructing vector field models.

vf_key

The key under which are the active vector field information.

source_center

Length 3 tuple of floats defining the center of the source particles. Defaults to the center of the dataset.

source_radius

Float radius of the source particle cloud. Defaults to one-tenth of the diagonal of the dataset’s spatial extent.

tip_factor

Scale factor applied to scaling the tips.

tip_radius

Radius of the tips.

key_added

The key under which to add the labels.

label

The label of arrows models.

stream_color

Color to use for plotting streamlines.

tip_color

Color to use for plotting tips.

alpha

The opacity of the color to use for plotting model.

**kwargs

Additional parameters that will be passed to streamlines function.

Returns:

3D vector field streamlines model. src: The source particles as pyvista.PolyData as well as the streamlines. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

streams_model

spateo.tdr.models.construct_genesis(adata: anndata.AnnData, fate_key: str = 'fate_morpho', n_steps: int = 100, logspace: bool = False, t_end: int | float | None = None, key_added: str = 'genesis', label: str | list | numpy.ndarray | None = None, color: str | list | dict = 'skyblue', alpha: float | list | dict = 1.0) Tuple[pyvista.MultiBlock, str | None][source]

Reconstruction of cell-level cell developmental change model based on the cell fate prediction results. Here we only need to enter the three-dimensional coordinates of the cells at different developmental stages.

Parameters:
adata

AnnData object that contains the fate prediction in the .uns attribute.

fate_key

The key under which are the active fate information.

n_steps

The number of times steps fate prediction will take.

logspace

Whether or to sample time points linearly on log space. If not, the sorted unique set of all times points from all cell states’ fate prediction will be used and then evenly sampled up to n_steps time points.

t_end

The length of the time period from which to predict cell state forward or backward over time.

key_added

The key under which to add the labels.

label

The label of cell developmental change model. If label == None, the label will be automatically generated.

color

Color to use for plotting model.

alpha

The opacity of the color to use for plotting model.

Returns:

A MultiBlock contains cell models for all stages. plot_cmap: Recommended colormap parameter values for plotting.

spateo.tdr.models.construct_genesis_X(stages_X: List[numpy.ndarray], n_spacing: int | None = None, key_added: str = 'genesis', label: str | list | numpy.ndarray | None = None, color: str | list | dict = 'skyblue', alpha: float | list | dict = 1.0) Tuple[pyvista.MultiBlock, str | None][source]

Reconstruction of cell-level cell developmental change model based on the cell fate prediction results. Here we only need to enter the three-dimensional coordinates of the cells at different developmental stages.

Parameters:
stages_X

The three-dimensional coordinates of the cells at different developmental stages.

n_spacing

Subdivided into n_spacing time points between two periods.

key_added

The key under which to add the labels.

label

The label of cell developmental change model. If label == None, the label will be automatically generated.

color

Color to use for plotting model.

alpha

The opacity of the color to use for plotting model.

Returns:

A MultiBlock contains cell models for all stages. plot_cmap: Recommended colormap parameter values for plotting.

spateo.tdr.models.construct_line(start_point: list | tuple | numpy.ndarray, end_point: list | tuple | numpy.ndarray, key_added: str | None = 'line', label: str = 'line', color: str = 'gainsboro', alpha: float = 1.0) Tuple[pyvista.PolyData, str | None][source]

Create a 3D line model.

Parameters:
start_point

Start location in [x, y, z] of the line.

end_point

End location in [x, y, z] of the line.

key_added

The key under which to add the labels.

label

The label of line model.

color

Color to use for plotting model.

alpha

The opacity of the color to use for plotting model.

Returns:

Line model. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

model

spateo.tdr.models.construct_lines(points: numpy.ndarray, edges: numpy.ndarray, key_added: str | None = 'line', label: str | list | numpy.ndarray = 'lines', color: str | list | dict = 'gainsboro', alpha: float | int | list | dict = 1.0) Tuple[pyvista.PolyData, str | None][source]

Create 3D lines model.

Parameters:
points

List of points.

edges

The edges between points.

key_added

The key under which to add the labels.

label

The label of lines model.

color

Color to use for plotting model.

alpha

The opacity of the color to use for plotting model.

Returns:

Lines model. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

model

spateo.tdr.models.construct_trajectory(adata: anndata.AnnData, fate_key: str = 'fate_develop', n_sampling: int | numpy.ndarray | None = None, sampling_method: str = 'trn', key_added: str = 'trajectory', label: str | list | numpy.ndarray | None = None, tip_factor: int | float = 5, tip_radius: float = 0.2, trajectory_color: str | list | dict = 'gainsboro', tip_color: str | list | dict = 'orangered', alpha: float = 1.0) Tuple[Any, str | None][source]

Reconstruction of cell developmental trajectory model based on cell fate prediction.

Parameters:
adata

AnnData object that contains the fate prediction in the .uns attribute.

fate_key

The key under which are the active fate information.

n_sampling

n_sampling is the number of coordinates to keep after sampling. If there are too many coordinates in start_points, the generated arrows model will be too complex and unsightly, so sampling is used to reduce the number of coordinates.

sampling_method

The method to sample data points, can be one of ['trn', 'kmeans', 'random'].

key_added

The key under which to add the labels.

label

The label of trajectory model.

tip_factor

Scale factor applied to scaling the tips.

tip_radius

Radius of the tips.

trajectory_color

Color to use for plotting trajectory model.

tip_color

Color to use for plotting tips.

alpha

The opacity of the color to use for plotting model.

Returns:

3D cell developmental trajectory model. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

trajectory_model

spateo.tdr.models.construct_trajectory_X(cells_states: numpy.ndarray | List[numpy.ndarray], init_states: numpy.ndarray | None = None, n_sampling: int | numpy.ndarray | None = None, sampling_method: str = 'trn', key_added: str = 'trajectory', label: str | list | numpy.ndarray | None = None, tip_factor: int | float = 5, tip_radius: float = 0.2, trajectory_color: str | list | dict = 'gainsboro', tip_color: str | list | dict = 'orangered', alpha: float | list | dict = 1.0) Tuple[Any, str | None][source]

Reconstruction of cell developmental trajectory model.

Parameters:
cells_states

Three-dimensional coordinates of all cells at all times points.

init_states

Three-dimensional coordinates of all cells at the starting time point.

n_sampling

n_sampling is the number of coordinates to keep after sampling. If there are too many coordinates in start_points, the generated arrows model will be too complex and unsightly, so sampling is used to reduce the number of coordinates.

sampling_method

The method to sample data points, can be one of ['trn', 'kmeans', 'random'].

key_added

The key under which to add the labels.

label

The label of trajectory model.

tip_factor

Scale factor applied to scaling the tips.

tip_radius

Radius of the tips.

trajectory_color

Color to use for plotting trajectory model.

tip_color

Color to use for plotting tips.

alpha

The opacity of the color to use for plotting model.

Returns:

3D cell developmental trajectory model. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

trajectory_model

spateo.tdr.models.add_model_labels(model: pyvista.PolyData | pyvista.UnstructuredGrid, labels: numpy.ndarray, key_added: str = 'groups', where: Literal['point_data', 'cell_data'] = 'cell_data', colormap: str | list | dict | numpy.ndarray = 'rainbow', alphamap: float | list | dict | numpy.ndarray = 1.0, mask_color: str | None = 'gainsboro', mask_alpha: float | None = 0.0, inplace: bool = False) Tuple[Optional[PolyData or UnstructuredGrid], Optional[Union[str]]][source]

Add rgba color to each point of model based on labels.

Parameters:
model

A reconstructed model.

labels

An array of labels of interest.

key_added

The key under which to add the labels.

where

The location where the label information is recorded in the model.

colormap

Colors to use for plotting data.

alphamap

The opacity of the color to use for plotting data.

mask_color

Color to use for plotting mask information.

mask_alpha

The opacity of the color to use for plotting mask information.

inplace

Updates model in-place.

Returns:

model.cell_data[key_added] or model.point_data[key_added], the labels array;

model.cell_data[f'{key_added}_rgba'] or model.point_data[f'{key_added}_rgba'], the rgba colors of the labels.

plot_cmap: Recommended colormap parameter values for plotting.

Return type:

A model, which contains the following properties

spateo.tdr.models.center_to_zero(model: pyvista.PolyData | pyvista.UnstructuredGrid, inplace: bool = False)[source]

Translate the center point of the model to the (0, 0, 0).

Parameters:
model

A 3D reconstructed model.

inplace

Updates model in-place.

Returns:

Model with center point at (0, 0, 0).

Return type:

model_z

spateo.tdr.models.collect_models(models: List[PolyData or UnstructuredGrid or DataSet], models_name: List[str] | None = None) pyvista.MultiBlock[source]

A composite class to hold many data sets which can be iterated over. You can think of MultiBlock like lists or dictionaries as we can iterate over this data structure by index and we can also access blocks by their string name. If the input is a dictionary, it can be iterated in the following ways:

>>> blocks = collect_models(models, models_name)
>>> for name in blocks.keys():
...     print(blocks[name])
If the input is a list, it can be iterated in the following ways:
>>> blocks = collect_models(models)
>>> for block in blocks:
...    print(block)
spateo.tdr.models.merge_models(models: List[PolyData or UnstructuredGrid or DataSet]) PolyData or UnstructuredGrid[source]

Merge all models in the models list. The format of all models must be the same.

spateo.tdr.models.multiblock2model(model, message=None)[source]

Merge all models in MultiBlock into one model

spateo.tdr.models.read_model(filename: str)[source]

Read any file type supported by vtk or meshio. :param filename: The string path to the file to read.

Returns:

Wrapped PyVista dataset.

spateo.tdr.models.rotate_model(model: pyvista.PolyData | pyvista.UnstructuredGrid, angle: list | tuple = (0, 0, 0), rotate_center: list | tuple = None, inplace: bool = False) pyvista.PolyData | pyvista.UnstructuredGrid | None[source]

Rotate the model around the rotate_center.

Parameters:
model

A 3D reconstructed model.

angle

Angles in degrees to rotate about the x-axis, y-axis, z-axis. Length 3 list or tuple.

rotate_center

Rotation center point. The default is the center of the model. Length 3 list or tuple.

inplace

Updates model in-place.

Returns:

The rotated model.

Return type:

model_r

spateo.tdr.models.save_model(model: pyvista.DataSet | pyvista.MultiBlock, filename: str, binary: bool = True, texture: str | numpy.ndarray = None)[source]

Save the pvvista/vtk model to vtk/vtm file. :param model: A reconstructed model. :param filename: Filename of output file. Writer type is inferred from the extension of the filename.

If model is a pyvista.MultiBlock object, please enter a filename ending with .vtm; else please enter a filename ending with .vtk.

Parameters:
binary

If True, write as binary. Otherwise, write as ASCII. Binary files write much faster than ASCII and have a smaller file size.

texture

Write a single texture array to file when using a PLY file.

Texture array must be a 3 or 4 component array with the datatype np.uint8. Array may be a cell array or a point array, and may also be a string if the array already exists in the PolyData.

If a string is provided, the texture array will be saved to disk as that name. If an array is provided, the texture array will be saved as ‘RGBA’

spateo.tdr.models.scale_model(model: pyvista.PolyData | pyvista.UnstructuredGrid, distance: float | int | list | tuple = None, scale_factor: float | int | list | tuple = 1, scale_center: list | tuple = None, inplace: bool = False) pyvista.PolyData | pyvista.UnstructuredGrid | None[source]

Scale the model around the center of the model.

Parameters:
model

A 3D reconstructed model.

distance

The distance by which the model is scaled. If 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 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.

scale_center

Scaling center. If scale factor is None, the scale_center will default to the center of the model.

inplace

Updates model in-place.

Returns:

The scaled model.

Return type:

model_s

spateo.tdr.models.translate_model(model: pyvista.PolyData | pyvista.UnstructuredGrid, distance: list | tuple = (0, 0, 0), inplace: bool = False) pyvista.PolyData | pyvista.UnstructuredGrid | None[source]

Translate the mesh.

Parameters:
model

A 3D reconstructed model.

distance

Distance to translate about the x-axis, y-axis, z-axis. Length 3 list or tuple.

inplace

Updates model in-place.

Returns:

The translated model.

Return type:

model_t