2

I wrote the following code where an ImageCollection is multiplied by different scale factors (469 in total). I created a list with all the factors and I combined it with the imageCollection in order to multiply each month with its corresponding factor. The results show a final collection with the scale factor applied.

https://code.earthengine.google.com/203deb3d2f9c19afe9236f4e53efbd0c

However, the final ImageCollection misses the system:time_index property. I was trying to use .CopyProperties but honestly, I do not know where.

Any suggestion?

var sum_month = ee.List.sequence(0, 39*12).map(function(n) { // .sequence: number of years from starting year to present
  var start = ee.Date('1981-01-01').advance(n, 'month'); // Starting date
  var end = start.advance(1, 'month'); // Step by each iteration

  return ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY")
        .filterDate(start, end)
        .sum()
        .set('system:time_start', start.millis());
});

var collection = ee.ImageCollection(sum_month)

var list = ee.List([
  0.884748080310752,
0.884748080310752,
0.884748080310752,
0.884748080310752,
0.884748080310752,
0.884748080310752,
0.884748080310752,
0.884748080310752,
0.884748080310752,
0.884748080310752,
0.884748080310752,
0.839632014230907,
0.839632014230907,
0.839632014230907,
0.839632014230907,
0.839632014230907,
0.839632014230907,
0.839632014230907,
0.839632014230907,
0.839632014230907,
0.839632014230907,
0.839632014230907,
0.839632014230907,
1.1229204406206,
1.1229204406206,
1.1229204406206,
1.1229204406206,
1.1229204406206,
1.1229204406206,
1.1229204406206,
1.1229204406206,
1.1229204406206,
1.1229204406206,
1.1229204406206,
1.1229204406206,
0.940763778922923,
0.940763778922923,
0.940763778922923,
0.940763778922923,
0.940763778922923,
0.940763778922923,
0.940763778922923,
0.940763778922923,
0.940763778922923,
0.940763778922923,
0.940763778922923,
0.940763778922923,
0.74844803241941,
0.74844803241941,
0.74844803241941,
0.74844803241941,
0.74844803241941,
0.74844803241941,
0.74844803241941,
0.74844803241941,
0.74844803241941,
0.74844803241941,
0.74844803241941,
0.74844803241941,
0.72039682140522,
0.72039682140522,
0.72039682140522,
0.72039682140522,
0.72039682140522,
0.72039682140522,
0.72039682140522,
0.72039682140522,
0.72039682140522,
0.72039682140522,
0.72039682140522,
0.72039682140522,
0.783237079191968,
0.783237079191968,
0.783237079191968,
0.783237079191968,
0.783237079191968,
0.783237079191968,
0.783237079191968,
0.783237079191968,
0.783237079191968,
0.783237079191968,
0.783237079191968,
0.783237079191968,
0.731030391679879,
0.731030391679879,
0.731030391679879,
0.731030391679879,
0.731030391679879,
0.731030391679879,
0.731030391679879,
0.731030391679879,
0.731030391679879,
0.731030391679879,
0.731030391679879,
0.731030391679879,
0.9502595494971,
0.9502595494971,
0.9502595494971,
0.9502595494971,
0.9502595494971,
0.9502595494971,
0.9502595494971,
0.9502595494971,
0.9502595494971,
0.9502595494971,
0.9502595494971,
0.9502595494971,
0.717754884271775,
0.717754884271775,
0.717754884271775,
0.717754884271775,
0.717754884271775,
0.717754884271775,
0.717754884271775,
0.717754884271775,
0.717754884271775,
0.717754884271775,
0.717754884271775,
0.717754884271775,
0.748972997706123,
0.748972997706123,
0.748972997706123,
0.748972997706123,
0.748972997706123,
0.748972997706123,
0.748972997706123,
0.748972997706123,
0.748972997706123,
0.748972997706123,
0.748972997706123,
0.748972997706123,
0.731569637966974,
0.731569637966974,
0.731569637966974,
0.731569637966974,
0.731569637966974,
0.731569637966974,
0.731569637966974,
0.731569637966974,
0.731569637966974,
0.731569637966974,
0.731569637966974,
0.731569637966974,
0.82600544303205,
0.82600544303205,
0.82600544303205,
0.82600544303205,
0.82600544303205,
0.82600544303205,
0.82600544303205,
0.82600544303205,
0.82600544303205,
0.82600544303205,
0.82600544303205,
0.82600544303205,
0.860265230004144,
0.860265230004144,
0.860265230004144,
0.860265230004144,
0.860265230004144,
0.860265230004144,
0.860265230004144,
0.860265230004144,
0.860265230004144,
0.860265230004144,
0.860265230004144,
0.860265230004144,
0.862360483501427,
0.862360483501427,
0.862360483501427,
0.862360483501427,
0.862360483501427,
0.862360483501427,
0.862360483501427,
0.862360483501427,
0.862360483501427,
0.862360483501427,
0.862360483501427,
0.862360483501427,
0.81595650516483,
0.81595650516483,
0.81595650516483,
0.81595650516483,
0.81595650516483,
0.81595650516483,
0.81595650516483,
0.81595650516483,
0.81595650516483,
0.81595650516483,
0.81595650516483,
0.81595650516483,
0.821726883652184,
0.821726883652184,
0.821726883652184,
0.821726883652184,
0.821726883652184,
0.821726883652184,
0.821726883652184,
0.821726883652184,
0.821726883652184,
0.821726883652184,
0.821726883652184,
0.821726883652184,
1.00465118580511,
1.00465118580511,
1.00465118580511,
1.00465118580511,
1.00465118580511,
1.00465118580511,
1.00465118580511,
1.00465118580511,
1.00465118580511,
1.00465118580511,
1.00465118580511,
1.00465118580511,
1.01705694232554,
1.01705694232554,
1.01705694232554,
1.01705694232554,
1.01705694232554,
1.01705694232554,
1.01705694232554,
1.01705694232554,
1.01705694232554,
1.01705694232554,
1.01705694232554,
1.01705694232554,
1.1700312418641,
1.1700312418641,
1.1700312418641,
1.1700312418641,
1.1700312418641,
1.1700312418641,
1.1700312418641,
1.1700312418641,
1.1700312418641,
1.1700312418641,
1.1700312418641,
1.1700312418641,
1.03065226648825,
1.03065226648825,
1.03065226648825,
1.03065226648825,
1.03065226648825,
1.03065226648825,
1.03065226648825,
1.03065226648825,
1.03065226648825,
1.03065226648825,
1.03065226648825,
1.03065226648825,
0.984661287553648,
0.984661287553648,
0.984661287553648,
0.984661287553648,
0.984661287553648,
0.984661287553648,
0.984661287553648,
0.984661287553648,
0.984661287553648,
0.984661287553648,
0.984661287553648,
0.984661287553648,
1.10198473295472,
1.10198473295472,
1.10198473295472,
1.10198473295472,
1.10198473295472,
1.10198473295472,
1.10198473295472,
1.10198473295472,
1.10198473295472,
1.10198473295472,
1.10198473295472,
1.10198473295472,
1.19921300316797,
1.19921300316797,
1.19921300316797,
1.19921300316797,
1.19921300316797,
1.19921300316797,
1.19921300316797,
1.19921300316797,
1.19921300316797,
1.19921300316797,
1.19921300316797,
1.19921300316797,
0.976655549015761,
0.976655549015761,
0.976655549015761,
0.976655549015761,
0.976655549015761,
0.976655549015761,
0.976655549015761,
0.976655549015761,
0.976655549015761,
0.976655549015761,
0.976655549015761,
0.976655549015761,
1.00965253592154,
1.00965253592154,
1.00965253592154,
1.00965253592154,
1.00965253592154,
1.00965253592154,
1.00965253592154,
1.00965253592154,
1.00965253592154,
1.00965253592154,
1.00965253592154,
1.00965253592154,
0.906334059359132,
0.906334059359132,
0.906334059359132,
0.906334059359132,
0.906334059359132,
0.906334059359132,
0.906334059359132,
0.906334059359132,
0.906334059359132,
0.906334059359132,
0.906334059359132,
0.906334059359132,
1.14708067935416,
1.14708067935416,
1.14708067935416,
1.14708067935416,
1.14708067935416,
1.14708067935416,
1.14708067935416,
1.14708067935416,
1.14708067935416,
1.14708067935416,
1.14708067935416,
1.14708067935416,
0.955497703496012,
0.955497703496012,
0.955497703496012,
0.955497703496012,
0.955497703496012,
0.955497703496012,
0.955497703496012,
0.955497703496012,
0.955497703496012,
0.955497703496012,
0.955497703496012,
0.955497703496012,
0.804850441796246,
0.804850441796246,
0.804850441796246,
0.804850441796246,
0.804850441796246,
0.804850441796246,
0.804850441796246,
0.804850441796246,
0.804850441796246,
0.804850441796246,
0.804850441796246,
0.804850441796246,
0.887492658652853,
0.887492658652853,
0.887492658652853,
0.887492658652853,
0.887492658652853,
0.887492658652853,
0.887492658652853,
0.887492658652853,
0.887492658652853,
0.887492658652853,
0.887492658652853,
0.887492658652853,
0.946400263687437,
0.946400263687437,
0.946400263687437,
0.946400263687437,
0.946400263687437,
0.946400263687437,
0.946400263687437,
0.946400263687437,
0.946400263687437,
0.946400263687437,
0.946400263687437,
0.946400263687437,
0.921730362937116,
0.921730362937116,
0.921730362937116,
0.921730362937116,
0.921730362937116,
0.921730362937116,
0.921730362937116,
0.921730362937116,
0.921730362937116,
0.921730362937116,
0.921730362937116,
0.921730362937116,
1.03023550595632,
1.03023550595632,
1.03023550595632,
1.03023550595632,
1.03023550595632,
1.03023550595632,
1.03023550595632,
1.03023550595632,
1.03023550595632,
1.03023550595632,
1.03023550595632,
1.03023550595632,
0.921572456964006,
0.921572456964006,
0.921572456964006,
0.921572456964006,
0.921572456964006,
0.921572456964006,
0.921572456964006,
0.921572456964006,
0.921572456964006,
0.921572456964006,
0.921572456964006,
0.921572456964006,
0.889937018095707,
0.889937018095707,
0.889937018095707,
0.889937018095707,
0.889937018095707,
0.889937018095707,
0.889937018095707,
0.889937018095707,
0.889937018095707,
0.889937018095707,
0.889937018095707,
0.889937018095707,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386,
0.916992726360386
]);

//Create an Image Collection, each image.constant(value of list)
var Image_Multiplication = function(collection,valuelist){
  var list_size = valuelist.size();
  var sequence = ee.List.sequence(0,list_size.subtract(ee.Number(1)));

  var value_collection = ee.ImageCollection(sequence.map(function(i){
    return ee.Image.constant(list.get(i));
  }));

  var value_collection_list = value_collection.toList(value_collection.size());
  var collection_list = collection.toList(collection.size());

  return ee.ImageCollection(sequence.map(function(i){
    var image = ee.Image(collection_list.get(ee.Number(i)));
    var value_image = ee.Image(value_collection_list.get(ee.Number(i)));
    var multiplication_image = image.multiply(value_image);
    return ee.Image(multiplication_image);
  }));

};

var value_collection = Image_Multiplication(collection,list);

print(value_collection);

Map.addLayer(collection.first(),{},'Original Images',false);
Map.addLayer(value_collection.first(),{},'Multiplied Image',false);
3

You will have to copy the image properties twice. The first time, you create a summed image from multiple images between start and end, thus you will have to pick one image to copy the properties from. for simplicity, I choose the first image:

var sum_month = ee.List.sequence(0, 39*12).map(function(n) { 
  var start = ee.Date('1981-01-01').advance(n, 'month'); // Starting date
  var end = start.advance(1, 'month'); // Step by each iteration

  // get collection filtered
  var imgColTemp = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY").filterDate(start, end);
  // get properties of the first image between the start and end
  var props = imgColTemp.first().toDictionary(imgColTemp.first().propertyNames());

  return imgColTemp.sum()
        .set('system:time_start', start.millis())
        .set(props); // set the properties
});

Then you create new image using multiply, and images loose their properties. Thus, copy them again at the end of your script:

    return ee.Image(multiplication_image)
          // copy image properties again
          .set(image.toDictionary(image.propertyNames()));

See full code

1

If you use .copyProperties() with default arguments, only ordinary (i.e. non-system) properties will be copied.

To copy all properties, including system properties, use .copyProperties(image, image.propertyNames()), or specify a list of properties that you want to copy.

See link to the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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