For my Google Earth Engine project, I am finding the mean NDVI for each year between 2000 and 2020 in protected areas a part of the World Database on Protected Areas (WDPA). As an example, I have included code written to find the yearly mean NDVI values in Salonga National Park, which is located in the Democratic Republic of the Congo (DRC). I am using the MODIS vegetation index produced on 16-day intervals.
The code finds the mean NDVI value within the park boundaries and then places it into a dictionary with the years as keys and mean NDVI as values. Is there an easier/more concise way to write this code? This example finds the mean NDVI for 2000 and 2001 so far.
var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');
var drcongo = countries.filter(ee.Filter.eq('country_co', 'CG'));
var styleParams = {
fillColor: 'b5ffb4',
color: '868686',
width: 2.5,
opacity: 0.6,
};
//Map.addLayer(drcongo, styleParams, 'DRC');
Map.setCenter(23.5, -2.5, 6);
var salonga = ee.FeatureCollection('WCMC/WDPA/current/polygons')
.filter(ee.Filter.and(
ee.Filter.bounds(drcongo.geometry()),
ee.Filter.eq('ORIG_NAME', 'Parc national de la Salonga')
));
//Map.addLayer(dataset, {}, 'Parc national de la Salonga');
var modisNDVI = ee.ImageCollection('MODIS/006/MOD13Q1')
.select('NDVI')
.map(
function(img) {
var rescaled_NDVI = img.select('NDVI')
.multiply(0.0001)
.rename('NDVI_rescaled');
return img.addBands(rescaled_NDVI);
}
);
var modisNDVI_2000 = modisNDVI.filter(ee.Filter.date('2000-01-01', '2000-12-31'));
var modisNDVI_2000_clip = modisNDVI_2000.mean().clip(salonga);
var mean_dict_2000 = modisNDVI_2000_clip.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: salonga.geometry(),
scale: 500,
});
var modisNDVI_2001 = modisNDVI.filter(ee.Filter.date('2001-01-01', '2001-12-31'));
var modisNDVI_2001_clip = modisNDVI_2001.mean().clip(salonga);
var mean_dict_2001 = modisNDVI_2001_clip.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: salonga.geometry(),
scale: 500,
});
var dictionary = ee.Dictionary({
2000: mean_dict_2000.get('NDVI_rescaled'),
2001: mean_dict_2001.get('NDVI_rescaled')
});
print('Parc national de la Salonga Annual NDVI', dictionary);