1

I got this error when trying to produce a time-series chart of NDVI in Sentinel-2. I've already tried something like .copyProperties(image)".set('system:time_start',image.get('system:time_start'))" but it did not work. How can I solve this?

var aoi = ee.Geometry.Polygon([[
[-52.992228448173776, 5.3639624330339855],
[-52.992228448173776, 5.216962579558439],
[-52.898158013603464, 5.216962579558439],
[-52.898158013603464, 5.3639624330339855]
]]).buffer(1e4)

function toSen2Composite(fromDate, toDate) {
  var filter = ee.Filter.and(
  ee.Filter.bounds(aoi),
  ee.Filter.date(fromDate, toDate)

  )

return ee.ImageCollection(
ee.Join.saveFirst('cloudProbability').apply({
    primary: ee.ImageCollection('COPERNICUS/S2_SR').filter(filter),
    secondary: ee.ImageCollection('COPERNICUS/S2_CLOUD_PROBABILITY').filter(filter),
    condition: ee.Filter.equals({leftField: 'system:index', rightField: 'system:index'})
})
).map(function (image) {
var cloudFree = ee.Image(image.get('cloudProbability')).lt(30)

return 
image.updateMask(cloudFree).divide(10000).copyProperties(image).set('system:time_start', 
image.get('system:time_start'))

})
 .select(
  ['B2','B3','B4','B8','B11','B12'],
  ['Blue','Green','Red','NIR','SWIR1','SWIR2'])
 .map(function(image) {
var ndvi = image.expression(
'((NIR - Red) / (NIR + Red))', {
  'NIR': image.select('NIR'),
  'Red': image.select('Red')
}).rename('NDVI')

return image.addBands(ndvi,null,true)
})
.median()
}
function toComposite(fromDate, toDate) {
return toSen2Composite(fromDate, toDate)
}
var composite = toComposite('2021-01-01', '2022-01-01')
var TS1 = ui.Chart.image.series(composite.select("NDVI"), aoi, ee.Reducer.median(),500, 
'system:time_start')
              .setOptions({
                          title: 'NDVI Time Series',
                          vAxis: {title: 'NDVI'}, });
print(TS1)
print(composite.bandNames())
Map.addLayer(composite, {bands: 'Red,Green,Blue', min: 0, max: 0.3, gamma: 1.6}, 'Sentinel-2')
Map.centerObject(aoi, 12)

https://code.earthengine.google.com/fa2696e4c372a20b4ea8c08dc1a24b42

1 Answer 1

0

Print your output before you try to plot it. Your variable composite doesn't contain a property system:time_start because you apply a median reducer over the imageCollection() which results in a loss of the individual image properties. Remove the median from your mapped function.

https://code.earthengine.google.com/67c6da9efa35fb84c68a0a3ccf947799

1

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.