Saturday 24 September 2016

javascript - Reducing hourly rainfall data to monthly data for particular period of time and making a timeseries chart


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);
chart.setOptions({
title: 'March-May Rainfall over years',
vAxis: {title: 'Rainfall (mm)'},
hAxis: {title: 'date', format: 'yy'},
});

print(image)
print(chart)


Answer



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);
chart.setOptions({
title: 'Summed March-May Rainfall over years',
vAxis: {title: 'Rainfall (mm)'},
hAxis: {title: 'date', format: 'yy'},
});

print(chart);

Link to script


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...