Maintaining image id after mapping image collection in Google Earth Engine

functiongoogle-earth-enginegoogle-earth-engine-javascript-api

I want to map a function over an image collection of Sentinel 1 images. After the calculation, the id and the properties are removed. I tried to maintain the id with .copyProperties in the return line but I got the error

Actual value for parameter 'id' must be a constant.

The function is very long, so I deleted the part between the brackets {...} in the line var calcLee. This link leads to the full script with the complete function: https://code.earthengine.google.com/8ee0437dfc5caedc4b9d284a77ae4282

function dbToPower(img){
      return ee.Image(10).pow(img.divide(10));
    }                                             
function powerToDb(img){
      return ee.Image(10).multiply(img.log10());
    }

function refinedLee(image) {
   
  var bandNames = image.bandNames();

  var image_power = dbToPower(image);
   
  var calcLee= ee.ImageCollection(bandNames.map(function(b){...})).toBands().rename(bandNames);
  
  var result = powerToDb(ee.Image(calcLee));
  return result.copyProperties(ee.Image(image.getString('id')));
 // return result;
}

Best Answer

You do not need to (and cannot) go through ee.Image lookup by ID to do this. Just copy from the image input:

return result.copyProperties(image);

For copying the asset ID of the image itself, it's a little more work, because “system properties” are not copied by default. The value reported as id in EE JSON outputs is actually the property named "system:id". This can be copied by doing it explicitly in a second step:

return result
    .copyProperties(image)
    .copyProperties(image, ['system:id']);
Related Question