-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drought
224 lines (185 loc) · 6.27 KB
/
Drought
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// REGION OF INTEREST
var ROI = roi
.filter(ee.Filter.eq('subcounty', 'Bura Sub County'))
.first()
.geometry();
// Visualizing the the ROI
Map.addLayer(ROI, {});
//SPECIFING THE DATES, MONTHS AND YEARS FOR THE DROUGHT MAPPING
var month = '03';
var year = '2019';
// Transformations for dates
var monthn = +month; // numerical
var yearn = +year; // numerical
var monthn1 = monthn+1;
if (monthn1 == 13) {
var monthn1 = 01;
}
var month1 = padLeadingZeros(monthn1,2);
// Zoom to AOI
Map.centerObject(ROI, 9);
// DEFINE VIS PARAMETERS
// Visualization Palette
var vis = ['d7191c', 'fdae61', 'ffffc0', 'a6d96a', '1a9641'];
// SPECIFIC MONTHS FOR ANALYSIS
// Filterout Specific Month for analysis
var imageFilter = ee.Filter.calendarRange(monthn,monthn,'month');
// selection of Historical time period for analysis
var startDate = ee.String('2000-').cat(month);
var endDate = ee.String((yearn-1).toString()).cat('-').cat(month1);
if (monthn1 == 1) {
var endDate = ee.String((yearn).toString()).cat('-').cat(month1);
}
// LOAD DATASETS, MODIS FOR VEGETATION MAPPING-COMPUTE VCI.
// Load Terra Vegetation Indices 16-Day Global 250m Collection of Past time period
var collection = ee.ImageCollection('MODIS/006/MOD13Q1').filterDate(startDate, endDate).filter(imageFilter);
// Scale factor for NDVI
var factor_NDVI = function(image){
return image.multiply(0.0001).divide(3.2768);
};
// Map factor function for NDVI
var ndvi = collection.select('NDVI').map(factor_NDVI);
// minimum and maximum NDVI
var minNDVI = ndvi.min();
var maxNDVI = ndvi.max();
// Specific month time to see the drought like condition
var imageStartDate = year.concat('-',month);
var imageEndDate = ee.String((yearn).toString()).cat('-').cat(month1);
if (monthn1 == 1) {
var imageEndDate = ee.String((yearn+1).toString()).cat('-').cat(month1);
}
// Terra Vegetation Indices 16-Day Global 250m Collection of drought monitroing time period
var image = ee.ImageCollection('MODIS/006/MOD13Q1').filterDate(imageStartDate, imageEndDate).filter(imageFilter).max();
// VCI
// VCI = ((NDVI - MIN_NDVI)/(MAX_NDVI - MIN_NDVI))*100
//calculation of VCI and clipping according to the AOI
var imageNDVI = image.select('NDVI');
imageNDVI = factor_NDVI(imageNDVI);
var cal1 = imageNDVI.subtract(minNDVI);
var cal2 = maxNDVI.subtract(minNDVI);
var VCI = cal1.divide(cal2).clip(ROI);
print(VCI, "VCI")
// VCI display to map
Map.addLayer(VCI,{
min: -1,
max: 1,
palette: vis}, 'VCI',false);
// TCI
// VCI = ((LST - MIN_LST)/(MAX_LST- MIN_LST))*100
// Load collection for TCI
var collection = ee.ImageCollection('MODIS/006/MOD11A2').filterDate(startDate, endDate).filter(imageFilter);
var lst = collection.select('LST_Day_1km');
// minimum and maximum LST
var minLST = lst.min();
var maxLST = lst.max();
// LST Collection of drought monitroing time period
var image = ee.ImageCollection('MODIS/006/MOD11A2').filterDate(imageStartDate, imageEndDate).filter(imageFilter).max();
var imageLST = image.select('LST_Day_1km');
// calculation of TCI and clipping according to the AOI
var TCI = (maxLST.subtract(imageLST)).divide(maxLST.subtract(minLST)).clip(ROI);
print(TCI, "TCI")
// TCI display to map
Map.addLayer(TCI,{
min: -1,
max: 1,
palette: vis}, 'TCI',false);
// VHI
// VEGETATION HEALTH INDEX, IS USED TO DETERMINE WITH THE REGION IS DROUGHT AFFECTED OR NOT.
// calculation of VHI
var VHI = (VCI.multiply(0.5)).add(TCI.multiply(0.5));
print(VHI, "VHI")
// VHI display to map
Map.addLayer(VHI,{
min: -1,
max: 1,
palette: vis}, 'VHI',false);
// CLASSIFING THE VHI
// VHI classification into classes based on threshold values to calculate Drought Index
var image02 = ee.Image(VHI.lt(0.1).and(VHI.gte(-1)));
var image04 = ee.Image(((VHI.gte(0.1)).and(VHI.lt(0.2))).multiply(2));
var image06 = ((VHI.gte(0.2)).and(VHI.lt(0.3))).multiply(3);
var image08 = ((VHI.gte(0.3)).and(VHI.lt(0.4))).multiply(4);
var image10 = (VHI.gte(0.4)).multiply(5);
var Drought_Index = (image02.add(image04).add(image06).add(image08).add(image10));
var Drought_Index = Drought_Index.float();
// Drought display to map
Map.addLayer(Drought_Index,{
min: 1,
max: 5,
palette: vis}, 'Drought Index');
// EXPORTING THE FINAL IMAGE
// Export to Google Drive
// Export.image.toDrive({
// image: Drought_Index,
// description: 'Drought_Index_VHI',
// fileNamePrefix: 'Drought_Index_VHI',
// region: ROI,
// scale: 1000,
// crs: 'EPSG:4326',
// skipEmptyTiles: true
// });
// GENERATING THE LEGEND IN GEE
//////////////////////////////////////////////////////////////////////////////////
//Drought Index Legend
///////////////////////////////////////////////////////////////////////////////
var legend = ui.Panel({
style: {
position: 'bottom-left',
padding: '8px 15px'
}
});
// Create and add the legend title.
var legendTitle = ui.Label({
value: 'Drought Index (VHI)',
style: {
fontWeight: 'bold',
fontSize: '18px',
margin: '0 0 4px 0',
padding: '0'
}
});
legend.add(legendTitle);
// Creates and styles 1 row of the legend.
var makeRow = function(color, name) {
// Create the label that is actually the colored box.
var colorBox = ui.Label({
style: {
backgroundColor: '#' + color,
// Use padding to give the box height and width.
padding: '8px',
margin: '0 0 4px 0'
}
});
// Create the label filled with the description text.
var description = ui.Label({
value: name,
style: {margin: '0 0 4px 6px'}
});
return ui.Panel({
widgets: [colorBox, description],
layout: ui.Panel.Layout.Flow('horizontal')
});
};
// Legend Rows
legend.add(makeRow('d7191c', 'Extreme'));//1
legend.add(makeRow('fdae61', 'Severe'));//2
legend.add(makeRow('ffffc0', 'Moderate'));//3
legend.add(makeRow('a6d96a', 'Mild'));//4
legend.add(makeRow('1a9641', 'No Drought'));//5
// Add Legend to Map
Map.add(legend);
// Function used for transforming dates to string and having leading 0, if necessary
function padLeadingZeros(num, size) {
var s = num+"";
while (s.length < size) s = "0" + s;
return s;
}
//CHIRPS TIME SERIES CHARTS
//Filter image collection
var precip = chirps.filterDate('2010-01-01','2022-12-31');
//Create and print rainfall chart
print(ui.Chart.image.series(chirps.limit(5000),ROI,ee.Reducer.mean(),1000).setOptions({
title: 'Tana River PPT Over Months',
hAxis: {title: 'Day'},
vAxis:{title:'rainfall (mm/day)'}
}));