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_names
and extract crops.Implemented for 10X spatial datasets. For Z-stacks, the specified
library_id
or list oflibrary_id
need 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.obsm
where spatial coordinates are stored.library_id (
Union
[str
,Sequence
[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 (
Optional
[Iterable
[Any
]]) – Observations fromanndata.AnnData.obs_names
for which to generate the crops. If None, all observations are used.If True, yields a
dict
where keys are layers and values arenumpy.ndarray
.If a
str
, yields onenumpy.ndarray
for the specified layer.If a
typing.Sequence
, yields atuple
ofnumpy.ndarray
for 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_array
and the number of dimensions onsqueeze
.
- Return type
Union
[Iterator
[ImageContainer
],Iterator
[ndarray
[Any
,dtype
[Any
]]],Iterator
[tuple
[ndarray
[Any
,dtype
[Any
]],...
]],Iterator
[dict
[str
,ndarray
[Any
,dtype
[Any
]]]]]