首页 > 解决方案 > 从 Google 地球引擎上的 NEX-GDDP 产品导出每日气候数据

问题描述

我正在使用 NEX-GDDP 获取 2018 年 1 月 1 日至 2099 年 12 月 31 日期间 21 个 GCM 模型的每日气候学(降水量、最低温度和最高温度)数据。我为一个场景中的一个模型制作了这个脚本

//Dataset
var dataset = ee.ImageCollection('NASA/NEX-GDDP')
              .filter(ee.Filter.date('2018-01-01', '2099-12-31'))
              .filterMetadata('scenario','equals','rcp45')
              .filterMetadata('model','equals','MPI-ESM-LR')

//Points of interest 
var Acomayo = ee.Geometry.Point([-71.689166667, -13.921388889]),
var Machupicchu = ee.Geometry.Point([-72.545555556, -13.166666667]),
var Urubamba = ee.Geometry.Point([-72.129116546, -13.323123791]),
var Pisac = ee.Geometry.Point([-71.849444444, -13.415833333]),
var Ccatcca = ee.Geometry.Point([-71.56, -13.609722222]),
var GranjaKcayra = ee.Geometry.Point([-71.875, -13.556666667]),
var Pomacanchi = ee.Geometry.Point([-71.5357971, -14.027777778]),
var Sicuani = ee.Geometry.Point([-71.236944444, -14.253333333]);

var pts = ee.FeatureCollection(ee.List([ee.Feature(Acomayo),ee.Feature(Machupicchu),ee.Feature(Urubamba),ee.Feature(Pisac)
                                       ,ee.Feature(Ccatcca),ee.Feature(GranjaKcayra),ee.Feature(Pomacanchi),ee.Feature(Sicuani)]));

//Export to table .CSV
// Empty Collection to fill
var ft = ee.FeatureCollection(ee.List([]));

//Without removal of null values ----------------------------------
//Function to extract values from image collection based on point file and export as a table 
var fill = function(img, ini) {
// type cast
var inift = ee.FeatureCollection(ini);

// gets the values for the points in the current img
var ft2 = img.reduceRegions(pts, ee.Reducer.first(),30);

// gets the date of the img
var date = img.date().format("yyyy/MM/dd");
var scenario = img.get("scenario");
var model = img.get("model");


// writes the date in each feature
var ft3 = ft2.map(function(f){return f.set("date", date, "scenario", scenario, "model", model)});
// merges the FeatureCollections
return inift.merge(ft3);
};

// Iterates over the ImageCollection
var newft = ee.FeatureCollection(dataset.iterate(fill, ft));
//print(newft);

// Export

Export.table.toDrive({
  collection: newft,
  description: 'GCM_diario',
  folder: 'Downscalling_Diario',
  fileFormat: 'csv'
});

脚本可以正常运行两天两点,但是对于我需要的当前点和时间段,它在 5 小时后仍然可以正常工作。为了减少数据量我认为这些想法:

  1. 将产品中21个GCM模型的每日数据取平均值,作为一个ImgaeCollection,所以只需要按场景分开即可。
  2. 仅将每个变量(Pp、Tmin、Tmax)的 ImageCollection 导出到 NetCDF 包含点的区域(不知道是否可能)。
geometry = ee.Geometry.Polygon(
        [[[-72.77555636882136, -12.867571480133547],
          [-72.77555636882136, -14.670820732958893],
          [-70.69914035319636, -14.670820732958893],
          [-70.69914035319636, -12.867571480133547]]], null, false);

如果有其他方法可以下载这些数据,我会打开来做。

标签: javascriptjakarta-eegoogle-earth-engine

解决方案


使用.iterate()可能会占用大量内存,并且容易出现内存错误。更直接的方法是选择您想要关注的特定点,遍历所有感兴趣的日子,并使用它.reduceRegion()来获取所需的信息。然后,您可以将时间序列导出为 CSV 并将其转换为您想要的任何格式。

这是一个获取所有模型和场景的所有变量的示例:

// specify start and end date
// Change as needed
var startDate = ee.Date('2018-01-01');
var endDate = ee.Date('2019-01-01');

// get the dataset between date range and extract band on interest
var dataset = ee.ImageCollection('NASA/NEX-GDDP')
                  .filter(ee.Filter.date(startDate,endDate));

// get projection and band information
var firstImage = dataset.first();
var bandNames = firstImage.bandNames();
var proj = firstImage.projection();

var point = ee.Geometry.Point([-71.689166667, -13.921388889])

// calculate number of days to map and extract data for
var n = endDate.difference(startDate,'day').subtract(1);

// map over each date and extract all climate model values
var timeseries = ee.FeatureCollection(
  ee.List.sequence(0,n).map(function(i){
    var t1 = startDate.advance(i,'day');
    var t2 = t1.advance(1,'day');
    var dailyColl = dataset.filterDate(t1, t2);
    var dailyImg = dailyColl.toBands();
    // rename bands to handle different names by date
    var bands = dailyImg.bandNames();
    var renamed = bands.map(function(b){
      var split = ee.String(b).split('_');
      return split.slice(0,2).cat(split.slice(-1)).join('_');
    });
    // extract the data for the day and add time information
    var dict = dailyImg.rename(renamed).reduceRegion({
      reducer: ee.Reducer.mean(),
      geometry: point,
      scale: proj.nominalScale()
    }).combine(
      ee.Dictionary({'system:time_start':t1.millis(),'isodate':t1.format('YYYY-MM-dd')})
    );
    return ee.Feature(point,dict);
  })
);
print(timeseries);

// get properties to chart (all climate models)
var props = timeseries.first().propertyNames().removeAll(['system:time_start','system:index','isodate']);

// Make a chart of the results.
var chart = ui.Chart.feature.byFeature(timeseries, 'system:time_start', props.getInfo());
print(chart);

Map.addLayer(point);
Map.centerObject(point,6);

// export feature collection to CSV
Export.table.toDrive({
  collection: timeseries,
  description: 'NEX-GDDP-timeseries',
  fileFormat: 'CSV',
});

使用长日期范围 (2018-2099) 时,您可能会在代码编辑器中遇到内存错误,但导出应该可以工作。另外,请记住,Earth Engine 导出有点简单,因此逐点导出将是最好的方法,1) 避免内存错误和 2) 将生成的 CSV 保持在一个点。您可以将所有点合并在一起并将每个点的时间序列导出到一个文件中,但是一旦导出可能就很难使用......

这是一个工作链接:https ://code.earthengine.google.com/139432f76ae3f6a81b1459762325ef7f


推荐阅读