what is the right reducer to get a spatial mean, and not a temporal one?
This is determined not by the reducer, but what you use the reducer in. Both of these perform spatial reductions (combining many pixels in an image into one value):
ee.Image.reduceRegion
takes a region of interest (geometry) and reduces all unmasked pixels of the image that intersect the region.
ee.Image.reduceRegions
takes a feature collection and reduces all unmasked pixels of the image that intersect each feature's geometry — it's what you should use when you have multiple regions of interest.
Since you also have one image per month, you'll need to write reduceRegions
inside of map
over the collection of month images.
This is fairly straightforward; the messy part will be the further work to convert the plant features into columns of the table, which will be something like:
var results = monthImages.map(function (image) {
// Compute the reduction.
var plantsWithReductions = image.select('my_band').reduceRegions({
collection: plants,
reducer: ee.Reducer.mean(),
});
// Extract three parallel lists of the plants' feature IDs, geometries,
// and reduction results.
var plantIds = plants.reduceToColumns(ee.Reducer.toList(), ['system:index']);
var plantGeometries = plants.reduceToColumns(ee.Reducer.toList(), ['.geo']);
var plantResults = plantsWithReductions.reduceToColumns(ee.Reducer.toList(), ['my_band']);
// Convert the parallel lists into feature properties and put those properties
// on the image. (You could also use ee.Feature(null) if you don't want to
// copy any properties from the image.)
return image
.setMulti(ee.Dictionary.fromLists(
plantIds.map(function (id) { return ee.String(id).cat('_geo'); }),
plantGeometries))
.setMulti(ee.Dictionary.fromLists(
plantIds.map(function (id) { return ee.String(id).cat('_mean'); }),
plantResults));
});
Export.table.toDrive({
collection: results,
...
});
If you'd be satisfied with a CSV that contains one row per month-plant combination, that's much simpler:
var results = monthImages.map(function (image) {
return image.select('my_band').reduceRegions({
collection: plants,
reducer: ee.Reducer.mean(),
});
}).flatten();
.flatten()
turns a feature collection (months) containing feature collections (plants for each month) into a collection of all of the features inside the inner collections.