Parallelizing custom functions
Parallelizing custom functions#
Almost all of xarray’s built-in operations work on Dask arrays.
Sometimes analysis calls for functions that aren’t in xarray’s API (e.g. scipy). There are three ways to apply these functions in parallel on each block of your xarray object:
Use apply_ufunc to apply functions that consume and return duck arrays. This automates extracting the data from Xarray objects, applying a function, and then converting the bare array result back to a Xarray object.
Which method you use ultimately depends on the type of input objects expected by the function you’re wrapping, and the level of performance or convenience you desire.