spateo.tdr.interpolations ========================= .. py:module:: spateo.tdr.interpolations Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/spateo/tdr/interpolations/interpolation_deeplearn/index /autoapi/spateo/tdr/interpolations/interpolation_dl/index /autoapi/spateo/tdr/interpolations/interpolation_gaussianprocess/index /autoapi/spateo/tdr/interpolations/interpolation_gp/index /autoapi/spateo/tdr/interpolations/interpolation_sparseVFC/index /autoapi/spateo/tdr/interpolations/interpolation_vtk/index /autoapi/spateo/tdr/interpolations/utils/index Functions --------- .. autoapisummary:: spateo.tdr.interpolations.deep_intepretation spateo.tdr.interpolations.gp_interpolation spateo.tdr.interpolations.kernel_interpolation spateo.tdr.interpolations.vtk_interpolation spateo.tdr.interpolations.get_X_Y_grid Package Contents ---------------- .. py:function:: deep_intepretation(source_adata: anndata.AnnData, target_points: Optional[numpy.ndarray] = None, keys: Union[str, list] = None, spatial_key: str = 'spatial', layer: str = 'X', max_iter: int = 1000, data_batch_size: int = 2000, autoencoder_batch_size: int = 50, data_lr: float = 0.0001, autoencoder_lr: float = 0.0001, **kwargs) -> anndata.AnnData Learn a continuous mapping from space to gene expression pattern with the deep neural net model. :param source_adata: AnnData object that contains spatial (numpy.ndarray) in the `obsm` attribute. :param target_points: The spatial coordinates of new data point. If target_coords is None, generate new points based on grid_num. :param keys: Gene list or info list in the `obs` attribute whose interpolate expression across space needs to learned. :param spatial_key: The key in ``.obsm`` that corresponds to the spatial coordinate of each bucket. :param layer: If ``'X'``, uses ``.X``, otherwise uses the representation given by ``.layers[layer]``. :param max_iter: The maximum iteration the network will be trained. :param data_batch_size: The size of the data sample batches to be generated in each iteration. :param autoencoder_batch_size: The size of the auto-encoder training batches to be generated in each iteration. Must be no greater than batch_size. . :param data_lr: The learning rate for network training. :param autoencoder_lr: The learning rate for network training the auto-encoder. Will have no effect if network_dim equal data_dim. :param \*\*kwargs: Additional parameters that will be passed to the training step of the deep neural net. :returns: an anndata object that has interpolated expression. :rtype: interp_adata .. py:function:: gp_interpolation(source_adata: anndata.AnnData, target_points: Optional[numpy.ndarray] = None, keys: Union[str, list] = None, spatial_key: str = 'spatial', layer: str = 'X', training_iter: int = 50, device: str = 'cpu', method: Literal['SVGP', 'ExactGP'] = 'SVGP', batch_size: int = 1024, shuffle: bool = True, inducing_num: int = 512, verbose: bool = True) -> anndata.AnnData Learn a continuous mapping from space to gene expression pattern with the Gaussian Process method. :param source_adata: AnnData object that contains spatial (numpy.ndarray) in the `obsm` attribute. :param target_points: The spatial coordinates of new data point. If target_coords is None, generate new points based on grid_num. :param keys: Gene list or info list in the `obs` attribute whose interpolate expression across space needs to learned. :param spatial_key: The key in ``.obsm`` that corresponds to the spatial coordinate of each bucket. :param layer: If ``'X'``, uses ``.X``, otherwise uses the representation given by ``.layers[layer]``. :param training_iter: Max number of iterations for training. :param device: Equipment used to run the program. You can also set the specified GPU for running. ``E.g.: '0'``. :returns: an anndata object that has interpolated expression. :rtype: interp_adata .. py:function:: kernel_interpolation(source_adata: anndata.AnnData, target_points: Optional[numpy.ndarray] = None, keys: Union[str, list] = None, spatial_key: str = 'spatial', layer: str = 'X', lambda_: float = 0.02, lstsq_method: str = 'scipy', **kwargs) -> anndata.AnnData Learn a continuous mapping from space to gene expression pattern with Kernel method (sparseVFC). :param source_adata: AnnData object that contains spatial (numpy.ndarray) in the `obsm` attribute. :param target_points: The spatial coordinates of new data point. If target_coords is None, generate new points based on grid_num. :param keys: Gene list or info list in the `obs` attribute whose interpolate expression across space needs to learned. :param spatial_key: The key in ``.obsm`` that corresponds to the spatial coordinate of each bucket. :param layer: If ``'X'``, uses ``.X``, otherwise uses the representation given by ``.layers[layer]``. :param lambda_: Represents the trade-off between the goodness of data fit and regularization. Larger Lambda_ put more weights on regularization. :param lstsq_method: The name of the linear least square solver, can be either 'scipy` or `douin`. :param \*\*kwargs: Additional parameters that will be passed to SparseVFC function. :returns: an anndata object that has interpolated expression. :rtype: interp_adata .. py:function:: vtk_interpolation(source_adata: anndata.AnnData, target_points: Optional[numpy.ndarray] = None, keys: Union[str, list] = None, spatial_key: str = 'spatial', layer: str = 'X', radius: Optional[float] = None, n_points: Optional[int] = None, kernel: Literal['shepard', 'gaussian', 'linear'] = 'shepard', null_strategy: Literal[0, 1, 2] = 1, null_value: Union[int, float] = 0) -> anndata.AnnData Learn a continuous mapping from space to gene expression pattern with the method contained in VTK. :param source_adata: AnnData object that contains spatial (numpy.ndarray) in the `obsm` attribute. :param target_points: The spatial coordinates of new data point. If target_coords is None, generate new points based on grid_num. :param keys: Gene list or info list in the `obs` attribute whose interpolate expression across space needs to learned. :param spatial_key: The key in ``.obsm`` that corresponds to the spatial coordinate of each bucket. :param layer: If ``'X'``, uses ``.X``, otherwise uses the representation given by ``.layers[layer]``. :param 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. :param n_points: Specify the number of points for the source object to hold. If n_points (number of the closest points to use) is set then radius value is ignored. :param kernel: The kernel of interpolations kernel. Available `kernels` are: * `shepard`: vtkShepardKernel is an interpolations kernel that uses the method of Shepard to perform interpolations. 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 interpolations 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 interpolations kernel that averages the contributions of all points in the basis. :param null_strategy: Specify a strategy to use when encountering a "null" point during the interpolations 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 interpolations. :param null_value: see above. :returns: an anndata object that has interpolated expression. :rtype: interp_adata .. py:function:: 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. :param adata: AnnData object that contains spatial (numpy.ndarray) in the `obsm` attribute. :param 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. :param X: The spatial coordinates of each data point. :param Y: The gene expression of the corresponding data point. :param 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. :rtype: X