1

Question: Why won't image reduce region accept either a scale or a reprojection, in most of my cases but not all.

Context: I'm trying to find if a landsat pixel has any cloud (based on SimpleCloudScore) and then if no cloud I will extract the other bands to csv, I know this is intensive and slow but will only be done for a few select pixels. The errors may be something to do with the region being a point but it has worked for some of the points.

def arethereclouds(image):
    image_cloud = image.select('cloud')
    total_cloud = image_cloud.reduceRegion(**{
        'reducer': ee.Reducer.sum(), 
        'geometry': eefeature_point,
        'maxPixels': 100000,
        'scale': 30,
        
    })
    im = ee.Algorithms.If(ee.Number(total_cloud.get('cloud')).gt(1), ee.Image.constant(-999).rename('extraction_band'), image)
    return im 

I started with the error "EEException: Image.reduceRegions: The default WGS84 projection is invalid for aggregations. Specify a scale or crs & crs_transform." for some, not all of the features I've tried

So I added

 'crs': 'EPSG:3857' , 
 'crsTransform':[1,0,0,0,1,0]

to the reducer, resulting in the error "EEException: ImageCollection.toBands: Error in map(ID=LC08_186029_20130505): Image.reduceRegion: Cannot specify both crsTransform and scale."

But when I remove scale from the reducer, we go the full circle back to the original EEexception?

Efforts to fix it I've tried:

  • adding a buffer to the feature to see if it was some issue there
  • different EPSGs
  • different scales

1 Answer 1

0

Here's a complete, runnable example that completes without error. If you're getting errors with different input, the problem might be there. But you haven't provided any information on it.

import ee

ee.Initialize()

image = ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_194053_20201124').select(['B1'], ['cloud'])
    
eefeature_point = image.geometry().centroid()

def arethereclouds(image):
    image_cloud = image.select('cloud')
    total_cloud = image_cloud.reduceRegion(
        reducer=ee.Reducer.sum(), 
        geometry=eefeature_point,
        maxPixels=100000, 
        scale=30    
    )
    im = ee.Algorithms.If(ee.Number(total_cloud.get('cloud')).gt(1), ee.Image.constant(-999).rename('extraction_band'), image)
    return im 

arethereclouds(image).getInfo()

This outputs

{'type': 'Image',
 'bands': [{'id': 'extraction_band',
   'data_type': {'type': 'PixelType',
    'precision': 'int',
    'min': -999,
    'max': -999},
   'crs': 'EPSG:4326',
   'crs_transform': [1, 0, 0, 0, 1, 0]}]}
2
  • Thanks, but that still results in the same errors.
    – svollowork
    Jul 7, 2021 at 16:49
  • I updated my answer. Jul 7, 2021 at 16:59

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.