I am trying to calculate the total monthly precipitation rate using the Rainf_f_tavg band of the GLDAS-2.1 image collection on Google Earth Engine (https://developers.google.com/earth-engine/datasets/catalog/NASA_GLDAS_V021_NOAH_G025_T3H#bands). This is the code I have so far. However I keep getting the error user memory limit exceeded.
I assume this happens because I am trying to analyse images over such a long timeframe (2001-2020), but I still get the error even when I am analysing a much shorter time frame. I can only analyse 1 single year without getting an error. I used the code in the answer to this question to try and reduce the images that need to be analysed by first computing the daily means Download GLDAS precipitation monthly 1 km resolution data by Earth-engine but it still seems to be too much. Is there any way around this or a way that I can reduce the number of images that need to be analysed further? Or is there a similar dataset I could use which is less computationally intensive?
var startDate = ee.Date('2001-01-01');
var endDate = ee.Date('2020-12-31');
var startYear = startDate.get('year');
var endYear = endDate.get('year');
var years = ee.List.sequence(startYear, endYear);
var months = ee.List.sequence(1,12);
var lst = ee.ImageCollection("NASA/GLDAS/V021/NOAH/G025/T3H")
.select('Rainf_f_tavg')
.filterDate(startDate, endDate);
print(lst.size());
var days = endDate.difference(startDate, 'days');
var daysStep = 1;
var timeSeries = ee.ImageCollection(
ee.List.sequence(0, days.subtract(1), daysStep)
.map(function (offsetDays) {
var start = startDate.advance(offsetDays, 'days');
var end = start.advance(daysStep, 'days');
var composite = lst
.filterDate(start, end)
.mean(); // You need to decide how to combine the images
return composite
.set('system:time_start', start.millis())
.set('empty', composite.bandNames().size().eq(0));
})
).filterMetadata('empty', 'equals', 0);
print(timeSeries.size());
var transformed = timeSeries.map(function (image) {
var date = image.get('system:time_start');
var img = image.multiply(86400).set('system:time_start', date);
return img;
});
//print(transformed);
// make monthly mean mosaics
// loop over the years and months to get summed monthly images
var byMonth = ee.ImageCollection(ee.FeatureCollection(years.map(function(y){
var yearCollection = transformed.filter(ee.Filter.calendarRange(y, y, 'year'));
var byYear = ee.ImageCollection.fromImages(
months.map(function(m) {
var maxImage = yearCollection.filter(ee.Filter.calendarRange(m, m, 'month'))
.reduce(ee.Reducer.sum());
var date = ee.Date.fromYMD(y, m, 1).format("MM_dd_YYYY");
return maxImage.set('system:time_start', ee.Date.fromYMD(y, m, 1)).rename(date);
//.set('month', m).set('year', y); // eventually set year and month
}));
return byYear;
})).flatten());
// filter the empty one out
var outputMonthly = byMonth.filter(ee.Filter.listContains('system:band_names', 'constant').not())
.sort('system:time_start').toBands();
var features = outputMonthly.reduceRegions(donetsk, ee.Reducer.first(), 30);
//print(features);
Export.table.toDrive(features,
"Donetsk_monthly_precip_totals_2000_2005_v21");