Skip to main content

How to get evalscript that calculates NDVI for each available satellite repectively

  • April 26, 2024
  • 13 replies
  • 664 views

in the project i am working on, i should calculate the ndvi for all satellite missions.
i know how to structure and build the request, but it seems the evalscript through which the ndvi is calculated differs according to the selected satellite mission.
my question is, can i refer to EO Browser
and copy the evalscript from it? i mean, one can check the evalscript used in the latterly mentioned link, can i simply copy the evalscript from it and paste it in my code?! is that possible

13 replies

  • 4852 posts replied to
  • April 26, 2024

It is unlikely to work since the EO Browser script includes some other outputs for additional functionality specific to the browser.

Your best bet is to get a very simple NDVI evalscript, like under the Raw tab in the custom scripts repository Normalized difference vegetation index | Sentinel Hub custom scripts

And then replace the input bands in the script. The same custom script page also shows you which bands are used for other satellites.


  • Author
  • 3963 posts replied to
  • April 26, 2024

thanks
i referred to the link you posted in your answer, however, i could not find info about sentinel-3 and sentinel-5
aren’t they able to get ndvi vlaues?!


  • 4852 posts replied to
  • April 26, 2024

Sentinel-5 isn’t able to produce NDVI. For Sentinel 3 it is:

(B17 - B08) / (B17 + B08)


  • Author
  • 3963 posts replied to
  • April 26, 2024

thanks
but would you please tell me where did get this infor?
i checked this link but i could not find it

thanks


  • 4852 posts replied to
  • April 26, 2024

NDVI needs a Red and NIR band. Check the available bands for the sensor you want to use (S5P listed here Sentinel-5P L2) and see if they have a red and NIR band. If not, calculating NDVI is not possible.


  • Author
  • 3963 posts replied to
  • April 26, 2024

would you please tell me why the following evalscript does not work for sentinelhub-3

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

  • 4852 posts replied to
  • April 26, 2024

You have to use Sentinel 3 OLCI


  • Author
  • 3963 posts replied to
  • April 26, 2024

yes, i was using the identifier sentinel-3-olci as shown in the below posted request,…it does not work even in the request-builder

request:

"input": {
	"bounds": {
	  "geometry": {
		"type": "Polygon",
		"coordinates": [
		  [
			[
			  1445883.5319464942,
			  6569386.912474411
			],
			[
			  1443278.0408928054,
			  6557300.32588317
			],
			[
			  1461009.851474265,
			  6565840.548767853
			],
			[
			  1445883.5319464942,
			  6569386.912474411
			]
		  ]
		]
	  },
	  "properties": {
		"crs": "http://www.opengis.net/def/crs/EPSG/0/3857"
	  }
	},
	"data": [
	  {
		"dataFilter": {
		  "timeRange": {
			"from": "2022-01-01T00:00:00Z",
			"to": "2022-01-16T23:59:59Z"
		  }
		},
		"type": "sentinel-3-olci"
	  }
	]
  },
  "output": {
	"width": 512,
	"height": 348.742,
	"responses": [
	  {
		"identifier": "default",
		"format": {
		  "type": "image/tiff"
		}
	  }
	]
  },
  "evalscript": "//VERSION=3\n    function setup() {\n      return{\n        input: [{\n          bands: [\"B08\", \"B17\"]\n        }],\n        output: {\n          id: \"default\",\n          bands: 1,\n          sampleType: SampleType.FLOAT32\n        }\n      }\n    }\n    \n    function evaluatePixel(sample) {\n      let ndvi = (sample.B17 - sample.B08) / (sample.B17 + sample.B08)\n      return [ ndvi ]\n    }"

  • 4852 posts replied to
  • April 26, 2024

Does it show an error?


  • Author
  • 3963 posts replied to
  • April 26, 2024

in the request-builder it says something went wrong
and in my code, i receive bad-request


  • 4852 posts replied to
  • April 26, 2024

For me your request works.

Can you try this request:

curl -X POST https://creodias.sentinel-hub.com/api/v1/process \
 -H 'Content-Type: application/json' \
 -H 'Authorization: Bearer ' \
 -d '{
  "input": {
    "bounds": {
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              1445883.5319464942,
              6569386.912474411
            ],
            [
              1443278.0408928054,
              6557300.32588317
            ],
            [
              1461009.851474265,
              6565840.548767853
            ],
            [
              1445883.5319464942,
              6569386.912474411
            ]
          ]
        ]
      },
      "properties": {
        "crs": "http://www.opengis.net/def/crs/EPSG/0/3857"
      }
    },
    "data": [
      {
        "dataFilter": {
          "timeRange": {
            "from": "2022-01-01T00:00:00Z",
            "to": "2022-01-16T23:59:59Z"
          }
        },
        "type": "sentinel-3-olci"
      }
    ]
  },
  "output": {
    "width": 512,
    "height": 348.742,
    "responses": [
      {
        "identifier": "default",
        "format": {
          "type": "image/tiff"
        }
      }
    ]
  },
  "evalscript": "//VERSION=3\n    function setup() {\n      return{\n        input: [{\n          bands: [\"B08\", \"B17\"]\n        }],\n        output: {\n          id: \"default\",\n          bands: 1,\n          sampleType: SampleType.FLOAT32\n        }\n      }\n    }\n    \n    function evaluatePixel(sample) {\n      let ndvi = (sample.B17 - sample.B08) / (sample.B17 + sample.B08)\n      return [ ndvi ]\n   } "
}'

  • Author
  • 3963 posts replied to
  • April 26, 2024

Morning

the code you posted worked for me, while the same code with a change in the coordinates does not work.
it seems that there are some locations for which there is no data available from “sentinel-3-olci”. is that true please? if yes, how can i know the covered locations for which there are available data for each repective satellite? is that possible?


  • 4852 posts replied to
  • April 26, 2024

That is true, you can use the Catalog API to check what is available. For more general information please check with the satellite owner directly (ESA).