Почему «reducer.mean» не приводит к среднему значению? - PullRequest
0 голосов
/ 31 мая 2019

Я пытаюсь получить среднее значение NDVI для каждой даты доступных снимков в Landsat 8 для нескольких полигонов.

Я перепробовал несколько вариантов кода, хотя приведенная ниже, кажется, приблизила меня, но ee.Reducer.mean не добавляет столбец «среднего» в мой вывод.

var table = ee.FeatureCollection("users/patterletzky/Idaho_AOI"),
table2 = ee.FeatureCollection("users/patterletzky/SA_test"),
table3 = ee.FeatureCollection("users/patterletzky/ndvi_table_assest2");

//Add the area of interest (AOI)
var AOI = ee.FeatureCollection(table);

//Add the studyarea polygons into the stdyars feature collection
var stdyars = ee.FeatureCollection(table2);

// Load the LandSat 8 collection 
// Filter by the Idaho AOI
var L8_clipped = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
              .filterBounds(stdyars)
              .filterDate('2013-02-09', '2013-04-09')
              .map(function(image){return image.clip(AOI)});

//Get the scale of the collection
var L8_scale = L8_clipped.first().projection().nominalScale();

// This function adds a band representing the image timestamp.
//var addTime = function(image) {
//  return image.addBands(image.metadata('system:time_start'));
//};

// NDVI Functions for L8 
function NDVI_L8(image) {
var datestr = ee.Date(image.get('system:time_start')).format('yyyy-MM-dd');
var ndvi = image.normalizedDifference(['B5', 'B4']);
//adds the band (ndvi) to the image called in the function i.e., L8mc
return ndvi.rename(datestr);
}

//Call the NDVI_L8 function
var L8mcn = L8_clipped.map(NDVI_L8);

// stack function to create one image 
var stackCollection= function(collection) {
//create an initial image
var first = ee.Image(collection.first()).select([]);

//Function that appends aband to an image
var appendBands = function(image,previous) {
return ee.Image(previous).addBands(image);
};
 return ee.Image(collection.iterate(appendBands,first));
};

//Run the function to name and stack ndvi bands
var ndvi_stacked = stackCollection(L8mcn);

//Obtain the mean of the polgyon region
var NDVI_final = ndvi_stacked.reduceRegions({
  collection:stdyars,
  reducer:ee.Reducer.mean(),
  scale: L8_scale});

var exp_tble = ee.batch.Export.table.toDrive({
   collection:NDVI_final,
   folder:'Google EE result',
   selectors:(["Studyarea","date","mean"]),
});

Мне бы хотелось, чтобы в таблице были столбцы изучения области, даты (изображений), среднего NDVI

...