ImageContainer.generate_spot_crops

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 of library_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 (default: 'spatial')

Key in anndata.AnnData.obsm where spatial coordinates are stored.

library_id Sequence[str] | str | None (default: None)

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_names for which to generate the crops. If None, all observations are used.

as_array str | bool (default: False)

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().

Yields:
  • If return_obs = True, yields a tuple (crop, obs_name). Otherwise, yields just the crops.

  • The type of the crops depends on as_array and the number of dimensions on squeeze.

Return type:

Iterator[ImageContainer] | Iterator[NDArray[Any]] | Iterator[tuple[NDArray[Any], ...]] | Iterator[dict[str, NDArray[Any]]]