1

I'm trying to re-scale an image collection using the solution provided here and then to reduce it using the timestamp as per this example. The script fails with the error:

NPP trend: Layer error: ImageCollection.reduce: Error in map(ID=2004_01_01): Image.metadata: Metadata property 'system:time_start' not found.

Can anyone tell me where I'm going wrong?

My script:

  var addTime = function(image) {
  return image.addBands(image.metadata('system:time_start')
    .divide(1000 * 60 * 60 * 24 * 365));
};

var scaleNPP = function(image) {
  return image.expression('float(b("Npp")/10000)')
};

var collection = ee.ImageCollection("MODIS/006/MOD17A3H")
  .filterDate('2004-01-01', '2010-07-01')
  .filterBounds(NNam)
  .map(scaleNPP);

var trend = collection.select(['system:time_start', 'Npp'])
  .reduce(ee.Reducer.linearFit());

2 Answers 2

1

When using the expression function you get a new image that has no properties. To copy the properties from the same image you are computing, you have to use copyProperties function.

var addTime = function(image) {
  return image.addBands(image.metadata('system:time_start')
    .divide(1000 * 60 * 60 * 24 * 365));
};

var scaleNPP = function(image) {
  return image.expression('float(b("Npp")/10000)')
              .copyProperties({source: image})
};

var collection = ee.ImageCollection("MODIS/006/MOD17A3H")
  .filterDate('2004-01-01', '2010-07-01')
  .filterBounds(NNam)
  .map(scaleNPP);

var trend = collection.select(['system:time_start', 'Npp'])
  .reduce(ee.Reducer.linearFit());
1
  • Thanks Rodrigo, I'm afraid your suggestion doesn't work. However a friend at GEE India shared the corrected script, below with the following explanation: A couple of things going on there - looks like you forgot to call .map(addTime) so there is no time band, hence the error operation in the scaleNPP function is making & returning a new single band image each time, so all the properties are lost. This has to do with EE objects being immutable, so in-place operations are not possible. making a new image for scaled NPP and adding it as a band gets you around this.
    – Ravi
    Dec 27, 2018 at 1:58
0
var addTime = function(image) {
  return image.addBands(image.metadata('system:time_start')
  .divide(1000 * 60 * 60 * 24 * 365));
};

var scaleNPP = function(image) {
  var nppScaled = image.expression('float(b("Npp")/10000)').rename('Npp_scaled');
  return image.addBands(nppScaled);
};

var collection = ee.ImageCollection("MODIS/006/MOD17A3H")
  .filterDate('2004-01-01', '2010-07-01')
  .filterBounds(geo)
  .map(addTime)//.aside(print) //uncomment this aside to print intermediate result
  .map(scaleNPP);
print(collection);

var trend = collection.select(['system:time_start', 'Npp_scaled'])
  .reduce(ee.Reducer.linearFit());

// Display the trend with increasing slopes in green, decreasing in red.
Map.addLayer(
    trend, //.clip(geometry),
    {min: 0, max: [-0.1, 0.1, 10], bands: ['scale', 'scale', 'offset']},'NPP trend');

Your Answer

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

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