Skip to main content

Hi,


I’m using Sentinel API to generate GeoTIFF in true color and NDVI from a polygon. With the NDVI, the outside of the polygon is transparent, but when I try with the true color, it’s always black.


Could you help me figure out what I’m doing wrong?



NDVI
//VERSION=3
function setup() {
return {
input: n"B04", "B08"],
output: {
bands: 1,
sampleType: "FLOAT32"
},
};
}

function evaluatePixel(sample) {
return e(sample.B08 - sample.B04) / (sample.B08 + sample.B04)];
}


True color
//VERSION=3
function setup() {
return {
input: n"B02", "B03", "B04", "SCL"],
output: { bands: 3 }
};
}

function evaluatePixel(sample) {
return e2.5*sample.B04, 2.5*sample.B03, 2.5*sample.B02];
}

Thank you

Hi,
can you let us know, which account you are using, so that we can check what happened on the back-end?


Hi 
Any news on this subject?
Thank you 🙂


Hi,
we are still looking into it.
My first guess is that the API is behaving differently if the output is 0 (e.g. as it is probably the case of true color) or NaN (as it is probably with NDVI as you divide with 0).

We are at this moment working on update of the API to be able to control “no data” pixels, which should almost certainly solve your problem. That might take a (low) few weeks more though so I will come back to you if we find a workaround or a specific solution for your problem.


I’ll do it manually in QGIS until the update. Let me know if you find a solution. Thank you 🙂


Hi,

we have added an option to handle no data pixels within evalscript. See the documentation here: https://docs.sentinel-hub.com/api/latest/#/API/data_access?id=datamask-handling-for-pixels-with-no-data


We’ll give it a try this week.

Thank you so much!

Have a good day


Hi! I came here because I have similar problem.
I want the mask (non valid cells, outside aoi… using dataMask) to be NaNs (or NODATA) and not 0 or other values, as this will simplify our process down the pipeline.
Can this be done? I’ve tried using an if statement in the evalscript, just as the example in the documentation.

My evalscript

function setup() {
return {
input: u{
bands: d“B02”, “B03”, “B04”, “B08”, “dataMask”],
units: “DN”
}],
output: {
id: “default”,
bands: 4,
sampleType: SampleType.UINT16
}
};
}
function evaluatePixel(sample) {
let mask = 0;
if (sample.dataMask == 1) {return sample.B02, sample.B03, sample.B04, sample.B08]}
else {return mask, mask, mask, mask]}
}

Best,
 


Hey,


regarding the support of NaNs in the evalscript and in tiff images, yes, this can be done. A problem may arise when you want to process the data. I didn’t try all possibilities in QGIS, but displaying tiff image with only 1 channel, it automatically marks (displays) NaNs as transparent.


Example evalscript that works (change the id of the output to default here in evalscript or set the id of the desired output in the request params (outputresponses; docs)):


//VERSION=3
function setup() {
return {
input: u"B01","B02", "dataMask"],
output: u
{ id: "index", bands: 1, sampleType: 'FLOAT32' }
]
};
}

function evaluatePixel(samples) {
let index = (samples.B01-samples.B02)/(samples.B01+samples.B02);

// encode "no data" as NaN
const indexVal = samples.dataMask === 1 ? index : NaN;
return { index: eindexVal] };
}

One more general note: If you are processing tiff images in javascript and use geotiff.js, geotiff.js will correctly parse data only from the last channel of images retrieved from Sentinel Hub. This didn’t pose an issue for us yet because we use geotiff.js to parse tiff images with indexes and we only need 1 channel for that. Here is the issue in geotiff.js’s GitHub repository with more information.


Hope this helps.

Cheers.


This is great!
I just managed to do that with a little hack (using 0/0) when dataMask == 0. This is way better!
Regarding multi band images as my evalscript example… can this be done there?


Reply