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_id
name. For not mentionedlibrary_id
’s the identity function is applied.- Parameters:
func (
Union
[Callable
[...
,ndarray
[Any
,dtype
[Any
]]],Mapping
[str
,Callable
[...
,ndarray
[Any
,dtype
[Any
]]]]]) – A function or a mapping of{'{library_id}': function}
which takes anumpy.ndarray
as input and produces an image-like output.layer (
Optional
[str
]) – Image layer inimg
that should be processed. If None and only 1 layer is present, it will be selected.new_layer (
Optional
[str
]) – Name of the new layer. If None andcopy = False
, overwrites the data inlayer
.channel (
Optional
[int
]) – Applyfunc
only over a specificchannel
. If None, use all channels.chunks (
Union
[str
,tuple
[int
,int
],None
]) – Chunk size fordask
. If None, don’t usedask
.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 whetherdepth
is present infn_kwargs
. Only used whenchunks != None
. Usedepth
to control boundary artifacts iffunc
requires data from neighboring chunks, by default,boundary = 'reflect
is used.
- Return type:
- Returns:
: If
copy = True
, returns a new container withlayer
.- Raises:
ValueError – If the
func
returns 0 or 1 dimensional array.