Google Earth Engine – Summarize 16-Day MODIS Image (MOD13Q1) into Mean Yearly Value

google-earth-enginegoogle-earth-engine-javascript-apimodisndvi

I am new to GEE (about two weeks) and trying to understand the response of NDVI (as proxy for phenology) to temperature and precipitation in the Oban forest of Nigeria. I am using MOD13Q1 (250 m), MOD11A2 (1000 m), and Monthly GPM (11132 m) or TRMM 3B43 (27830 m).

I want to summarize the 16-day Modis data into monthly and yearly values, then export the values into R for further analysis (trend analysis, regression and lag in NDVI response to climate parameters (temperature and precipitation)).

I have been able to generate, set boundaries, scale, parse for QA and visualize the time series of the data in the current format.

var CRNP_Oban = ee.FeatureCollection("users/sijehasuk/CRNP_Oban2"),
    ndvi = ee.ImageCollection("MODIS/061/MOD13Q1"),
    lst_day = ee.ImageCollection("MODIS/061/MOD11A2");

// 1 ****************************************************************************
/////////////////////////////////////////////////
//// Extract MODIS NDVI data from 16-day MOD13Q1 250m resolution
// Creat Filter of quality pixels
var mask = function(im) {
  return im.updateMask(im.select("SummaryQA").eq(0));
};

// Import NDVI data
var ndvi = ee.ImageCollection(ndvi)
.filterDate('2000-01-01','2020-01-01')
.map(mask)
.select("NDVI")
.filterBounds(CRNP_Oban);

//Rescale
var rescale = function(image) {
    var temp = image.toFloat().multiply(0.0001);
    image = image.addBands(temp);
    return image;
};
var rescaleNDVI = ndvi.map(rescale);

// Charts NDVI time series (mean, max and min) ## NDVI_1 is the rescaled band
print(ui.Chart.image.series(rescaleNDVI.select("NDVI_1"), CRNP_Oban,
    ee.Reducer.mean(), 250));
print(ui.Chart.image.series(rescaleNDVI.select("NDVI_1"), CRNP_Oban,
    ee.Reducer.max(), 250));
print(ui.Chart.image.series(rescaleNDVI.select("NDVI_1"), CRNP_Oban,
    ee.Reducer.min(), 250));

How can I summarize all data into a monthly (single mean image value) and yearly (single mean image value) format (possibly with the minimum, maximum and mean Reducers) that can be exported individually? The reason for the yearly data is to produce a yearly trend and do some regression analysis.

The Code can be accessed here: https://code.earthengine.google.com/?accept_repo=users/sijehasuk/stackexchange Asset can be accessed here: https://code.earthengine.google.com/?asset=users/sijehasuk/CRNP_Oban2

Best Answer

An easy way to make monthly mean composites is to map over a list containing a sequence of numbers to advance the start date. Then you just need to filter the collection by date, calculate the mean and set the 'time_start' property. Finally, you cast that result into an image collection.

// Number of months: 20 years * 12 months
var months = ee.List.sequence(0, ee.Number(20).multiply(12), 1);
var startDate = '2000-01-01';
print('months',months);

// Map over months and cast into image collection
var monthlyMean = ee.ImageCollection(months.map(function(n){
  // Create start and end dates for each month
  var start = ee.Date(startDate).advance(n, 'months');
  var end = start.advance(1, 'months');
  
  // Filter date and calculate mean
  // Set system:time_start as start
  var filterIm = rescaleNDVI.filterDate(start, end)
                             .mean()
                             .set('system:time_start', start);
  return(filterIm);   
}));

// Monthly values    
print(ui.Chart.image.series(monthlyMean.select("NDVI_1"), CRNP_Oban,
    ee.Reducer.mean(), 250));
print(ui.Chart.image.series(monthlyMean.select("NDVI_1"), CRNP_Oban,
    ee.Reducer.max(), 250));
print(ui.Chart.image.series(monthlyMean.select("NDVI_1"), CRNP_Oban,
    ee.Reducer.min(), 250));