voyagerpy.spatial.compute_spatial_lag#
- voyagerpy.spatial.compute_spatial_lag(adata: AnnData, feature: str, graph_name: None | str | ndarray = None, inplace: bool = False, layer: str | None = None) AnnData#
Compute the spatial lag of a feature. The spatial lag is the weighted average of the feature in the neighborhood of each spot.
- Parameters:
adata (AnnData) – the AnnData object to compute the spatial lag for.
feature (str) – The feature to compute the spatial lag for. Must be a column in
adata.obsor in``adata.var_names``.graph_name (Union[None, str, np.ndarray], optional) – The neighborhood graph to use, defaults to None. If None, use the default graph. If a string, use the graph stored in
adata.uns["spatial"][graph_name]. If an array, use the array as the adjacency matrix.inplace (bool, optional) – Whether to add the lagged_features to the AnnData object in place or copy it, defaults to False
layer (Optional[str], optional) – If not None, use this layer for the feature if the feature is a gene, defaults to None
- Raises:
TypeError – If the graph_name is not of type
None,str, ornp.ndarray.- Returns:
The updated AnnData object. The spatial lag is stored in
adata.obs["lagged_" + feature]. If inplace is False, the return a copy of AnnData.- Return type:
AnnData