0

I'm working on timeseries with Google Earth Engine. I'm new to GEE and Javascript. I'm trying to add a band to each image of an image collection with the mean value (IN TIME) of another band of the same collection, i.e. a value obtained with reduce(ee.Reducer.mean()). Basically I need to have for every pixel of every image of the collection, the value of a certain band ['B'] and the average value of ['B'] in time. Even if it sounds quite easy... I'm completely stuck!

Thank you to anyone who can help me!

Ortenstein
  • 3
  • 1
  • 2

1 Answers1

0
var mean = collection.select(['B'], ['B_mean']).mean();

var collectionWithMean = collection.map(function (image) {
  return image.addBands(mean);
});

The first step is to take the mean. The form of select I'm using here renames the band, which is necessary since it's going to be added back to the same images and so it needs a different name.

(.mean() is a shorthand for .reduce(ee.Reducer.mean()). You can use either one.)

Then we use map on the collection to add the band to each image, and we're done. The images in the collection have bands named B and B_mean.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108