0

I'm using google earth engine and I've used a function I found online (Click here) called temporalCollection to calculate monthly averages over a year. I've then displayed them on the map, but was hoping to produce a chart for them also. See code below.

var BIOT = ee.Feature(  // BIOT
ee.Geometry.Rectangle(70.7, -4.7, 72.9, -7.7), {label: 'BIOT'});

var sst = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI').select('sst')

var sstMonthly = temporalCollection(sst, ee.Date('2013-01-01'), 12, 1, 
'month');
print('sstMonthly', sstMonthly)

var check = ee.Image(sstMonthly.first());
Map.addLayer(check, {bands: 'sst_mean', min: 0, max: 40, 
'palette':"0000ff,32cd32,ffff00,ff8c00,ff0000"}, 'check')

print(ui.Chart.image.series(sstMonthly, BIOT, ee.Reducer.mean(), 500));

However, I'm getting an error for the chart. All other aspects seem to be running fine.

Error generating chart: No features contain non-null values of 
"system:time_start".

I'm not too sure what this error is, or what I'm missing. I've just followed the basic code from the tutorial. I'm very new to GEE, there's not too many workshops or forums out there and any help is very appreciated.

mikejwilliamson
  • 405
  • 1
  • 7
  • 17

1 Answers1

2

The error means: each image in your image collection (sstMonthly) does not have the system:time_start property or value of this property is null. By default, the series chart needs this property to know the position of each image in the series chart.

Regarding the temporalCollection function you provided, each image created by this function does not have system:time_start property. This is natural because any image created by reducing an image collection will not have system:time_start by default (as GEE has no idea what time to assign to it).

There're several ways to overcome this issue, depending on what value you want to display in the horizontal axis of your series chart.

If you just want to display the date of the first image captured in that month, simply add 1 line to the end of the temporalCollection function code:

    return collection.filterDate(startDate, endDate)
      .reduce(ee.Reducer.mean().combine({
        reducer2: ee.Reducer.minMax(),
        sharedInputs: true
      }))
      .set('system:time_start', startDate.millis());

This will set system:time_start property of your reduced image the same value of startDate. Your series chart should work properly now.

Kevin
  • 338
  • 1
  • 3
  • 9