I have table of 10 points that I want to extract the mean and standard deviation of NDVI from sentinel within a buffered area for a time period. I am running into a problem where when I reduce it and try to export it to a csv, I get a lot of duplicated rows with 0 values for the calculated statistics.
Here is the code I am working with:
print(sample);
// buffering around points
var bufferPoly = function(feature) {
return feature.buffer(2500); // adjust for buffer size in meters
};
var zone = sample.map(bufferPoly);
print(zone);
// Importing sentinel and cropping around feature collection
var sentinel = ee.ImageCollection("COPERNICUS/S2_SR").filterDate('2020-10-01', '2020-10-05')
.select([
'B4','B8',
])
.filterBounds(zone)
.map(function(image){return image.clip(zone)});
var count = sentinel.size(); // seeing how many bands there are...shouldn't be too many
print('Bands of sentinel: ', count);
print(sentinel); // we can see what is actually here, it is a collection of 12 images each having two bands
// Calculating NDVI for each image
// NDVI Function
function ndvi(im) {
return im.normalizedDifference(['B8', 'B4']);
}
// mapping the ndvi function over all images
var ndvi = sentinel.map(ndvi);
var count = ndvi.size(); // seeing how many bands there are
print('Bands of ndvi: ', count);
print(ndvi); //We can see that it is a collection of 12 images with one ndvi band
//Now to reduce the image collection in a summary
//now extracting to the polygon
var reducers = ee.Reducer.mean().combine({
reducer2: ee.Reducer.stdDev(),
sharedInputs: true
});
var scale = ndvi.first().projection().nominalScale();
var reduced = ndvi.map(function(image){
return image.reduceRegions({
collection:zone ,
reducer:reducers,
scale: scale
});
});
var count = reduced.size(); // There are 12 bands here
print('Bands of reduced: ', count);
print(reduced);
var table = reduced.flatten();
var count = table.size(); // There are 120 bands here
print('Bands of table: ', count);
print(table);
Export.table.toDrive({
collection: table,
description:'Example',
fileFormat: 'csv'
});
For some reason, this is giving me 12 duplicated rows per the original row in the table. Any idea what is happening here?
link to code: https://code.earthengine.google.com/?scriptPath=users%2Fddlawton%2FAUS_SOILS_TEST%3AExtraction_code