-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexplorer_utils
1273 lines (1051 loc) · 42.9 KB
/
explorer_utils
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// released under Open Source GPL License Copyright © 2023 Ka Hei Chow
// ################################################## //
// ### World Bank Intra-Urban Data Explorer Tool #### //
// ################################################## //
// This script provides export functions for all available layers,
// summarized in layer_dict dict
// It is used to download multiple regional rasters in customised resolution
// to facilitate EO-based intra-urban analysis
// import module
var basemap = require('users/pinkychow1010/WB_IntraUrban:basemap_resources');
var palettes = require('users/gena/packages:palettes');
var helper = require('users/pinkychow1010/WB_IntraUrban:helper'); // utils functions
var text = require('users/pinkychow1010/WB_IntraUrban:data_text');
//###############################//
//## ##//
//## CONFIGURATIONS ##//
//## ##//
//###############################//
// descriptions for data layers
exports.info_dict = {
'EXPOSURE | Land Use Cover': text.worldcover,
'EXPOSURE | Population Count': text.ghsl,
'EXPOSURE | Urban Density': text.urban,
'EXPOSURE | Urbanization Degree': text.ghsl,
'EXPOSURE | Landscan Population': text.landscan,
'EXPOSURE | Enhanced Vegetation Index': text.evi,
'EXPOSURE | Vegetation Continuous Fields': text.vcf,
'HAZARD | Summer Day Temperature': text.modis,
'HAZARD | Summer Night Temperature': text.modis,
'HAZARD | Palmer Drought Severity Index': text.pdsi,
'HAZARD | Urban Heat Island Day': text.uhi,
'HAZARD | Urban Heat Island Night': text.uhi,
'HAZARD | Apparent Temperature Mean': text.hitisae,
'HAZARD | Apparent Temperature Min': text.hitisae,
'HAZARD | Apparent Temperature Max': text.hitisae,
'HAZARD | Mean Radiant Temperature Mean': text.hitisae,
'HAZARD | Mean Radiant Temperature Min': text.hitisae,
'HAZARD | Mean Radiant Temperature Max': text.hitisae,
'HAZARD | Wet Bulb Temperature Mean': text.hitisae,
'HAZARD | Wet Bulb Temperature Min': text.hitisae,
'HAZARD | Wet Bulb Temperature Max': text.hitisae,
'HAZARD | Wet Bulb Globe Temperature Mean': text.hitisae,
'HAZARD | Wet Bulb Globe Temperature Min': text.hitisae,
'HAZARD | Wet Bulb Globe Temperature Max': text.hitisae,
'HAZARD | Land Surface Temperature': text.lst,
'HAZARD | Keetch-Byram Drought Index': text.kbdi,
'VULNERABILITY | Relative Wealth Index': text.rwi,
'VULNERABILITY | Critical Infrastructure Index': text.cisi
};
// project url link for data layers
exports.url_dict = {
'EXPOSURE | Land Use Cover': "https://esa-worldcover.org/en",
'EXPOSURE | Population Count': "https://ghsl.jrc.ec.europa.eu/ghs_pop.php",
'EXPOSURE | Urban Density': "https://esa-worldcover.org/en",
'EXPOSURE | Urbanization Degree': "https://ghsl.jrc.ec.europa.eu/ghs_smod2023.php",
'EXPOSURE | Landscan Population': "https://sdi.eea.europa.eu/catalogue/srv/api/records/39e6a1fb-5217-4e22-ab2e-68d50d11faeb",
'EXPOSURE | Enhanced Vegetation Index': "https://developers.google.com/earth-engine/datasets/catalog/MODIS_061_MOD13Q1",
'EXPOSURE | Vegetation Continuous Fields': 'https://developers.google.com/earth-engine/datasets/catalog/MODIS_006_MOD44B',
'HAZARD | Summer Day Temperature': "https://modis.gsfc.nasa.gov/data/dataprod/mod11.php",
'HAZARD | Summer Night Temperature': "https://modis.gsfc.nasa.gov/data/dataprod/mod11.php",
'HAZARD | Palmer Drought Severity Index': "https://www.climatologylab.org/terraclimate.html",
'HAZARD | Urban Heat Island Day': "https://yceo.yale.edu/research/global-surface-uhi-explorer",
'HAZARD | Urban Heat Island Night': "https://yceo.yale.edu/research/global-surface-uhi-explorer",
'HAZARD | Apparent Temperature Mean': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Apparent Temperature Min': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Apparent Temperature Max': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Mean Radiant Temperature Mean': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Mean Radiant Temperature Min': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Mean Radiant Temperature Max': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Wet Bulb Temperature Mean': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Wet Bulb Temperature Min': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Wet Bulb Temperature Max': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Wet Bulb Globe Temperature Mean': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Wet Bulb Globe Temperature Min': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Wet Bulb Globe Temperature Max': 'https://gee-community-catalog.org/projects/hitisae/',
'HAZARD | Land Surface Temperature': 'https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LC09_C02_T1_L2',
'HAZARD | Keetch-Byram Drought Index': 'https://developers.google.com/earth-engine/datasets/catalog/UTOKYO_WTLAB_KBDI_v1#description',
'VULNERABILITY | Relative Wealth Index': "https://dataforgood.facebook.com/dfg/tools/relative-wealth-index",
'VULNERABILITY | Critical Infrastructure Index': "https://www.nature.com/articles/s41597-022-01218-4"
};
// dictionary for default resolution
exports.resolution_dict = {
'EXPOSURE | Land Use Cover': 10,
'EXPOSURE | Population Count': 38,
'EXPOSURE | Urban Density': 2000,
'EXPOSURE | Landscan Population': 1000,
'EXPOSURE | Urbanization Degree': 1000,
'EXPOSURE | Enhanced Vegetation Index': 250,
'EXPOSURE | Vegetation Continuous Fields': 250,
'HAZARD | Summer Day Temperature': 1000,
'HAZARD | Summer Night Temperature': 1000,
'HAZARD | Palmer Drought Severity Index': 2000,
'HAZARD | Urban Heat Island Day': 300,
'HAZARD | Urban Heat Island Night': 300,
'HAZARD | Apparent Temperature Mean': 2000,
'HAZARD | Apparent Temperature Min': 2000,
'HAZARD | Apparent Temperature Max': 2000,
'HAZARD | Mean Radiant Temperature Mean': 2000,
'HAZARD | Mean Radiant Temperature Min': 2000,
'HAZARD | Mean Radiant Temperature Max': 2000,
'HAZARD | Wet Bulb Temperature Mean': 2000,
'HAZARD | Wet Bulb Temperature Min': 2000,
'HAZARD | Wet Bulb Temperature Max': 2000,
'HAZARD | Wet Bulb Globe Temperature Mean': 2000,
'HAZARD | Wet Bulb Globe Temperature Min': 2000,
'HAZARD | Wet Bulb Globe Temperature Max': 2000,
'HAZARD | Land Surface Temperature': 30,
'HAZARD | Keetch-Byram Drought Index': 2000,
'VULNERABILITY | Relative Wealth Index': 2000,
'VULNERABILITY | Critical Infrastructure Index': 2000
};
// dictionary for filename definitions
exports.filename_dict = {
'EXPOSURE | Land Use Cover': 'ESA-WorldCover-2020',
'EXPOSURE | Population Count': 'Population-GPW-2015',
'EXPOSURE | Urban Density': 'ESA-WorldCover-derived-urban-density',
'EXPOSURE | Landscan Population': 'Population-Landscan-2021',
'EXPOSURE | Urbanization Degree': 'GHSL-2015-urbanization-degree',
'EXPOSURE | Enhanced Vegetation Index': 'Enhanced-Vegetation-Index-2022-summer',
'EXPOSURE | Vegetation Continuous Fields': 'MODIS-Vegetation-Continuous-Fields-Current-Year',
'HAZARD | Summer Day Temperature': 'MODIS-LST-day',
'HAZARD | Summer Night Temperature': 'MODIS-LST-night',
'HAZARD | Palmer Drought Severity': 'PDSI-median-2010-to-2023',
'HAZARD | Urban Heat Island Day': 'Urban-Heat-Island-Day-Yale',
'HAZARD | Urban Heat Island Night': 'Urban-Heat-Island-Night-Yale',
'HAZARD | Apparent Temperature Mean': 'Apparent-Temperature-Mean',
'HAZARD | Apparent Temperature Min': 'Apparent-Temperature-Min',
'HAZARD | Apparent Temperature Max': 'Apparent-Temperature-Max',
'HAZARD | Mean Radiant Temperature Mean': 'Mean-Radiant-Temperature-Mean',
'HAZARD | Mean Radiant Temperature Min': 'Mean-Radiant-Temperature-Min',
'HAZARD | Mean Radiant Temperature Max': 'Mean-Radiant-Temperature-Max',
'HAZARD | Wet Bulb Temperature Mean': 'Wet-Bulb-Temperature-Mean',
'HAZARD | Wet Bulb Temperature Min': 'Wet-Bulb-Temperature-Min',
'HAZARD | Wet Bulb Temperature Max': 'Wet-Bulb-Temperature-Max',
'HAZARD | Wet Bulb Globe Temperature Mean': 'Wet-Bulb-Globe-Temperature-Mean',
'HAZARD | Wet Bulb Globe Temperature Min': 'Wet-Bulb-Globe-Temperature-Min',
'HAZARD | Wet Bulb Globe Temperature Max': 'Wet-Bulb-Globe-Temperature-Max',
'HAZARD | Land Surface Temperature': 'Land-Surface-Temperature-2022-Summer-Day',
'HAZARD | Keetch-Byram Drought Index': 'Latest-Keetch-Byram-Drought-Index',
'VULNERABILITY | Relative Wealth Index': 'Facebook-Relative-Wealth-Index',
'VULNERABILITY | Critical Infrastructure Index': 'Critical-Infrastructure-Spatial-Index'
};
// dictionary for resampling algorithms
exports.reducer_dict = {
'EXPOSURE | Land Use Cover': ee.Reducer.mode(), // retain discrete class
'EXPOSURE | Population Count': ee.Reducer.sum(), // population count per pixel
'EXPOSURE | Urban Density': ee.Reducer.mean(), // ratio
'EXPOSURE | Landscan Population': ee.Reducer.sum(),
'EXPOSURE | Urbanization Degree': ee.Reducer.mean(),
'EXPOSURE | Enhanced Vegetation Index': ee.Reducer.median(),
'EXPOSURE | Vegetation Continuous Fields': ee.Reducer.median(),
'HAZARD | Summer Day Temperature': ee.Reducer.median(), // median to prevent influence from outliners
'HAZARD | Summer Night Temperature': ee.Reducer.median(), // median to prevent influence from outliners
'HAZARD | Palmer Drought Severity': ee.Reducer.mean(),
'HAZARD | Urban Heat Island Day': ee.Reducer.median(),
'HAZARD | Urban Heat Island Night': ee.Reducer.median(),
'HAZARD | Apparent Temperature Mean': ee.Reducer.mean(),
'HAZARD | Apparent Temperature Min': ee.Reducer.mean(),
'HAZARD | Apparent Temperature Max': ee.Reducer.mean(),
'HAZARD | Mean Radiant Temperature Mean': ee.Reducer.mean(),
'HAZARD | Mean Radiant Temperature Min': ee.Reducer.mean(),
'HAZARD | Mean Radiant Temperature Max': ee.Reducer.mean(),
'HAZARD | Wet Bulb Temperature Mean': ee.Reducer.mean(),
'HAZARD | Wet Bulb Temperature Min': ee.Reducer.mean(),
'HAZARD | Wet Bulb Temperature Max': ee.Reducer.mean(),
'HAZARD | Wet Bulb Globe Temperature Mean': ee.Reducer.mean(),
'HAZARD | Wet Bulb Globe Temperature Min': ee.Reducer.mean(),
'HAZARD | Wet Bulb Globe Temperature Max': ee.Reducer.mean(),
'HAZARD | Land Surface Temperature': ee.Reducer.median(),
'HAZARD | Keetch-Byram Drought Index': ee.Reducer.median(),
'VULNERABILITY | Relative Wealth Index': ee.Reducer.median(),
'VULNERABILITY | Critical Infrastructure Index': ee.Reducer.mean()
};
// dictionary for action labels and corresponding functions (call map layer display + return layer for export)
exports.layer_dict = {
'EXPOSURE | Land Use Cover': export_landuse,
'EXPOSURE | Population Count': export_population,
'EXPOSURE | Urban Density': export_urban_density,
'EXPOSURE | Landscan Population': export_landscan_pop,
'EXPOSURE | Urbanization Degree': export_urban_degree,
'EXPOSURE | Enhanced Vegetation Index': export_evi,
'EXPOSURE | Vegetation Continuous Fields': export_vcf,
'HAZARD | Summer Day Temperature': export_summer_lst,
'HAZARD | Summer Night Temperature': export_summer_lst_night,
'HAZARD | Palmer Drought Severity': export_pdsi,
'HAZARD | Urban Heat Island Day': export_uhi_day,
'HAZARD | Urban Heat Island Night': export_uhi_night,
'HAZARD | Apparent Temperature Mean': export_AT_mean,
'HAZARD | Apparent Temperature Min': export_AT_min,
'HAZARD | Apparent Temperature Max': export_AT_max,
'HAZARD | Mean Radiant Temperature Mean': export_MRT_mean,
'HAZARD | Mean Radiant Temperature Min': export_MRT_min,
'HAZARD | Mean Radiant Temperature Max': export_MRT_max,
'HAZARD | Wet Bulb Temperature Mean': export_WBT_mean,
'HAZARD | Wet Bulb Temperature Min': export_WBT_min,
'HAZARD | Wet Bulb Temperature Max': export_WBT_max,
'HAZARD | Wet Bulb Globe Temperature Mean': export_WBGT_mean,
'HAZARD | Wet Bulb Globe Temperature Min': export_WBGT_min,
'HAZARD | Wet Bulb Globe Temperature Max': export_WBGT_max,
'HAZARD | Land Surface Temperature': export_l8_st,
'HAZARD | Keetch-Byram Drought Index': export_kbdi,
'VULNERABILITY | Relative Wealth Index': export_rwi,
'VULNERABILITY | Critical Infrastructure Index': export_cisi
};
//###############################//
//## ##//
//## EXPORT FUNCTIONS ##//
//## ##//
//###############################//
// *** Layout ***
// Name of Data Layer
// function export_name(aoi) { // function name export_*
// var layer = ee.Image("data-layer").clip(aoi); // regional raster image (not collection)
// // predefined visualization params
// var vis = {min:minVal, max:maxVal, palette:['#000004','#57106e','#bc3754','#f98e09','#fcffa4']}; //inferno
// Map.addLayer(layer, vis, "Index"); // add layer to map
// var legend = helper.add_colorbar(vis, "Index");
// Map.add(legend); // always add legend
// Map.centerObject(aoi, 8); // always center object
// return layer; // return image for user export
// }
// Keetch-Byram Drought Index (KBDI)
function export_kbdi(aoi) {
var layer = ee.ImageCollection('UTOKYO/WTLAB/KBDI/v1')
.select('KBDI')
.limit(1, 'system:time_start', false)
.first()
.clip(aoi); // latest image for kbdi drought index
layer = layer.rename(
'KBDI_'+layer.get('system:index').getInfo()
);
var vis = {
min: 0,
max: 800,
palette: [
'001a4d', '003cb3', '80aaff', '336600',
'cccc00', 'cc9900', 'cc6600', '660033'
]
};
Map.addLayer(layer, vis, "Index");
var legend = helper.add_colorbar(vis, "Index");
Map.add(legend);
Map.centerObject(aoi, 8);
return layer;
}
// Landsat 8 Surface Temperature
function export_l8_st(aoi) {
var yearFilter = ee.Filter.date(ee.Date("2022-01-01"), ee.Date("2023-01-01"));
var summerFilter = helper.get_summer(aoi);
var landsat = ee.ImageCollection("LANDSAT/LC09/C02/T1_L2")
.map(maskL8sr)
.filter(yearFilter)
.filter(summerFilter)
.filter(ee.Filter.lt('CLOUD_COVER', 30))
.median()
.clip(aoi);
var b10 = landsat.select(['ST_B10'])
.multiply(0.00341802).add(149)
.subtract(273.15)
.rename('LST');
// predefined visualization params
var max = b10.reduceRegion({
reducer: ee.Reducer.max(),
geometry: aoi.geometry(),
crs: 'EPSG:4326',
scale: 1000,
maxPixels: 1e9
}).get('LST').getInfo();
var min = b10.reduceRegion({
reducer: ee.Reducer.min(),
geometry: aoi.geometry(),
crs: 'EPSG:4326',
scale: 1000,
maxPixels: 1e9
}).get('LST').getInfo();
var vis = {min:min, max:max, palette:['#000004','#57106e','#bc3754','#f98e09','#fcffa4']}; //inferno
Map.addLayer(b10, vis, "Landsat 8 median LST (summer 2022)"); // add layer to map
var legend = helper.add_colorbar(vis, "Celsius");
Map.add(legend);
Map.centerObject(aoi, 8);
return b10;
}
function maskL8sr(col) {
// #################################
// ### Landsat 8 cloud mask #####
// #################################
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = (1 << 3);
var cloudsBitMask = (1 << 5);
// Get the pixel QA band.
var qa = col.select("QA_PIXEL");
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
return col.updateMask(mask);
}
// Terra MODIS Vegetation Continuous Fields (VCF) product
function export_vcf(aoi) { // function name export_*
// import dataset
var dataset = ee.ImageCollection('MODIS/006/MOD44B')
.limit(1, 'system:time_start', false).first()
.clip(aoi).select('Percent_NonVegetated');
// set up visualization params
var vis = {
min: 10.0,
max: 100.0,
palette: ['074b03', '0a9501', 'bbe029', 'yellow', 'red']
};
Map.centerObject(dataset, 8);
Map.addLayer(dataset, vis, "%"); // add layer to map
var legend = helper.add_colorbar(vis, "Index");
Map.add(legend);
Map.centerObject(aoi, 8);
return dataset.int8();
}
// Enhanced Vegetation Index (EVI)
function export_evi(aoi) {
var summer = helper.get_summer(aoi);
var dataset = ee.ImageCollection('MODIS/061/MOD13Q1')
.filter(summer)
.filter(ee.Filter.date('2022-01-01', '2023-01-01'))
.median()
.multiply(0.0001)
.clip(aoi);
var evi = dataset.select('EVI');
var eviVis = {
min: 0.0,
max: 0.5,
palette: [
'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
'66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
'012E01', '011D01', '011301'
],
};
Map.addLayer(evi, eviVis, "Enhanced Vegetation Index");
var legend = helper.add_colorbar(eviVis, "Index");
Map.add(legend);
Map.centerObject(aoi, 8);
return evi;
}
// WBT
function export_WBT_mean(aoi) {
var img = get_thermal_idx(aoi, "WBT", "mean");
return img;
}
function export_WBT_min(aoi) {
var img = get_thermal_idx(aoi, "WBT", "min");
return img;
}
function export_WBT_max(aoi) {
var img = get_thermal_idx(aoi, "WBT", "max");
return img;
}
// WBGT
function export_WBGT_mean(aoi) {
var img = get_thermal_idx(aoi, "WBGT", "mean");
return img;
}
function export_WBGT_min(aoi) {
var img = get_thermal_idx(aoi, "WBGT", "min");
return img;
}
function export_WBGT_max(aoi) {
var img = get_thermal_idx(aoi, "WBGT", "max");
return img;
}
// UTCI
function export_UTCI_mean(aoi) {
var img = get_thermal_idx(aoi, "UTCI", "mean");
return img;
}
function export_UTCI_min(aoi) {
var img = get_thermal_idx(aoi, "UTCI", "min");
return img;
}
function export_UTCI_max(aoi) {
var img = get_thermal_idx(aoi, "UTCI", "max");
return img;
}
// AT
function export_AT_mean(aoi) {
var img = get_thermal_idx(aoi, "AT", "mean");
return img;
}
function export_AT_min(aoi) {
var img = get_thermal_idx(aoi, "AT", "min");
return img;
}
function export_AT_max(aoi) {
var img = get_thermal_idx(aoi, "AT", "max");
return img;
}
// MRT
function export_MRT_mean(aoi) {
var img = get_thermal_idx(aoi, "MRT", "mean");
return img;
}
function export_MRT_min(aoi) {
var img = get_thermal_idx(aoi, "MRT", "min");
return img;
}
function export_MRT_max(aoi) {
var img = get_thermal_idx(aoi, "MRT", "max");
return img;
}
// ESI
function export_ESI_mean(aoi) {
var img = get_thermal_idx(aoi, "ESI", "mean");
return img;
}
function export_ESI_min(aoi) {
var img = get_thermal_idx(aoi, "ESI", "min");
return img;
}
function export_ESI_max(aoi) {
var img = get_thermal_idx(aoi, "ESI", "max");
return img;
}
// generic function for extracting thermal index data
function get_thermal_idx(aoi, index, stat){
// B1: Min, B2: Mean and B3: Maximum
var band_dict = {
"min": "b1",
"mean": "b2",
"max": "b3"
};
// names for index
var idx_dict = {
"AT": "Apparent Temperature (AT)",
"ESI": "Environment Stress Index (ESI)",
"MRT": "Mean Radiant Temperature (MRT)",
"UTCI": "Universal Thermal Climate Index (UTCI)",
"UTCI2": "UTCI for indoor environment",
"UTCI3": "UTCI for outdoor shaded space",
"HI": "Heat Index (HI)",
"Humidex": "Humidity Index (Humidex)",
"WBGT": "Wet-bulb Globe Temperature (WBGT)",
"WBT": "Wet Bulb Temperature (WBT)",
"WCT": "Wind Chill Temperature (WCCT)",
"NET": "Net Effective Temperature (NET)"
};
var ds = ee.ImageCollection("projects/sat-io/open-datasets/HITISEA/"+index);
var img = ds
.filter(ee.Filter.date(ee.Date('2015-06-01'), ee.Date('2019-10-01')))
.filter(ee.Filter.calendarRange(6, 9, 'month'))
.select(band_dict[stat])
.limit(1, 'system:time_start', false).median().clip(aoi); // summer mean between 2015 to 2019
var max = img.reduceRegion({
reducer: ee.Reducer.max(),
geometry: aoi.geometry(),
crs: 'EPSG:4326',
scale: 1000,
maxPixels: 1e9
}).get(band_dict[stat]).getInfo();
var min = img.reduceRegion({
reducer: ee.Reducer.min(),
geometry: aoi.geometry(),
crs: 'EPSG:4326',
scale: 1000,
maxPixels: 1e9
}).get(band_dict[stat]).getInfo();
var vis = {min:min, max:max, palette:['#000004','#57106e','#bc3754','#f98e09','#fcffa4']}; //inferno
Map.addLayer(img, vis, idx_dict[index]);
var legend = helper.add_colorbar(vis, index);
Map.add(legend);
Map.centerObject(aoi, 8);
return img;
}
// Critical Infrastructure Spatial Index
function export_cisi(aoi) {
var cisi = ee.Image("projects/sat-io/open-datasets/CISI/global_CISI").clip(aoi);
var vis = {min:0, max:0.2, palette:['#000004','#57106e','#bc3754','#f98e09','#fcffa4']}; //inferno
Map.addLayer(cisi, vis, "Critical Infrastructure Spatial Index");
var legend = helper.add_colorbar(vis, "Index");
Map.add(legend);
Map.centerObject(aoi, 8);
return cisi;
}
// Urban Heat Island Index Summer Days (Yale)
function export_uhi_day(aoi) {
var uhi = ee.ImageCollection('YALE/YCEO/UHI/Summer_UHI_yearly_pixel/v4')
.select('Daytime')
.filter(ee.Filter.inList('system:index', ["2018"]))
.first();
var vis = {min:-4, max:6, palette:['#000004','#57106e','#bc3754','#f98e09','#fcffa4']}; //inferno
Map.addLayer(uhi.clip(aoi), vis, "UHI Summer Days");
var legend = helper.add_colorbar(vis, "Index");
Map.add(legend);
Map.centerObject(aoi, 8);
return uhi.clip(aoi);
}
// Urban Heat Island Index Summer Nights (Yale)
function export_uhi_night(aoi) {
var uhi = ee.ImageCollection('YALE/YCEO/UHI/Summer_UHI_yearly_pixel/v4')
.select('Nighttime')
.filter(ee.Filter.inList('system:index', ["2018"]))
.first();
var vis = {min:-4, max:6, palette:['#000004','#57106e','#bc3754','#f98e09','#fcffa4']}; //inferno
Map.addLayer(uhi.clip(aoi), vis, "UHI Summer Nights");
var legend = helper.add_colorbar(vis, "Index");
Map.add(legend);
Map.centerObject(aoi, 8);
return uhi.clip(aoi);
}
// Relative Wealth Index (Facebook)
function export_rwi(aoi) {
var rwi = ee.FeatureCollection("projects/sat-io/open-datasets/facebook/relative_wealth_index");
var aoi_rwi = rwi.filterBounds(aoi).map(
function(point) {
return point.buffer(2000);
});
var rwi_raster = aoi_rwi.filter(ee.Filter.notNull(['rwi']))
.reduceToImage({
properties: ['rwi'],
reducer: ee.Reducer.mean(),
})
.clip(aoi)
.setDefaultProjection('EPSG: 4326'); // debug rwi export issues: https://developers.google.com/earth-engine/apidocs/ee-featurecollection-reducetoimage
// display layer
var vis = {min: -1, max: 1.5, palette: ['red','orange','yellow','green','blue']};
Map.addLayer(rwi_raster, vis, "Relative Wealth Index (facebook)");
// add legend to raster layer
var legend = helper.add_colorbar(vis, "Index");
Map.add(legend);
Map.centerObject(aoi, 5);
return rwi_raster;
}
// Urbanization Degree GHSL
function export_urban_degree(aoi) {
var dataset = ee.ImageCollection('JRC/GHSL/P2016/SMOD_POP_GLOBE_V1')
.filter(ee.Filter.date('2015-01-01', '2015-12-31'));
var degreeOfUrbanization = dataset.select('smod_code').sum().clip(aoi);
var vis = {
min: 0.0,
max: 3.0,
palette: ['#ffd700','#ffb51e','#e36c18','#a22922']
};
// display layer
Map.addLayer(degreeOfUrbanization, vis, 'Degree of Urbanization GHSL 2015');
Map.centerObject(aoi, 8);
// add legend to raster layer
var legend = helper.add_colorbar(vis, "Degree");
Map.add(legend);
var ref = ee.ImageCollection('JRC/GHSL/P2016/SMOD_POP_GLOBE_V1').first().projection();
return degreeOfUrbanization.setDefaultProjection(ref);
}
// Palmer Drought Severity Index
function export_pdsi(aoi) {
// return the list of coordinates
var centroid = aoi.first().geometry().centroid();
var listCoords = ee.Array.cat(centroid.coordinates(), 0);
var yCoords = ee.List(listCoords).getInfo()[1];
var south = ee.Number(yCoords).lt(0);
var shift = south.multiply(6).getInfo();
var summerFilter = ee.Filter.calendarRange(5+shift, 9+shift, "month");
var yearFilter = ee.Filter.date(ee.Date("2010-01-01"),ee.Date("2023-01-01"));
var dataset = ee.ImageCollection('IDAHO_EPSCOR/TERRACLIMATE')
.filter(yearFilter).filter(summerFilter);
var drought_index = dataset.select('pdsi').median().multiply(0.01).clip(aoi);
var vis = {
min: -4.0,
max: 5.0,
palette: ['red','yellow','green','blue'],
};
// display layer
Map.addLayer(drought_index, vis, 'PDSI long-term median (2010-2023)');
Map.centerObject(aoi, 8);
// add legend to raster layer
var legend = helper.add_colorbar(vis, "PDSI");
Map.add(legend);
var ref = ee.ImageCollection('IDAHO_EPSCOR/TERRACLIMATE').first().projection();
return drought_index.setDefaultProjection(ref);
}
// Landscan population estimate HD 2021
function export_landscan_pop(aoi) {
var popcount_intervals =
'<RasterSymbolizer>' +
' <ColorMap type="intervals" extended="false" >' +
'<ColorMapEntry color="#CCCCCC" quantity="0" label="No Data"/>' +
'<ColorMapEntry color="#FFFFBE" quantity="5" label="Population Count (Estimate)"/>' +
'<ColorMapEntry color="#FEFF73" quantity="25" label="Population Count (Estimate)"/>' +
'<ColorMapEntry color="#FEFF2C" quantity="50" label="Population Count (Estimate)"/>' +
'<ColorMapEntry color="#FFAA27" quantity="100" label="Population Count (Estimate)"/>' +
'<ColorMapEntry color="#FF6625" quantity="500" label="Population Count (Estimate)"/>' +
'<ColorMapEntry color="#FF0023" quantity="2500" label="Population Count (Estimate)"/>' +
'<ColorMapEntry color="#CC001A" quantity="5000" label="Population Count (Estimate)"/>' +
'<ColorMapEntry color="#730009" quantity="185000" label="Population Count (Estimate)"/>' +
'</ColorMap>' +
'</RasterSymbolizer>';
// Define a dictionary which will be used to make legend and visualize image on map
var dict = {
"names": [
"0",
"1-5",
"6-25",
"26-50",
"51-100",
"101-500",
"501-2500",
"2501-5000",
"5001-185000"
],
"colors": [
"#CCCCCC",
"#FFFFBE",
"#FEFF73",
"#FEFF2C",
"#FFAA27",
"#FF6625",
"#FF0023",
"#CC001A",
"#730009"
]};
// Create a panel to hold the legend widget
var legend = ui.Panel({
style: {
position: 'bottom-left',
padding: '8px 15px'
}
});
// Function to generate the legend
function addCategoricalLegend(panel, dict, title) {
// Create and add the legend title.
var legendTitle = ui.Label({
value: title,
style: {
fontWeight: 'bold',
fontSize: '18px',
margin: '0 0 4px 0',
padding: '0'
}
});
panel.add(legendTitle);
var loading = ui.Label('Loading legend...', {margin: '2px 0 4px 0'});
panel.add(loading);
// 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')
});
};
// Get the list of palette colors and class names from the image.
var palette = dict.colors;
var names = dict.names;
loading.style().set('shown', false);
for (var i = 0; i < names.length; i++) {
panel.add(makeRow(palette[i], names[i]));
}
Map.add(panel);
}
var landscan_global = ee.ImageCollection("projects/sat-io/open-datasets/ORNL/LANDSCAN_GLOBAL");
var landscan_2021 = landscan_global.sort('system:time_start',false).first().clip(aoi);
addCategoricalLegend(legend, dict, 'Population Sum (1 km2)');
Map.addLayer(landscan_2021.sldStyle(popcount_intervals), {}, 'Population Count Estimate LANDSCAN HD 2021');
return landscan_2021.clip(aoi);
}
// define function for Summer Temperature
// exports.export_summer_lst_night =
function export_summer_lst_night(aoi) {
// calculate geometry of vector layer
var bbox = aoi.geometry();
// determine location in south / north hemisphere (different summer months)
var centroid = bbox.centroid();
var listCoords = ee.Array.cat(centroid.coordinates(), 0);
var yCoords = ee.List(listCoords).getInfo()[1];
// south/ north
var south = ee.Number(yCoords).lt(0);
var shift = south.multiply(6).getInfo();
// evaluation year
var start_year = ee.Date("2020-01-01");
var end_year = ee.Date("2021-01-01");
// filter dataset to evaluation year
var yearFilter = ee.Filter.date(
start_year.advance(-1, "year"),
end_year.advance(1, "year")
);
// get summer months depends on location
var summerFilter = ee.Filter.calendarRange(5+shift, 9-shift, "month");
var lst = ee.ImageCollection("MODIS/061/MOD11A2")
//.map(maskClouds) // to be done: add MODIS cloud masking
.select("LST_Night_1km") // day time temperature
.filter(yearFilter) // filter year
.filter(summerFilter) // filter season
.median() // get median
.multiply(0.02) // apply scale factor
.subtract(272.15) // apply offset
.clip(bbox); // limit bounds
// visualization format
var vis = {
min: 20.0,
max: 40.0,
palette: ['blue', 'white', 'red'],
};
// add layer for land surface temperature
Map.addLayer(lst, vis, 'MODIS LST Night 2020');
Map.centerObject(bbox, 8);
// add legend to raster layer
var legend = helper.add_colorbar(vis, "LST Night");
Map.add(legend);
// for some reason, the original projection altered after temporal filtering
// this line is necessary to set back valid projection for the output layer
var ref = ee.ImageCollection("MODIS/061/MOD11A2").first().projection();
return lst.setDefaultProjection(ref);
}
/**
* Calculate summer land surface temperature: export summer average temperature to interactive dashboard.
*
* This function is used to construct a MODIS-based LST gridded dataset based on location inputs from users.
*
* @author Ka Hei Chow.
*
* @see helper.add_colormap
* @link 'users/pinkychow1010/GEE:WorldBank/helper'
* @global
*
* @fires add LST raster layer
* @listens select area of interest
*
* @param {ee.Geometry.Polygon} vector A vector layer which consists of a single polygon (admin boundary).
*
* @return {ee.Image} Single LST data layer bounds by selected admin 2 boundary.
*
*/
// exports.export_summer_lst =
function export_summer_lst(aoi) {
// calculate geometry of vector layer
var bbox = aoi.geometry();
// determine location in south / north hemisphere (different summer months)
var centroid = bbox.centroid();
var listCoords = ee.Array.cat(centroid.coordinates(), 0);
var yCoords = ee.List(listCoords).getInfo()[1];
// south/ north
var south = ee.Number(yCoords).lt(0);
var shift = south.multiply(6).getInfo();
// evaluation year
var start_year = ee.Date("2020-01-01");
var end_year = ee.Date("2021-01-01");
// filter dataset to evaluation year
var yearFilter = ee.Filter.date(
start_year.advance(-1, "year"),
end_year.advance(1, "year")
);
// get summer months depends on location
var summerFilter = ee.Filter.calendarRange(5+shift, 9-shift, "month");
var lst = ee.ImageCollection("MODIS/061/MOD11A2")
//.map(maskClouds) // to be done: add MODIS cloud masking
.select("LST_Day_1km") // day time temperature
.filter(yearFilter) // filter year
.filter(summerFilter) // filter season
.median() // get median
.multiply(0.02) // apply scale factor
.subtract(272.15) // apply offset
.clip(bbox); // limit bounds
// visualization format
var vis = {
min: 20.0,
max: 40.0,
palette: ['blue', 'white', 'red'],
};
// add layer for land surface temperature
Map.addLayer(lst, vis, 'MODIS LST Day 2020');
Map.centerObject(bbox, 8);
// add legend to raster layer
var legend = helper.add_colorbar(vis, "LST Day");
Map.add(legend);
// for some reason, the original projection altered after temporal filtering
// this line is necessary to set back valid projection for the output layer
var ref = ee.ImageCollection("MODIS/061/MOD11A2").first().projection();
return lst.setDefaultProjection(ref);
}
// define function for Population Count
/**
* World Population: export population density layer to interactive dashboard.
*
* This function is used to construct a population count gridded dataset based on location inputs from users.
*
* @author Ka Hei Chow.
*
* @see helper.add_colormap
* @link 'users/pinkychow1010/GEE:WorldBank/helper'
* @global
*
* @fires add population density raster layer
* @listens select area of interest
*
* @param {ee.Geometry.Polygon} vector A vector layer which consists of a single polygon (admin boundary).
*
* @return {ee.Image} Single population count data layer bounds by selected admin 2 boundary.
*
*/
// exports.export_population =
function export_population(aoi) {
// compute vector boundary
var bbox = aoi.geometry();
// get population dataset (GHSL 2015)
var dataset = ee.ImageCollection('JRC/GHSL/P2016/POP_GPW_GLOBE_V1')
.filter(ee.Filter.date('2015-01-01', '2015-12-31')).first();
var pop = dataset.select('population_count').clip(bbox); // limit bounds
// visualization format
var vis = {
min: 0.0,
max: 200.0,
palette: ['060606', '337663', '337663', 'ffffff'],
};
// add layer for population
Map.addLayer(pop, vis, 'GSHL Population 2015');
Map.centerObject(bbox, 8);
// add legend to raster layer
var legend = helper.add_colorbar(vis, "Population");
Map.add(legend);
return pop;
}
// define function for ESA world cover 2020