spateo.tdr
#
Subpackages#
spateo.tdr.models
spateo.tdr.widgets
spateo.tdr.widgets.changes
spateo.tdr.widgets.clip
spateo.tdr.widgets.deep_interpolation
spateo.tdr.widgets.interpolation_nn
spateo.tdr.widgets.interpolations
spateo.tdr.widgets.morphogenesis
spateo.tdr.widgets.morphology
spateo.tdr.widgets.nn_losses
spateo.tdr.widgets.pick
spateo.tdr.widgets.slice
spateo.tdr.widgets.tree
spateo.tdr.widgets.utils
spateo.tdr.widgets.vtk_interpolate
Package Contents#
Classes#
This module loads and retains the data pairs (X, Y) and delivers the batches of them to the DeepInterpolation |
|
This is a global solver for principal curves that uses neural networks. |
|
Base class for all neural network modules. |
|
Base class for all neural network modules. |
|
As discussed above, we aim to provide each sine nonlinearity with activations that are standard |
|
Base class for all neural network modules. |
|
Base class for all neural network modules. |
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. |
|
Generate a principal elastic tree. |
|
This is the global module that contains principal curve and nonlinear principal component analysis algorithms that |
|
Generate a simple principal tree. |
|
Find the closest tree node to any point in the model. |
|
|
|
|
|
Find the closest principal tree node to any point in the model through KDTree. |
|
Find the closest principal tree node to any point in the model through KDTree. |
|
Pick the interested part of a model using a 3D box widget. Only one model can be generated. |
|
Pick the interested part of a model using a 2D rectangle widget. |
|
Learn a continuous mapping from space to gene expression pattern with the deep neural net model. |
|
Prepare the X (spatial coordinates), Y (gene expression) and grid points for the kernel or deep model. |
|
Learn a continuous mapping from space to gene expression pattern with the Kernel method (sparseVFC). |
|
Obtain the optimal mapping relationship and developmental direction between cells for samples between continuous developmental stages. |
|
Calculating and predicting the vector field during development by the Kernel method (sparseVFC). |
|
Calculate acceleration for each cell with the reconstructed vector field function. |
|
Calculate curl for each cell with the reconstructed vector field function. |
|
Calculate curvature for each cell with the reconstructed vector field function. |
|
Calculate divergence for each cell with the reconstructed vector field function. |
|
Calculate jacobian for each cell with the reconstructed vector field function. |
|
Calculate torsion for each cell with the reconstructed vector field function. |
|
Calculate the velocity for each cell with the reconstructed vector field function. |
|
Calculating and predicting the vector field during development by the Kernel method (sparseVFC). |
|
Prediction of cell developmental trajectory based on reconstructed vector field. |
|
Return the basic morphological characteristics of model, |
|
Calculate the kernel density of a 3D point cloud model. |
|
Add a checkbox button widget to pick the desired groups through the interactive window and output the picked groups. |
|
Pick the intersection between two mesh models. |
|
Pick the point cloud inside the mesh model and point cloud outside the mesh model. |
|
Add a checkbox button widget to pick the desired groups through the interactive window and output the picked groups. |
|
Pick the desired groups. |
|
Create a slice of the input dataset along a specified axis or |
|
Create many slices of the input dataset along a specified axis or |
|
This function is a pure Python implementation of the DDRTree algorithm. |
|
|
|
Interpolate over source to port its data onto the current object using various kernels. |
|
|
Mean absolute difference (weighted) |
|
Mean squared error (weighted) |
|
Cosine similarity (weighted) |
|
|
Mean absolute difference |
|
Mean squared error |
Cosine similarity |
- spateo.tdr.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.multiblock2model(model, message=None)#
Merge all models in MultiBlock into one model
- spateo.tdr.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.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.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.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.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.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.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
- spateo.tdr.ElPiGraph_tree(X: numpy.ndarray, NumNodes: int = 50, **kwargs) Tuple[numpy.ndarray, numpy.ndarray] #
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.
- **kwargs
Other parameters used in elpigraph.computeElasticPrincipalTree. For details, please see: https://github.com/j-bac/elpigraph-python/blob/master/elpigraph/_topologies.py
- Returns
The nodes in the principal tree. edges: The edges between nodes in the principal tree.
- Return type
nodes
- spateo.tdr.Principal_Curve(X: numpy.ndarray, NumNodes: int = 50, scale_factor: Union[int, float] = 1, **kwargs) Tuple[numpy.ndarray, numpy.ndarray] #
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 25. The more complex the curve, the higher this number should be.
- 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.SimplePPT_tree(X: numpy.ndarray, NumNodes: int = 50, **kwargs) Tuple[numpy.ndarray, numpy.ndarray] #
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.
- **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.changes_along_branch(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], spatial_key: Optional[str] = None, map_key: Union[str, list] = None, nodes_key: str = 'nodes', key_added: str = 'tree', label: str = 'tree', rd_method: Literal[ElPiGraph, SimplePPT, PrinCurve] = 'ElPiGraph', NumNodes: int = 50, color: str = 'gainsboro', inplace: bool = False, **kwargs) Tuple[Union[pyvista.DataSet, pyvista.PolyData, pyvista.UnstructuredGrid], pyvista.PolyData, float] #
Find the closest tree node to any point in the model.
- Parameters
- model
A reconstructed model.
- spatial_key
If spatial_key is None, the spatial coordinates are in model.points, otherwise in model[spatial_key].
- map_key
The key in model that corresponds to the gene expression.
- nodes_key
The key that corresponds to the coordinates of the nodes in the tree.
- key_added
The key that corresponds to tree label.
- label
The label of tree model.
- rd_method
The method of constructing a tree.
- NumNodes
Number of nodes for the tree model.
- color
Color to use for plotting tree model.
- inplace
Updates model in-place.
- Returns
Updated model if inplace is True. tree_model: A three-dims principal tree model. tree_length: The length of the tree model.
- Return type
model
- spateo.tdr.changes_along_line(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], key: Union[str, list] = None, n_points: int = 100, vec: Union[tuple, list] = (1, 0, 0), center: Union[tuple, list] = None) Tuple[numpy.ndarray, numpy.ndarray, pyvista.MultiBlock, pyvista.MultiBlock] #
- spateo.tdr.changes_along_shape(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], spatial_key: Optional[str] = None, key_added: Optional[str] = 'rd_spatial', dim: int = 2, inplace: bool = False, **kwargs)#
- spateo.tdr.map_gene_to_branch(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], tree: pyvista.PolyData, key: Union[str, list], nodes_key: Optional[str] = 'nodes', inplace: bool = False)#
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.map_points_to_branch(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], nodes: numpy.ndarray, spatial_key: Optional[str] = None, key_added: Optional[str] = 'nodes', inplace: bool = False, **kwargs)#
Find the closest principal tree node to any point in the model through KDTree.
- Parameters
- model
A reconstructed model.
- nodes
The nodes in the principal tree.
- spatial_key
The key that corresponds to the coordinates of the point in the model. If spatial_key is None, the coordinates are model.points.
- key_added
The key under which to add the nodes labels.
- inplace
Updates model in-place.
- kwargs
Other parameters used in scipy.spatial.KDTree.
- Returns
model.point_data[key_added], the nodes labels array.
- Return type
A model, which contains the following properties
- spateo.tdr.interactive_box_clip(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid, pyvista.MultiBlock], key: str = 'groups', invert: bool = False) pyvista.MultiBlock #
Pick the interested part of a model using a 3D box widget. Only one model can be generated.
- Parameters
- model
Reconstructed 3D model.
- key
The key under which are the labels.
- invert
Flag on whether to flip/invert the pick.
- Returns
A MultiBlock that contains all models you picked.
- Return type
picked_model
- spateo.tdr.interactive_rectangle_clip(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid, pyvista.MultiBlock], key: str = 'groups', invert: bool = False, bg_model=None) pyvista.MultiBlock #
Pick the interested part of a model using a 2D rectangle widget. Multiple models can be generated at the same time.
- Parameters
- model
Reconstructed 3D model.
- key
The key under which are the labels.
- invert
Flag on whether to flip/invert the pick.
- bg_model
A visualization-only background model to help clip our target model.
- Returns
A MultiBlock that contains all models you picked.
- Return type
picked_model
- class spateo.tdr.DataSampler(path_to_data: Union[str, None] = None, data: Union[anndata.AnnData, dict, None] = None, skey: str = 'spatial', ekey: str = 'M_s', wkey: Union[str, None] = None, normalize_data: bool = False, number_of_random_samples: str = 'all', weighted: bool = False)#
Bases:
object
This module loads and retains the data pairs (X, Y) and delivers the batches of them to the DeepInterpolation module upon calling. The module can load tha data from a .mat file. The file must contain two 2D matrices X and Y with equal rows.
X: The spatial coordinates of each cell / binning / segmentation. Y: The expression values at the corresponding coordinates X.
- generate_batch(batch_size: int, sample_subset_indices: str = 'all')#
Generate random batches of the given size “batch_size” from the (X, Y) sample pairs.
- Parameters
- batch_size
If the batch_size is set to “all”, all the samples will be returned.
- sample_subset_indices
This argument is used when you want to further subset the samples (based on the factors such as quality of the samples). If set to “all”, it means it won’t filter out samples based on their qualities.
- class spateo.tdr.DeepInterpolation(model: types.ModuleType, data_sampler: object, sirens: bool = False, enforce_positivity: bool = False, loss_function: Union[Callable, None] = weighted_mse(), smoothing_factor: Union[float, None] = True, stability_factor: Union[float, None] = True, load_model_from_buffer: bool = False, buffer_path: str = 'model_buffer/', hidden_features: int = 256, hidden_layers: int = 3, first_omega_0: float = 30.0, hidden_omega_0: float = 30.0, **kwargs)#
- high2low(high_batch)#
- low2high(low_batch)#
- predict(input_x=None, to_numpy=True)#
- train(max_iter: int, data_batch_size: int, autoencoder_batch_size: int, data_lr: float, autoencoder_lr: float, sample_fraction: float = 1, iter_per_sample_update: Union[int, None] = None)#
The training method for the DeepInterpolation model object
- Parameters
- max_iter
The maximum iteration the network will be trained.
- data_batch_size
The size of the data sample batches to be generated in each iteration.
- autoencoder_batch_size
The size of the auto-encoder training batches to be generated in each iteration. Must be no greater than batch_size. .
- data_lr
The learning rate for network training.
- autoencoder_lr
The learning rate for network training the auto-encoder. Will have no effect if network_dim equal data_dim.
- sample_fraction
The best sample fraction to be filtered out of the velocity samples.
- iter_per_sample_update
The frequency of updating the subset of best samples (in terms of per iterations). Will have no effect if velocity_sample_fraction and time_course_sample_fraction are set to 1.
- save()#
- load()#
- spateo.tdr.deep_intepretation(adata: Optional[anndata.AnnData] = None, genes: Optional[List] = None, X: Optional[numpy.ndarray] = None, Y: Optional[numpy.ndarray] = None, NX: Optional[numpy.ndarray] = None, grid_num: List = [50, 50, 50], **kwargs) anndata.AnnData #
Learn a continuous mapping from space to gene expression pattern with the deep neural net model.
- Parameters
- adata
AnnData object that contains spatial (numpy.ndarray) in the obsm attribute.
- genes
Gene list whose interpolate expression across space needs to learned. If Y is provided, genes will only be used to retrive the gene annotation info.
- X
The spatial coordinates of each data point.
- Y
The gene expression of the corresponding data point.
- NX
The spatial coordinates of new data point. If NX is None, generate new points based on grid_num.
- grid_num
Number of grid to generate. Default is 50 for each dimension. Must be non-negative.
- **kwargs
Additional parameters that will be passed to the training step of the deep neural net.
- Returns
an anndata object that has interpolated expression. The row of the adata object is a grid point within the convex hull formed by the input data points while each column corresponds a gene whose expression values are interpolated.
- Return type
interp_adata
- spateo.tdr.get_X_Y_grid(adata: Optional[anndata.AnnData] = None, genes: Optional[List] = None, X: Optional[numpy.ndarray] = None, Y: Optional[numpy.ndarray] = None, grid_num: List = [50, 50, 50]) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray] #
Prepare the X (spatial coordinates), Y (gene expression) and grid points for the kernel or deep model.
- Parameters
- adata
AnnData object that contains spatial (numpy.ndarray) in the obsm attribute.
- genes
Gene list whose interpolate expression across space needs to learned. If Y is provided, genes will only be used to retrive the gene annotation info.
- X
The spatial coordinates of each data point.
- Y
The gene expression of the corresponding data point.
- grid_num
Number of grid to generate. Default is 50 for each dimension. Must be non-negative.
- Returns
spatial coordinates. Y: gene expression of the associated spatial coordinates. Grid: grid points formed with the input spatial coordinates. grid_in_hull: A list of booleans indicates whether the current grid points is within the convex hull formed by
the input data points.
- Return type
X
- spateo.tdr.kernel_interpolation(adata: Optional[anndata.AnnData] = None, genes: Optional[List] = None, X: Optional[numpy.ndarray] = None, Y: Optional[numpy.ndarray] = None, NX: Optional[numpy.ndarray] = None, grid_num: List = [50, 50, 50], lambda_: float = 0.02, lstsq_method: str = 'scipy', **kwargs) anndata.AnnData #
Learn a continuous mapping from space to gene expression pattern with the Kernel method (sparseVFC).
- Parameters
- adata
AnnData object that contains spatial (numpy.ndarray) in the obsm attribute.
- genes
Gene list whose interpolate expression across space needs to learned. If Y is provided, genes will only be used to retrive the gene annotation info.
- X
The spatial coordinates of each data point.
- Y
The gene expression of the corresponding data point.
- NX
The spatial coordinates of new data point. If NX is None, generate new points based on grid_num.
- grid_num
Number of grid to generate. Default is 50 for each dimension. Must be non-negative.
- lambda
Represents the trade-off between the goodness of data fit and regularization. Larger Lambda_ put more weights on regularization.
- lstsq_method
The name of the linear least square solver, can be either ‘scipy` or douin.
- **kwargs
Additional parameters that will be passed to SparseVFC function.
- Returns
an anndata object that has interpolated expression. The row of the adata object is a grid point within the convex hull formed by the input data points while each column corresponds a gene whose expression values are interpolated.
- Return type
interp_adata
- spateo.tdr.cell_directions(adatas: List[anndata.AnnData], layer: str = 'X', genes: Optional[Union[list, numpy.ndarray]] = None, spatial_key: str = 'align_spatial', key_added: str = 'mapping', alpha: float = 0.001, numItermax: int = 200, numItermaxEmd: int = 100000, dtype: str = 'float32', device: str = 'cpu', keep_all: bool = False, inplace: bool = True, **kwargs) Optional[List[anndata.AnnData]] #
Obtain the optimal mapping relationship and developmental direction between cells for samples between continuous developmental stages.
- Parameters
- adatas
AnnData object of samples from continuous developmental stages.
- layer
If
'X'
, uses.X
to calculate dissimilarity between spots, otherwise uses the representation given by.layers[layer]
.- genes
Genes used for calculation. If None, use all common genes for calculation.
- spatial_key
The key in
.obsm
that corresponds to the spatial coordinate of each cell.- .uns. : The key that will be used for the vector field key in
- key_added
The key that will be used in
.obsm
.X_{key_added}
-TheX_{key_added}
that will be used for the coordinates of the cell that maps optimally in the next stage.V_{key_added}
-TheV_{key_added}
that will be used for the cell developmental directions.
- alpha
Alignment tuning parameter. Note: 0 <= alpha <= 1.
When
alpha = 0
only the gene expression data is taken into account, while whenalpha =1
only the spatial coordinates are taken into account.- numItermax
Max number of iterations for cg during FGW-OT.
- numItermaxEmd
Max number of iterations for emd during FGW-OT.
- dtype
The floating-point number type. Only
float32
andfloat64
.- device
Equipment used to run the program. You can also set the specified GPU for running.
E.g.: '0'
- keep_all
Whether to retain all the optimal relationships obtained only based on the pi matrix, If
keep_all
is False, the optimal relationships obtained based on the pi matrix and the nearest coordinates.- inplace
Whether to copy adata or modify it inplace.
- **kwargs
Additional parameters that will be passed to
pairwise_align
function.
- Returns
An
AnnData
object is updated/copied with theX_{key_added}
andV_{key_added}
in the.obsm
attribute.
- spateo.tdr.morphofield(adata: anndata.AnnData, spatial_key: str = 'align_spatial', V_key: str = 'V_mapping', key_added: str = 'VecFld_morpho', NX: Optional[numpy.ndarray] = None, grid_num: Optional[List[int]] = None, M: int = 100, lambda_: float = 0.02, lstsq_method: str = 'scipy', min_vel_corr: float = 0.8, restart_num: int = 10, restart_seed: Union[List[int], Tuple[int], numpy.ndarray] = (0, 100, 200, 300, 400), inplace: bool = True, **kwargs) Optional[anndata.AnnData] #
Calculating and predicting the vector field during development by the Kernel method (sparseVFC).
- Parameters
- adata
AnnData object that contains the cell coordinates of the two states after alignment.
- spatial_key
The key from the
.obsm
that corresponds to the spatial coordinates of each cell.- V_key
The key from the
.obsm
that corresponds to the developmental direction of each cell.- key_added
The key that will be used for the vector field key in
.uns
.- NX
The spatial coordinates of new data point. If NX is None, generate new points based on grid_num.
- grid_num
The number of grids in each dimension for generating the grid velocity. Default is
[50, 50, 50]
.- M
The number of basis functions to approximate the vector field.
- lambda
Represents the trade-off between the goodness of data fit and regularization. Larger Lambda_ put more weights on regularization.
- lstsq_method
The name of the linear least square solver, can be either
'scipy'
or'douin'
.- min_vel_corr
The minimal threshold for the cosine correlation between input velocities and learned velocities to consider as a successful vector field reconstruction procedure. If the cosine correlation is less than this threshold and
restart_num
> 1,restart_num
trials will be attempted with different seeds to reconstruct the vector field function. This can avoid some reconstructions to be trapped in some local optimal.- restart_num
The number of retrials for vector field reconstructions.
- restart_seed
A list of seeds for each retrial. Must be the same length as
restart_num
or None.- inplace
Whether to copy adata or modify it inplace.
- **kwargs
Additional parameters that will be passed to
SparseVFC
function.
- Returns
An
AnnData
object is updated/copied with thekey_added
dictionary in the.uns
attribute.The
key_added
dictionary which contains:X: Current state. valid_ind: The indices of cells that have finite velocity values. X_ctrl: Sample control points of current state. ctrl_idx: Indices for the sampled control points. Y: Velocity estimates in delta t. beta: Parameter of the Gaussian Kernel for the kernel matrix (Gram matrix). V: Prediction of velocity of X. C: Finite set of the coefficients for the P: Posterior probability Matrix of inliers. VFCIndex: Indexes of inliers found by sparseVFC. sigma2: Energy change rate. grid: Grid of current state. grid_V: Prediction of velocity of the grid. iteration: Number of the last iteration. tecr_vec: Vector of relative energy changes rate comparing to previous step. E_traj: Vector of energy at each iteration. method: The method of learning vector field. Here method == ‘sparsevfc’.
Here the most important results are X, V, grid and grid_V.
X: Cell coordinates of the current state. V: Developmental direction of the X. grid: Grid coordinates of current state. grid_V: Prediction of developmental direction of the grid.
- spateo.tdr.morphofield_acceleration(adata: anndata.AnnData, vf_key: str = 'VecFld_morpho', key_added: str = 'acceleration', method: str = 'analytical', inplace: bool = True) Optional[anndata.AnnData] #
Calculate acceleration for each cell with the reconstructed vector field function.
- Parameters
- adata
AnnData object that contains the reconstructed vector field.
- vf_key
The key in
.uns
that corresponds to the reconstructed vector field.- key_added
The key that will be used for the acceleration key in
.obs
and.obsm
.- method
The method that will be used for calculating acceleration field, either
'analytical'
or'numerical'
.'analytical'
method uses the analytical expressions for calculating acceleration while'numerical'
method uses numdifftools, a numerical differentiation tool, for computing acceleration.'analytical'
method is much more efficient.- inplace
Whether to copy adata or modify it inplace.
- Returns
An
AnnData
object is updated/copied with thekey_added
in the.obs
and.obsm
attribute.The
key_added
in the.obs
which contains acceleration. Thekey_added
in the.obsm
which contains acceleration vectors.
- spateo.tdr.morphofield_curl(adata: anndata.AnnData, vf_key: str = 'VecFld_morpho', key_added: str = 'curl', method: str = 'analytical', inplace: bool = True) Optional[anndata.AnnData] #
Calculate curl for each cell with the reconstructed vector field function.
- Parameters
- adata
AnnData object that contains the reconstructed vector field.
- vf_key
The key in
.uns
that corresponds to the reconstructed vector field.- key_added
The key that will be used for the torsion key in
.obs
.- method
The method that will be used for calculating torsion field, either
'analytical'
or'numerical'
.'analytical'
method uses the analytical expressions for calculating torsion while'numerical'
method uses numdifftools, a numerical differentiation tool, for computing torsion.'analytical'
method is much more efficient.- inplace
Whether to copy adata or modify it inplace.
- Returns
An
AnnData
object is updated/copied with thekey_added
in the.obs
and.obsm
attribute.The
key_added
in the.obs
which contains magnitude of curl. Thekey_added
in the.obsm
which contains curl vectors.
- spateo.tdr.morphofield_curvature(adata: anndata.AnnData, vf_key: str = 'VecFld_morpho', key_added: str = 'curvature', formula: int = 2, method: str = 'analytical', inplace: bool = True) Optional[anndata.AnnData] #
Calculate curvature for each cell with the reconstructed vector field function.
- Parameters
- adata
AnnData object that contains the reconstructed vector field.
- vf_key
The key in
.uns
that corresponds to the reconstructed vector field.- key_added
The key that will be used for the curvature key in
.obs
and.obsm
.- formula
Which formula of curvature will be used, there are two formulas, so formula can be either
{1, 2}
. By default it is 2 and returns both the curvature vectors and the norm of the curvature. The formula one only gives the norm of the curvature.- method
The method that will be used for calculating curvature field, either
'analytical'
or'numerical'
.'analytical'
method uses the analytical expressions for calculating curvature while'numerical'
method uses numdifftools, a numerical differentiation tool, for computing curvature.'analytical'
method is much more efficient.- inplace
Whether to copy adata or modify it inplace.
- Returns
An
AnnData
object is updated/copied with thekey_added
in the.obs
and.obsm
attribute.The
key_added
in the.obs
which contains curvature. Thekey_added
in the.obsm
which contains curvature vectors.
- spateo.tdr.morphofield_divergence(adata: anndata.AnnData, vf_key: str = 'VecFld_morpho', key_added: str = 'divergence', method: str = 'analytical', vectorize_size: Optional[int] = 1000, inplace: bool = True) Optional[anndata.AnnData] #
Calculate divergence for each cell with the reconstructed vector field function.
- Parameters
- adata
AnnData object that contains the reconstructed vector field.
- vf_key
The key in
.uns
that corresponds to the reconstructed vector field.- key_added
The key that will be used for the acceleration key in
.obs
and.obsm
.- method
The method that will be used for calculating acceleration field, either
'analytical'
or'numerical'
.'analytical'
method uses the analytical expressions for calculating acceleration while'numerical'
method uses numdifftools, a numerical differentiation tool, for computing acceleration.'analytical'
method is much more efficient.- vectorize_size
vectorize_size is used to control the number of samples computed in each vectorized batch.
If vectorize_size = 1, there’s no vectorization whatsoever.
If vectorize_size = None, all samples are vectorized.
- inplace
Whether to copy adata or modify it inplace.
- Returns
An
AnnData
object is updated/copied with thekey_added
in the.obs
attribute.The
key_added
in the.obs
which contains divergence.
- spateo.tdr.morphofield_jacobian(adata: anndata.AnnData, vf_key: str = 'VecFld_morpho', key_added: str = 'jacobian', method: str = 'analytical', inplace: bool = True) Optional[anndata.AnnData] #
Calculate jacobian for each cell with the reconstructed vector field function.
- Parameters
- adata
AnnData object that contains the reconstructed vector field.
- vf_key
The key in
.uns
that corresponds to the reconstructed vector field.- key_added
The key that will be used for the jacobian key in
.obs
and.obsm
.- method
The method that will be used for calculating jacobian field, either
'analytical'
or'numerical'
.'analytical'
method uses the analytical expressions for calculating jacobian while'numerical'
method uses numdifftools, a numerical differentiation tool, for computing jacobian.'analytical'
method is much more efficient.- inplace
Whether to copy adata or modify it inplace.
- Returns
An
AnnData
object is updated/copied with thekey_added
in the.obs
and.uns
attribute.The
key_added
in the.obs
which contains jacobian. Thekey_added
in the.uns
which contains jacobian tensor.
- spateo.tdr.morphofield_torsion(adata: anndata.AnnData, vf_key: str = 'VecFld_morpho', key_added: str = 'torsion', method: str = 'analytical', inplace: bool = True) Optional[anndata.AnnData] #
Calculate torsion for each cell with the reconstructed vector field function.
- Parameters
- adata
AnnData object that contains the reconstructed vector field.
- vf_key
The key in
.uns
that corresponds to the reconstructed vector field.- key_added
The key that will be used for the torsion key in
.obs
and.obsm
.- method
The method that will be used for calculating torsion field, either
'analytical'
or'numerical'
.'analytical'
method uses the analytical expressions for calculating torsion while'numerical'
method uses numdifftools, a numerical differentiation tool, for computing torsion.'analytical'
method is much more efficient.- inplace
Whether to copy adata or modify it inplace.
- Returns
An
AnnData
object is updated/copied with thekey_added
in the.obs
and.uns
attribute.The
key_added
in the.obs
which contains torsion. Thekey_added
in the.uns
which contains torsion matrix.
- spateo.tdr.morphofield_velocity(adata: anndata.AnnData, vf_key: str = 'VecFld_morpho', key_added: str = 'velocity', inplace: bool = True) Optional[anndata.AnnData] #
Calculate the velocity for each cell with the reconstructed vector field function.
- Parameters
- adata
AnnData object that contains the reconstructed vector field.
- vf_key
The key in
.uns
that corresponds to the reconstructed vector field.- key_added
The key that will be used for the velocity key in
.obsm
.- inplace
Whether to copy adata or modify it inplace.
- Returns
An
AnnData
object is updated/copied with thekey_added
in the.obsm
attribute which contains velocities.
- spateo.tdr.morphofield_X(X: numpy.ndarray, V: numpy.ndarray, NX: Optional[numpy.ndarray] = None, grid_num: Optional[List[int]] = None, M: int = 100, lambda_: float = 0.02, lstsq_method: str = 'scipy', min_vel_corr: float = 0.8, restart_num: int = 10, restart_seed: Union[List[int], Tuple[int], numpy.ndarray] = (0, 100, 200, 300, 400), **kwargs) dict #
Calculating and predicting the vector field during development by the Kernel method (sparseVFC).
- Parameters
- X
The spatial coordinates of each cell.
- V
The developmental direction of each cell.
- NX
The spatial coordinates of new data point (grid). If
NX
is None, generate grid based ongrid_num
.- grid_num
The number of grids in each dimension for generating the grid velocity. Default is
[50, 50, 50]
.- M
The number of basis functions to approximate the vector field.
- lambda
Represents the trade-off between the goodness of data fit and regularization. Larger Lambda_ put more weights on regularization.
- lstsq_method
The name of the linear least square solver, can be either
'scipy'
or'douin'
.- min_vel_corr
The minimal threshold for the cosine correlation between input velocities and learned velocities to consider as a successful vector field reconstruction procedure. If the cosine correlation is less than this threshold and
restart_num
> 1,restart_num
trials will be attempted with different seeds to reconstruct the vector field function. This can avoid some reconstructions to be trapped in some local optimal.- restart_num
The number of retrials for vector field reconstructions.
- restart_seed
A list of seeds for each retrial. Must be the same length as
restart_num
or None.- **kwargs
Additional parameters that will be passed to
SparseVFC
function.
- Returns
- X: Current state.
valid_ind: The indices of cells that have finite velocity values. X_ctrl: Sample control points of current state. ctrl_idx: Indices for the sampled control points. Y: Velocity estimates in delta t. beta: Parameter of the Gaussian Kernel for the kernel matrix (Gram matrix). V: Prediction of velocity of X. C: Finite set of the coefficients for the P: Posterior probability Matrix of inliers. VFCIndex: Indexes of inliers found by sparseVFC. sigma2: Energy change rate. grid: Grid of current state. grid_V: Prediction of velocity of the grid. iteration: Number of the last iteration. tecr_vec: Vector of relative energy changes rate comparing to previous step. E_traj: Vector of energy at each iteration. method: The method of learning vector field. Here method == ‘sparsevfc’.
Here the most important results are X, V, grid and grid_V.
X: Cell coordinates of the current state. V: Developmental direction of the X. grid: Grid coordinates of current state. grid_V: Prediction of developmental direction of the grid.
- Return type
A dictionary which contains
- spateo.tdr.morphopath(adata: anndata.AnnData, vf_key: str = 'VecFld_morpho', key_added: str = 'fate_morpho', layer: str = 'X', direction: str = 'forward', interpolation_num: int = 250, t_end: Optional[Union[int, float]] = None, average: bool = False, cores: int = 1, inplace: bool = True, **kwargs) Optional[anndata.AnnData] #
Prediction of cell developmental trajectory based on reconstructed vector field.
- Parameters
- adata
AnnData object that contains the reconstructed vector field function in the
.uns
attribute.- vf_key
The key in
.uns
that corresponds to the reconstructed vector field.- key_added
The key under which to add the dictionary Fate (includes
t
andprediction
keys).- layer
Which layer of the data will be used for predicting cell fate with the reconstructed vector field function.
- direction
The direction to predict the cell fate. One of the
forward
,backward
orboth
string.- interpolation_num
The number of uniformly interpolated time points.
- t_end
The length of the time period from which to predict cell state forward or backward over time.
- average
The method to calculate the average cell state at each time step, can be one of
origin
ortrajectory
. Iforigin
used, the average expression state from the init_cells will be calculated and the fate prediction is based on this state. Iftrajectory
used, the average expression states of all cells predicted from the vector field function at each time point will be used. Ifaverage
isFalse
, no averaging will be applied.- cores
Number of cores to calculate path integral for predicting cell fate. If cores is set to be > 1, multiprocessing will be used to parallel the fate prediction.
- inplace
Whether to copy adata or modify it inplace.
- **kwargs
Additional parameters that will be passed into the
fate
function.
- Returns
An
AnnData
object is updated/copied with thekey_added
dictionary in the.uns
attribute.The
key_added
dictionary which contains:t: The time at which the cell state are predicted. prediction: Predicted cells states at different time points. Row order corresponds to the element order in
t. If init_states corresponds to multiple cells, the expression dynamics over time for each cell is concatenated by rows. That is, the final dimension of prediction is (len(t) * n_cells, n_features). n_cells: number of cells; n_features: number of genes or number of low dimensional embeddings. Of note, if the average is set to be True, the average cell state at each time point is calculated for all cells.
- spateo.tdr.model_morphology(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], pc: Optional[PolyData or UnstructuredGrid] = None) Dict[str, Union[float, Any]] #
Return the basic morphological characteristics of model, including model volume, model surface area, volume / surface area ratio,etc.
- Parameters
- model
A reconstructed surface model or volume model.
- pc
A point cloud representing the number of cells.
- Returns
- A dictionary containing the following model morphological features:
morphology[‘Length(x)’]: Length (x) of model. morphology[‘Width(y)’]: Width (y) of model. morphology[‘Height(z)’]: Height (z) of model. morphology[‘Surface_area’]: Surface area of model. morphology[‘Volume’]: Volume of model. morphology[‘V/SA_ratio’]: Volume / surface area ratio of model; morphology[‘cell_density’]: Cell density of model.
- Return type
morphology
- spateo.tdr.pc_KDE(pc: pyvista.PolyData, key_added: str = 'kde', kernel: str = 'gaussian', bandwidth: float = 1.0, colormap: Union[str, list, dict] = 'hot_r', alphamap: Union[float, list, dict] = 1.0, inplace: bool = False) Union[pyvista.PolyData, pyvista.UnstructuredGrid] #
Calculate the kernel density of a 3D point cloud model.
- Parameters
- pc
A point cloud model.
- key_added
The key under which to add the labels.
- kernel
The kernel to use. Available kernel are: * ‘gaussian’ * ‘tophat’ * ‘epanechnikov’ * ‘exponential’ * ‘linear’ * ‘cosine’
- bandwidth
The bandwidth of the kernel.
- colormap
Colors to use for plotting pcd. The default colormap is ‘hot_r’.
- alphamap
The opacity of the colors to use for plotting pcd. The default alphamap is 1.0.
- inplace
Updates model in-place.
- Returns
- Reconstructed 3D point cloud, which contains the following properties:
pc[key_added], the kernel density.
- Return type
pc
- spateo.tdr.interactive_pick(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid, pyvista.MultiBlock], key: str = 'groups', checkbox_size: int = 27, label_size: int = 12) pyvista.MultiBlock #
Add a checkbox button widget to pick the desired groups through the interactive window and output the picked groups.
- Parameters
- model
Reconstructed 3D model.
- key
The key under which are the groups.
- checkbox_size
The size of the button in number of pixels.
- label_size
The font size of the checkbox labels.
- Returns
A MultiBlock that contains all models you picked.
- spateo.tdr.overlap_mesh_pick(mesh1: pyvista.PolyData, mesh2: pyvista.PolyData) pyvista.PolyData #
Pick the intersection between two mesh models.
- Parameters
- mesh1
Reconstructed 3D mesh model.
- mesh2
Reconstructed 3D mesh model.
- Returns
The intersection mesh model.
- Return type
select_mesh
- spateo.tdr.overlap_pc_pick(pc: pyvista.PolyData, mesh: pyvista.PolyData) [pyvista.PolyData, pyvista.PolyData] #
Pick the point cloud inside the mesh model and point cloud outside the mesh model.
- Parameters
- pc
Reconstructed 3D point cloud model corresponding to mesh.
- mesh
Reconstructed 3D mesh model.
- Returns
Point cloud inside the mesh model. outside_pc: Point cloud outside the mesh model.
- Return type
inside_pc
- spateo.tdr.overlap_pick(main_mesh: pyvista.PolyData, other_mesh: pyvista.PolyData, main_pc: Optional[pyvista.PolyData] = None, other_pc: Optional[pyvista.PolyData] = None)#
Add a checkbox button widget to pick the desired groups through the interactive window and output the picked groups.
- Parameters
- main_mesh
Reconstructed 3D mesh model.
- other_mesh
Reconstructed 3D mesh model.
- main_pc
Reconstructed 3D point cloud model corresponding to main_mesh.
- other_pc
Reconstructed 3D point cloud model corresponding to other_mesh.
- Returns
A MultiBlock that contains all models you picked.
- spateo.tdr.three_d_pick(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid, pyvista.MultiBlock], key: str = 'groups', picked_groups: Union[str, list] = None) pyvista.MultiBlock #
Pick the desired groups.
- spateo.tdr.interactive_slice(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid, pyvista.MultiBlock], key: str = 'groups', method: Literal[interactive_slice.axis, orthogonal] = 'axis', axis: Literal[x, y, z] = 'x') pyvista.MultiBlock #
Create a slice of the input dataset along a specified axis or create three orthogonal slices through the dataset on the three cartesian planes.
- Parameters
- model
Reconstructed 3D model.
- key
The key under which are the labels.
- method
The methods of slicing a model. Available method are: * ‘axis’: Create a slice of the input dataset along a specified axis. * ‘orthogonal’: Create three orthogonal slices through the dataset on the three cartesian planes.
- axis
The axis to generate the slices along. Only works when method is ‘axis’.
- Returns
A MultiBlock that contains all models you sliced.
- Return type
sliced_model
- spateo.tdr.three_d_slice(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], method: Literal[three_d_slice.axis, orthogonal, three_d_slice.line] = 'axis', n_slices: int = 10, axis: Literal[x, y, z] = 'x', vec: Union[tuple, list] = (1, 0, 0), center: Union[tuple, list] = None) Union[pyvista.PolyData, Tuple[pyvista.MultiBlock, pyvista.MultiBlock, pyvista.PolyData]] #
Create many slices of the input dataset along a specified axis or create three orthogonal slices through the dataset on the three cartesian planes or slice a model along a vector direction perpendicularly.
- Parameters
- model
Reconstructed 3D model.
- method
The methods of slicing a model. Available method are: * ‘axis’: Create many slices of the input dataset along a specified axis. * ‘orthogonal’: Create three orthogonal slices through the dataset on the three cartesian planes.
This method is usually used interactively without entering a position which slices are taken.
’line’: Slice a model along a vector direction perpendicularly.
- n_slices
The number of slices to create along a specified axis. Only works when method is ‘axis’ or ‘line’.
- axis
The axis to generate the slices along. Only works when method is ‘axis’.
- vec
The vector direction. Only works when method is ‘line’.
- center
A 3-length sequence specifying the position which slices are taken. Defaults to the center of the model.
- Returns
If method is ‘axis’ or ‘orthogonal’, return a MultiBlock that contains all models you sliced; else return a tuple that contains line model, all models you sliced and intersections of slices model and line model.
- class spateo.tdr.NLPCA#
Bases:
object
This is a global solver for principal curves that uses neural networks. .. attribute:: None
- fit(data: numpy.ndarray, epochs: int = 500, nodes: int = 25, lr: float = 0.01, verbose: int = 0)#
This method creates a model and will fit it to the given m x n dimensional data.
- Parameters
- data
A numpy array of shape (m,n), where m is the number of points and n is the number of dimensions.
- epochs
Number of epochs to train neural network, defaults to 500.
- nodes
Number of nodes for the construction layers. Defaults to 25. The more complex the curve, the higher this number should be.
- lr
Learning rate for backprop. Defaults to .01
- verbose
Verbose = 0 mutes the training text from Keras. Defaults to 0.
- project(data: numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray] #
The project function will project the points to the curve generated by the fit function. Given back is the projection index of the original data and a sorted version of the original data.
- Parameters
- data
m x n array to project to the curve
- Returns
A one-dimension array that contains the projection index for each point in data. all_sorted: A m x n+1 array that contains data sorted by its projection index, along with the index.
- Return type
proj
- spateo.tdr.DDRTree(X: numpy.ndarray, maxIter: int = 20, sigma: Union[int, float] = 0.001, gamma: Union[int, float] = 10, eps: int = 0, dim: int = 2, Lambda: Union[int, float] = 1.0, ncenter: Optional[int] = None)#
This function is a pure Python implementation of the DDRTree algorithm.
- Parameters
- X
DxN, data matrix list.
- maxIter
Maximum iterations.
- eps
Relative objective difference.
- dim
Reduced dimension.
- Lambda
Regularization parameter for inverse graph embedding.
- sigma
Bandwidth parameter.
- gamma
Regularization parameter for k-means.
- ncenter
number of nodes allowed in the regularization graph
- Returns
- A tuple of Z, Y, stree, R, W, Q, C, objs
W is the orthogonal set of d (dimensions) linear basis vector Z is the reduced dimension space stree is the smooth tree graph embedded in the low dimension space Y represents latent points as the center of
- spateo.tdr.cal_ncenter(ncells, ncells_limit=100)#
- spateo.tdr.interpolate_model(model, source, source_key: Union[str, list] = None, radius: Optional[float] = None, N: Optional[int] = None, kernel: Literal[shepard, gaussian, linear] = 'shepard', where: Literal[point_data, cell_data] = 'cell_data', nullStrategy: Literal[0, 1, 2] = 1, nullValue: Union[int, float] = 0)#
Interpolate over source to port its data onto the current object using various kernels.
- Parameters
- model
Model that require interpolation.
- source
A data source that provides coordinates and data. Usually a point cloud object.
- source_key
Which data to migrate to the model object. If source_key is None, migrate all to the model object.
- radius
Set the radius of the point cloud. If you are generating a Gaussian distribution, then this is the standard deviation for each of x, y, and z.
- N
Specify the number of points for the source object to hold. If N (number of the closest points to use) is set then radius value is ignored.
- kernel
The kernel of interpolation kernel. Available kernels are: * shepard: vtkShepardKernel is an interpolation kernel that uses the method of Shepard to perform
interpolation. The weights are computed as 1/r^p, where r is the distance to a neighbor point within the kernel radius R; and p (the power parameter) is a positive exponent (typically p=2).
- gaussian: vtkGaussianKernel is an interpolation kernel that simply returns the weights for all
points found in the sphere defined by radius R. The weights are computed as: exp(-(s*r/R)^2) where r is the distance from the point to be interpolated to a neighboring point within R. The sharpness s simply affects the rate of fall off of the Gaussian.
- linear: vtkLinearKernel is an interpolation kernel that averages the contributions of all points in
the basis.
- where
The location where the data is stored in the model.
- nullStrategy
- Specify a strategy to use when encountering a “null” point during the interpolation process.
Null points occur when the local neighborhood(of nearby points to interpolate from) is empty.
- Case 0: an output array is created that marks points as being valid (=1) or null (invalid =0), and
the nullValue is set as well
Case 1: the output data value(s) are set to the provided nullValue
Case 2: simply use the closest point to perform the interpolation.
- nullValue
see above.
- Returns
Interpolated model.
- Return type
interpolated_model
- class spateo.tdr.A(network_dim, data_dim, hidden_features=256, hidden_layers=1, activation_function=torch.nn.functional.leaky_relu)#
Bases:
torch.nn.Module
Base class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will have their parameters converted too when you call
to()
, etc.Note
As per the example above, an
__init__()
call to the parent class must be made before assignment on the child.- Variables
- training : bool
Boolean represents whether this module is in training or evaluation mode.
- forward(inp)#
- class spateo.tdr.B(network_dim, data_dim, hidden_features=256, hidden_layers=3, activation_function=torch.nn.functional.leaky_relu)#
Bases:
torch.nn.Module
Base class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will have their parameters converted too when you call
to()
, etc.Note
As per the example above, an
__init__()
call to the parent class must be made before assignment on the child.- Variables
- training : bool
Boolean represents whether this module is in training or evaluation mode.
- forward(inp)#
- class spateo.tdr.SineLayer(in_features, out_features, bias=True, is_first=False, omega_0=30.0)#
Bases:
torch.nn.Module
As discussed above, we aim to provide each sine nonlinearity with activations that are standard normal distributed, except in the case of the first layer, where we introduced a factor ω0 that increased the spatial frequency of the first layer to better match the frequency spectrum of the signal. However, we found that the training of SIREN can be accelerated by leveraging a factor ω0 in all layers of the SIREN, by factorizing the weight matrix W as W = Wˆ ∗ ω0, choosing. This keeps the distribution of activations constant, but boosts gradients to the weight matrix Wˆ by the factor ω0 while leaving gradients w.r.t. the input of the sine neuron unchanged
- init_weights()#
- forward(input)#
- forward_with_intermediate(input)#
- class spateo.tdr.h(input_network_dim, output_network_dim, hidden_features=256, hidden_layers=3, sirens=False, first_omega_0=30.0, hidden_omega_0=30.0)#
Bases:
torch.nn.Module
Base class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will have their parameters converted too when you call
to()
, etc.Note
As per the example above, an
__init__()
call to the parent class must be made before assignment on the child.- Variables
- training : bool
Boolean represents whether this module is in training or evaluation mode.
- forward(inp)#
- class spateo.tdr.MainFlow(h, A=None, B=None, enforce_positivity=False)#
Bases:
torch.nn.Module
Base class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will have their parameters converted too when you call
to()
, etc.Note
As per the example above, an
__init__()
call to the parent class must be made before assignment on the child.- Variables
- training : bool
Boolean represents whether this module is in training or evaluation mode.
- forward(t, x, freeze=None)#
- spateo.tdr.weighted_mean(x, weights)#
- spateo.tdr.weighted_mad()#
Mean absolute difference (weighted)
- spateo.tdr.weighted_mse()#
Mean squared error (weighted)
- spateo.tdr.weighted_cosine_distance()#
Cosine similarity (weighted)
- spateo.tdr.mad()#
Mean absolute difference
- spateo.tdr.mse()#
Mean squared error
- spateo.tdr.cosine_distance()#
Cosine similarity