Apply function on coordinate pair along particular axis using multiple variables in Xarray

1.1k views Asked by At

My xarray Dataset has three dimensions,

  • x,y,t

and 2 variables,

  • foo, bar

I would like to apply function baz() on every x, y coordinate pair's time series t

baz() will accept an array of foo-s and and array of bar-s for a given (x, y)

I'm having a tough time understanding whether or not built in structures to handle/distribute this exists in either, xarray, pandas, numpy, or dask.

Any hints?

My current approach is writing a python array iterator, or exploring ufunc:

  • The issues with iterating over something in python is that I have to deal with concurrency myself and that there is overhead in the iteration.

  • The issues with ufunc is that I don't understand it enough and seems like it's a function that is applied to individual elements of the array, not subsets along axes.

The hopeful part of me is looking for something that is xarray native or daskable.

1

There are 1 answers

2
j08lue On BEST ANSWER

Sounds (vaguely) like you are looking for Dataset.reduce:

ds.reduce(baz, dim=('x', 'y'))