Is anyone aware of a toolbox to calculate climate indices from xarray datasets/dataarrays. I’m specifically looking for drought indices (SPI, SPEI, PDSI) and Nino regions indices. But other indices such as NAO, MJO, PDO would be useful as well.
I am aware: xclim (which do not contain the above mentioned indices) and the climate indices package which can be made to work with xarray but do not have the oceanic indices.
One needed feature is the ability to choose the reference period for calculating these indices.
This is an interesting question Deborah, thanks for asking.
Could you say more about why you think this package would be valuable?
I am of the opinion (with is just that, MY opinion, not the last word) that perhaps we do not necessarily want or need such a package. Hopefully the indices are simple enough that they can be computed through a few straightforward lines of xarray code. (For example, I assign the Nino3.4 index as a homework problem.)
Most of the complexity of calculating an index is not in the generic definition of the index itself, but rather dealing with the peculiarities of the input dataset. What sort of grid is it on? How do I perform a regional average appropriate to that grid? Do I need to resample in time? What are the variables named? Do the units need to be converted? etc. etc. etc. It would be very hard to maintain a “package” to handle all of this special logic for each possible dataset out there in the wild. New special cases would probably have to be added for almost every new possible input dataset. So I see this as a case where providing a package is probably not worth the effort in terms of maintenance.
Instead, a better value in terms of effort would probably be obtained by creating a pure documentation site which gives examples of how to calculate each index for a few different datasets. This code could then be copied / modified by users who wish to adapt it to their particular dataset.
I was thinking along the lines of having the few lines of code after pre-processing. Pure documentation would work along with examples for some special cases.
I’m actually wondering why xclim is not included in the pangeo image for the bias-correction functionality. This is the only package that I am aware of that nicely enables what I’m looking for (trend-preserving quantile-based approach) in an xarray-friendly way.
I’m less interested in the climate indices, though to @rabernat 's concern, they do seem to be attending to a lot of the pre- and post-processing things that one would need to do, and have nice documentation.
mapping the abstract band names to specific datasets
While it was originally written for Earth Engine, the index definitions also can be used with xarray / dask via the spyndex package.
I realize that spectral indices are fairly simple, and don’t have to deal with many of the edge cases that @rabernat mentions. They are usually applied per pixel, and any spatial grid / resampling considerations are separate (i.e. handled during pre- or post-processing). They are usually applied to individual (multi-band) rasters, so temporal resampling considerations are also separate. But many of the climate indices that I am most familiar with (ex: ETCCDI) could be handled similarly to the spectral indices. The drought indices (SPI, SPEI, PDSI) mentioned seem quite similar to the spectral index pattern.
It seems like the second set of climate indices (NAO, MJO, PDO) would require some type of generalization so the index definitions would include the spatial and/temporal regions of aggregation. But that doesn’t seem particularly problematic to do, and it probably wouldn’t add that much complexity to the model.