1

I want to create monthly averages for the MODIS Land Surface Temperature (LST) product for several ROIs. I am able to create an image collection containing the monthly averaged MODIS data, but I have not figured out how to reduce this data for the ROIs.

Here is the first part, with help from here and here:

var modis = ee.ImageCollection('MODIS/006/MOD11A2');
var months = ee.List.sequence(1, 12);

Map.centerObject(areas, 7);
Map.addLayer(areas, {}, 'ROI');

// First I divide the data into monthly averages
var byMonth = ee.ImageCollection.fromImages(
      months.map(function (m) {
        return modis.filter(ee.Filter.calendarRange(m, m, 'month'))
                    .select(0).mean() // selecting band 1: LST_Day_1km
                    .set('month', m); 
}));
print('byMonth:', byMonth);

var check = ee.Image(byMonth.first());
Map.addLayer(check, {}, 'check');

Then comes the next part, where I try to use .reduceRegions() to reduce over multiple regions (my FeatureCollection "areas"). The idea is to loop/map through the 12 months, reducing the monthly data from "byMonth" to a value for each ROI. Unfortunately it doesn't work.

var reduced = months.map(function(mm) { 
  return byMonth.reduceRegions({
  collection: areas, // a featureCollection containing multiple polygons
  reducer: ee.Reducer.mean(),
  scale: 30,
  maxPixels: 1e9
}).filter(ee.Filter.eq('month', mm));
});
print(reduced);
1

You had a bunch of bugs in there. This ought to do it:

var modis = ee.ImageCollection('MODIS/006/MOD11A2');
var months = ee.List.sequence(1, 12);

Map.centerObject(areas, 7);
Map.addLayer(areas, {}, 'ROI');

// First I divide the data into monthly averages
var byMonth = ee.ImageCollection.fromImages(
      months.map(function (m) {
        return modis.filter(ee.Filter.calendarRange(m, m, 'month'))
                    .select(0).mean() // selecting band 1: LST_Day_1km
                    .set('month', m); 
}));
print('byMonth:', byMonth);

var check = ee.Image(byMonth.first());
Map.addLayer(check, {}, 'check');

var reduced = months.map(function(mm) { 
  return ee.Image(byMonth
      .filter(ee.Filter.eq('month', mm))
      .first())
      .reduceRegions({
        collection: areas, // a featureCollection containing multiple polygons
        reducer: ee.Reducer.mean(),
        scale: 1000,
      });
});
print(reduced.get(0));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.