I don't use GEE a lot but I have to use it to extract daily rainfall data from the CHIRPS database. It should be simple but I am stuck. The outcome should be one CSV file with three columns: polygon code, date, mean rainfall (using zonal statistics). I tried the following code. It works for a single image but I am struggling to map it over the image collection.
var imgcol = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY"),
coc = ee.FeatureCollection("users/asifishti/CoC_subdis")
//The shapefile is available here:
//https://code.earthengine.google.com/?asset=users/asifishti/CoC_subdis
//Time range
var img_col = imgcol.filter(ee.Filter.date ('2005-01-01', '2010-12-30'));
var image = img_col.first()
//deriving the date of the image
var date= image.get('system:index')
//zonal statistics
var mean_rain = function (feature){
var rain = img.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: feature.geometry(),
scale: 5500, //the CHIRPS dataset has 0.05 degree resolution
maxPixels: 5e12
});
var sdis_rain = feature.set('Mean Rainfall', rain.get('precipitation'))
.set ("Date", date);
return sdis_rain;
};
//running the function for all features in the shapefile
var rainfall = coc.map(mean_rain);
print (rainfall);
Export.table.toDrive ({
collection: rainfall,
description: 'Mean Rain',
selectors: ['subdistric', 'Date', 'Mean Rainfall']
})