1

I wrote a code in GEE to first aggregate half-hourly GPM data into cumulative daily precipitation and then aggregate daily data into cumulative monthly data. In the next step, to ensure that my code worked correctly, I decided to compare the monthly generated image with the GPM official monthly data. However, the maps of the two monthly precipitation are not the same. I multiplied the summation of 48 half-hourly images by 0.5 since the precipitation unit in these images is mm/hr, but some inconsistencies are still observed in some parts.

  • Does anyone have the same experience?

  • Would you mind please checking my code to see if I have made any mistakes?

I also attached the code:

var countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017"),
    GPM_monthly = ee.ImageCollection("NASA/GPM_L3/IMERG_MONTHLY_V06"),
    GPM = ee.ImageCollection("NASA/GPM_L3/IMERG_V06"),
    visParams = {"palette":["000096","0064ff","00b4ff","33db80","9beb4a","ffeb00","ffb300","ff6400","eb1e00","af0000"]};

// Defining the geometry to clip images with.
var geometry = countries.filter(ee.Filter.eq('country_na', 'Iran'));

// ------------------------------- MONTHLY ---------------------------------------
// Writing a fuction to calculate the number of hours in each month.
var addMonthlyPrecip = function (img) {
  var start = ee.Date(img.get('system:time_start'));
  var end = start.advance(1, 'month');
  var hoursInMonth = end.difference(start, 'hours');
  return img.multiply(hoursInMonth);
};

// Filtering and clipping monthly images.
var monthlyPrec_mm_hr = GPM_monthly
                  .filterBounds(geometry)
                  .filterDate("2014-03-01", "2014-04-01")
                  .select("precipitation");
                  
var monthlyPrec_mm_month = monthlyPrec_mm_hr.map(addMonthlyPrecip);
print('monthlyPrec_mm_month:', monthlyPrec_mm_month);

/*
var monthlyPrec_mm_month_stack = monthlyPrec_mm_month.toBands();
print('monthlyPrec_mm_month_stack:', monthlyPrec_mm_month_stack);

Export.image.toDrive({
  image : monthlyPrec_mm_month_stack,
  description : 'monthlyPrec_mm_month_stack',
  scale : 10000,
  region : geometry,
  crs : "EPSG:4326"
});
*/

Map.addLayer(monthlyPrec_mm_month.map(function(image) { return image.clip(geometry); })
            , visParams
            , 'monthlyPrec_mm_month'
            , false);

// ------------------------------- Daily2Monthly ---------------------------------

/*
function add_date(img){
    var date  = ee.Date(img.get('system:time_start'));
    var date_daily = date.format('YYYY-MM-dd');
    return img.set('date_daily', date_daily);
}
*/

var clipedColl = GPM
                .select('precipitationCal')
                .filterBounds(geometry);

var startDate = ee.Date.fromYMD(2014, 3, 1);
var endDate   = ee.Date.fromYMD(2014, 4, 1);

var numberOfDays = endDate.difference(startDate, 'days');

// Aggregating half hourly images to daily.
var dailyPrec = ee.ImageCollection(
    ee.List.sequence(0, numberOfDays.subtract(1))
    .map(function (dayOffset) {
      var start = startDate.advance(dayOffset, 'days');
      var end = start.advance(1, 'days');
      return clipedColl
        .filterDate(start, end)
        .sum()
        .set('system:time_start', start.millis());
    })
);

print('dailyPrec:', dailyPrec);

// Aggregating daily images to monthly.
var numberOfYears = endDate.difference(startDate, 'years');
var monthlyFromDaily = ee.ImageCollection(
    ee.List.sequence(0, numberOfYears.multiply(12).subtract(1))
    .map(function(monthOffset) {
      var start = startDate.advance(monthOffset, 'month');
      var end = start.advance(1, 'month');
      return dailyPrec
        .filterDate(start, end)
        .sum()
        .set('system:time_start', start.millis());
    })
);

// Multiplying each image to 0.5.
var monthlyFromDailyMultiplied = monthlyFromDaily.map(function(img){
  return img.multiply(0.5);
});
print('monthlyFromDailyMultiplied:', monthlyFromDailyMultiplied);

/*
var monthlyFromDailyMultiplied_stack = monthlyFromDailyMultiplied.toBands();
print('monthlyFromDailyMultiplied_stack:', monthlyFromDailyMultiplied_stack);

Export.image.toDrive({
  image : monthlyFromDailyMultiplied_stack,
  description : 'monthlyFromDailyMultiplied_stack_New',
  scale : 10000,
  region : geometry,
  crs : "EPSG:4326"
});
*/

Map.addLayer(monthlyFromDailyMultiplied.map(function(image) { return image.clip(geometry); })
            , visParams
            , 'monthlyFromDaily'
            , false);

Moreover, I subtracted the half-hourly aggregated image from official GPM monthly data out of GEE, and the difference image is attached. Note that the title of the image is based on GEE code variables.

The title of the image is based on GEE code variables

1 Answer 1

0

if you have a look at the unit of your monthly GPM-IMERG data is also mm/hr. In this case, if you would like to convert it to monthly totals, you need to multiply each value by the number of hours in that month.

Get the number of days in each month

days_in_month = ds.time.dt.days_in_month.  # This can be done with `xarray` in python 

Calculate monthly totals

precipitation_monthly_total = precipitation_mm_hr * days_in_month * 24  

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.