I want to determine the 'global' minimum and maximum value for a calculated variable in Google Earth Engine. Essentially, my goal is to use a global geometry in reduceRegion(). However, Earth Engine complains when I use an unbounded geometry (image.geometry()) as my region argument. Is there a way to get the range of a calculated image in GEE?
Here is my code:
////////////////////////////////////////////////////////
// Get global min and max of SPEI from TerraClim data///
////////////////////////////////////////////////////////
// Get dataset
var terraClim = ee.ImageCollection('IDAHO_EPSCOR/TERRACLIMATE').filterDate('2017-10-01', '2018-09-30');
terraClim = terraClim.select('pr', 'pet');
// Calculate SPEI from the precipitation and potential evapotranspiration bands
var spei = terraClim.map(function(img){
img = ee.Image(img);
var pr = img.select("pr");
var pet = img.select("pet");
var spei = img.expression('pr - pet', {pr:pr,pet:pet});
return img.select()
//.addBands(pr.rename('pr'))
//.addBands(pet.rename('pet'))
.addBands(spei.rename('spei'))
.set('system:time_start', img.get('system:time_start'));
});
Map.addLayer(spei.first(),
{min:-2000, max:100, palette:['white','red', 'orange', 'yellow', 'brown', 'green', 'blue', 'purple']}, 'spei');
// Get global min and max values of SPEI using reduceRegion
var spei_min = spei.first().reduceRegion({
reducer: ee.Reducer.min(),
geometry: spei.geometry(),
bestEffort: true,
});
var spei_max = spei.first().reduceRegion({
reducer: ee.Reducer.max(),
geometry: spei.geometry(),
bestEffort: true,
});
print('Global minimum SPEI:', spei_min);
print('Global maximum SPEI:', spei_max);
Here is the error I get when I try to print the resulting dictionaries:
Image.reduceRegion: Provide 'geometry' parameter when aggregating over an unbounded image.
Link to my code in code editor: https://code.earthengine.google.com/32957edb7eb0b4797b503dc7605a10b5