I'm looking to sum precipitation for a period of 10-days prior to a specified date. This is just an example - in fact, I have around 60 different dates and I don't want to select each the date manually as done below. Is there a way to iterate through the dates?
// CSV file
var coord = ee.FeatureCollection("users/eginamalaj/site_test");
// Select sampling date
var datesampl = '2018-05-06';
var s1 = coord.filter(ee.Filter.eq('date', datesampl));
// Assign time interval
var dates = new Date(datesampl);
var start = new Date(dates.getTime() - 10*24*60*60*1000); // 10-days before
var end = new Date(dates.getTime() - 1*24*60*60*1000); // exclude sampling day
// Get image and sum for the time interval
var precImage = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
.filterBounds(coord)
.filterDate(start, end)
.select('precipitation')
.sum();
// Extract precipitation for the sampling sites
var precSample = precImage.sampleRegions({
collection: s1,
scale: 30,
geometries: true
});
//////// Repeat above with a different date
var datesampl2 = '2018-09-12'
var s2 = coord.filter(ee.Filter.eq('date', datesampl2));
var dates2 = new Date(datesampl2);
var start2 = new Date(dates2.getTime() - 10*24*60*60*1000); // 10-days before
var end2 = new Date(dates2.getTime() - 1*24*60*60*1000); // exclude sampling day
var precImage2 = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
.filterBounds(coord)
.filterDate(start, end)
.select('precipitation')
.sum();
var precSample2 = precImage2.sampleRegions({
collection: s1,
scale: 30,
geometries: true
});
// Combine them
var combined = precSample.merge(precSample2);
print(combined);
Code and data: https://code.earthengine.google.com/cd0a2c60fb8ddefbb9508abfc1a806bb