Skip to main content

Hello everyone, i want to ask you if there is a way to calculate the avrage NDVI of a land crop knowing that i already have it’s polygone coordinates, all i can get so far is the image of it,



i’m using Maxim’s Lamare script for Mapping crop NDVI with Sentinel-1 and Sentinel-2

thank you,

There are two approaches to calculate the average NDVI, depending on the method you are using to query the data.


If you are using Python, you could access the data in a numpy array and perform statistical calculations on the array in Python.


An alternative approach would be to use our Statistical API, by creating a layer in your dashboard, and calling it with the API.


In both cases, you will need to change my Evalscript a little bit. Indeed, currently the data returned aren’t the actual physical values but RGB colours associated to values for visualisation purposes.


Rather than return the 3 bands in the evalscript, you would want to return 1 band with either the ndvi variable or the s1_ndvi variable.


sure i will try Statistical API and see the result, thank you.


i used this evalscript
evalscript = """ //VERSION=3 function setup() { return{ input: [{ bands: ["B04", "B08"] }], output: { id: "default", bands: 1, sampleType: SampleType.FLOAT32 } } } function evaluatePixel(sample) { let ndvi = (sample.B08 - sample.B04) / (sample.B08 + sample.B04) return [ ndvi ] } """

while using this methode to calculate NDVI from numpy matrice i get after request

response = request.get_data()


newarr = np.vstack(response)

a = np.ma.array(newarr, mask=np.isnan(newarr))
np.average(a)

Reply