0

I'm trying to extract the day of maximum and minimum value of time series. The day of minimum value must be after the day of the max value. The day of max can be get by using ".qualityMosaic" in a function. I have troubles in make a working function for the detection of the date if the min.

How can I implement the right function?

///////////////////////////////////////////////////////////////////////
// THESE FUNCTIONS WORKS FOR A SINGLE YEAR
var max = LTAdata_to_process.qualityMosaic('precipitation').select('day');
print(max,'max')

var min = LTAdata_to_process.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')

It looks quite complex because for the detection of the date of min for each of the year I need to use the respective date of max calculated in the previous step.

Here is the link to the code https://code.earthengine.google.com/e382ce2fc0140e827a887301d409e0fe

Any suggestion?

  • Please provide a code snippet within your question body. – PolyGeo Jan 12 at 8:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.