-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSession 1 Classification_GEE_Exercice_on_GEE
More file actions
183 lines (133 loc) · 5.76 KB
/
Session 1 Classification_GEE_Exercice_on_GEE
File metadata and controls
183 lines (133 loc) · 5.76 KB
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
// This exercice can be accessed at: https://code.earthengine.google.com/c5f6321229fb56c71bdc1c3b5ce544a7
//+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
//S. Aparício (Solenix), I. Alonso (Solenix) ☁☁☁\_(ツ)_/☁☁☁
//MIT LICENSE CC BY EUMETSAT
//+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
//🔥🛰️
// Session 1 “Hands-on: Classification of fire burns"
// PARTICIPANT'S VERSION
///////////////////////////////////////////////////////////////////////////
////////////////////// 1. VISUALIZING DEFINED AOI ////////////////
///////////////////////////////////////////////////////////////////////////
//______________
//_**STEP 1**___
var AOI = // *your code
//Visualise it
// *your code
///////////////////////////////////////////////////////////////////////////
////////////// 2. PREPARING SATELLITE IMAGERY /////////////////////////
///////////////////////////////////////////////////////////////////////////
//______________
//_**STEP 2**___
//Selecting date range - after the fire
var start = //* your code
var finish = //* your code
//Selecting date range - before the fire
var startpast = //* your code
var finishpast = //* your code
////////////// CREATING COLLECTION OF IMAGES///////////////////////////////
//______________
//_**STEP 3**___
//Sentinel-2 collection after the fire
var S2after = //* your code
//Sentinel-2 collection before the fire
var S2before = //* your code
////////////// CLOUD MASK FUNCTION ///////////////////////////////
//______________
//_**STEP 4**___
//Cloud mask S2 function
function maskS2clouds(image) {
var qa = image.select('QA60');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = ee.Number(2).pow(10).int(); //Math.pow(2,10)
var cirrusBitMask = ee.Number(2).pow(11).int(); //Math.pow(2,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 the masked and scaled data.
return image.updateMask(mask); // add >>>> .divide(10000) >>>Diving by 10000 converts toa
}
/////////// APPLY CLOUD MASK FUNCTION TO ALL IMAGES IN THE COLLECTION///////////////////////////////
//______________
//_**STEP 5**___
//Applying the function to remove clouds to all the collection
var S2Acloudfree = //* your code
var S2Bcloudfree = //* your code
/////////// CREATE A SINGLE IMAGE ///////////////////////////////
//______________
//_**STEP 6**___
//Creating a single image with the median of the collection
var S2A = //* your code
var S2B = //* your code
/////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// VISUALIZING SATELLITE IMAGERY /////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
//______________
//_**STEP 7**___
//Creating visualization settings for false color
var False_vis = {
min: 0,
max: 2500,
gamma: 1.4,
bands: ['B8', 'B4', 'B3']
};
//Creating visualization settings for true color
var rgb_vis = {
min: 0,
max: 2500,
gamma: 0.89,
bands: ['B4', 'B3', 'B2']
};
Map.addLayer(S2A.clip(AOI), False_vis, 'S2 After Fire (False Color)')
Map.addLayer(S2B.clip(AOI), False_vis, 'S2 Before Fire (False Color)')
Map.addLayer(S2A.clip(AOI), rgb_vis, 'S2 After Fire (True Color)')
Map.addLayer(S2B.clip(AOI), rgb_vis, 'S2 Before Fire (True Color)')
/////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// CREATING TRAINING DATASET ////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
//______________
//_**STEP 8**___
//collect more training data on geometry imports>burn/noburn and selecting on the map
//combine the polygons from both classes
var polygons = //**your code
//selection of the bands to be used
var bands = //**your code
//______________
//_**STEP 9**___
//collecting training data
var training = //**your code
// Roughly 80% training, 20% testing.
var split = 0.8;
//Spliting with the split value after assigned random values
var trainingRandom = training.randomColumn('random');
var trainingSplit = trainingRandom.filter(ee.Filter.lt('random', split)); //for classification
var testingSplit = trainingRandom.filter(ee.Filter.gte('random', split)); //for validation and accuracy
///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// TRAINING THE MODEL /////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
//______________
//_**STEP 10**___
// Training classifiers with training (splited) data
var trainedRF = //**your code
/////////////////////////////////////////////////////////////
////////////// RUN CLASSIFICATION ///////////////////////////
////////////////////////////////////////////////////////////
//______________
//_**STEP 11**___
// Classify the Image with the same bands used for training.
var classified = //**your code
/////////////////////////////////////////////////////////////
////////////// vISUALIZE RESULTING CLASSIFICATION /////////
////////////////////////////////////////////////////////////
//______________
//_**STEP 12**___
var visClassRFS1S2 = classified.visualize({
min:0,
max:2,
palette: ['E6E600','A6FFE6']
});
Map.addLayer(classified.clip(AOI), {min: 0, max: 1, palette: ['green','red']}, 'RandomForest Burnt');
/*
var burnS2 = S2A.normalizedDifference(['B11', 'B8']);
Map.addLayer(burnS2.clip(PT), {}, 'Burnt Radio ');
*/