mesa.ecospatial.calculate_diversity_index

mesa.ecospatial.calculate_diversity_index(spatial_data, library_key, library_id, spatial_key, patches, cluster_key, metric='Shannon Diversity', return_comp=False)

Calculate the heterogeneity index for a set of patches using specified metrics.

Parameters:
  • spatial_data (Union[ad.AnnData, pd.DataFrame]) – The spatial data to be analyzed. This can be either an AnnData object or a DataFrame.

  • library_key (str) – Key to access the library data within spatial_data.

  • library_id (str) – Identifier for the library to analyze within spatial_data.

  • spatial_key (Union[str, List[str]]) – Key(s) to access spatial coordinates or related data in spatial_data.

  • patches (list) – List of spatial regions or patches to compute the diversity index for.

  • cluster_key (str) – Key to access clustering data, defining groups within patches.

  • metric (str, optional) – The diversity metric to use, e.g., ‘Shannon Diversity’. Default is ‘Shannon Diversity’.

  • return_comp (bool, optional) – If True, returns a comprehensive result object containing additional details along with the heterogeneity indices. Default is False.

Returns:

If return_comp is False, returns a pd.Series with heterogeneity indices for each patch. If return_comp is True, returns an additional pd.Series with cell compositions.

Return type:

pd.Series