I have written a code that is taking data from MODIS about NDVI, filter for March only , calculates the mean value for the whole month and clip it with geometry. The NDVI data is for period of years, for example, from 2000-2003.
The problem is that I need to run this process for few periods, 2000-2003, 2004-2007 and more and I dont want to use copy paste. So I want to create a loop but I'm coming from python and the exmples I have seen here in this forum confused me a little because I dont understand what the loop contains.
If someone can explain me the logic or how to put it inside a loop it will be very helpful.
This is the code I have worked on untill now:
var dataset = ee.ImageCollection('MODIS/006/MOD13A1')
.filter(ee.Filter.date('2000-03-01', '2003-03-31'))
.select('NDVI');
// filter the image collection to contain only images from March
var onlyMarch = dataset.filter(ee.Filter.calendarRange(3, 3,'month'));
print(onlyMarch);
// make a composite (mean image) of the images of March and clip to the geometry
var meanImage = onlyMarch.mean().clip(table).divide(10000);
print(meanImage);
var mean20002003 = meanImage.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: table,
scale:500
});
//var ndvi = dataset.select('NDVI')
var ndviParams = {min: 0, max: 1, palette: [
'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
'66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
'012E01', '011D01', '011301'
]};
Map.centerObject(table, 7);
Map.addLayer(meanImage,ndviParams,'NDVI20002003');
print(mean20002003,'mean NDVI 2000-2003')