Last active
September 13, 2022 12:04
-
-
Save horvatdino/e42a8c3c31c1ee2dc2b96c185551462f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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