I have the following code to do four steps:
1- Load MODIS MOD13Q1 and MYD13Q1 datasets
2- Merge collections
3- Import EVI data with good QA
4- Calculate monthly max EVI values for every pixel
The code works with no error. But when I download a test data for a month (e.g., Oct 2010) from AρρEEARS and calculate max EVI in R it gives me different results for most of pixels.
It seems there is something wrong in my code but I couldn't figure it out. I would appreciate any assistance
Code
// roi
var roi = ee.Geometry.Polygon(
[[[13.473092187466195, -20.861424970758563],
[13.473092187466195, -35.51661935495365],
[36.76410781246619, -35.51661935495365],
[36.76410781246619, -20.861424970758563]]], null, false);
// Load MODIS MOD13Q1 dataset
var MOD13Q1 = ee.ImageCollection('MODIS/061/MOD13Q1')
.filterDate('2002-07-01','2022-12-31')
.filterBounds(roi)
print(MOD13Q1);
// Load MODIS MYD13Q1 dataset
var MYD13Q1 = ee.ImageCollection('MODIS/061/MYD13Q1')
.filterDate('2002-07-01','2022-12-31')
.filterBounds(roi)
print(MYD13Q1);
// merge collections
var MOD_merged = MOD13Q1.merge(MYD13Q1)
print(MOD_merged)
// Import EVI data with good QA
var mask = function(im) {
return im.updateMask(im.select("SummaryQA").eq(0));
};
var EVIs = ee.ImageCollection(MOD_merged)
.map(mask)
.select("EVI")
.filterBounds(roi);
// sort by date
var MOD_merge_sorted = EVIs.sort("system:time_start")
.filterBounds(roi);
print(MOD_merge_sorted)
// Calculate monthly max EVI values
var start_date = ee.Date("2002-07-01");
var end_date = ee.Date("2022-12-31");
var monthly_images = function(IC) {
// Get number of months in interval
var n_months = ee.List.sequence(0, end_date.difference(start_date, "month").round().subtract(1));
// Iterate monthly max over all months in the interval
var images = n_months.map(function(n) {
// Get images for given month
var start = start_date.advance(n, "month");
var end = start.advance(1, "month");
var filtered = IC.filterDate(start, end);
var max = filtered.max();
return max.set("month", start.get("month"), "year", start.get("year"));
});
return ee.ImageCollection.fromImages(images);
};
var ndvi_monthly_max = monthly_images(MOD_merge_sorted)
.filterBounds(roi)
print(ndvi_monthly_max,"max")
Map.addLayer(ndvi_monthly_max,{min:-2000,max:10000,palette:['Orange','Green']}, "EVIs")
//List EVI to Export max EVI collection
var list=ndvi_monthly_max.toList(246);
for (var i=0;i<246;i++){
var image=ee.Image(list.get(i))
var yr= image.get("year")
var name=ee.String(yr)
.cat(image.get("month"))
.getInfo();
print(name);
// Export collection
Export.image.toDrive({
image: image,
description: name,
fileNamePrefix: name,
scale: 250,
region:roi,
maxPixels: 3984216672400,
fileFormat: 'GeoTIFF',
folder: 'Modis_250_Monthly_Max_EVI',
formatOptions: {
cloudOptimized: true
}
});
}