Google Earth Engine - 计算一个时间段内最长干旱期的天数

Google Earth Engine - counts days of the longest dry period in a time period

我正在尝试在 Google Earth Engine 中绘制降雨 <1 毫米的最大连续天数。

这是link代码

https://code.earthengine.google.com/22b5c20d2700a2ffb5989f892838ac58

首先,如果雨 <=1,我将集合重新分类为 0,如果 >1,则为 1。 然后我运行应该计算最长干燥期天数的代码,但只有当干燥期到达时间段结束时才能这样做。

例如,如果我正在寻找 4 天时间步长中最长的干燥期,我会得到以下系列:

rain days 1 2 3 4   output
          0,0,1,1 = 0 dry days
          0,1,0,0 = 2 dry days
0 = rain<=1 and 
1 = rain>1 (as per the first step)

有谁能帮忙解决这个问题吗? 谢谢

我认为您提供的代码离我们不远。要跟踪干燥期,您必须使用 .iterate()。我以一种有点不同的方式尝试了你的应用程序,我不是在迭代前对数据进行分类,而是计算每天哪些像素是干燥的,并计算一个像素干燥的累积天数,否则它被设置为零:

// DATA
var collection = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY");

// Define time range
var startyear = 2000;
var endyear = 2017;

var startmonth = 1;
var endmonth = 12;

// Set date in ee date format
var startdate = ee.Date.fromYMD(startyear,startmonth,1);
var enddate = ee.Date.fromYMD(endyear,endmonth,31);

// Filter data
var datain_t = collection.filterDate(startdate, enddate)
  .filter(ee.Filter.calendarRange(startmonth,endmonth, 'month'))
  .select("precipitation").map(function(img){
     return img.addBands(ee.Image.constant(0).uint8().rename('counter'));
  })
  .sort('system:time_start');

// // START 
var dataset = datain_t
.filterDate("2016-08-01","2016-08-30")
.sort('system:time_start:');
print(dataset,"dataset");

var precipThresh = 1; // mm

function drySpells(img, list){
  // get previous image
  var prev = ee.Image(ee.List(list).get(-1));
  // find areas gt precipitation threshold (gt==0, lt==1)
  var dry = img.select('precipitation').lt(precipThresh);
  // add previous day counter to today's counter
  var accum = prev.select('counter').add(dry).rename('counter');
  // create a result image for iteration
  // precip < thresh will equal the accumulation of counters
  // otherwise it will equal zero
  var out = img.select('precipitation').addBands(
        img.select('counter').where(dry.eq(1),accum)
      ).uint8();
  return ee.List(list).add(out);
}

// create first image for iteration
var first = ee.List([ee.Image(dataset.first())]);

// apply dry speall iteration function
var maxDrySpell = ee.ImageCollection.fromImages(
    dataset.iterate(drySpells,first)
).max(); // get the max value

// display results
Map.addLayer(maxDrySpell.select('counter'),{min:0,max:30,palette:'#9ecae1,#ffffff,#ffeda0,#feb24c,#f03b20'},'Max Dry Spells');

这是代码的 link:https://code.earthengine.google.com/80b4c0f7e82a5f0da316af1d2a55dd59

请勿尝试 运行 此分析的时间过长,否则 Earth Engine 会出错。希望对您有所帮助!