mantispy.tl.neighbors_local_density#
- mantispy.tl.neighbors_local_density(adata, k=15, by='Metadata_ImageID', key_added='Metadata_LocalDensity', copy=False)[source]#
Local cell density: how many cells per unit area surround each cell in its field of view.
The density is the
k-nearest-neighbour estimate,kdivided by the area of the disc reaching thek-th nearest cell, in cells per square unit ofMetadata_Center_XandMetadata_Center_Y(usually pixels). Higher means more crowded. Local crowding changes morphology independently of treatment. Consider regressing it out withregress_out()before attributing a change to a perturbation.- Parameters:
- adata
AnnData Single-cell object carrying
Metadata_Center_XandMetadata_Center_Y.- k
int(default:15) Number of neighbors whose disc sets the density; a field with fewer cells uses all of them.
- by
str(default:'Metadata_ImageID') obscolumn identifying the field of view. Neighbors are searched within each field only, since coordinates from different images are not comparable.- key_added
str(default:'Metadata_LocalDensity') obscolumn written.- copy
bool(default:False) Return a modified copy instead of mutating in place.
- adata
- Return type:
- Returns:
None, or the modified copy. Writesobs[key_added], and a cell alone in its field, or one sharing its position with all of its neighbours, getsNaN.- Raises:
KeyError –
obsis missingMetadata_Center_XorMetadata_Center_Y.