# Google Earth Engine: Multiply an image collection by a different number depending on the month

I am trying to multiply a monthly imageCollection by a different number depending on the month. What I want is to multiply all the pixels of the first 12 months by 0.85, the following 12 months by 0.95, the following 12 by 0.65. All this for a total of 468 months from 1981 to 2019 (the example contains only 2 years, 24 months).

``````var monthly_sum = ee.List.sequence(0, 2*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());
});

print(monthly_sum)

var my_list = ee.List([]);

var otherList = 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.95,
0.95,
0.95,
0.95,
0.95,
0.95,
0.95,
0.95,
0.95,
0.95,
0.95,
0.95
])
``````

Which would be the easiest way to multiply each monthly image by the corresponding multiplicative factor creating a new imageCollection?

Thanks,

• You should include the relevant (and possibly simplified) code in the question post, so that readers can see it without leaving the site. Apr 30, 2020 at 13:36

You can scale an image collection by a list of scaling factors using the following approach, which constructs a list of (image, scaling factor) pairs, and then multiplies them together.

``````// Copyright 2020 Google LLC.

var originalCollection = ee.ImageCollection([
ee.Image(1.0).double(),
ee.Image(2.0).double(),
ee.Image(3.0).double(),
ee.Image(4.0).double(),
]);
var scalingFactors = ee.List([
1.0,
10.0,
100.0,
1000.0,
]);

// Combine into a list of elements containing an image and a scaling factor.
var MAX_ELEMENTS = 1000;
var zippedList = originalCollection.toList(MAX_ELEMENTS).zip(scalingFactors);

// Map a function over the list to scale each image.
var scaledCollection = ee.ImageCollection.fromImages(
zippedList.map(function (_list) {
_list = ee.List(_list);
var _img = ee.Image(_list.get(0));
var _scale = _list.getNumber(1);
var _scaledImage = _img.multiply(_scale);
return _scaledImage.double();  // Set the data type, so the collection is consistent.
})
);

// Verify the images are scaled by inspecting the map layer.