The goal I am trying to achieve is to output imagery for my roi representing maximum NDVI for each season for each year in my Landsat time series (1982 - 2020). I know how to make greenest pixel composites in earth engine and divide it annually using this method:

function ndviForYear(year) {
  var startDate = ee.Date.fromYMD(year, 1, 1);
  var collection = final_col
    .filterDate(startDate, startDate.advance(1, 'year'));
  var reduced = collection
      .combine(ee.Reducer.percentile([80]), null, true)
  return reduced
    .set('year', year);

var ndviCollection = ee.ImageCollection(
  ee.List.sequence(1982, 2020).map(ndviForYear)

I want a similar output, but instead of one image for each year, I want maximum (80th percentile) seasonal NDVI -- so four images per year (winter, spring, summer, fall). Does anyone know how to easily modify this script to achieve this?

Here is the full code link: https://code.earthengine.google.com/88ebcdcce75e477236b8f74f222319e9 Here is the link to the roi asset: https://code.earthengine.google.com/?asset=users/alo266/Sierra_Ancha

1 Answer 1


The following is the update of your code, resulting in 4 images in each year for every year.

// create start index for each season
var season_start = ee.List.sequence(0, 9, 3);

function ndviForYear(year) {
  var startDate = ee.Date.fromYMD(year, 1, 1);

  var make_datelist = function (n) {
    return startDate.advance(n, "month");

  // have start date of every season
  var fourSeasons = season_start.map(make_datelist); 

  var computeNDVI = function (d1) {
    var start = ee.Date(d1);
    var end = start.advance(3, "month");
    var date_range = ee.DateRange(start, end);

    var collection = final_col.filterDate(
      startDate.advance(1, "year")

    collection = collection.filterDate(date_range);
    var reduced = collection
      .select("nd", "system:time_start")
        ee.Reducer.count().combine(ee.Reducer.percentile([80]), null, true)
    return reduced.set("year", year);
  return fourSeasons.map(computeNDVI);

var ndviCollection = ee
  .ImageCollection(ee.List.sequence(1982, 2020).map(ndviForYear).flatten())
  .select('nd_p80', 'system:time_start_p80');


Full code here https://code.earthengine.google.com/fd503af08a1b5f7782f6b9097e1da7a3

  • For unknown reason, I am only able get the output from 1984 :( If someone could help figure out why, that would be great for the OP Nov 27, 2021 at 11:13

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.