我正在尝试提取时间序列的最大值和最小值的日期。最小值的日期必须在最大值的日期之后。可以通过在函数中使用“ .qualityMosaic”来获得最大值。我在设置工作功能以检测日期(如果最小值)时遇到麻烦。
如何实现正确的功能?
/////////THESE FUNCTIONS WORKS FOR A SINGLE YEAR (EXAMPLE)
var max = example.qualityMosaic('precipitation').select('day');
print(max,'max')
var min = example.map(
function(img) {
var date = img.date().millis()
return img.updateMask(max.lt(date))
}).select('precipitation', 'day').reduce(ee.Reducer.min(2)).rename('precipitation','day')
print(min,'min')
///////////HERE IS AS I HAVE IMPLEMENTED FOR A TIME-SERIES WITH > 1 YEAR
// Find the day of max for each year
var max = ee.ImageCollection(
years.map(function (y) {
var start = ee.Date.fromYMD(y, startmonth,startday);
var stop = ee.Date.fromYMD (y,endmonth,endday);
var x = collection.filterDate(start, stop)
var w = x.qualityMosaic('precipitation').select('day')
return w.set({'year': y})
}).flatten());
print(max,'max')
Map.addLayer(max, {min: 1, max: 365}, 'max')
// Find the day of min after day of max for each year
var min = ee.ImageCollection(
years.map(function (y) {
var start = ee.Date.fromYMD(y, startmonth,startday);
var stop = ee.Date.fromYMD (y,endmonth,endday);
var x = collection.filterDate(start, stop)
var z = max.filter(ee.Filter.calendarRange(y, y, 'year'))
var w = x.map(
function(img) {
var date = img.date().millis()
var k = img.updateMask(z.lt(date))
return k
}).select('precipitation', 'day').reduce(ee.Reducer.min(2)).rename('precipitation','day')
return w
}).flatten());
print(min,'min')
Map.addLayer(min, {min: 1, max: 365}, 'min')
这看起来非常复杂,因为要检测每年的最小日期,我需要使用上一步中计算出的最大日期。
这是代码的链接 https://code.earthengine.google.com/03e80671a65c95a60535dbd1c50ebe93
有什么建议吗? 谢谢!
答案 0 :(得分:1)
这可能有效https://code.earthengine.google.com/6a035a4a301f5bebcf7f40d4be9a551c更改了第119行
var z = ee.Image(max
.filterMetadata('year', 'equals', y).first());