2

I need to compute the mean monthly precipitation sum between 2001 and 2021 (May to September). I know ho to compute the mean over all months of the period but I don't know how to handle the unit. My first attempt to compute the monthly sum was to multiply each value (mm/hr) with the number of hours (24*31) but there are months with only 30 days so this leads to higher values in June and September. Is there any way to solve this problem?

Before that I tried to use the half-hour GPM Dataset (which I preferred first because I need to do this with 2022 as well to compute the anomaly) to just compute the sum of all values per month but I always got the error "User memory limit exceeded" while computing so I changed my strategy.

var gpmMonthly = ee.ImageCollection("NASA/GPM_L3/IMERG_MONTHLY_V06").select('precipitation').filterDate('2001-01-01', '2021-09-01')

var gpmMonthly = gpmMonthly.map(function(image) {
  return image.multiply(31*24).copyProperties(image, ['system:time_start'])
})

var months = ee.List.sequence(1, 12);

var monthlyMean = ee.ImageCollection.fromImages(
      months.map(function (m) {
        return gpmMonthly.filter(ee.Filter.calendarRange(m, m, 'month'))
                    .select(0).mean()
                    .set('month', m);
}))

monthlyMean = monthlyMean.filter(ee.Filter.rangeContains('month', 5, 9))

1 Answer 1

2

You can convert your function:

var gpmMonthly = gpmMonthly.map(function(image) {
  return image.multiply(31*24).copyProperties(image, ['system:time_start'])
})

in the following function:

var gpmMonthlySum = gpmMonthly_list.map(function(image) {
  
  var date = ee.Date(ee.Image(image).get('system:time_start'));
  var year = date.get('year');
  var month = date.get('month');
  
  var typeYear = ee.Number(year).mod(4).eq(0).and(ee.Number(year).mod(100).neq(0)).or(ee.Number(year).mod(400).eq(0));
  
  var days = ee.Algorithms.If(month.eq(1)
                                   .or(month.eq(3))
                                   .or(month.eq(5))
                                   .or(month.eq(7))
                                   .or(month.eq(8))
                                   .or(month.eq(10))
                                   .or(month.eq(12)), 31, 
             ee.Algorithms.If(month.eq(4)
                                   .or(month.eq(6))
                                   .or(month.eq(9))
                                   .or(month.eq(11)), 30, 
            ee.Algorithms.If(month.eq(2).and(typeYear.eq(0)), 28, 29)));
  
  return ee.Image(image).multiply(ee.Number(days).multiply(24)).copyProperties(image, ['system:time_start']);

});

where days per month are assigned as follows: 31 for January, March, May, July, August, October and December (1, 3, 5, 7, 8, 10, 12); 30 for April, June, September, November (4, 6, 9, 11); 28 for February (2) on not leap year (365 days) and 29 for February (2) on leap year (366 days).

Complete code looks as follows:

    var gpmMonthly = ee.ImageCollection("NASA/GPM_L3/IMERG_MONTHLY_V06")
      .select('precipitation')
      .filterDate('2001-01-01', '2021-09-01');
    
    print(gpmMonthly);
    
    var gpmMonthly_list = gpmMonthly.toList(gpmMonthly.size());
    
    var gpmMonthlySum = gpmMonthly_list.map(function(image) {
      
      var date = ee.Date(ee.Image(image).get('system:time_start'));
      var year = date.get('year');
      var month = date.get('month');
      
      var typeYear = ee.Number(year).mod(4).eq(0).and(ee.Number(year).mod(100).neq(0)).or(ee.Number(year).mod(400).eq(0));
      
      var days = ee.Algorithms.If(month.eq(1)
                                       .or(month.eq(3))
                                       .or(month.eq(5))
                                       .or(month.eq(7))
                                       .or(month.eq(8))
                                       .or(month.eq(10))
                                       .or(month.eq(12)), 31, 
                 ee.Algorithms.If(month.eq(4)
                                       .or(month.eq(6))
                                       .or(month.eq(9))
                                       .or(month.eq(11)), 30, 
                ee.Algorithms.If(month.eq(2).and(typeYear.eq(0)), 28, 29)));
      
      return ee.Image(image).multiply(ee.Number(days).multiply(24)).copyProperties(image, ['system:time_start']);
    
    });
    
    gpmMonthlySum = ee.ImageCollection(gpmMonthlySum);
    
    var months = ee.List.sequence(1, 12);
    
    var monthlyMean = ee.ImageCollection.fromImages(
          months.map(function (m) {
            return gpmMonthlySum.filter(ee.Filter.calendarRange(m, m, 'month'))
                        .select(0).mean()
                        .set('month', m);
    }))
    
    monthlyMean = monthlyMean.filter(ee.Filter.rangeContains('month', 5, 9));
    
    print(monthlyMean);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.