在Google地球引擎中导出大型时间序列

时间:2017-12-07 14:55:32

标签: time-series largenumber google-earth-engine

如何导出特定区域的大型时间序列?我们的想法是获得一个表格,其中包含该区域的日期和平均带宽值。在这种情况下,它将是一个区域的平均NDVI。

var collectionModNDVI = ee.ImageCollection('MODIS/006/MOD13Q1')
        .filterDate('2002-01-01', '2017-11-17');

在单点时间系列的情况下,它将是

var geom = ee.Geometry.Point(-1,40).buffer(250);

print(ui.Chart.image.series(collectionModNDVI, geom, ee.Reducer.mean(), 30));

这很好用,你可以得到一个图表,你可以在csv中下载时间系列。但是当它是一个大区域时,我会遇到内存和计算时间问题。

var table2 = ee.Geometry.Rectangle(-1,40,0,41); 

chart = ui.Chart.image.seriesByRegion(collectionModNDVI,table2,
       ee.Reducer.mean(), 'NDVI',30, 'system:time_start', 'label');

print(chart);

使用此代码我收到以下错误“超出用户内存限制”。

我也试过这个:

Export.table.toDrive({
  collection: chart,
  description:'vectorsToDriveExample',
  fileFormat: 'csv'
});

但是我得到了同样的错误并且“d.yc不是函数”。

1 个答案:

答案 0 :(得分:0)

您需要提供有关如何格式化表的更多信息。以下是两种导出单个波段的方法示例:

var roi = /* color: #d63000 */ee.Geometry.Polygon(
        [[[-122.27577209472656, 37.891247253777074],
          [-122.27577209472656, 37.86875557241152],
          [-122.24040985107422, 37.86875557241152],
          [-122.24040985107422, 37.891247253777074]]], null, false);

// Load imagery.
var l8 = ee.ImageCollection('LANDSAT/LC8_SR')
    .filterBounds(roi)
    .filterDate('2016-01-01', '2016-12-31')
    .map(function(image) {
      var qa = image.select('cfmask');
      var mask = qa.neq(2).and(qa.neq(4));
      return image.updateMask(mask).divide(10000);
    });
print('Size of Landsat collection', l8.size()); // 21

// Load an Earth Engine table.
var blocks = ee.FeatureCollection('TIGER/2010/Blocks');
var subset = blocks.filterBounds(roi);
print('Size of Census blocks subset', subset.size()); // 409

Map.centerObject(roi, 13);
Map.addLayer(blocks, {color: 'gray'}, 'blocks');
Map.addLayer(subset, {}, 'subset');

// Collect block, image, value triplets.
var triplets = l8.map(function(image) {
  return image.select('B1').reduceRegions({
    collection: subset.select(['blockid10']), 
    reducer: ee.Reducer.mean(), 
    scale: 30
  }).filter(ee.Filter.neq('mean', null))
    .map(function(f) { 
      return f.set('imageId', image.id());
    });
}).flatten();
print(triplets.first());

// Format a table of triplets into a 2D table of rowId x colId.
var format = function(table, rowId, colId) {
  // Get a FeatureCollection with unique row IDs.
  var rows = table.distinct(rowId);
  // Join the table to the unique IDs to get a collection in which
  // each feature stores a list of all features having a common row ID. 
  var joined = ee.Join.saveAll('matches').apply({
    primary: rows, 
    secondary: table, 
    condition: ee.Filter.equals({
      leftField: rowId, 
      rightField: rowId
    })
  });

  return joined.map(function(row) {
      // Get the list of all features with a unique row ID.
      var values = ee.List(row.get('matches'))
        // Map a function over the list of rows to return a list of
        // column ID and value.
        .map(function(feature) {
          feature = ee.Feature(feature);
          return [feature.get(colId), feature.get('mean')];
        });
      // Return the row with its ID property and properties for
      // all matching columns IDs storing the output of the reducer.
      // The Dictionary constructor is using a list of key, value pairs.
      return row.select([rowId]).set(ee.Dictionary(values.flatten()));
    });
};

var link = '78503bfa1fb76b3a9fa06b515d1e2488';

var table1 = format(triplets, 'imageId', 'blockid10');

var desc1 = 'table1_demo_' + link; 
Export.table.toDrive({
  collection: table1, 
  description: desc1, 
  fileNamePrefix: desc1,
  fileFormat: 'CSV'
});

var table2 = format(triplets, 'blockid10', 'imageId');

var desc2 = 'table2_demo_' + link;
Export.table.toDrive({
  collection: table2, 
  description: desc2, 
  fileNamePrefix: desc2,
  fileFormat: 'CSV'
});

该示例来自this presentation,与this page相关联。