I am trying to calculate the monthly LAI composite, but somehow code is not working. Need Suggestions? It shows this error, Line 36: image.get is not a function.
// Define the start and end dates
var startDate = '2006-01-01';
var endDate = '2020-12-31';
// Function to calculate monthly LAI mean
var calculateMonthlyLAI = function(year, month) {
var startDate = ee.Date.fromYMD(year, month, 1);
var endDate = startDate.advance(1, 'month');
var lai = ee.ImageCollection('MODIS/061/MOD15A2H')
.filterBounds(region)
.filterDate(startDate, endDate)
.select('Lai_500m')
.mean()
.set('system:time_start', startDate.millis())
.set('system:time_end', endDate.millis());
return lai;
};
// Create an empty image collection to store the monthly LAI
var monthlyLAI = ee.ImageCollection([]);
// Iterate over the years and months
for (var year = 2006; year <= 2020; year++) {
for (var month = 1; month <= 12; month++) {
var lai = calculateMonthlyLAI(year, month);
var temporaryCollection = ee.ImageCollection([lai]); // Create a temporary collection with the single lai image
monthlyLAI = monthlyLAI.merge(temporaryCollection);
}
}
// Function to export an image to Google Drive
var exportImage = function(image) {
var dateString = ee.Date(image.get('system:time_start')).format('YYYY-MM');
var fileName = ee.String('monthly_lai_').cat(dateString);
Export.image.toDrive({
image: ee.Image(image),
description: fileName,
folder: 'GEE_exports',
scale: 500,
region: region,
fileFormat: 'GeoTIFF'
});
};
// Export each monthly LAI image
monthlyLAI.toList(monthlyLAI.size()).getInfo().forEach(function(image) {
exportImage(image);
});