使用 Google Earth Engine 从时间序列中提取最大值和最小值的日期

Date of max and min value extraction from time series using Google Earth Engine

我正在尝试提取时间序列的最大值和最小值的日期。最小值日必须在最大值日之后。可以通过在函数中使用“.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')

它看起来很复杂,因为为了检测每年的最小日期,我需要使用在上一步中计算出的各自的最大日期。

这是代码的 link https://code.earthengine.google.com/03e80671a65c95a60535dbd1c50ebe93

有什么建议吗? 谢谢!!

这可行https://code.earthengine.google.com/6a035a4a301f5bebcf7f40d4be9a551c 更改了第 119 行

var z = ee.Image(max
    .filterMetadata('year', 'equals', y).first());