sparrow.tb.cluster_intensity

sparrow.tb.cluster_intensity#

sparrow.tb.cluster_intensity(sdata, mapping, img_layer, labels_layer, output_layer, channels=None, chunks=10000, overwrite=False)#

Calculates average intensity of each channel in img_layer per SOM cluster as available in the labels_layer, and saves it as a table layer in sdata as output_layer. Average intensity per metacluster is calculated using the mapping.

This function computes average intensity for each SOM cluster identified in the labels_layer and stores the results in a new table layer (output_layer). Average intensity per metacluster is added to sdata.tables[output_layer].uns. The intensity calculation can be subset by channels and adjusted for chunk size for efficient processing. SOM clusters can be calculated using sp.im.flowsom.

Parameters:
  • sdata (SpatialData) – The input SpatialData object.

  • mapping (Series) – A pandas Series mapping SOM cluster IDs (index) to metacluster IDs (values).

  • img_layer (Union[str, Iterable[str]]) – The image layer of sdata from which the intensity is calculated.

  • labels_layer (Union[str, Iterable[str]]) – The labels layer in sdata that contains the SOM cluster IDs. I.e. the output_layer_clusters labels layer obtained through sp.im.flowsom.

  • output_layer (str) – The output table layer in sdata where results are stored.

  • channels (Union[int, str, Iterable[int], Iterable[str], None] (default: None)) – Specifies the channels to be included in the intensity calculation.

  • chunks (str | int | tuple[int, ...] | None (default: 10000)) – Chunk sizes for processing. If provided as a tuple, it should contain chunk sizes for c, (z), y, x.

  • overwrite (default: False) – If True, overwrites the output_layer if it already exists in sdata.

Return type:

SpatialData

Returns:

: The input sdata with the new table layer added.

Raises:

AssertionError – If some labels in labels_layer are not found in the provided mapping pandas Series.

See also

sparrow.im.flowsom

flowsom pixel clustering.