squidpy.im.ImageContainer.generate_spot_crops
- ImageContainer.generate_spot_crops(adata, spatial_key='spatial', library_id=None, spot_diameter_key='spot_diameter_fullres', spot_scale=1.0, obs_names=None, as_array=False, squeeze=True, return_obs=False, **kwargs)[source]
Iterate over
anndata.AnnData.obs_namesand extract crops.Implemented for 10X spatial datasets. For Z-stacks, the specified
library_idor list oflibrary_idneed to match the name of the Z-dimension. Always extracts 2D crops from the specified Z-dimension.- Parameters:
adata (
AnnData) – Annotated data object.spatial_key (
str) – Key inanndata.AnnData.obsmwhere spatial coordinates are stored.library_id (
Sequence[str] |str|None) –If None, there should only exist one entry in
anndata.AnnData.uns['{spatial_key}'].If a
str, first searchanndata.AnnData.obs['{library_id}']which contains the mapping from observations to library ids, then searchanndata.AnnData.uns['{spatial_key}'].
spot_diameter_key (
str) – Key inanndata.AnnData.uns['{spatial_key}']['{library_id}']['scalefactors']where the spot diameter is stored.spot_scale (
float) – Scaling factor for the spot diameter. Larger values mean more context.obs_names (
Iterable[Any] |None) – Observations fromanndata.AnnData.obs_namesfor which to generate the crops. If None, all observations are used.If True, yields a
dictwhere keys are layers and values arenumpy.ndarray.If a
str, yields onenumpy.ndarrayfor the specified layer.If a
typing.Sequence, yields atupleofnumpy.ndarrayfor the specified layers.Otherwise, yields
squidpy.im.ImageContainer.
squeeze (
bool) – Remove singleton dimensions from the results ifas_array = True.return_obs (
bool) – Whether to also yield names fromobs_names.kwargs (
Any) – Keyword arguments forcrop_center().
- Yields:
If
return_obs = True, yields atuple(crop, obs_name). Otherwise, yields just the crops.The type of the crops depends on
as_arrayand the number of dimensions onsqueeze.
- Return type:
Iterator[ImageContainer] |Iterator[ndarray[tuple[Any,...],dtype[Any]]] |Iterator[tuple[ndarray[tuple[Any,...],dtype[Any]],...]] |Iterator[dict[str,ndarray[tuple[Any,...],dtype[Any]]]]