Resampling Band 5(20m to 10m resolution) using Evalscript

Hi Forum,

I am new to using SentinelHub to automate vegetation index. I have a custom script in the Evalscript to calculate NDRE. My code is as below:

//VERSION=3
function setup() {
  return {
    input: ["B08", "B05", "dataMask"], // Ensure correct band names
    output: [
      {
        id: "default",
        bands: 4, // Output bands for the color visualization
      },
      {
        id: "index",
        bands: 1, // Output band for index value
        sampleType: 'FLOAT32'
      },
      {
        id: "eobrowserStats",
        bands: 2, // Output bands for eobrowserStats
        sampleType: 'FLOAT32'
      },
      {
        id: "dataMask",
        bands: 1 // Output band for the dataMask
      }
    ]
  };
}

function evaluatePixel(sample) {
  // Convert to reflectance if needed
  var b08 = sample.B08 / 1000;
  var b05 = sample.B05 / 1000;

  // Calculate NDRE
  var ndre = (b08 - b05) / (b08 + b05);

  // Check dataMask value
  const indexVal = (sample.dataMask === 1) ? ndre : NaN; // NDRE index without no-data values

  // Reclassify NDRE and assign colors
  var imgVals;
  if (!isNaN(ndre)) { // Ensure NDRE is a number
    if (ndre >= 0.6 && ndre <= 1.0) {
      imgVals = [0, 0.498, 0, sample.dataMask]; // Color for NDRE 0.6 - 1.0 (Very Healthy)
    } else if (ndre >= 0.4 && ndre < 0.6) {
      imgVals = [0, 0.745, 0, sample.dataMask]; // Color for NDRE 0.4 - 0.6 (Healthy)
    } else if (ndre >= 0.2 && ndre < 0.4) {
      imgVals = [0.996, 0.996, 0, sample.dataMask]; // Color for NDRE 0.2 - 0.4 (Moderately Stressed)
    } else if (ndre >= -1 && ndre < 0.2) {
      imgVals = [0.745, 0, 0, sample.dataMask]; // Color for NDRE -1 - 0.2 (No Vegetation)
    } else {
      // Use #3275a8 as the default color (for NDRE outside the specified ranges)
      imgVals = [0.196, 0.459, 0.658, sample.dataMask]; // Equivalent to #3275a8
    }
  } else {
    imgVals = [0.196, 0.459, 0.658, sample.dataMask]; // Default color for NaN values
  }

  // Return the 4 outputs and define content for each one
  return {
    default: imgVals,
    index: [indexVal],
    eobrowserStats: [indexVal, 0], // No cloud value
    dataMask: [sample.dataMask]
  };
}

My problem is, does the resampling between these 2 bands have been automated to change Band 5 from 20m to 10m resolution? Currently working on visualizing NDRE using Band 8(10m) and 5(20m). The output of the code is quite different from what we’ve calculated manually on ArcGis Pro. Is there any solution or something I’m missing? Thank you in advance!

Summary

This text will be hidden

Hi!

Yes the Band 5 is automatically resampled. How the band is resampled is decided by the upsampling parameter which can optionally be set to the desired value in the processing API request body. See here for more information: Sentinel-2 L2A

When using requests builder to build your request you can change the sampling mode by clicking on Options in the data collection pane:

However also keep in mind that depending on your area of interest and chosen coordinate reference system, Sentinel Hub needs to reproject the data which will slightly change the raw data values.

1 Like

Hi Jonas, thank you for your clarification!

I have resampled the band as you mentioned and the output is as below. I’m using Bilinear for Upsampling:

However, the final output in Sentinel Hub is different from what I calculated in ArcGIS Pro which is my current reference. The colour visualization between these two are different, hence I’m suspecting there might be due to different value caused by different bands.

Here is my ArcGIS output:

Does the outcome would be different even though the source I’m using in ArcGIS is similar from Sentinel Hub itself? I have followed the resampling method from ArcGIS but I can’t figure out why the outputs are different

Thanks again!

Hello Ludfi,

it is not guaranteed that the visualization is the same in the two applications. Please compare the raw pixel values directly.

1 Like

Thank you a lot Jonas for the suggestions.

Apparently, I overcome the issue by downloading the raw data from EO Browser in a specific AOI.kml instead of Copernicus. As before I did my calculation in ArcGIS Pro by using the raw band from Copernicus without any specific AOI (I did ‘extract by mask’ after calculation in ArcGIS).

Again, thank you so much for your help and suggestions. Cheers!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.