Google Earth Engine-计算一个时间段内最长的干旱天数 [英] Google Earth Engine - counts days of the longest dry period in a time period

查看:43
本文介绍了Google Earth Engine-计算一个时间段内最长的干旱天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to map the max number of consecutive days with rain <1 mm in Google Earth Engine.

这是代码的链接

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

首先,如果rain< = 1,我将集合重新分类为0,如果> 1,我将分类为1.然后,我运行了应该计算出最长干燥期的天数的代码,但是只有在干燥期达到该时间段的末尾时,它才能这样做.

First I reclassify the collection with 0 if rain <=1 and 1 if >1. Then I run the code that should count the days of the longest dry period, but it is able to do so only if the dry period reach the end of the time period.

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

For instance if I am looking for the longest dry period in 4 days timestep i get the following series:

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)

有人可以帮助解决这个问题吗?谢谢

Does anyone can help in solving this? Thanks

推荐答案

我认为您在提供的代码中相距不远.要跟踪干法术,您必须使用 .iterate().我以一种稍微不同的方式对您的应用程序进行了测试,而不是在迭代之前对数据进行分类,而是计算每天哪些像素干燥,然后将像素干燥的累计天数保留下来,否则将其设置为零:

I don't think you were far off in your code that you provided. To keep track of the dry spells you have to use .iterate(). I took a stab at your application in a little different way where instead of classifying the data before the iteration, I calculate which pixels are dry each day and carry over the accumulated days that a pixel is dry, otherwise it is set to zero:

// 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');

以下是代码的链接: https://code.earthengine.google.com/80b4c0f7e82a5f0da316af1d2a55

请勿长时间运行此分析,否则Earth Engine会出错.我希望这会有所帮助!

Don't try to run this analysis for too long of a time period or Earth Engine will give an error. I hope this helps!

这篇关于Google Earth Engine-计算一个时间段内最长的干旱天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆