apply_ufunc
Xarray method that applies custom function on underlying array in xarray. The underlying array can be a numpy or a dask array (need verification).
How it works?
- When xarray DataArray is given to
apply_ufunc
, it gets the underlying array, and passes to the custom function. Custom function returns the result array which again wrapped byapply_ufunc
and returned to us. - When xarray DataSet is given, it loops over the data variables(DataArray), passes each of the data array to the custom function, gets the result array and wraps in Data Array and then in Data set and returns.
- All the input DataSet/DataArray metadata gets populated on the result by
apply_ufunc
. - By default, attributes are not populated on the result but can retained using
keep_attrs=True
.
Note
vectorize=True
doesn’t work when input array is a dask array.
Syntax
It is the minimal syntax
xr.apply_ufunct(custom_function, dataset/dataarray, pos_args, kwargs={}, keep_attrs=True)
input_core_dims
- This parameter takes the dimensions to which the function would be operated on.
- specified dimensions are moved to last. for example,
input_core_dims=["time"]("time")
will be moved to last dimension.