apply_along_da_axis#
- movement.utils.broadcasting.apply_along_da_axis(f, data, dimension, new_dimension_name=None)[source]#
Apply a function
f
acrossdimension
ofdata
.f
should be callable asf(input_1D)
whereinput_1D
is a one- dimensionalnumpy.typing.ArrayLike
object. It should return either a scalar or one-dimensionalnumpy.typing.ArrayLike
object.- Parameters:
f (Callable) – Function that takes 1D inputs and returns either scalar or 1D outputs. This will be cast across the
dimension
of thedata
.data (xarray.DataArray) – Values to be cast over.
dimension (str) – Dimension of
data
to broadcastf
across.new_dimension_name (str, optional) – If
f
returns non-scalar values, the dimension in the output that these values are returned along is given the namenew_dimension_name
. Defaults to"result"
.
- Returns:
Result of broadcasting
f
along thedimension
ofdata
.If
f
returns a scalar or(1,)
-shaped output, the output has one fewer dimension thandata
, withdimension
being dropped. All other dimensions retain their names and sizes.If
f
returns a(n,)
-shaped output forn > 1
; all non-dimension
dimensions ofdata
retain their shapes. Thedimension
dimension itself is replaced with a new dimension,new_dimension_name
, containing the output of the application off
.
- Return type: