I had already asked this question for Earth Engine Javascript.The link is given below I have NDVI layer in Earth Engine. I want to assign and calculate area of good and bad ndvi area I wamted to do the same thing in Python API for earth engine. But it is showing the following error- EEException: Invalid argument for ee.Reducer(): ({'geometry': [[74.022029, 20.103245], [74.022029, 20.116564], [74.038048, 20.116564], [74.038048, 20.103245]], 'reducer': , 'scale': 10},). Must be a ComputedObject. I am also sharing a snippet of my code in Python-

    ndvi = clip.normalizedDifference(['B8', 'B4'])
    avg=ndvi.gt(0.2) and(ndvi.lte(0.35)).rename('avg')
    ndvi.addBands(['bad', 'avg', 'good'])
    print (ndvi)
    areas = ndvi.select(['bad', 'avg','good']).multiply(ee.Image.pixelArea()).reduceRegion({'reducer':ee.Reducer 
    print (areas)

You can't specify arguments with a dictionary in Python; Python has it's own method for specifying keyword arguments:

areas = (ndvi.select(['bad', 'avg','good']).multiply(ee.Image.pixelArea())
    .reduceRegion(reducer=ee.Reducer.sum(), geometry=geometry1, scale=10))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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