Reduce daily data to monthly using Google Earth Engine

喜夏-厌秋 提交于 2021-01-27 10:14:43

问题


I am looking at precipitation data (both GPM and CHIRPS) for different provinces in Indonesia using Google Earth Engine. GPM is sub-daily (every 30 minutes) and CHIRPS is daily. I am only interested in getting the monthly values. Unlike here and here I am not interested in getting the multi-annual monthly values, but simply the average of each month and make a time series.

Here I found a way to create a list of values containing the mean of each month.

Edit: Thanks to Nicholas Clinton's answer I managed to get it to work:

var fc = ee.FeatureCollection('ft:1J2EbxO3zzCLggEYc57Q4mzItFFaaPCAHqe1CBA4u') // Containing multiple polygons
    .filter(ee.Filter.eq('name', 'bangka')); // Here I select my ROI

Map.addLayer(fc, {}, 'area');
Map.centerObject(fc, 7);

var aggregate_array = fc.aggregate_array('name');
print('Name of area: ', aggregate_array, 'Selected data in FeatureCollection:', fc);

var month_mean = ee.List.sequence(0, 16*12).map(function(n) { // .sequence: number of years from starting year to present
  var start = ee.Date('2002-01-01').advance(n, 'month'); // Starting date
  var end = start.advance(1, 'month'); // Step by each iteration

  return ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY")
        .filterDate(start, end)
        .mean()
        .set('system:time_start', start.millis());
});
print(month_mean); 

var collection = ee.ImageCollection(month_mean);

print(collection);

// Plotting

var area_name = fc.aggregate_array('name').getInfo();
var title = 'CHIRPS [mm/hr] for ' + area_name;

var TimeSeries = ui.Chart.image.seriesByRegion({
    imageCollection: collection,
    regions: fc,
    reducer: ee.Reducer.mean(),
    scale: 5000,
    xProperty: 'system:time_start',
    seriesProperty: 'label'
  }).setChartType('ScatterChart')
    .setOptions({
      title: title,
      vAxis: {title: '[mm/hr]'},
      lineWidth: 1,
      pointSize: 1,
    });

print('TimeSeries of selected area:', TimeSeries);

回答1:


Have not tested, but should be something like this (or set some other date property):

return ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY")
      .filterDate(start, end)
      .sum()
      .set('system:time_start', start.millis());



回答2:


aggregate_prob function in pkg_trend, works just like aggregate in R language.

var imgcol_all = ee.ImageCollection('NASA/GPM_L3/IMERG_V05');

function add_date(img){
    var date  = ee.Date(img.get('system:time_start'));
    var date_daily = date.format('YYYY-MM-dd');
    return img.set('date_daily', date_daily);
}

var startdate = ee.Date.fromYMD(2014,3,1);
var enddate   = ee.Date.fromYMD(2014,4,1);
var imgcol = imgcol_all
    .filter(ee.Filter.date(startdate,enddate)).select('precipitationCal')
    .map(add_date);
// imgcol = pkg_trend.imgcol_addSeasonProb(imgcol); 
print(imgcol.limit(3), imgcol.size());

var pkg_trend = require('users/kongdd/public:Math/pkg_trend.js');
var imgcol_daily = pkg_trend.aggregate_prop(imgcol, "date_daily", 'sum');
print(imgcol_daily);

Map.addLayer(imgcol_daily, {}, 'precp daily');

The GEE link is https://code.earthengine.google.com/2e04ad4a4bee6789af23bfac42f63025



来源:https://stackoverflow.com/questions/51710608/reduce-daily-data-to-monthly-using-google-earth-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!