voyagerpy.spatial.set_geometry#

voyagerpy.spatial.set_geometry(adata: AnnData, geom: str, values: GeoSeries | None = None, index: Index | None = None, dim: str | Literal['barcode', 'gene'] = 'barcode', inplace: bool = True) AnnData#

Set the geometry of the AnnData object. This function sets the geometry of the AnnData object in adata.obsm["geometry"], which is a gpd.GeoDataFrame. If the geometry dataframe does not exist, it will be created. If values is not None, it will be set as the geometry values.

Parameters:
  • adata (AnnData) – Annotated data matrix

  • geom (str) – The name of the geometry column to set. If the column does not exist, it will be created and populated with values.

  • values (Optional[gpd.GeoSeries], optional) – The geometry series to populate the geom column with, by default None. Must not be None if the column geom does not exist.

  • index (Optional[pd.Index], optional) – The index to associate with values. If None, will use the geometry dataframe’s indexing, by default None`.

  • dim (Union[str, Literal["barcode", "gene"]], optional) – The type of geometry to set, by default “barcode”. If “barcode”, will set the geometry of the barcodes. If “gene”, will set the geometry of the genes. Otherwise, the geometry is assumed to be annotation geometry, residing in adata.uns[“spatial”][“geometry][dim]. Defaults to “barcode”.

  • inplace (bool, optional) – Whether to modify adata inplace. If False, a copy is made, by default True.

Returns:

The updated AnnData object. If inplace is True, returns a copy. This object will have geom column in the respective geometry dataframe set as its geometry.

Return type:

AnnData

Raises:

ValueError – If values is None and geom does not exist.