apply_along_da_axis#

movement.utils.broadcasting.apply_along_da_axis(f, data, dimension, new_dimension_name=None)[source]#

Apply a function f across dimension of data.

f should be callable as f(input_1D) where input_1D is a one- dimensional numpy.typing.ArrayLike object. It should return either a scalar or one-dimensional numpy.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 the data.

  • data (xarray.DataArray) – Values to be cast over.

  • dimension (str) – Dimension of data to broadcast f 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 name new_dimension_name. Defaults to "result".

Returns:

Result of broadcasting f along the dimension of data.

  • If f returns a scalar or (1,)-shaped output, the output has one fewer dimension than data, with dimension being dropped. All other dimensions retain their names and sizes.

  • If f returns a (n,)-shaped output for n > 1; all non- dimension dimensions of data retain their shapes. The dimension dimension itself is replaced with a new dimension, new_dimension_name, containing the output of the application of f.

Return type:

xarray.DataArray