It took me a while to compute this script, it works perfectly, but I think that it is very raw and long.
The goal of the script is to produce a graph of cumulated rainfall with 3 lines:
- Cumulated rainfall of the rainiest year
- Cumulated rainfall in the current year (for example from 1st January until April)
- Cumulated rainfall of the driest year
Do you have any suggestions on how to simplify the script?
// Cumulative function
var compute = function(day) {
// Filter the collection from start date till the day of computatiton
var begin1 = startMin
var begin2 = start
var begin3 = startMax
var current1 = startMin.advance(day, 'day')
var current2 = start.advance(day, 'day')
var current3 = startMax.advance(day, 'day')
var filtered1 = collMin.filter(ee.Filter.date(begin1, current1))
var filtered2 = coll.filter(ee.Filter.date(begin2, current2))
var filtered3 = collMax.filter(ee.Filter.date(begin3, current3))
// Use sum() to calculate total rainfall in the period
// Make sure to set the start_time for the image
var cumulativeImage = filtered1.reduce(ee.Reducer.sum())
.set('system:time_start', current1.millis()).rename('min')
.addBands(filtered2.reduce(ee.Reducer.sum())
.set('system:time_start', current2.millis()).rename('current'))
.addBands(filtered3.reduce(ee.Reducer.sum())
.set('system:time_start', current3.millis()).rename('max'))
return cumulativeImage
}
The code is also available on Google Earth Engine.