forked from sentinel-hub/custom-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
executable file
·67 lines (58 loc) · 1.37 KB
/
script.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
//VERSION=3 (auto-converted from 1)
/*
Author: Karl Chastko
*/
function setup() {
return {
input: [{
bands: [
"B03",
"B11"
]
}],
output: { bands: 3 },
mosaicking: "ORBIT"
}
}
function calcNDSI(sample) {
ndsi = (sample.B03 - sample.B11)/ (0.01 + sample.B03 + sample.B11);
return ((ndsi>0.2)&(sample.B03>0.15)) ? (ndsi) : 0.0
}
function evaluatePixel(samples,scenes) {
var avg1 = 0;
var count1 = 0;
var avg2 = 0;
var count2 = 0;
var avg3 = 0;
var count3 = 0;
var endMonth = scenes[0].date.getMonth();
for (var i=0;i<samples.length;i++) {
var ndvi = calcNDSI(samples[i]);
if (scenes[i].date.getMonth()==endMonth)
{
avg3 = avg3 + ndvi;
count3++;
}
else if (scenes[i].date.getMonth()==(endMonth-1))
{
avg2 = avg2 + ndvi;
count2++;
}
else
{
avg1= avg1 + ndvi;
count1++;
}
}
avg1 = avg1/count1;
avg2 = avg2/count2;
avg3 = avg3/count3;
return [avg1*5,avg2*5,avg3*5];
}
function preProcessScenes (collections) {
collections.scenes.orbits = collections.scenes.orbits.filter(function (orbit) {
var orbitDateFrom = new Date(orbit.dateFrom)
return orbitDateFrom.getTime() >= (collections.to.getTime()-3*31*24*3600*1000);
})
return collections
}