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 thelabels_layer
, and saves it as a table layer insdata
asoutput_layer
. Average intensity per metacluster is calculated using themapping
.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 tosdata.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 usingsp.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 ofsdata
from which the intensity is calculated.labels_layer (
Union
[str
,Iterable
[str
]]) – The labels layer insdata
that contains the SOM cluster IDs. I.e. theoutput_layer_clusters
labels layer obtained throughsp.im.flowsom
.output_layer (
str
) – The output table layer insdata
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 forc
,(z)
,y
,x
.overwrite (default:
False
) – If True, overwrites theoutput_layer
if it already exists insdata
.
- 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.