5

My goal is to get monthly NDVI medians in Google Earth Engine. This helpful post got me started: reduce image collection to get annual monthly sum precipitation

However, I am using Landsat (not MODIS). This script does run but the map layer has "no bands to visualize".

  1. How can I visualize the bands? (Maybe the issue is that this dataset only has 1 band?).
  2. How can I add all 12 map layers, one per month? (perhaps with stacking?)
var ndvi = ee.ImageCollection('LANDSAT/LT5_L1T_32DAY_NDVI');

var months = ee.List.sequence(1, 12);

// Group by month, and then reduce within groups by mean();
// the result is an ImageCollection with one image for each
// month.
var byMonth = ee.ImageCollection.fromImages(
  months.map(function (m) {
    return ndvi.filter(ee.Filter.calendarRange(m, m, 'month'))
                .select().median()
                .set('month', m);
}));
print(byMonth);

Map.addLayer(ee.Image(byMonth.first()));
4
  • Try removing the instance .select() inside the map. This function is used to selects bands from an image and it was empty. I tried it and it seems to work. Be aware that you are making multi-annual monthly medians this way (but maybe that was the point).
    – Kamo
    Apr 16, 2018 at 15:20
  • This doesn't answer your question (your title and your question do not match), but here is a script I put together for doing this at the annual resolution: code.earthengine.google.com/ecbddc2c2a191c12d6bd16dfab164452 You'll notice there's a bit of masking--for water, and for edges of scenes where there's invalid data.
    – Jon
    Apr 16, 2018 at 15:20
  • @Kamo: thanks! that did it. Perhaps I wasn't clear, but yes, multi-annual monthly medians are exactly what I was after. I am still not sure how to look at the month-by-month results (something in that last command)
    – Erik Marsh
    Apr 16, 2018 at 23:36
  • @Jon: that is a great script; I like how you filter the dates and use multiple Landsat datasets based on year. Very useful
    – Erik Marsh
    Apr 16, 2018 at 23:40

2 Answers 2

14

For the record, here is a good way to do this:

var imageCollection = ee.ImageCollection("LANDSAT/LT05/C01/T1");
var months = ee.List.sequence(1, 12);

var composites = ee.ImageCollection.fromImages(months.map(function(m) {
  var filtered = imageCollection.filter(ee.Filter.calendarRange({
    start: m,
    field: 'month'
  }));
  var composite = ee.Algorithms.Landsat.simpleComposite(filtered);
  return composite.normalizedDifference(['B4', 'B3']).rename('NDVI')
      .set('month', m);
}));
print(composites);

var check = ee.Image(composites.first());
Map.addLayer(check, {min: 0, max: 1}, 'check');

For the search robots, this is a "temporally grouped reduction."

2

I found another way to get multi-annual monthly (and seasonal) NDVI medians. It's based on this useful post: Selection of only monthly data on Google earth engine

The code is not elegant but it gets the job done (I define variables for each month and season instead of looping through them). Hopefully it's useful! https://code.earthengine.google.com/cc2e0f6c4f67885405236024abea0d86

2
  • 3
    I would NOT use those NDVI composites. They are full of clouds. Apr 17, 2018 at 16:03
  • 1
    Yes, but they have great resolution (30m). I chose a median (instead of a mean) because it's not affected by outliers such as cloudy or NoData pixels. Each monthly median has 28 data points (one per year), which seems like enough to arrive at a stable median. I also tried it with 8-day averages, which is much slower, but significantly increases the sample size.
    – Erik Marsh
    Apr 17, 2018 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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