# Multiply two image collections with different sizes based on dates

by cdcerv   Last Updated August 13, 2019 20:22 PM - source

I have two image collections. They are both filtered by date beginning on Jan 1, 2019, and ending on today's date. The size of the first (kc) is 35 images and the second (ETo) is 225. The first has an image every 16 days, whereas the second collection has one daily.

I am trying to multiply in a loop the last kc image by groups of 5 ETo images by looking at their date. If the current ETo image in loop has a date more recent than the last kc image, move to the next kc image and wait for a new increment. This is the logic I thought of:

``````newCollection = []
i = 0
currentDate = kc[0].date
foreach ETo as etoImg:
if (etoImg.date >= kc[i].date):
i++
currentDate = etoImg[i].date
newCollection.push(etoImg * kc[i])
``````

Having said that, this is the code I made for calculating that:

``````var kclist = kcAccum.sort('system:time_start').toList(kcAccum.size());
var kcindex = 0;
var ETaColl = ETo.sort('system:time_start').map(function(etoimage) {
var currkcimage = ee.Image(kclist.get(kcindex));
if(currkcimage.get("system:time_start") < etoimage.get("system:time_start")) {
kcindex++;
}
return (etoimage.multiply(currkcimage))
.copyProperties(etoimage, ["system:time_start"]);
});

var ETaChart = ui.Chart.image.series(ETaColl, geom);
print(ETaChart);
``````

The problem is that once the graph is printed, it shows very strange values, very different from what was expected.

The first value shown in the ETo graph is 1.953. The last in kc is 0.228. Therefore, the first value in the resulting graph should be 0.445. However, it has a value of 0.374. Similarly, the last value shown in the ETo graph is 6. The last in kc is 0.103. Therefore, the last value in the resulting graph should be 0.618. However, it has a value of 1.149.

That is how I concluded the calculations were wrong. Does anyone have any suggestions as to what I may be doing wrong here?

I have heard it is possible interpolate image collections to generate images for the dates where the kc collection has no images. However, I don't really know how I could do that. I am open to suggestions.

This is the ETo graph:

This is the kc graph:

resulting:

Tags :