Reputation: 83
I am using the script below to calculate and export EVI2 values derived from Sentinel-2 data to a table. Since the 10-meter spatial resolution of Sentinel-2 is insufficient to represent the area I need, I applied a 30-meter buffer to my points to include information from the surrounding area.
var table = ee.FeatureCollection("projects/ee-marciobcure/assets/coordenadas_dexter_2025").limit(5);
var geometry = table
.limit(5)
.geometry()
.buffer({'distance': 30});
// Sentinel 2
var idCollection = 'COPERNICUS/S2_SR_HARMONIZED';
//Definição da ImageCollection e Filtros Geoespaciais
function maskS2clouds(image) {
var qa = image.select('QA60');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask)
.copyProperties(image, ['system:time_start']);
}
var col = ee.ImageCollection(idCollection)
.filterDate('2015-01-01', '2024-01-31')//filtro de intervalo de período
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))//filtro de nuvens
.map(maskS2clouds)
.select(['B8', 'B4']); //B2, B3, B4, B8, B11
col = col.filter(ee.Filter.bounds(geometry));
//Map.addLayer(col);
//print("col", col);
print(col.size());
var table_list = table.toList(table.size());
var newCol = table_list.map(function (ele) {
var new_col = col.filter(ee.Filter.bounds(ee.Feature(ele).geometry()));
var getData = new_col.toList(new_col.size()).map(function (e) {
var date = ee.Date(ee.Image(e).get("system:time_start")).format().slice(0,10);
var evi2 = ee.Image(e).expression(
'2.5*(NIR-RED)/(NIR+(2.4*RED)+1)', {
'NIR': ee.Image(e).select('B8').divide(10000),
'RED': ee.Image(e).select('B4').divide(10000)
}).rename('EVI2');
var value = ee.Image(evi2).reduceRegion({
reducer: ee.Reducer.mean(),
geometry: ee.Feature(ele).geometry(),
scale: 30
}).get('EVI2');
var ft = ee.Feature(null, {'date': date,
'value': value,
'plot_id': ee.Feature(ele).get('plot_id'),
});
return ft;
});
return getData;
});
print(newCol.size());
// // Export the time-series as a csv.
Export.table.toDrive({
collection: ee.FeatureCollection(newCol.flatten()),
selectors: 'date, value, plot_id',
description: 's2_Dexter_2025',
folder: 'Dexter2025_csv'
});
I have three questions:
scale
argument in the reduceRegion
function? Did I use it properly?error Collection.toList: The value of 'count' must be positive. Got: 0
when running my script in Google Earth Engine?.limit(5)
to table
and edited the code above.)I kept the number of points to 5 to save time, effort, and storage.
Upvotes: 1
Views: 88
Reputation: 2434
the scale parameter defines the size of the pixels used to perform the operation (in your case reduceRegion). GEE will first rescale and align the different pixels to the requested scale using the asset internal pyrramiding policy (see documentation.
So when the reducer is applied, your pixel are already 30m resolve (using MEAN in the case of this asset) so only one pixel will be considered in your reduceRegion. In this specific use case you won't see the diff becasue you are using the same reducer as the pyramiding policy but for other situation I would recomend to use the native resolution (10m) so you keep the control over the reducing mechanism.
Upvotes: 0