forked from malikarrahiem/urbanheatislandbandung
-
Notifications
You must be signed in to change notification settings - Fork 0
/
earthenginecode
233 lines (202 loc) · 7.85 KB
/
earthenginecode
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
225
226
227
228
229
230
231
232
233
//1. Menentukan area penelitian
var Bandung = ee.FeatureCollection('ft:1xaEFm8u4y7anwS9XNazLID6lJHlOYrlWUZen0x2a').geometry();
//jika ingin menentukan area penelitian sendiri, Anda bisa membuat polygon, menamai polygon itu terserah anda (secara default adalah geometry)
//kemudian di ke 6 berikut Anda menulis aoi = (nama yang Anda kehendaki)
var aoi = Bandung;
Map.setCenter(107.6055, -6.9303, 11);
//aoi = bandung untuk area kota Bandung, aoi = Cekban untuk area Cekungan Bandung
//2.1 Membuat fungsi NDVI untuk dihitung belakangan
var addNDVI = function(image) {
return image.addBands(image.normalizedDifference(['B5', 'B4']).rename('NDVI'));
};
//2.2 Membuat fungsi batas tutupan awan. Membuat limit awan 30%
var cloudMask = function(image) {
var clouds = ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud']);
return image.updateMask(clouds.lte(30));
};
//2.3 Memilih satelit dan batas waktu pengambilan gambar
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_RT_TOA')
.filterBounds(aoi)
.filterDate('2013-04-01', '2018-12-31')
.map(addNDVI)
.map(cloudMask);
print(l8);
//2.4 Memilih kanal yang diperlukan untuk penelitian (B10 dan NDVI)
var l8_2 = l8.select(['B10', 'NDVI']);
var l8_2_NDVI = l8.select(['NDVI']);
//2.5 Membuat fungsi merubah nilai B10 menjadi suhu dalam Celsius
var toCelsius2_l8 = function(image){
var time = image.get('system:time_start');
var celsius = image.expression('(B10/(1+(10.8*B10/14388)*log((0.004*((ndvi-0.2)/0.3)+0.986))))-273.15',
{'ndvi': image.select('NDVI'), 'B10': image.select('B10')})
.rename("celsius")
.set('system:time_start',time);
return celsius;
};
//2.6 Membuat database baru l8_2_2
var l8_2_2 = l8_2.map(toCelsius2_l8);
//3.1 Membuat tabel time-series suhu rata-rata area penelitian
var l8_2_2_time_median_region = l8_2_2.map(function(i) {
return i.select('celsius').reduceRegions({
collection: aoi,
reducer: ee.Reducer.median(),
scale: 100 //bisa dibuat resolusi 30
}).filter(ee.Filter.neq('median', null))
.map(function(f) {
return f.set('system:time_start',null);
});
}).flatten();
// //3.1 Mengekspor table ke Google Drive
// Export.table.toDrive({
// collection: l8_2_2_time_median_region.select(['.*'],null,false),
// description: 'l8_2_2_time_median_region',
// folder:"/gee-analyses",
// fileFormat: 'CSV'
// });
//3.2 Membuat tabel time-series standar deviasi suhu area penelitian
var l8_2_2_time_stdev_region = l8_2_2.map(function(i) {
return i.select('celsius').reduceRegions({
collection: aoi,
reducer: ee.Reducer.stdDev(),
scale: 100
}).filter(ee.Filter.neq('stdDev', null))
.map(function(f) {
return f.set('system:time_start',null);
});
}).flatten();
// //3.2 Mengekspor tabel standar deviasi ke Google Drive
// Export.table.toDrive({
// collection: l8_2_2_time_stdev_region.select(['.*'],null,false),
// description: 'l8_2_2_time_stdev_region',
// folder:"/gee-analyses",
// fileFormat: 'CSV'
// });
//3.2 Membuat tabel time-series jumlah piksel area penelitian
var l8_2_2_time_count_region = l8_2_2.map(function(i) {
return i.select('celsius').reduceRegions({
collection: aoi,
reducer: ee.Reducer.count(),
scale: 100
}).filter(ee.Filter.neq('count', null))
.map(function(f) {
return f.set('system:time_start',null);
});
}).flatten();
// Export.table.toDrive({
// collection: l8_2_2_time_count_region.select(['.*'],null,false),
// description: 'l8_2_2_time_count_region',
// folder:"/gee-analyses",
// fileFormat: 'CSV'
// });
//3.3 Membuat histogram piksel di area penelitian
var l8_2_2_time_hist_region = l8_2_2.map(function(i) {
return i.select('celsius').reduceRegions({
collection: aoi,
reducer: ee.Reducer.histogram(null, 0.25, null),
scale: 100
});
}).flatten();
// Export.table.toDrive({
// collection: l8_2_2_time_hist_region,
// description: 'l8_2_2_time_hist_region',
// folder:"/gee-analyses",
// fileFormat: 'geoJSON'
// });
//3.4 Membuat gambar rata-rata temperatur area penelitian
var l8_2_2_mean_region_image = l8_2_2.reduce(ee.Reducer.mean());
//Memunculkan gambar rata-rata temperatur area penelitian di peta
Map.addLayer(l8_2_2_mean_region_image.clip(aoi), {palette:['blue','green','orange','red'],min:0,max:35, scale:30}, 'mean temperature 2013-2018');
print(l8_2_2_mean_region_image);
// Mengekspor gambar ke google drive
Export.image.toDrive({
image: l8_2_2_mean_region_image.clip(aoi),
description: 'l8_2_2_mean_region_image',
folder:"/gee-analyses",
scale: 30,
region: aoi,
crs: 'EPSG:3857',
maxPixels:1e13
});
//3.5 Membuat gambar median temperatur area penelitian
var l8_2_2_median_region_image = l8_2_2.reduce(ee.Reducer.median());
//Memunculkan gambar median temperatur area penelitian ke peta
Map.addLayer(l8_2_2_median_region_image.clip(aoi), {palette:['blue','green','orange','red'],min:0,max:35, scale:30}, 'median temperature 2013-2018');
//Mengekspor gambar ke google drive
Export.image.toDrive({
image: l8_2_2_median_region_image.clip(aoi),
description: 'l8_2_2_median_region_image',
folder:"/gee-analyses",
scale: 30,
region: aoi,
crs: 'EPSG:3857',
maxPixels:1e13
});
//3.6 Membuat gambar yang menunjukkan standar deviasi temperatur di area penelitian
var l8_2_2_stdev_region_image = l8_2_2.reduce(ee.Reducer.stdDev());
//Mengekspor gambar ke google drive
// Export.image.toDrive({
// image: l8_2_2_stdev_region_image.clip(aoi),
// description: 'l8_2_2_stdev_region_image',
// folder:"/gee-analyses",
// scale: 100,
// region: aoi,
// crs: 'EPSG:3857',
// maxPixels:1e13
// });
// // 3.7 Membuat gambar rata-rata tahunan
// var l8_2_2_series1_mean = l8_2_2.filterDate('2013-04-11', '2014-12-31').mean();
// var l8_2_2_series2_mean = l8_2_2.filterDate('2015-01-01', '2015-12-31').mean();
// var l8_2_2_series3_mean = l8_2_2.filterDate('2016-01-01', '2016-12-31').mean();
// var l8_2_2_series4_mean = l8_2_2.filterDate('2017-01-01', '2017-12-31').mean();
// var l8_2_2_series5_mean = l8_2_2.filterDate('2018-01-01', '2019-04-30').mean();
//4 Membuat grafik seri waktu masing-masing tata guna lahan. Grafik ini sebenarnya adalah program yang berbeda. Untuk itu kita akan
//menentukan area penelitian yang baru. Area penelitiannya bisa berupa titik, atau berupa polygon. Saya memilih menggunakan polygon kecil.
// membuat simbologi
var COLOR = {
CITY: 'ff0000',
PARK: '0000ff',
FOREST: '00ff00'
};
// menentukan area yang ingin dibuat grafik seri waktunya
var kota = ee.Feature( // Kota.
ee.Geometry.Rectangle(107.60, -6.920, 107.602, -6.922),
{label: 'Kota'});
var baksil = ee.Feature( // Babakan Siliwangi.
ee.Geometry.Rectangle(107.606, -6.889, 107.608, -6.891),
{label: 'Baksil'});
var tahura = ee.Feature( // Tahura Djuanda.
ee.Geometry.Rectangle(107.654, -6.832, 107.656, -6.834),
{label: 'Tahura'});
var titikpengamatan = new ee.FeatureCollection([kota, baksil, tahura]);
//Membuat grafik time-series area penelitian dan suhu
var tempTimeSeries = ui.Chart.image.seriesByRegion({
imageCollection: l8_2_2,
regions: titikpengamatan,
reducer: ee.Reducer.median(),
band: "celsius",
scale: 200,
xProperty: 'system:time_start',
seriesProperty: 'label'
});
tempTimeSeries.setChartType('ScatterChart');
tempTimeSeries.setOptions({
title: 'Temperatur di beberapa titik di Kota Bandung',
vAxis: {
title: 'Temperatur (Celsius)'
},
lineWidth: 0.7,
pointSize: 2,
series: {
0: {color: COLOR.CITY},
1: {color: COLOR.FOREST},
2: {color: COLOR.PARK}
}
});
print(tempTimeSeries);
//Menampilkan polygon di layar
Map.addLayer(baksil, {color: COLOR.PARK});
Map.addLayer(tahura, {color: COLOR.FOREST});
Map.addLayer(kota, {color: COLOR.CITY});
//kode program ini adalah modifikasi kode dari Antony Cak "Characterizing Temporal and Spatial Changes in Land Surface Temperature Across The Amazon Basin
//Using Thermal and Infrared Satellite Data" yang dipresentasikan dalam Dipresentasikan pada American Geophysical Union, Fall Meeting 2017
//tautan https://github.com/tonycak/amazon_lst