opendvp.io.adata_to_voronoi#
- adata_to_voronoi(adata, x_y=('X_centroid', 'Y_centroid'), classify_by=None, color_dict=None, voronoi_area_quantile=0.98, merge_adjacent_shapes=False, save_as_detection=True)#
Generate a GeoDataFrame of Voronoi polygons from AnnData centroids.
This function computes Voronoi polygons from centroid coordinates in AnnData.obs Optionally annotates them with class labels and colors for QuPath, and returns a GeoDataFrame.
- Return type:
GeoDataFrame
|None
Parameters:#
- adata: AnnData
AnnData object with cell metadata and centroid coordinates.
- x_y: tuple, default (“X_centroid”, “Y_centroid”)
Tuple of column names in adata.obs for X and Y coordinates.
- classify_by: str or None, optional
Column in adata.obs to use for classifying detections (e.g., cell type).
- color_dict: dict or None, optional
Dictionary mapping class/category names to RGB color lists.
- voronoi_area_quantile: float or None, default 0.98
Area quantile threshold for filtering large Voronoi polygons.
- merge_adjacent_shapes: bool, default False
If True, merges adjacent polygons of the same class.
- save_as_detection: bool, default True
If True, sets ‘objectType’ to ‘detection’ for QuPath.
Returns:#
- GeoDataFrame:
GeoDataFrame of Voronoi polygons with optional class/color annotation.
Raises:#
- ValueError:
If required columns are missing or input types are incorrect.
Examples:#
>>> import anndata as ad >>> import pandas as pd >>> import numpy as np >>> from opendvp.io.adata_to_voronoi import adata_to_voronoi >>> obs = pd.DataFrame( ... {"X_centroid": np.random.rand(5), "Y_centroid": np.random.rand(5), "celltype": ["A", "B", "A", "B", "A"]} ... ) >>> adata = ad.AnnData(obs=obs) >>> gdf = adata_to_voronoi(adata, classify_by="celltype") >>> print(gdf.head())