-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsalinity.js
122 lines (100 loc) · 2.75 KB
/
salinity.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
var aoi =
/* color: #d63000 */
/* displayProperties: [
{
"type": "rectangle"
}
] */
ee.Geometry.Polygon(
[
[
[-40.40384448271022, -20.212920175954984],
[-40.40384448271022, -20.370064065281447],
[-40.190984375288345, -20.370064065281447],
[-40.190984375288345, -20.212920175954984],
],
],
null,
false
);
var water_mask = ee
.Image("JRC/GSW1_3/GlobalSurfaceWater")
.select("seasonality")
.eq(12);
function maskS2clouds(image) {
var qa = image.select("QA60");
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
// Both flags should be set to zero, indicating clear conditions.
var mask = qa
.bitwiseAnd(cloudBitMask)
.eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
}
function addBands(img) {
var SSS = img.expression(
"139.566970 + (86.21318 * log (band2)) - (24.62518 * log (band4))",
{
//https://www.researchgate.net/publication/348379244_Estuary_zone_based_on_sea_level_salinity_in_Ciletuh_Bay_West_Java
band2: img.select("B2"),
band4: img.select("B4"),
}
);
var SSSname = SSS.rename(["SSS"]);
return img.addBands([SSSname]);
}
var s2_1 = ee
.ImageCollection("COPERNICUS/S2_HARMONIZED")
.filterDate("2023-06-29", "2023-06-30")
.filterBounds(aoi)
.map(maskS2clouds)
.map(addBands)
.sort("CLOUD_COVER", true)
.first();
var palette = [
"141bd7",
"42b2ff",
"44ffd3",
"4cff72",
"4fff39",
"fdff15",
"ffa013",
"ff1b11",
];
var style_ndsi = { min: 0, max: 36, bands: ["SSS"], palette: palette };
var visSentinel = {
min: 0,
max: 0.3,
bands: ["B4", "B3", "B2"],
};
Map.addLayer(s2_1.clip(aoi).updateMask(water_mask), style_ndsi, "NDSI");
Map.addLayer(s2_1.clip(aoi), visSentinel, "RGB (B4, B3, B2)");
Map.setOptions("SATELLITE");
var leftMap = ui.Map();
var rightMap = ui.Map();
var ndsi_img = ui.Map.Layer(s2_1.clip(aoi).updateMask(water_mask), style_ndsi);
var rgb_img = ui.Map.Layer(s2_1.clip(aoi), visSentinel);
var ndsi_layer = rightMap.layers();
var rgb_layer = leftMap.layers();
ndsi_layer.add(ndsi_img);
rgb_layer.add(rgb_img);
var ndsi_label = ui.Label("NDSI 2023-06-29");
ndsi_label.style().set("position", "bottom-right");
var rgb_label = ui.Label("RGB 2023-06-29");
rgb_label.style().set("position", "bottom-left");
leftMap.add(rgb_label);
rightMap.add(ndsi_label);
var splitPanel = ui.SplitPanel({
firstPanel: leftMap,
secondPanel: rightMap,
orientation: "horizontal",
wipe: true,
});
ui.root.clear();
ui.root.add(splitPanel);
var linkPanel = ui.Map.Linker([leftMap, rightMap]);
leftMap.centerObject(aoi, 13);
rightMap.setOptions("SATELLITE");
leftMap.setOptions("SATELLITE");