squidpy.im.ImageContainer.add_img

ImageContainer.add_img(img, layer=None, dims='default', library_id=None, lazy=True, chunks=None, copy=True, **kwargs)[source]

Add a new image to the container.

Parameters
  • img (Union[str, Path, ndarray[Any, dtype[Any]], DataArray, ImageContainer]) – In-memory 2, 3 or 4-dimensional array, a URL to a Zarr store (ending in .zarr), or a path to an on-disk image.

  • layer (Optional[str]) – Image layer in img that should be processed. If None and only 1 layer is present, it will be selected.

  • dims (Union[Literal[‘default’, ‘prefer_channels’, ‘prefer_z’], Sequence[str]]) –

    Where to save channel dimension when reading from a file or loading an array. Valid options are:

    • ’channels_last’ - load the last non-spatial dimension as channels.

    • ’z_last’ - load the last non-spatial dimension as Z-dimension.

    • ’default’ - same as ‘channels_last’, but for 4-dimensional arrays, tries to also load the first dimension as channels if the last non-spatial dimension is 1.

    • a sequence of dimension names matching the shape of img, e.g. ('y', 'x', 'z', 'channels'). ‘y’, ‘x’ and ‘z’ must always be present.

  • library_id (Union[str, Sequence[str], None]) – Name for each Z-dimension of the image. This should correspond to the library_id in anndata.AnnData.uns.

  • lazy (bool) – Whether to use dask to lazily load image.

  • chunks (Union[str, tuple[int, ...], None]) – Chunk size for dask. Only used when lazy = True.

  • copy (bool) – Whether to copy the underlying data if img is an in-memory array.

Return type

None

Returns

Nothing, just adds a new layer to data.

Raises
  • ValueError – If loading from a file/store with an unknown format or if a supplied channel dimension cannot be aligned.

  • NotImplementedError – If loading a specific data type has not been implemented.