[GIS] Metadata property ‘system:time_start’ not found after scaling MODIS NPP data

google-earth-engine

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());

Best Answer

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());
Related Question