1

I'm using Earth Engine with the Python API in colab, reducing Landsat NDVI over a ROI. I run the following:

imagereduce = image.reduceRegion(**{
    'reducer': ee.Reducer.mean(),
    'geometry': feature,
    'crs': 'EPSG:4326',
    'scale': 30,
    'maxPixels': 1e9
 })

And it give a dictionary object. I can do imagereduce.get('nd') to make it a computed object, but I can't extract the actual value. What I've tried:

  • imagereduce.get('nd').getInfo() processes endlessly with no result or exceeds user memory (same if I make it a number or string object)
  • imagereduce.evaluate() as shown here gives "Dictionary has no attribute evaluate"
  • print(imagereduce.serialize()) gives the metadata for the dictionary
  • doing the same process in javascript will give the value in the console, and will allow both .getInfo() and .evaluate to work, but I will need to (a) do this in python and (b) add the value to an array as I go

Any thoughts on how to get the server-side computed object to a client-side value?

1 Answer 1

2

The first suggestion appears to be correct, but as you noted exceeds the memory limit. If run with a larger scale it will print out results as I have shown with this simple example below

region = ee.Feature(ee.FeatureCollection('EPA/Ecoregions/2013/L3').filter(ee.Filter.eq('us_l3name', 'Sierra Nevada')).first()).geometry()
image = ee.ImageCollection("LANDSAT/LC08/C01/T1").filterBounds(region).first()


#note I have changed the scale
imagereduce = image.reduceRegion(**{
    'reducer': ee.Reducer.mean(),
    'geometry': region,
    'crs': 'EPSG:4326',
    'scale': 200,
    'maxPixels': 1e9
 })


print(imagereduce.get('B1').getInfo())

"There are multiple options to get past these errors: increase maxPixels, increase the scale, or set bestEffort to true, which automatically computes a new (larger) scale such that maxPixels is not exceeded. If you do not specify maxPixels, the default value is used." https://developers.google.com/earth-engine/guides/reducers_reduce_region

Your Answer

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

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