The GPM: Monthly Global Precipitation Measurement (GPM) v6 dataset consists of monthly images that have precipitation band with data in units of mm/hr. How can the precipitation data be converted into units of mm/month, respecting the variation in the length of individual months?
1 Answer
Start with an image collection of monthly precipitation data:
// Copyright 2020 Google LLC.
// SPDX-License-Identifier: Apache-2.0
var ic = ee.ImageCollection("NASA/GPM_L3/IMERG_MONTHLY_V06")
.filterDate('2019', '2021')
.select('precipitation');
Write a function that takes a monthly image, determines the number of hours in that month, calculates the precipitation in that month, and adds that information as a new band of the image:
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.addBands(img.multiply(hoursInMonth).rename('precip_mm_month'));
};
Next apply that function to every image in the collection.
ic = ic.map(addMonthlyPrecip);
The new data can now be displayed or analyzed further:
Map.addLayer(ic, {bands:'precip_mm_month', max: 720});
The results look rather ghostly...
The complete script is available here: https://code.earthengine.google.com/49de1393b88184d7d6a247dc2e1357bb