Your issue is produced because you also have to map by each feature in lotes feature collection. As your lotes feature collection is inaccessible by me, I created one by using three arbitrary point geometries in USA. Code looks as follows. It can be noted that myFeatures variable had to be changed for incorporating all features (in your case 273 and now 273x3 = 819) identified by an id (0 for feature 1, 1 for feature 2 and, so on).
var startDate = ee.Date('2016-08-01');
var endDate = ee.Date('2017-05-01');
// Specify Country names
//var lotes = ee.FeatureCollection('users/santiagomol/FTNNN');
var pt1 = ee.Geometry.Point([-111.283984375, 38.1155715234555]);
var pt2 = ee.Geometry.Point([-101.1765625, 33.48463317512623]);
var pt3 = ee.Geometry.Point([-87.55351562500002, 32.785457836903774]);
var lotes = ee.FeatureCollection([pt1, pt2, pt3]);
print(lotes);
Map.addLayer(lotes, {color:'red'}, "lotes");
Map.centerObject(lotes);
var lotes_lst = lotes.toList(lotes.size());
var dataset = ee.ImageCollection("NASA/GLDAS/V021/NOAH/G025/T3H")
.select('Tair_f_inst')
.filterDate(startDate, endDate);
var list_dataset = dataset.toList(dataset.size());
//init function
var groupFeats = lotes_lst.map(function (ele) {
var idx = lotes_lst.indexOf(ele);
var getTemperature = function(image) {
var value_temperat = ee.Image(image)
.reduceRegion(ee.Reducer.mean(), ee.Feature(ele).geometry())
.get('Tair_f_inst');
return value_temperat;
};
var count = dataset.size();
var temperat_list = dataset.toList(count).map(getTemperature);
var len = temperat_list.size();
var list = ee.List.sequence(0, len.subtract(1), 8);
var temp_list = list.map(function(el){
var start = ee.Number(el).int();
var end = ee.Number(el).add(8).int();
var new_list = ee.List([]);
new_list = new_list.add(idx);
var element = ee.List(temperat_list.slice(start, end)).reduce(ee.Reducer.min());
new_list = new_list.add(element);
var element2 = ee.List(temperat_list.slice(start, end)).reduce(ee.Reducer.max());
new_list = new_list.add(element2);
return new_list;
});
var allDates = ee.List(dataset.aggregate_array('system:time_start'));
var allDatesSimple = allDates.map(function(date){
return ee.Date(date).format().slice(0,10);
}).distinct();
var paired = allDatesSimple.zip(temp_list);
return paired;
}).flatten();
print("groupFeats", groupFeats);
var count = groupFeats.size();
//print("count", count);
var new_list = ee.List.sequence(0, count.subtract(1), 4);
//print("new list", new_list);
var tempValues = new_list.map(function (ele) {
var start = ee.Number(ele).int();
var end = ee.Number(ele).add(4).int();
return ee.List(groupFeats.slice(start, end));
});
print("tempValues", tempValues);
var myFeatures = ee.FeatureCollection(tempValues.map(function(el){
return ee.Feature(null, {
'date': ee.String(ee.List(el).get(0)),
'id': ee.Number(ee.List(el).get(1)),
'Tmin': ee.String(ee.List(el).get(2)),
'Tmax': ee.String(ee.List(el).get(3))
});
}));
//print(myFeatures);
// Export features, specifying corresponding names.
Export.table.toDrive(myFeatures,
"Temperature", //task
"GEE_Folder", //export folder
"daily_temperat", //file name
"CSV");
After running it in GEE code editor, I got following result.
It can be observed that id changed after 273 as expected.
After running the task, produced csv, opened in Libre Office, looks as expected.
Editing Note:
Based in your comment, I added in my point feature collection the column 'Ensayo_Cod' as follows:
var Ensayo_Cod = ee.List(['lote 1', 'lote 2', 'lote 3']);
// This function adds lote's name as a property.
var addName = function(ele) {
var idx = lotes_lst.indexOf(ele);
return ee.Feature(ele).set({Ensayo_Cod: Ensayo_Cod.get(idx)});
};
lotes_lst = lotes_lst.map(addName);
Now, I can modify groupFeats function in new_list variable as:
.
.
.
new_list = new_list.add(ee.Feature(ele).get('Ensayo_Cod')); //add lote's names instead id
.
.
.
Complete code is here. After running the code again, it can be observed that lote's names were added as expected.
Posting this for posterity and info for others.
In my reducer call I had the scale set way to high for some reason - possibly for faster computation I can't remember... My fix is below.
// filter and reduce (returns featureCollection)
var data = image.reduceRegions({
reducer: ee.Reducer.mean(),
collection: swaner_sites,
scale: 10 // Sentinel has NDVI pixel rez of 10 meters -> scale = 10
})
Once I changed the reducer scale from 1000, to 10 I started getting the answers I expected. So lesson learned, set you reducer scale = native pixel values of your imagery unless you are getting computational errors
Best Answer
Based in your error message, I search which is the command syntax for reduceRegions in this link. So, I modified following function in your code as:
After running complete code in GEE code editor (I assumed an arbitrary area for potreros geometry), it ran without any issue; as it can be observed in following picture.