Skip to content

Instantly share code, notes, and snippets.

@wolfhechel
Created October 3, 2022 13:45
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 wolfhechel/17a1a0b2c5a1cd5c9cb1e95375bddfb4 to your computer and use it in GitHub Desktop.
Save wolfhechel/17a1a0b2c5a1cd5c9cb1e95375bddfb4 to your computer and use it in GitHub Desktop.
Ship detection script for Sentinel hub, forked from custom-script hub.
//VERSION=3
// Ship detection with S1 and S2
// Original source: https://custom-scripts.sentinel-hub.com/custom-scripts/data-fusion/ship_detection_s1_s2/script.js
// Original author: Monja B. Šebela
// Fork author: Pontus J. Karlsson
function setup() {
return {
input: [
{datasource: "S2L1C", bands:["B02", "B03", "B04", "B08"], mosaicking: "ORBIT"},
{datasource: "S1GRD", bands:["VV", "VH"], mosaicking: "ORBIT"}
],
output: [
{ id: "default", bands: 3, sampleType: SampleType.AUTO }
]
};
}
function evaluatePixel(samples, inputData, inputMetadata, customData, outputMetadata) {
var S2L1C = samples.S2L1C[0]
var S1GRD = samples.S1GRD[0]
if (S1GRD == undefined || S2L1C == undefined) {
return {
default: [1,1,1]
}
}
let ndwi = (S2L1C.B03 - S2L1C.B08) / (S2L1C.B03 + S2L1C.B08)
if ((ndwi > 0.1) && ((S1GRD.VV > 0.3) || (S1GRD.VH > 0.3))) {
return {
default: [
1,
1,
1
]
}
} else if (ndwi > 0.1){
return {
default: [
(4 * S2L1C.B04) - 0.2,
(4 * S2L1C.B03) - 0.2,
(5 * S2L1C.B02) - 0.2
]
}
} else {
return {
default: [
(4 * S2L1C.B04) - 0.2,
(4 * S2L1C.B03) - 0.2,
(4 * S2L1C.B02) - 0.2
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment