Skip to main content
edited body
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82

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).

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).

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).

Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82

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