I am working with GSMaP image collection (hourly rainfall data) in Google Earth Engine. I would like to make a script which is calculating and making a chart of sum rainfall in particular location during the March-May over the last 10 years. I made a script based on my skills in the platform, please find it below. The made script runs very slow and at the end gives error: "Error generating chart: Computation timed out". How can I optimize the script and solve this issue?

var point = ee.Geometry.Point([68.27212640755545, 40.007493398363955]);

var img_1 = ee.ImageCollection("JAXA/GPM_L3/GSMaP/v6/reanalysis")
    .filterDate('2000-03-01', '2014-03-01').select('hourlyPrecipRateGC');

var img_2 = ee.ImageCollection("JAXA/GPM_L3/GSMaP/v6/operational")
    .filterDate('2014-03-01', '2030-12-31').select('hourlyPrecipRateGC');

var imgcol_2008 = img_1.merge(img_2)
    .filterDate('2008-03-01', '2008-05-31').sum(); 

var imgcol_2009 = img_1.merge(img_2)
    .filterDate('2009-03-01', '2009-05-31').sum();

var imgcol_2010 = img_1.merge(img_2)
    .filterDate('2010-03-01', '2010-05-31').sum();

var imgcol_2011 = img_1.merge(img_2)
    .filterDate('2011-03-01', '2011-05-31').sum();

var imgcol_2012 = img_1.merge(img_2)
    .filterDate('2012-03-01', '2012-05-31').sum();

var imgcol_2013 = img_1.merge(img_2)
    .filterDate('2013-03-01', '2013-05-31').sum();

var imgcol_2014 = img_1.merge(img_2)
    .filterDate('2014-03-01', '2014-05-31').sum();

var imgcol_2015 = img_1.merge(img_2)
    .filterDate('2015-03-01', '2015-05-31').sum();

var imgcol_2016 = img_1.merge(img_2)
    .filterDate('2016-03-01', '2016-05-31').sum();

var imgcol_2017 = img_1.merge(img_2)
    .filterDate('2017-03-01', '2017-05-31').sum();

var imgcol_2018 = img_1.merge(img_2)
    .filterDate('2018-03-01', '2018-05-31').sum();

var imgcol_2019 = img_1.merge(img_2)
    .filterDate('2019-03-01', '2019-05-31').sum();

var imgcol_2020 = img_1.merge(img_2)
    .filterDate('2020-03-01', '2020-05-31').sum();

var image = ee.ImageCollection([imgcol_2008, imgcol_2009, imgcol_2010, imgcol_2011, imgcol_2012, 
        imgcol_2013, imgcol_2014, imgcol_2015, imgcol_2016, imgcol_2017, imgcol_2018, 
            imgcol_2019, imgcol_2020]);

var chart = ui.Chart.image.series(image, point, ee.Reducer.mean(), 1000);
    title: 'March-May Rainfall over years',
    vAxis: {title: 'Rainfall (mm)'},
    hAxis: {title: 'date', format: 'yy'},


1 Answer 1


I tried it couple of times and indeed the computation timed out easily. Possibly this is due to the fact that the images you are using are global. A way to fix it is clip the images to a certain region of interest you are interested in.

Define an aoi:

var aoi = ee.Geometry.Polygon(
        [[[50.982280478435996, 51.31165773243619],[50.91620607976381, 49.65081091210988],
          [56.38950662923821, 49.85631932546316],[56.34540231988092, 51.29794548618846]]]);

Making the collection with clipping I would perform like this:

// make a list for the years to include
var startYear = 2008; var endYear = 2020;
var listYears = ee.List.sequence(startYear, endYear, 1);

var summedCollection = ee.ImageCollection.fromImages(listYears.map(function(year){
  var start = ee.Date.fromYMD(year, 3, 1);
  var end = ee.Date.fromYMD(year, 6, 01);
  // clip the images to reduce the size of the images
  var summedClipped = combined.filterDate(start, end).sum().clip(aoi)
  return summedClipped.rename('summedPrecipitation')
            .set('system:time_start', start.millis()).set('system:time_end', end.millis());

And then you can make some random point in your aoi or define them yourself later on and print a chart of the summed precipitation:

// print chart and data
var randomPoints = ee.FeatureCollection.randomPoints(aoi, 5);
var chart = ui.Chart.image.seriesByRegion(summedCollection, randomPoints, ee.Reducer.first(), 'summedPrecipitation', 1000);
    title: 'Summed March-May Rainfall over years',
    vAxis: {title: 'Rainfall (mm)'},
    hAxis: {title: 'date', format: 'yy'},

Link to script

  • Thank you for you suggestion. It works much more faster then previous script and provides result. But, I don't know why this script is giving over estimated rainfall event in the points. I have compared with the data which I have earlier acquired by extracting daily rainfall event in point scale. I tried also to find solution, unfortunately I found not find what is wrong here. Jan 14, 2019 at 10:20
  • I found the wrong part. It should be "var end = ee.Date.fromYMD(ee.Number(year), 6, 01);", not "var end = ee.Date.fromYMD(ee.Number(year).add(1), 6, 01);" Jan 14, 2019 at 12:04
  • 1
    Yes you are right, I used to make the year composites with both month and day equal to 1 January. In that case you need the year.add(1). I updated the answer.
    – Kuik
    Jan 14, 2019 at 12:17
  • One more question, please. How to edit ".set('system:time_start', start.millis()).set('system:time_end', end.millis())" to set only year, instead of full date? Jan 14, 2019 at 12:29
  • start.format('Y'). Similar for end
    – Kuik
    Jan 22, 2019 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.