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(default:'spatial') Key in
anndata.AnnData.obsmwhere spatial coordinates are stored.- library_id
Sequence[str] |str|None(default: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(default:'spot_diameter_fullres') Key in
anndata.AnnData.uns['{spatial_key}']['{library_id}']['scalefactors']where the spot diameter is stored.- spot_scale
float(default:1.0) Scaling factor for the spot diameter. Larger values mean more context.
- obs_names
Iterable[Any] |None(default:None) Observations from
anndata.AnnData.obs_namesfor which to generate the crops. If None, all observations are used.- as_array
str|bool(default:False) 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(default:True) Remove singleton dimensions from the results if
as_array = True.- return_obs
bool(default:False) Whether to also yield names from
obs_names.- kwargs
Any Keyword arguments for
crop_center().
- adata
- 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[Any]] |Iterator[tuple[NDArray[Any],...]] |Iterator[dict[str,NDArray[Any]]]