Sunday, 10 March 2019

Have NDVI layer and want to Calculate area(pixel area-reduce region) .in Python API for Earth Engine


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)

Answer



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))

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...