从 Google Earth Engine 上的 NEX-GDPP 产品导出每日气候数据

Exporting daily climatology data from NEX-GDDP product on Google Earth Engine

我正在使用 NEX-GDPP 获取 2018-01-01 至 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);

如果有其他方法可以下载此数据,我会打开它。

使用.iterate() 可能会占用大量内存并且容易出现内存错误。一个更直接的方法是 select 您想要关注的特定点,循环所有感兴趣的日子,然后使用 .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 保持为一个点。您可以将所有点合并在一起,并将每个点的时间序列导出到一个文件中,但是导出后可能很难处理...

这是一个有效的 link:https://code.earthengine.google.com/139432f76ae3f6a81b1459762325ef7f