Script Library
AdvancedRainfallAdvanced
CHIRPS Standardized Precipitation Index (SPI-3 / SPI-12)
Drought indicator from 40+ years of CHIRPS — SPI at 3- and 12-month accumulation windows.
Pipeline (4 steps)
- CHIRPS pentad → monthly precipitation totals
- 3- and 12-month rolling sums
- Standardise vs 1981-2020 climatology
- Classify drought (D0..D4 / W0..W4)
Datasets
- chirps-daily
- chirps-pentad
Simulated previewPaste the script in Earth Engine for live results
Outputs the script produces
map SPI-3 map
map SPI-12 map
chart SPI time series
var chirps = ee.ImageCollection('UCSB-CHG/CHIRPS/PENTAD').filterBounds(aoi);
var months = ee.List.sequence(0, ee.Date(Date.now()).difference(ee.Date('1981-01-01'),'month').subtract(1));
var monthly = ee.ImageCollection(months.map(function(m){
var start = ee.Date('1981-01-01').advance(m,'month');
var end = start.advance(1,'month');
return chirps.filterDate(start, end).sum().rename('precip')
.set('system:time_start', start.millis());
}));
function spi(coll, window) {
var w = window;
var rolling = coll.map(function(i){
var d = ee.Date(i.get('system:time_start'));
return coll.filterDate(d.advance(-w+1,'month'), d.advance(1,'month'))
.sum().rename('p' + w)
.set('system:time_start', d.millis());
});
var clim = rolling.filterDate('1981-01-01','2021-01-01');
var mu = clim.mean(), sd = clim.reduce(ee.Reducer.stdDev());
return rolling.map(function(i){ return i.subtract(mu).divide(sd).rename('SPI'+w)
.copyProperties(i, ['system:time_start']); });
}
var spi3 = spi(monthly, 3);
var spi12 = spi(monthly, 12);
Map.centerObject(aoi, 5);
Map.addLayer(spi3.sort('system:time_start', false).first(),
{min:-2.5, max:2.5, palette:['#7f1d1d','#ef4444','#fde047','#22c55e','#1e3a8a']}, 'SPI-3 latest');
Export.image.toDrive({image: spi3.sort('system:time_start',false).first().clip(aoi),
description: 'SPI3_latest', folder: 'gee_exports', region: aoi, scale: 5000, maxPixels: 1e13});import ee
ee.Initialize()