Thursday, 18 October 2018

google earth engine - GEE Change the number of pixels on chart


I'm trying to create a time series chart that will tell me that mean precipitation for a given imageCollection, but my polygon is too big and I get the next error message:



"Error generating chart: Collection.first: Error in map(ID=19991001): Image.reduceRegion: Too many pixels in the region. Found 67144509, but only 10000000 allowed."




How can I change the number of pixels and allow it to calculate the mean precipitation value for a given polygon? Whenever I run my code with the big polygon I get the error messege.


This is my code:


var geometry=table;
var dataset = ee.ImageCollection('NOAA/PERSIANN-CDR')
.filter(ee.Filter.date('1999-10-01', '2018-03-31'))
.filterBounds(geometry);

var precipitation = dataset.select('precipitation');


var onlyPercipitation = precipitation.filter(ee.Filter.calendarRange(10, 3,'month'));
print(onlyPercipitation);

print(ui.Chart.image.series(onlyPercipitation, geometry, ee.Reducer.mean(),30));

Answer



I got the same problem in one of my project, and came up with a workaround. The idea is to split the chart creation into 2 steps:



  • Reduce each image to the value of interest. This will create a Feature Collection from your Image Collection.

  • Create a chart from the resulted Feature Collection.



Example code:


// Create Feature Collection of mean value
var ft_col = onlyPrecipitation.map(function(img) {
var date = img.get('system:time_start')
var mean = img.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: geometry,
maxPixels: 1e13
}).get('precipitation')
return ee.Feature(null, { precipitation: mean, 'system:time_start': date })

})
// Create and print chart from ft_col
print(ui.Chart.feature.byFeature(ft_col, 'system:time_start', 'precipitation'))

By using img.reduceRegion, you can specify the maximum number of pixels to reduce via maxPixels. Feel free in increase it if 1e13 is not enough.


P.S. I think you mean onlyPrecipitation not onlyPercipitation in your code?


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