Как "сгладить" столбец объекта, который содержит словарь в словаре в качестве значений? - PullRequest
0 голосов
/ 03 февраля 2020

В движке Google Earth у меня есть код, который требует огромного подмножества FeatureCollection, чтобы справиться с этим. Затем из ImageCollection он выдает среднемесячное значение для NDVI и уменьшает его до среднего для каждой функции. Поскольку у меня есть featureCollection, который добавляет к каждому Feature свойству последовательность из 12 месяцев (например) значений ndvi + date. Я хочу поместить их в разные столбцы, у меня это в один столбец как [{'ndvi':value,'time':{'type':'date','value':value}},2,3,4 to 12]

код

var filter = ee.Filter.inList('ESTRATA',['Abuelo Abelardo y Abuela Celia de IgarabideEucalyptus dunnii2012Fustal']);

var subset = table.filter(filter)

print(subset.size());

//tarbajo con la imageCollection
var app = function (image)
    {
    //NDVI
    var ndvi = image.normalizedDifference(['B8', 'B4']);
    image = image.addBands(ndvi.rename('NDVI'));
    return image;
    }

// Function to mask clouds using the Sentinel-2 QA band.
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 the masked and scaled data, without the QA bands.
  return image.updateMask(mask).divide(10000)
      .select("B.*")
      .copyProperties(image, ["system:time_start"])
  }


var OLI = ee.ImageCollection("COPERNICUS/S2")
    .filterMetadata('CLOUDY_PIXEL_PERCENTAGE','less_than',10)
    .map(maskS2clouds)
    .map(app)
    .select('NDVI')
    ;

var startDate = ee.Date('2019-05-01'); // set analysis start time
var endDate = ee.Date('2020-01-31'); // set analysis end time

// calculate the number of months to process
var nMonths = ee.Number(endDate.difference(startDate,'month')).round();

var result = subset.map(function(feature){
  // map over each month
  var timeDict = ee.List.sequence(0,nMonths.subtract(1)).map(function (n){
    // calculate the offset from startDate
    var ini = startDate.advance(n,'month');
    // advance just one month
    var end = ini.advance(1,'month');
    // filter and reduce
    var data = OLI.filterDate(ini,end).mean()
    .reduceRegion({
      reducer: ee.Reducer.mean(),
      geometry: feature.geometry(),
      scale: 10
    });
    return data.combine(ee.Dictionary({'time':ini}))
  });
  // return feature with a timeseries property and results
  return feature.set('timeseries',timeDict);
});

print(result.select(["ESTRATA",'timeseries']));
...