squidpy.im.ImageContainer.apply
- ImageContainer.apply(func, layer=None, new_layer=None, channel=None, lazy=False, chunks=None, copy=True, drop=True, fn_kwargs=mappingproxy({}), **kwargs)[source]
Apply a function to a layer within this container.
For each Z-dimension a different function can be defined, using its
library_idname. For not mentionedlibrary_id’s the identity function is applied.- Parameters:
func (
Callable[...,ndarray[tuple[Any,...],dtype[Any]]] |Mapping[str,Callable[...,ndarray[tuple[Any,...],dtype[Any]]]]) – A function or a mapping of{'{library_id}': function}which takes anumpy.ndarrayas input and produces an image-like output.layer (
str|None) – Image layer inimgthat should be processed. If None and only 1 layer is present, it will be selected.new_layer (
str|None) – Name of the new layer. If None andcopy = False, overwrites the data inlayer.channel (
int|None) – Applyfunconly over a specificchannel. If None, use all channels.chunks (
str|tuple[int,int] |None) – Chunk size for Dask. If None, don’t use Dask.copy (
bool) – IfTrue, return the result, otherwise save it to the image container.drop (
bool) – Whether to drop Z-dimensions that were not selected byfunc. Only used whencopy = True.kwargs (
Any) – Keyword arguments fordask.array.map_overlap()ordask.array.map_blocks(), depending whetherdepthis present infn_kwargs. Only used whenchunks != None. Usedepthto control boundary artifacts iffuncrequires data from neighboring chunks, by default,boundary = 'reflectis used.
- Return type:
- Returns:
If
copy = True, returns a new container withlayer.- Raises:
ValueError – If the
funcreturns 0 or 1 dimensional array.