1

I'm running my code where I create weekly averages of a variables which are mapped to a list of days of year (DOY).

var SSTA_7d =  ee.ImageCollection.fromImages(
  years.map(function (y) {
      return DOY.map(function(d) {
      d = ee.Number(d);
      var SSTA_date = series_daily.filter(ee.Filter.calendarRange(y, y, 'year'))
                      .filter(ee.Filter.calendarRange(d, d.add(7), 'day_of_year'));
                      
      var img_last = ee.Image(SSTA_date.sort('system:time_start',true).first());
      var size = SSTA_date.size();

      var SSTA_filtered_7d = ee.Image(ee.Algorithms.If(size.eq(0),
                                            ee.Image.constant(0).toFloat(),
                                            ee.Image(series_daily.filter(ee.Filter.calendarRange(y, y, 'year'))
                                            .filter(ee.Filter.calendarRange(d, d.add(7), 'day_of_year'))
                                            .mean()
                                            )));
      
      return SSTA_filtered_7d.set('year', y)
              .set('DOY', d)
              .set('system:time_start', img_last.get('system:time_start'));

  });
  }).flatten()
);

But I'm getting this error.

ImageCollection (Error)
Element.get: Parameter 'object' is required.

From reading it might be because the image collection I'm using is empty or a server side issue. But I can't quite figure out where the issue lies. or why the image collection is empty if that's the case. My full code is here. Lines 118-141.

1 Answer 1

1

Error pops up because img_last images doesn't have a 'system:time_start'. You can corroborate that commenting set method as in following snippet code. However, another issue appears because you are trying to map an empty HS_SSTA_7d ImageCollection. So, I also commented printing DHW_HS.

.
.
.

var SSTA_7d =  ee.ImageCollection.fromImages(
  years.map(function (y) {
      return DOY.map(function(d) {
      d = ee.Number(d);
      var SSTA_date = series_daily.filter(ee.Filter.calendarRange(y, y, 'year'))
                      .filter(ee.Filter.calendarRange(d, d.add(7), 'day_of_year'));
                      
      var img_last = ee.Image(SSTA_date.sort('system:time_start',true).first());
      var size = SSTA_date.size();

      var SSTA_filtered_7d = ee.Image(ee.Algorithms.If(size.eq(0),
                                            ee.Image.constant(0).toFloat(),
                                            ee.Image(series_daily.filter(ee.Filter.calendarRange(y, y, 'year'))
                                            .filter(ee.Filter.calendarRange(d, d.add(7), 'day_of_year'))
                                            .mean()
                                            )));
      
      return SSTA_filtered_7d.set('year', y)
              .set('DOY', d);
              //.set('system:time_start', img_last.get('system:time_start'));

  });
  }).flatten()
);
.
.
.
//print(DHW_HS);

For additional corroboration of that you can delete .first method in img_last variable preserving its set 'system:time_start' method; as in following snippet code. In this case, none image of SSTA_7d ImageCollection has 'system:time_start' property despite they have DOY and year properties. You need to fix this before considering why HS_SSTA_7d ImageCollection is empty.

.
.
.
var SSTA_7d =  ee.ImageCollection.fromImages(
  years.map(function (y) {
      return DOY.map(function(d) {
      d = ee.Number(d);
      var SSTA_date = series_daily.filter(ee.Filter.calendarRange(y, y, 'year'))
                      .filter(ee.Filter.calendarRange(d, d.add(7), 'day_of_year'));
                      
      var img_last = ee.Image(SSTA_date.sort('system:time_start',true));
      var size = SSTA_date.size();

      var SSTA_filtered_7d = ee.Image(ee.Algorithms.If(size.eq(0),
                                            ee.Image.constant(0).toFloat(),
                                            ee.Image(series_daily.filter(ee.Filter.calendarRange(y, y, 'year'))
                                            .filter(ee.Filter.calendarRange(d, d.add(7), 'day_of_year'))
                                            .mean()
                                            )));
      
      return SSTA_filtered_7d.set('year', y)
              .set('DOY', d)
              .set('system:time_start', img_last.get('system:time_start'));

  });
  }).flatten()
);
.
.
.
//print(DHW_HS);
2
  • Thanks that's great i'll look into that, thanks for your help. Feb 5, 2021 at 14:22
  • You're welcome.
    – xunilk
    Feb 5, 2021 at 14:39

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.