Skip to content

Instantly share code, notes, and snippets.

@horvatdino
Last active September 13, 2022 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horvatdino/e42a8c3c31c1ee2dc2b96c185551462f to your computer and use it in GitHub Desktop.
Save horvatdino/e42a8c3c31c1ee2dc2b96c185551462f to your computer and use it in GitHub Desktop.
//VERSION=3
function setup() {
return {
input: ["B04", "B08", "SCL","dataMask"],
output: [
{ id: "default", bands: 4 },
{ id: "index", bands: 1, sampleType: 'FLOAT32' },
{ id: "eobrowserStats", bands: 2, sampleType: 'FLOAT32' },
{ id: "dataMask", bands: 1 }
]
};
}
function isCloud (scl) {
if ([1, 2, 7, 8, 9, 10, 11].includes(scl)) {
return true;
}
}
function evaluatePixel(samples) {
let val = index(samples.B08, samples.B04);
let imgVals = null;
const indexVal = samples.dataMask === 1 ? val : NaN;
const cloud = isCloud(samples.SCL)
imgVals = valueInterpolate(val,
[-0.3, 0, 0.3, 0.6],
[
[0.9, 0.9, 0.9, samples.dataMask],
[0.8, 0.78, 0.2, samples.dataMask],
[0.5, 0.8, 0, samples.dataMask],
[0.1, 0.3, 0, samples.dataMask],
])
return {
default: imgVals,
index: [indexVal],
eobrowserStats:[indexVal,cloud?1:0],
dataMask: [samples.dataMask]
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment