0

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'])
    #NDVI=ndvi.multiply(100).uint8()
    bad=ndvi.gte(0)and(ndvi.lte(0.2)).rename('bad')
    avg=ndvi.gt(0.2) and(ndvi.lte(0.35)).rename('avg')
    good=ndvi.gt(0.35)and(ndvi.lte(1)).rename('good')
    ndvi.addBands(['bad', 'avg', 'good'])
    print (ndvi)
    areas = ndvi.select(['bad', 'avg','good']).multiply(ee.Image.pixelArea()).reduceRegion({'reducer':ee.Reducer 
    .sum(),'geometry':geometry1,'scale':10});
    print (areas)
2

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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