spateo.tdr.models
#
Subpackages#
Package Contents#
Functions#
|
Computes a triangle mesh from a point cloud based on the alpha shape algorithm. |
|
Computes a triangle mesh from an oriented point cloud based on the ball pivoting algorithm. |
|
Reconstructing cells from point clouds. |
|
Surface mesh reconstruction based on 3D point cloud model. |
|
Repair the mesh where it was extracted and subtle holes along complex parts of the mesh. |
|
Computes a triangle mesh from a point cloud based on the marching cube algorithm. |
|
Computes a triangle mesh from an oriented point cloud based on the screened poisson reconstruction. |
|
Generate a 3D tetrahedral mesh from a scattered points and extract surface mesh of the 3D tetrahedral mesh. |
|
Generates a uniform point cloud with a larger number of points. |
|
Generate a uniformly meshed surface using voronoi clustering. |
|
Construct alignment lines between models after model alignment. |
|
Create a 3D arrow model. |
|
Create multiple 3D arrows model. |
|
Construct axis line. |
|
Construct a bounding box model of the model. |
|
Create a 3D vector field arrows model. |
|
Integrate a vector field to generate streamlines. |
|
Reconstruction of cell-level cell developmental change model based on the cell fate prediction results. Here we only |
|
Reconstruction of cell-level cell developmental change model based on the cell fate prediction results. Here we only |
|
Create a 3D line model. |
|
Create 3D lines model. |
|
Construct a model(space-model) with uniform spacing in the three coordinate directions. |
|
Reconstruction of cell developmental trajectory model based on cell fate prediction. |
|
Reconstruction of cell developmental trajectory model. |
|
Construct a point cloud model based on 3D coordinate information. |
|
Add rgba color to each point of model based on labels. |
|
Translate the center point of the model to the (0, 0, 0). |
|
A composite class to hold many data sets which can be iterated over. |
|
Merge all models in the models list. The format of all models must be the same. |
|
Merge all models in MultiBlock into one model |
|
Read any file type supported by vtk or meshio. |
|
Rotate the model around the rotate_center. |
|
Save the pvvista/vtk model to vtk/vtm file. |
|
Scale the model around the center of the model. |
|
Translate the mesh. |
|
Construct a volumetric mesh based on surface mesh. |
|
Voxelize the point cloud. |
- spateo.tdr.models.alpha_shape_mesh(pc: pyvista.PolyData, alpha: float = 2.0) pyvista.PolyData #
Computes a triangle mesh from a point cloud based on the alpha shape algorithm. Algorithm Overview:
For each real number α, define the concept of a generalized disk of radius 1/α as follows:
If α = 0, it is a closed half-plane; If α > 0, it is a closed disk of radius 1/α; If α < 0, it is the closure of the complement of a disk of radius −1/α.
Then an edge of the alpha-shape is drawn between two members of the finite point set whenever there exists a generalized disk of radius 1/α containing none of the point set and which has the property that the two points lie on its boundary. If α = 0, then the alpha-shape associated with the finite point set is its ordinary convex hull.
- Parameters
- pc
A point cloud model.
- alpha
Parameter to control the shape. With decreasing alpha value the shape shrinks and creates cavities. A very big value will give a shape close to the convex hull.
- Returns
A mesh model.
- spateo.tdr.models.ball_pivoting_mesh(pc: pyvista.PolyData, radii: List[float] = None)#
Computes a triangle mesh from an oriented point cloud based on the ball pivoting algorithm. Algorithm Overview:
The main assumption this algorithm is based on is the following: Given three vertices, and a ball of radius r, the three vertices form a triangle if the ball is getting “caught” and settle between the points, without containing any other point. The algorithm stimulates a virtual ball of radius r. Each iteration consists of two steps:
- Seed triangle - The ball rolls over the point cloud until it gets “caught” between three vertices and
settles between in them. Choosing the right r promises no other point is contained in the formed triangle. This triangle is called “Seed triangle”.
- Expanding triangle - The ball pivots from each edge in the seed triangle, looking for a third point. It
pivots until it gets “caught” in the triangle formed by the edge and the third point. A new triangle is formed, and the algorithm tries to expand from it. This process continues until the ball can’t find any point to expand to.
At this point, the algorithm looks for a new seed triangle, and the process described above starts all over.
- Useful Notes:
The point cloud is “dense enough”;
The chosen r size should be “slightly” larger than the average space between points.
- Parameters
- pc
A point cloud model.
- radii
The radii of the ball that are used for the surface reconstruction. This is a list of multiple radii that will create multiple balls of different radii at the same time.
- Returns
A mesh model.
- 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)#
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 ifgeometry = '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_surface(pc: pyvista.PolyData, key_added: str = 'groups', label: str = 'surface', color: Optional[str] = 'gainsboro', alpha: Union[float, int] = 1.0, uniform_pc: bool = False, uniform_pc_alpha: Union[float, int] = 0, cs_method: Literal[pyvista, alpha_shape, ball_pivoting, poisson, marching_cube] = 'marching_cube', cs_args: Optional[dict] = None, nsub: Optional[int] = 3, nclus: int = 20000, smooth: Optional[int] = 1000, scale_distance: Union[float, int, list, tuple] = None, scale_factor: Union[float, int, list, tuple] = None) Tuple[pyvista.PolyData, pyvista.PolyData] #
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
is0.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}- 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 thescale factor
is list, the model is scaled along the xyz axis at different distance. Ifscale_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 thescale factor
is list, the model is scaled along the xyz axis at different scales. Ifscale_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]
, thelabel
array;uniform_surf.cell_data[f'{key_added}_rgba']
, the rgba colors of thelabel
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]
, thegroupby
information.inside_pc.point_data[f'{key_added}_rgba']
, the rgba colors of thegroupby
information.
- Return type
uniform_surf
- spateo.tdr.models.fix_mesh(mesh: pyvista.PolyData) pyvista.PolyData #
Repair the mesh where it was extracted and subtle holes along complex parts of the mesh.
- spateo.tdr.models.marching_cube_mesh(pc: pyvista.PolyData, levelset: Union[int, float] = 0, mc_scale_factor: Union[int, float] = 1.0)#
Computes a triangle mesh from a point cloud based on the marching cube algorithm. Algorithm Overview:
The algorithm proceeds through the scalar field, taking eight neighbor locations at a time (thus forming an imaginary cube), then determining the polygon(s) needed to represent the part of the iso-surface that passes through this cube. The individual polygons are then fused into the desired surface.
- Parameters
- pc
A point cloud model.
- levelset
The levelset of iso-surface. It is recommended to set levelset to 0 or 0.5.
- mc_scale_factor
The scale of the model. The scaled model is used to construct the mesh model.
- Returns
A mesh model.
- spateo.tdr.models.poisson_mesh(pc: pyvista.PolyData, depth: int = 8, width: float = 0, scale: float = 1.1, linear_fit: bool = False, density_threshold: Optional[float] = None) pyvista.PolyData #
Computes a triangle mesh from an oriented point cloud based on the screened poisson reconstruction.
- Parameters
- pc
A point cloud model.
- depth
Maximum depth of the tree that will be used for surface reconstruction. Running at depth d corresponds to solving on a grid whose resolution is no larger than 2^d x 2^d x 2^d.
Note that since the reconstructor adapts the octree to the sampling density, the specified reconstruction depth is only an upper bound.
The depth that defines the depth of the octree used for the surface reconstruction and hence implies the resolution of the resulting triangle mesh. A higher depth value means a mesh with more details.
- width
Specifies the target width of the finest level octree cells. This parameter is ignored if depth is specified.
- scale
Specifies the ratio between the diameter of the cube used for reconstruction and the diameter of the samples’ bounding cube.
- linear_fit
If true, the reconstructor will use linear interpolation to estimate the positions of iso-vertices.
- density_threshold
The threshold of the low density.
- Returns
A mesh model.
- spateo.tdr.models.pv_mesh(pc: pyvista.PolyData, alpha: float = 2.0) pyvista.PolyData #
Generate a 3D tetrahedral mesh from a scattered points and extract surface mesh of the 3D tetrahedral mesh.
- Parameters
- pc
A point cloud model.
- alpha
Distance value to control output of this filter. For a non-zero alpha value, only vertices, edges, faces, or tetrahedron contained within the circumspect (of radius alpha) will be output. Otherwise, only tetrahedron will be output.
- Returns
A mesh model.
- spateo.tdr.models.uniform_larger_pc(pc: pyvista.PolyData, alpha: Union[float, int] = 0, nsub: Optional[int] = 5, nclus: int = 20000) pyvista.PolyData #
Generates a uniform point cloud with a larger number of points. If the number of points in the original point cloud is too small or the distribution of the original point cloud is not uniform, making it difficult to construct the surface, this method can be used for preprocessing.
- Parameters
- pc
A point cloud model.
- alpha
Specify alpha (or distance) value to control output of this filter. For a non-zero alpha value, only edges or triangles contained within a sphere centered at mesh vertices will be output. Otherwise, only triangles will be output.
- 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.
- Returns
A uniform point cloud with a larger number of points.
- Return type
new_pc
- spateo.tdr.models.uniform_mesh(mesh: pyvista.PolyData, nsub: Optional[int] = 3, nclus: int = 20000) pyvista.PolyData #
Generate a uniformly meshed surface using voronoi clustering.
- Parameters
- mesh
A mesh model.
- 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.
- Returns
A uniform mesh model.
- Return type
new_mesh
- spateo.tdr.models.construct_align_lines(model1_points: numpy.ndarray, model2_points: numpy.ndarray, key_added: str = 'check_alignment', label: Union[str, list, numpy.ndarray] = 'align_mapping', color: Union[str, list, dict, numpy.ndarray] = 'gainsboro', alpha: Union[float, int, list, dict, numpy.ndarray] = 1.0) pyvista.PolyData #
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.
- spateo.tdr.models.construct_arrow(start_point: Union[list, tuple, numpy.ndarray], direction: Union[list, tuple, numpy.ndarray], arrow_scale: Optional[Union[int, float]] = None, key_added: Optional[str] = 'arrow', label: str = 'arrow', color: str = 'gainsboro', alpha: float = 1.0, **kwargs) pyvista.PolyData #
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.
- spateo.tdr.models.construct_arrows(start_points: numpy.ndarray, direction: numpy.ndarray = None, arrows_scale: Optional[numpy.ndarray] = None, n_sampling: Optional[int] = None, sampling_method: str = 'trn', factor: float = 1.0, key_added: Optional[str] = 'arrow', label: Union[str, list, numpy.ndarray] = 'arrows', color: Union[str, list, dict, numpy.ndarray] = 'gainsboro', alpha: Union[float, int, list, dict, numpy.ndarray] = 1.0, **kwargs) pyvista.PolyData #
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.
- spateo.tdr.models.construct_axis_line(axis_points: numpy.ndarray, key_added: str = 'axis', label: str = 'axis_line', color: str = 'gainsboro', alpha: Union[float, int, list, dict, numpy.ndarray] = 1.0) pyvista.PolyData #
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.
- spateo.tdr.models.construct_bounding_box(model: Union[pyvista.DataSet, pyvista.MultiBlock], expand_dist: Union[int, float, list, tuple] = (0, 0, 0), grid_num: Optional[Union[List[int], Tuple[int]]] = None, key_added: str = 'bounding_box', label: str = 'bounding_box', color: str = 'gainsboro', alpha: float = 0.5) pyvista.PolyData #
Construct a bounding box model of the model.
- Parameters
- model
A three dims model.
- expand_dist
The length of space-model to be extended in all directions.
- grid_num
Number of grid to generate.
- key_added
The key under which to add the labels.
- label
The label of space-model.
- color
Color to use for plotting space-model.
- alpha
The opacity of the color to use for plotting space-model.
- Returns
A bounding box model.
- spateo.tdr.models.construct_field(model: pyvista.PolyData, vf_key: str = 'VecFld_morpho', arrows_scale_key: Optional[str] = None, n_sampling: Optional[int] = None, sampling_method: str = 'trn', factor: float = 1.0, key_added: str = 'v_arrows', label: Union[str, list, numpy.ndarray] = 'vector field', color: Union[str, list, dict, numpy.ndarray] = 'gainsboro', alpha: float = 1.0, **kwargs) pyvista.PolyData #
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.
- spateo.tdr.models.construct_field_streams(model: pyvista.PolyData, vf_key: str = 'VecFld_morpho', source_center: Optional[Tuple[float]] = None, source_radius: Optional[float] = None, tip_factor: Union[int, float] = 10, tip_radius: float = 0.2, key_added: str = 'v_streams', label: Union[str, list, numpy.ndarray] = 'vector field', stream_color: str = 'gainsboro', tip_color: str = 'orangered', alpha: float = 1.0, **kwargs)#
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.
- 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: Optional[Union[int, float]] = None, key_added: str = 'genesis', label: Optional[Union[str, list, numpy.ndarray]] = None, color: Union[str, list, dict] = 'skyblue', alpha: Union[float, list, dict] = 1.0) pyvista.MultiBlock #
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.
- spateo.tdr.models.construct_genesis_X(stages_X: List[numpy.ndarray], n_spacing: Optional[int] = None, key_added: str = 'genesis', label: Optional[Union[str, list, numpy.ndarray]] = None, color: Union[str, list, dict] = 'skyblue', alpha: Union[float, list, dict] = 1.0) pyvista.MultiBlock #
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.
- spateo.tdr.models.construct_line(start_point: Union[list, tuple, numpy.ndarray], end_point: Union[list, tuple, numpy.ndarray], key_added: Optional[str] = 'line', label: str = 'line', color: str = 'gainsboro', alpha: float = 1.0) pyvista.PolyData #
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.
- spateo.tdr.models.construct_lines(points: numpy.ndarray, edges: numpy.ndarray, key_added: Optional[str] = 'line', label: Union[str, list, numpy.ndarray] = 'lines', color: Union[str, list, dict] = 'gainsboro', alpha: Union[float, int, list, dict] = 1.0) pyvista.PolyData #
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.
- spateo.tdr.models.construct_space(model: Union[pyvista.DataSet, pyvista.MultiBlock], expand_dist: Union[int, float, list, tuple] = (0, 0, 0), grid_num: Optional[Union[List[int], Tuple[int]]] = None, key_added: Optional[str] = 'space', label: str = 'space', color: str = 'gainsboro', alpha: float = 0.5) pyvista.UniformGrid #
Construct a model(space-model) with uniform spacing in the three coordinate directions. The six surfaces of the commonly generated space-model are exactly the boundaries of the model, but the space-model can also be expanded by expand_dist.
- Parameters
- model
A three dims model.
- expand_dist
The length of space-model to be extended in all directions.
- grid_num
Number of grid to generate.
- key_added
The key under which to add the labels.
- label
The label of space-model.
- color
Color to use for plotting space-model.
- alpha
The opacity of the color to use for plotting space-model.
- Returns
A space-model with uniform spacing in the three coordinate directions.
- spateo.tdr.models.construct_trajectory(adata: anndata.AnnData, fate_key: str = 'fate_develop', n_sampling: Optional[int] = None, sampling_method: str = 'trn', key_added: str = 'trajectory', label: Optional[Union[str, list, numpy.ndarray]] = None, tip_factor: Union[int, float] = 5, tip_radius: float = 0.2, trajectory_color: Union[str, list, dict] = 'gainsboro', tip_color: Union[str, list, dict] = 'orangered', alpha: float = 1.0) pyvista.PolyData #
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.
- Return type
trajectory_model
- spateo.tdr.models.construct_trajectory_X(cells_states: Union[numpy.ndarray, List[numpy.ndarray]], init_states: Optional[numpy.ndarray] = None, n_sampling: Optional[int] = None, sampling_method: str = 'trn', key_added: str = 'trajectory', label: Optional[Union[str, list, numpy.ndarray]] = None, tip_factor: Union[int, float] = 5, tip_radius: float = 0.2, trajectory_color: Union[str, list, dict] = 'gainsboro', tip_color: Union[str, list, dict] = 'orangered', alpha: Union[float, list, dict] = 1.0) pyvista.PolyData #
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.
- Return type
trajectory_model
- spateo.tdr.models.construct_pc(adata: anndata.AnnData, spatial_key: str = 'spatial', groupby: Union[str, tuple] = None, key_added: str = 'groups', mask: Union[str, int, float, list] = None, colormap: Union[str, list, dict] = 'rainbow', alphamap: Union[float, list, dict] = 1.0) pyvista.PolyData #
Construct a point cloud model based on 3D coordinate information.
- Parameters
- adata
AnnData object.
- 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 pcd. The default colormap is
'rainbow'
.- alphamap
The opacity of the colors to use for plotting pcd. The default alphamap is
1.0
.
- Returns
- A point cloud, which contains the following properties:
pc.point_data[key_added]
, thegroupby
information.pc.point_data[f'{key_added}_rgba']
, the rgba colors of thegroupby
information.pc.point_data['obs_index']
, the obs_index of each coordinate in the original adata.
- Return type
pc
- spateo.tdr.models.add_model_labels(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid, pyvista.UniformGrid], labels: numpy.ndarray, key_added: str = 'groups', where: Literal[point_data, cell_data] = 'cell_data', colormap: Union[str, list, dict, numpy.ndarray] = 'rainbow', alphamap: Union[float, list, dict, numpy.ndarray] = 1.0, mask_color: Optional[str] = 'gainsboro', mask_alpha: Optional[float] = 0.0, inplace: bool = False) PolyData or UnstructuredGrid #
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]
ormodel.point_data[key_added]
, the labels array;model.cell_data[f'{key_added}_rgba']
ormodel.point_data[f'{key_added}_rgba']
, the rgba colors of the labels.- Return type
A model, which contains the following properties
- spateo.tdr.models.center_to_zero(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], inplace: bool = False)#
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: Optional[List[str]] = None) pyvista.MultiBlock #
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 #
Merge all models in the models list. The format of all models must be the same.
- spateo.tdr.models.multiblock2model(model, message=None)#
Merge all models in MultiBlock into one model
- spateo.tdr.models.read_model(filename: str)#
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: Union[pyvista.PolyData, pyvista.UnstructuredGrid], angle: Union[list, tuple] = (0, 0, 0), rotate_center: Union[list, tuple] = None, inplace: bool = False) Union[pyvista.PolyData, pyvista.UnstructuredGrid, None] #
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: Union[pyvista.DataSet, pyvista.MultiBlock], filename: str, binary: bool = True, texture: Union[str, numpy.ndarray] = None)#
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: Union[pyvista.PolyData, pyvista.UnstructuredGrid], distance: Union[float, int, list, tuple] = None, scale_factor: Union[float, int, list, tuple] = 1, scale_center: Union[list, tuple] = None, inplace: bool = False) Union[pyvista.PolyData, pyvista.UnstructuredGrid, None] #
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: Union[pyvista.PolyData, pyvista.UnstructuredGrid], distance: Union[list, tuple] = (0, 0, 0), inplace: bool = False) Union[pyvista.PolyData, pyvista.UnstructuredGrid, None] #
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
- spateo.tdr.models.voxelize_mesh(mesh: Union[pyvista.PolyData, pyvista.UnstructuredGrid], voxel_pc: Union[pyvista.PolyData, pyvista.UnstructuredGrid] = None, key_added: str = 'groups', label: str = 'voxel', color: Optional[str] = 'gainsboro', alpha: Union[float, int] = 1.0, smooth: Optional[int] = 200) pyvista.UnstructuredGrid #
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']
andvoxel_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).
- Return type
voxel_model
- spateo.tdr.models.voxelize_pc(pc: pyvista.PolyData, voxel_size: Optional[numpy.ndarray] = None) pyvista.UnstructuredGrid #
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