-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsumi-statistics-evalscript.js
222 lines (207 loc) · 5.62 KB
/
sumi-statistics-evalscript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//VERSION=3
// Switch to use same script either for statistics (0) or for eo-browser visualization for 2-step classifier (1) or 3-step classifier (2)
const MODE = 0 // [0,1,2]
// Define index values
// A: 2-phase classification
let A_DRY1 = 1;
let A_DRY2 = 2;
let A_DRY3 = 3;
let A_DRY4 = 4;
let A_WATER1 = 5;
let A_WATER2 = 6;
let A_WATER3 = 7;
// B: 3-phase classification
let B_DRY1 = 1;
let B_DRY2 = 2;
let B_WETVEG1 = 3;
let B_WETVEG2 = 4;
let B_WATER = 5;
function mndwi12(samples) {
return index(samples.B03, samples.B12);
}
function mndwi11(samples) {
return index(samples.B03, samples.B11);
}
function classify_A_2cl(sample) {
// ternary operator: TEST ? TRUE : FALSE
// mosaicmod2lk.png
return (sample.B11 >= 1396)
? (sample.B04 >= 391)
? A_DRY1
: (mndwi12(sample) >= -0.43)
? A_DRY2
: (sample.B12>=1496)
? A_DRY3
: A_WATER1
: (sample.B8A >= 1817)
? (sample.B11 >= 1247)
? A_DRY4
: A_WATER2
: A_WATER3;
}
function classify_B_3cl(sample) {
// ternary operator: TEST ? TRUE : FALSE
// lopulliset_mallit.pdf
return (sample.B11 < 1247)
? (sample.B04 < 153)
? B_WATER
: B_WETVEG1
: (sample.B04 < 278)
? (mndwi11(sample)<-0.64)
? B_WETVEG2
: B_DRY1
: B_DRY2;
}
function domasking(samples) {
// Return 1/0 as dataMask: 1=DATA, 0 NODATA
CLOUDFREE=[1];
CLOUD=[0];
//no-data as cloud for SUMI-case as we need full coverage
if (samples.dataMask == 0) {
return CLOUD;
}
// First use the 160m mask
if (samples.CLM) {
return CLOUD;
}
// If 160 m mask is cloudfree, check relevant L2A-flags
switch (samples.SCL) {
// No Data (Missing data) (black)
case 0: return CLOUD;
// Saturated or defective pixel (red)
case 1: return CLOUD;
// Dark features / Shadows (very dark grey)
case 2: return CLOUDFREE;
// Cloud shadows (dark brown)
case 3: return CLOUDFREE;
// Vegetation (green)
case 4: return CLOUDFREE;
// Not-vegetated (dark yellow)
case 5: return CLOUDFREE;
// Water (dark and bright) (blue)
case 6: return CLOUDFREE;
// Unclassified (dark grey) // Changed to cloud 20220202, back to cloudfree on 20220208
case 7: return CLOUDFREE;
// Cloud medium probability (grey)
case 8: return CLOUD;
// Cloud high probability (white)
case 9: return CLOUD;
// Thin cirrus (very bright blue)
case 10: return CLOUD;
// Snow or ice (very bright pink)
case 11: return CLOUD;
// default is cloudfree
default : return CLOUDFREE;
}
}
function evaluatePixelForStatisticalAPI(samples) {
return {
dataMask: domasking(samples),
B11: [samples.B11],
B12: [samples.B12],
CL2: [classify_A_2cl(samples)],
CL3: [classify_B_3cl(samples)],
scl: [samples.SCL]
}
}
function evaluatePixelForWMS2lk(samples) {
CL2 = classify_A_2cl(samples)
colors = [[84, 61, 13],//DRY_1
[38, 27, 3],//DRY_2
[92, 45, 7],//DRY_3
[36, 21, 9],//DRY_4
[35, 202, 232],//WATER_1
[35, 104, 232],//WATER_2
[24, 15, 189]//WATER_3
]
r = colors[CL2-1][0]
g = colors[CL2-1][1]
b = colors[CL2-1][2]
return [r,g,b,domasking(samples)*255]
}
function evaluatePixelForWMS3lk(samples) {
CL3 = classify_B_3cl(samples)
colors = [[84, 61, 13],//DRY_1
[38, 27, 3],//DRY_2
[53, 252, 3],//WETVEG_1
[39, 117, 19],//WETVEG_2
[35, 202, 232]//WATER_1
]
r = colors[CL3-1][0]
g = colors[CL3-1][1]
b = colors[CL3-1][2]
return [r,g,b,domasking(samples)*255]
}
function evaluatePixel(samples) {
// Usage mode
switch (MODE) {
case 0:
return evaluatePixelForStatisticalAPI(samples);
case 1:
return evaluatePixelForWMS2lk(samples);
case 2:
return evaluatePixelForWMS3lk(samples);
}
}
function setup() {
// Set output based on usage mode
input = [{
bands: [
"B03",
"B04",
"B8A",
"B11",
"B12",
"SCL",
"CLM",
"dataMask"
],
units: "DN"
}]
switch (MODE) {
case 0:
return {
input : input,
output : [
{
id: "B11",
bands: 1,
sampleType: "UINT16"
},
{
id: "B12",
bands: 1,
sampleType: "UINT16"
},
{
id: "CL2",
bands: 1,
sampleType: "UINT8"
},
{
id: "CL3",
bands: 1,
sampleType: "UINT8"
},
{
id: "scl",
bands: 1,
sampleType: "UINT8"
},
{
id: "dataMask",
bands: 1
}]
}
case 1:
return {
input : input,
output : { bands: 4, noDataValue: 0, sampleType: "UINT8" }
}
case 2:
return {
input : input,
output : { bands: 4, noDataValue: 0, sampleType: "UINT8" }
}
}
}