spateo.tdr.models.models_individual =================================== .. py:module:: spateo.tdr.models.models_individual Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/spateo/tdr/models/models_individual/mesh/index /autoapi/spateo/tdr/models/models_individual/mesh_methods/index /autoapi/spateo/tdr/models/models_individual/mesh_utils/index /autoapi/spateo/tdr/models/models_individual/point_clouds/index /autoapi/spateo/tdr/models/models_individual/voxel/index Functions --------- .. autoapisummary:: spateo.tdr.models.models_individual.construct_cells spateo.tdr.models.models_individual.construct_surface spateo.tdr.models.models_individual.construct_pc spateo.tdr.models.models_individual.voxelize_mesh spateo.tdr.models.models_individual.voxelize_pc Package Contents ---------------- .. py:function:: 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. :param pc: A point cloud object, including ``pc.point_data["obs_index"]``. :param geometry: The geometry of generating cells. Available ``geometry`` are: * geometry = ``'cube'`` * geometry = ``'sphere'`` * geometry = ``'ellipsoid'`` :param cell_size: A numpy.ndarray object including the relative radius/length size of each cell. :param xyz_scale: The scale factor for the x-axis, y-axis and z-axis. :param n_scale: The ``squareness`` parameter in the x-y plane adn z axis. Only works if ``geometry = 'ellipsoid'``. :param 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. :rtype: ds_glyph .. py:function:: 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] = 3000, scale_distance: Union[float, int, list, tuple] = None, scale_factor: Union[float, int, list, tuple] = None) -> Tuple[Union[pyvista.PolyData, pyvista.UnstructuredGrid, None], pyvista.PolyData, Optional[str]] Surface mesh reconstruction based on 3D point cloud model. :param pc: A point cloud model. :param key_added: The key under which to add the labels. :param label: The label of reconstructed surface mesh model. :param color: Color to use for plotting mesh. The default ``color`` is ``'gainsboro'``. :param alpha: The opacity of the color to use for plotting mesh. The default ``alpha`` is ``0.8``. :param uniform_pc: Generates a uniform point cloud with a larger number of points. :param uniform_pc_alpha: Specify alpha (or distance) value to control output of this filter. :param 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. :param cs_args: Parameters for various surface reconstruction methods. Available ``cs_args`` are: * ``'pyvista'``: {'alpha': 0} * ``'alpha_shape'``: {'alpha': 2.0} * ``'ball_pivoting'``: {'radii': [1]} * ``'poisson'``: {'depth': 8, 'width'=0, 'scale'=1.1, 'linear_fit': False, 'density_threshold': 0.01} * ``'marching_cube'``: {'levelset': 0, 'mc_scale_factor': 1, 'dist_sample_num': 100} :param 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. :param nclus: Number of voronoi clustering. :param smooth: Number of iterations for Laplacian smoothing. :param scale_distance: The distance by which the model is scaled. If ``scale_distance`` is float, the model is scaled same distance along the xyz axis; when the ``scale factor`` is list, the model is scaled along the xyz axis at different distance. If ``scale_distance`` is None, there will be no scaling based on distance. :param scale_factor: The scale by which the model is scaled. If ``scale factor`` is float, the model is scaled along the xyz axis at the same scale; when the ``scale factor`` is list, the model is scaled along the xyz axis at different scales. If ``scale_factor`` is None, there will be no scaling based on scale factor. :returns: A reconstructed surface mesh, which contains the following properties: ``uniform_surf.cell_data[key_added]``, the ``label`` array; ``uniform_surf.cell_data[f'{key_added}_rgba']``, the rgba colors of the ``label`` array. inside_pc: A point cloud, which contains the following properties: ``inside_pc.point_data['obs_index']``, the obs_index of each coordinate in the original adata. ``inside_pc.point_data[key_added]``, the ``groupby`` information. ``inside_pc.point_data[f'{key_added}_rgba']``, the rgba colors of the ``groupby`` information. plot_cmap: Recommended colormap parameter values for plotting. :rtype: uniform_surf .. py:function:: construct_pc(adata: anndata.AnnData, layer: str = 'X', 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) -> Tuple[pyvista.PolyData, Optional[str]] Construct a point cloud model based on 3D coordinate information. :param adata: AnnData object. :param layer: If ``'X'``, uses ``.X``, otherwise uses the representation given by ``.layers[layer]``. :param spatial_key: The key in ``.obsm`` that corresponds to the spatial coordinate of each bucket. :param groupby: The key that stores clustering or annotation information in ``.obs``, a gene name or a list of gene names in ``.var``. :param key_added: The key under which to add the labels. :param mask: The part that you don't want to be displayed. :param colormap: Colors to use for plotting pc. The default colormap is ``'rainbow'``. :param alphamap: The opacity of the colors to use for plotting pc. The default alphamap is ``1.0``. :returns: A point cloud, which contains the following properties: ``pc.point_data[key_added]``, the ``groupby`` information. ``pc.point_data[f'{key_added}_rgba']``, the rgba colors of the ``groupby`` information. ``pc.point_data['obs_index']``, the obs_index of each coordinate in the original adata. plot_cmap: Recommended colormap parameter values for plotting. :rtype: pc .. py:function:: 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) -> Tuple[Union[pyvista.UnstructuredGrid, Any], Optional[str]] Construct a volumetric mesh based on surface mesh. :param mesh: A surface mesh model. :param voxel_pc: A voxel model which contains the ``voxel_pc.cell_data['obs_index']`` and ``voxel_pc.cell_data[key_added]``. :param key_added: The key under which to add the labels. :param label: The label of reconstructed voxel model. :param color: Color to use for plotting mesh. The default color is ``'gainsboro'``. :param alpha: The opacity of the color to use for plotting model. The default alpha is ``0.8``. :param smooth: The smoothness of the voxel model. :returns: A reconstructed voxel model, which contains the following properties: `voxel_model.cell_data[key_added]`, the `label` array; `voxel_model.cell_data[f'{key_added}_rgba']`, the rgba colors of the `label` array. `voxel_model.cell_data['obs_index']`, the cell labels if not (voxel_pc is None). plot_cmap: Recommended colormap parameter values for plotting. :rtype: voxel_model .. py:function:: voxelize_pc(pc: pyvista.PolyData, voxel_size: Optional[numpy.ndarray] = None) -> pyvista.UnstructuredGrid Voxelize the point cloud. :param pc: A point cloud model. :param voxel_size: The size of the voxelized points. The shape of voxel_size is (pc.n_points, 3). :returns: A voxel model. :rtype: voxel