I've been trying to write a function for time series data script that currently looks like this:

var fall_1987_mf = final_col
Map.addLayer(fall_1987_mf,ndviParams,"fall 1987");

var fall_1988_mf = final_col
Map.addLayer(fall_1988_mf,ndviParams,"fall 1989");

var fall_1989_mf = final_col
Map.addLayer(fall_1989_mf,ndviParams,"fall 1989");

var fall_1990_mf = final_col
Map.addLayer(fall_1990_mf,ndviParams,"fall 1990");

and so on.... This currently runs from 1982 to 2020 and I am going to do it for the three other seasons and I would obviously would prefer a more concise way to code this out. My ideal output is 12 image collections with one for each season in each of the 3 rois (mf, nf, and sf).

Link to full script: https://code.earthengine.google.com/93740a3a82c2354055f618ce00cdec47

1 Answer 1


You could map over a list of years:

var fall_mf_collection = ee.ImageCollection(
  ee.List.sequence(1982, 2020).map(function(year) {
    year = ee.Number(year)
    return final_col
      .select('ndvi', 'time')
      .filterDate(ee.Date.fromYMD(year, 9, 22), ee.Date.fromYMD(year, 12, 22))
      .set('year', year)


Your Answer

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

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