0

I'm trying to make a collection of Landsat8 images for each month of each year, copying the properties of system:time_start of the first image of each respective month, however some months don't have any image, so copyproperties gives an error in those cases

NDVI = my Landsat 8 collection processed

In the following code, im regrouping the images according to month/year

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

var byMonthYear = ee.ImageCollection.fromImages(
  years.map(function(y) {
    return months.map(function (m) {
      var imgmes = NDVI
        .filter(ee.Filter.calendarRange(y, y, 'year'))
        .filter(ee.Filter.calendarRange(m, m, 'month'))
      return imgmes.median()
        .set('month', m).set('year', y)
        .copyProperties(imgmes.first(), ['system:time_start'])
        ;
  });
}).flatten());
print(byMonthYear)

How can I set a default time_start for months with 0 images, or how can I ignore months without images?

1 Answer 1

0

Fixed adding an if in between

var byMonthYear = ee.ImageCollection.fromImages(
  years.map(function(y) {
    return months.map(function (m) {
      var imgmes = NDVI
        .filter(ee.Filter.calendarRange(y, y, 'year'))
        .filter(ee.Filter.calendarRange(m, m, 'month'))
      var fesh = ee.Algorithms.If(imgmes.first(), imgmes.first().get('system:time_start'),ee.Date('2012-12-31'));
      return imgmes.median()
        .set('month', m).set('year', y)
        .set({'system:time_start': fesh})
//        .copyProperties(imgmes.first(), ['system:time_start'])
        ;
  });
}).flatten());
print(byMonthYear)

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.