Skip to main content
syntax highlighting
Source Link
Kersten
  • 9.9k
  • 3
  • 39
  • 59
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));
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));
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));
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));
Source Link

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));