forked from sentinel-hub/custom-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
70 lines (61 loc) · 1.49 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
68
69
70
//VERSION=3 (auto-converted from 1)
function setup() {
return {
input: [{
bands: [
"VV",
"VH"
]
}],
output: { bands: 3 },
mosaicking: "ORBIT"
}
}
function calcRVI(sample) {
var denom = sample.VH*2+sample.VV*2;
return ((denom!=0) ? (sample.VH*8) / denom : 0.0);
}
function stretch(val, min, max) {
return (val-min)/(max-min);
}
function evaluatePixel(samples,scenes) {
var avg1 = 0.2;
var count1 = 0;
var avg2 = 0.2;
var count2 = 0;
var avg3 = 0.2;
var count3 = 0;
var endMonth = scenes[0].date.getMonth();
for (var i=0;i<samples.length;i++) {
var rvi = calcRVI(samples[i]);
if (scenes[i].date.getMonth()==endMonth)
{
avg3 = avg3 + rvi;
count3++;
}
else if (scenes[i].date.getMonth()==(endMonth-1))
{
avg2 = avg2 + rvi;
count2++;
}
else
{
avg1= avg1 + rvi;
count1++;
}
}
avg1 = avg1/count1;
avg2 = avg2/count2;
avg3 = avg3/count3;
avg1 = stretch(avg1, 0.25, 0.75);
avg2 = stretch(avg2, 0.25, 0.75);
avg3 = stretch(avg3, 0.25, 0.75);
return [avg1,avg2,avg3];
}
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
}