sbegueria / SPEI

An R package for computing the Standardized Precipitation-Evapotranspiration Index (SPEI), Penman-Monteith and other reference evapotranspiration, SPI, etc.
78 stars 34 forks source link

Unclear incidence of NA values in SPEI calculation #60

Open Strossi opened 1 year ago

Strossi commented 1 year ago

Hi, I am using this nice function to calculate future drought occurence globally. I computed the waterbalance using thorntwaite PET from tas deducted from precipitation data.

However, some locations on the planet, in the future stages (e.g. 2100, nlyr = 1572), are NA

I have done some analysis of some of these locations passing the waterbalance timeseries into the spei computation: e.g. for waterbalance layer 1501:1572 (2095 Jan-2100 Dec) we have values (in mm/month): 27.952274 21.689123 14.123683 17.460701 15.812398 37.006592 -66.429031 -259.123688 -220.037247 -97.774490 16.421326 19.157841 8.140391 9.198980 10.007673 6.265563 16.597578 29.495974 -100.427887 -332.850922 -331.282867 -96.347923 22.364281 9.272121 11.917697 23.926107 16.230862 27.928892 9.588178 19.053209 5.622412 -274.853882 -356.673981 -155.222855 -15.708746 17.407471 23.696455 25.058372 8.793851 14.453787 22.954494 18.429659 -32.144138 -337.259491 -323.165253 -114.420425 -12.792349 22.798891 12.963151 21.595062 14.063710 37.609177 16.736898 20.830385 -152.715103 -376.798645 -339.518524 -124.014435 -15.229343 11.399895 11.069696 11.272403 2.432789 15.543382 5.513311 3.631964 20.173397 -59.663048 -119.842651 -238.099121 -6.724354 17.916309 23.279354

Passing it into SPEI spei(data = wb_ts[1501:1572], scale = 3, na.rm = F, verbose = F)

Passing wb_ts[1524:1572] or +1524 starts returning non-finite values.

However, what is critical is that when the entire gcm + historical reference is passed to SPEI, some of the values are again NA, even if they are not NA in subsets (1501:1572 e.g.).

Would love to understand why this occurs.