I created a feature collection where features are grid cells, columns are monthly images and the values represent pixel area. I would like to find the mean for each feature over all columns. I tried to use reduceColumns but I get the mean for each column rather than for each feature.


//----load image collection, filter, and create an image with multiple bands

var datasetAll = ee.ImageCollection(MODIS/006/MCD64A1)
                  .filter(ee.Filter.date('2000-01-01', '2019-12-31'))

var DSall1B = datasetAll.select('BurnDate')

var DSallImage = DSall1B.toBands()

 //----filtering grid to the area

 var grid1degreeF = grid1degree.filterBounds(border);

//----creating a layer where pixels value are the pixel area in m^2

var DSallValue1 = DSallImage.where(DSallImage, 1)

var DSallAPP1 = DSallValue1.multiply(ee.Image.pixelArea())

//----summing area in each grid cell over all bands

var DSallAPP1d1 = DSallAPP1.reduceRegions({
  reducer: ee.Reducer.sum(),
  collection: grid1degreeF,
  scale: 500,

Here are my assets:

border- https://code.earthengine.google.com/?asset=users/stavo/amazon_border_harvard

grid- https://code.earthengine.google.com/?asset=users/stavo/Vectorgrid_1degree

This is where I got so far. I end up with the feature collection I described before and now I wish to get the mean for each cell over all columns (dates).

This is the method I tried:

var properties = DSallAPP1.bandNames();

var means = DSallAPP1d1
  reducer: ee.Reducer.mean().repeat(229),
  selectors: properties

After calculating the means I was planning to use reduceToImage so I can end up with an image of the area means over time divided into grid cells. I assume that my method is not the most efficient one. Please advise how to calculate the means or how to approach the issue differently.

1 Answer 1


I'm not complete sure what you're looking for here. This calculates the mean monthly area with fires, per feature:

var monthlyFires = datasetAll
  .map(function (image) { return image.mask() })

var monthlyAreaPerRegion = monthlyFires
    reducer: ee.Reducer.sum(),
    collection:  grid1degree.filterBounds(border),
    scale: 500

var areaImage = ee.ImageCollection(
  monthlyAreaPerRegion.map(function (feature) {
    return ee.Image(feature.getNumber('sum'))

Map.addLayer(areaImage, {min: 0, max: 260000000, palette: 'green, yellow, red'})


  • Thank you for your effort Daniel! I have no experience with functions so far so I don't completely understand it. However, the result I am getting here is a dictionary with the means of each month. What I was after is an image/feature collection with the means of each grid cell (features, not columns). To get to the means of columns I could have simply used the reduceColumns function
    – Stavo
    Commented Jan 30, 2020 at 14:32
  • So, you're looking for mean area burnt during your date range, per feature? Commented Jan 30, 2020 at 15:56
  • I've updated my answer. Commented Jan 30, 2020 at 16:58
  • The script is working but it is still not the desired result. If I understand correctly, you are doing a mean over the mask values of each pixel and then multiply by an area image to receive a mean area per pixel. later you sum up the pixels according to the grid cells. I would like to do a mean of the area sum in each grid cell (not each pixel), since I will be using different grid sizes and I would also like to exclude from the mean months in which there were no fires at all. Also, could the solution be related to aggregate_mean?
    – Stavo
    Commented Feb 11, 2020 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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