I'm trying to get the max value of a generated cumulativeCost Image in Earth Engine, via the Python API. I thought reduceRegion should work, but it dies.

My relevant code:

malawi = ee.FeatureCollection('USDOS/LSIB/2017').filter(ee.Filter.inList('COUNTRY_NA', ["Malawi"]))  
malawi_geometry = malawi.geometry()  

nl_raw = ee.ImageCollection('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS')
nl_three_newest = nl_raw.sort('system:time_start', False).limit(3)
nl_stable_lights_only = nl_three_newest.select('stable_lights')
nl_quality_mosaic = nl_stable_lights_only.qualityMosaic('stable_lights')
nl_clipped_to_malawi = nl_quality_mosaic.clip(malawi_geometry)
has_light_at_all = nl_clipped.gte(1)
no_light_at_all = nl_clipped.lt(1)
has_light_at_all_mask = ee.Image().toByte().paint(has_light_at_all.geometry(), 1).updateMask(has_light_at_all)
max_dist = 70 * 1000
dist_to_light_at_all_from_light_mask = no_light_at_all.cumulativeCost(has_light_at_all_mask, max_dist)
dist_to_light_at_all_from_light_mask_max = dist_to_light_at_all_from_light_mask.reduceRegion(

You can check the whole code with comments and displayed maps in Python here:
Or in the web editor in Javascript:

The problem is that the final print dies with this message:

HttpError 400 when requesting https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/value:compute?prettyPrint=false&alt=json returned "EEException: Object too large (133984872 bytes)."

What I've tried:

  • I've checked all the intermediary ImageCollections and Images, put them on a map and they look exactly like they should.
  • I've tried the exact same reduceRegion function with other images, like the nl_quality_mosaic_max or the nl_clipped_to_malawi_max (the results of the previous steps before the cumulativeCost) and with everything else it works as it should: the print(*.getInfo()) gives back a dictionary like "{'stable_lights': 63}".
  • I've tried the same code in the web editor (converted it to javascript, see link above) and exactly the same thing happens.
  • I've tried everything to get any kind of information of the dist_to_light_at_all_from_light_mask_max object like size, type, keys, tried to serialize it and print a slice of that etc etc, but nothing works, I get similar errors, or sometimes just a timeout.
  • Tried to search for the problem, but google and stack came up with exactly nothing.

So what I'm hoping somebody will be able to help me with:

  • Why is it not working?
  • What should I do to make this solution work?
  • If that's not possible, what's the best way to find out the maximum value in a cumulative_cost image?

The motivation for this that I will generate many similar images in different areas, with different light-intensity cutoffs (or even other types of objects from other ImageCollections) etc, ergo the "maximum distance any point can have in the selected region from a lightsource at least this intense" value will range from hundred to the hundred-thousands meters. And of course I want to display these maps on a colorscale, but to do that I need to know the range it has to cover. And also this exact number is a useful information I need to store for later use.

  • As per the Tour there should be only one question asked per question. I think it's much better to ask a single direct question than to ask several related questions to broach it from different directions.
    – PolyGeo
    Jul 8, 2022 at 22:27

1 Answer 1


For some operations you simply need to export an intermediate result before you can continue. In this case, just export the output of the cumulative cost as an asset.

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.