Climate Indices Toolbox

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.

Thanks in advance!

2 Likes

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.

1 Like

Hi Deborah,

You could ask xclim about adding the drought indices (or even contribute them!)

There is an issue about adding ocean “indicators”: Ocean-related indicator · Issue #415 · Ouranosinc/xclim · GitHub

Deepak

2 Likes

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.

1 Like

Thank you! Will add the ocean ones. And I can contribute SPI/SPEI.

2 Likes

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.

There is no reason. The image reflects what users in our environments ask for.

If you want to add xclim, a PR is welcome! pangeo-docker-images/environment.yml at master · pangeo-data/pangeo-docker-images · GitHub

Fair enough. I will prepare a PR, so that folks can give it consideration. Thanks!

GitHub - pankajkarman/bias_correction: python library for bias correction also corrects bias for xarray data types

As a potential approach for consideration, members of the Earth Engine community created:

The package defines spectral indices for optical and radar satellite observation datasets. It works by:

  • defining indices using abstract band names
  • 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.

  • Tyler
1 Like