forked from sentinel-hub/custom-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
130 lines (112 loc) · 3.63 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
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
//VERSION=3 (auto-converted from 1)
/*
Surface Soil Moisture (SSM) retrieval using change detection approach.
Author Details:
Narayana Rao B.
206-MRSLab, CSRE,
IIT Bombay, India.
A detailed explanation of the implemented algorithm can be found in the following articles.
Wagner, W., Lemoine, G., Borgeaud, M. and Rott, H., 1999.
A study of vegetation cover effects on ERS scatterometer data.
IEEE Transactions on Geoscience and Remote Sensing, 37(2), pp.938-948.
B. Bauer-Marschallinger et al.,
"Toward Global Soil Moisture Monitoring With Sentinel-1: Harnessing Assets and Overcoming Obstacles,"
in IEEE Transactions on Geoscience and Remote Sensing, vol. 57, no. 1, pp. 520-539, Jan. 2019.
*/
function setup() {
return {
input: [{
bands: [
"VV",
"VH"
]
}],
output: { bands: 3 },
mosaicking: "ORBIT"
}
}
function filterScenes (scenes, inputMetadata)
{
return scenes.filter(function (scene) {
// Considering 36 months data to avoid seasonal variations in masking
return scene.date.getTime()>=(inputMetadata.to.getTime()-36*30*24*3600*1000) ; // Data from 36 months to current date
});
}
function evaluatePixel(samples, scenes)
{
var count = 0;
var Mv = 0;
var max = 0;
var min =2.0;
var sum_VV = 0;
for (var i=0;i<samples.length-1;i++)
{
max = samples[i].VV > max ? samples[i].VV:max; // Calculating all time maximum--Wet index
min = samples[i].VV < min ? samples[i].VV:min; // Calculating all time minimum--Dry index
sum_VV += samples[i].VV;
count++;
}
// Overall range of intensity values Anologous to 0-100% soil moisture
var sensitivity = max-min;
// If overall averge is more than 6dB i.e., High intensity always usually urban areas.
// Generating urban area mask using -6dB threshold
urban_mask = 10*Math.log10(sum_VV/count) > -6 ? 0 : 1;
// If overall averge is less than 17dB i.e., low intensity always usually water bodies.
// Generating permanent water body mask using -17dB threshold
water_mask = 10*Math.log10(sum_VV/count) < -17 ? 0 : 1;
// Assuming change in bckscatter intensity only because of change in soil moisture.
Mv = ((samples[0].VV) - min)/(sensitivity);
Mv = Mv*water_mask*urban_mask;// Applying urban and permanent water body mask
/*
Assigning colormap for enhanced visualisation
*/
var v = Mv;
var vmin = 0;
var vmax = 0.6;
var diffv = vmax - vmin;
var r = 0.0;
var g = 0.0;
var b = 0.0;
if (v < vmin){
v = vmin;
}
if (v > vmax){
v = vmax;
}
//Threshold values for colorMap
var T1 = 0.1;
var T2 = 0.3;
var T3 = 0.4;
var T4 = 0.5;
var Thresh_1 = (vmin + T1 * diffv);
var Thresh_2 = (vmin + T2 * diffv);
var Thresh_3 = (vmin + T3 * diffv);
var Thresh_4 = (vmin + T4 * diffv);
if (v <= 0)
{
r=1;
g=1;
b=1;
}
else if (v < Thresh_1) { r = 0.5 + (v - vmin) / (Thresh_1 - vmin) / 2; }
else if (v < Thresh_2)
{
r = 1;
g = (v - Thresh_1) / (Thresh_2 - Thresh_1);
b = 0;
}
else if (v < Thresh_3)
{
r = 1 + (Thresh_2 - v) / (Thresh_3 - Thresh_2);
g = 1;
b = (v - Thresh_2) / (Thresh_3 - Thresh_2);
}
else if (v < Thresh_4)
{
r = 0;
g = 1 + (Thresh_3 - v) / (Thresh_4 - Thresh_3);
b = 1;
}
else { b = 1.0 + (Thresh_4 - v) / (vmax - Thresh_4) / 2; }
return [r, g, b];
}