Friday, 3 November 2017

google earth engine - reduce image collection to get annual monthly sum precipitation


I'm using GRIDMET image collection in Google Earth Engine, which has daily climate data from ~1980 to present. I would like to create an image collection of monthly (May-September: each month) sum precipitation for each year (1986-2016). I've been trying to create a function to do so, but can't figure it out.


https://code.earthengine.google.com/ceba35ee52955ec5e174e0293cebb7b8



Answer



Here is an example that should get you started:


var modis = ee.ImageCollection('MODIS/MOD13A1');


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

// Group by month, and then reduce within groups by mean();
// the result is an ImageCollection with one image for each
// month.
var byMonth = ee.ImageCollection.fromImages(
months.map(function (m) {
return modis.filter(ee.Filter.calendarRange(m, m, 'month'))
.select(1).mean()

.set('month', m);
}));
print(byMonth);

Map.addLayer(ee.Image(byMonth.first()));

Obviously you're going to want to replace the mean() with sum(), etc.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...