SIGN IN

In Sentinel Hub, the calculated and output values depend on what users specify in their evalscripts (or custom scripts). By calculated values we are referring to the values that are returned from the evaluatePixel() function or from a simple script. Output values are values returned from Sentinel Hub, after the calculated values go through formatting defined by sampleType. In the evalscript, calculated and output values are controlled by:

  • In the setup() function, the requested bands and units define what values are used as input for the calculation (in simple scripts, default units are used). For example, if Sentinel–2 band B04 is requested in REFLECTANCE, the input values will be in the range 0–1. If Sentinel–2 band B04 is requested in DN (digital numbers), the input values for the calculation will be in the range 0–10000. Typical value ranges can be found in our data documentation, chapter Units for each data collection.
  • The evaluatePixel() function defines the actual calculation (in simple scripts, the entire script is its equivalent). Sentinel Hub uses double precision for all calculations and rounds only the final calculated values before they are outputted.
  • The value of the sampleType parameter in the setup() function define the format of the output values. Possible values are AUTO, UINT8, UINT16 and FLOAT32. See our sampleType documentation for more details. When the sampleType is not specified (e.g. in simple scripts), the default value AUTO will be used. sampleType.AUTO takes calculated values from the interval 0–1 and stretch them to 0– 255. If your calculated values are not in the range 0–1, make sure you either scale them to this range in the evaluatePixel() function or specify another sampleType.

Example 1: NDVI

In this example, we want to output values of the NDVI index, calculated based on Sentinel–2 data. Our evaluatePixel() function is:


function evaluatePixel(sample) {
    let NDVI =  (sample.B08 – sample.B04)/( sample.B08 + sample.B04)
    return [NDVI]
}

The requested units in this example do not have any influence on the calculated values of the NDVI. The output values returned by Sentinel Hub (black values in the table) for different sampleTypes are:

Calculated Value sampleType.AUTO sampleType.UINT8 sampleType.UINT16 sampleType.FLOAT32
-1 0 0 0 -1
0 0 0 0 0
0.25 64 0 0 0.25
1 255 1 1 1

Use sampleType:“FLOAT32” to return full floating -1 to 1 values. See the example here.

If you do not need values, but a vizualization, you can use sampleType:“AUTO”, but make sure to either:

  • map the NDVI values to the 0–1 interval in the evaluatePixel() function, e.g.:

    
    function evaluatePixel(sample) {
        let NDVI =  (sample.B08 – sample.B04)/( sample.B08 + sample.B04)
        return [(NDVI+1)/2]
    }
  • use a visualizer or a color visualization function, e.g. valueInterpolate.

Example 2: Sentinel–2 band B04

In this example, we want to output raw values of Sentinel–2 band 4. Our evaluatePixel() function looks like this:

function evaluatePixel(sample) {
     return [sample.B04]
}

If we request units: “REFLECTANCE”, the output values returned by Sentinel Hub (black values in the table) for different sampleTypes are:

Calculated Value sampleType.AUTO sampleType.UINT8 sampleType.UINT16 sampleType.FLOAT32
0 0 0 0 0
0.25 64 0 0 0.25
0.5 128 1 1 0.5
1 255 1 1 1
1.05 255 1 1 1.05

If we request units: “DN”, the output values returned by Sentinel Hub (black values in the table) for different sampleTypes are:

Calculated Value sampleType.AUTO sampleType.UINT8 sampleType.UINT16 sampleType.FLOAT32
0 0 0 0 0
2500 255 255 2500 2500
5000 255 255 5000 5000
10000 255 255 10000 10000
10500 255 255 10500 10500

Example 3: Brightness Temperature Bands

Here we output a Sentinel–3 SLSTR band F1 with typical values between 250–320 representing brightness temperature in Kelvin. The evaluatePixel() function is:


function evaluatePixel(sample) {
    return [sample.F1]
}

The output values returned by Sentinel Hub (black values in the table) for different sampleTypes are:

Calculated Value sampleType.AUTO sampleType.UINT8 sampleType.UINT16 sampleType.FLOAT32
250 255 250 250 250
255 255 255 255 255
275.3 255 255 275 275.3
320 255 255 320 320

Use sampleType:“FLOAT32” to return original values. If integer values are still acceptable for your application, use sampleType:“UINT16”.

If you do not need values but a vizualization, you can use sampleType:“AUTO”, but make sure to either:

  • map the values to the 0–1 interval in the evaluatePixel() function, e.g.:

    
    function evaluatePixel(sample) {
        return [sample.F1/320]
    }
    
  • use a visualizer or a color visualization function, e.g. valueInterpolate.