iamsuman commited on
Commit
d217564
·
1 Parent(s): 2dc4a78

add wildfire mapping in home page

Browse files
Files changed (1) hide show
  1. pages/05_California_wildfire.py +160 -0
pages/05_California_wildfire.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ee
2
+ import geemap
3
+ import solara
4
+
5
+ def applyBurnedPopulationMask(image, burnedData):
6
+ popMask = image.select('population').neq(0) # masking out areas that have 0 population
7
+ burnedMask = burnedData.select('BurnDate').neq(0) # masking out areas that were not burned
8
+ mask = popMask.And(burnedMask) # only keep areas that were both burned and have a population
9
+ return image.updateMask(mask).select("population").copyProperties(image, ['population'])
10
+
11
+
12
+
13
+ class Map(geemap.Map):
14
+ def __init__(self, **kwargs):
15
+ super().__init__(**kwargs)
16
+ self.add_ee_data()
17
+ self.basemap_added = False
18
+ # self.add_plot_gui()
19
+
20
+
21
+ def add_ee_data(self):
22
+ california_area = ee.FeatureCollection("TIGER/2018/States").filter(ee.Filter.eq('NAME', 'California'))
23
+ # population grid
24
+ popdataset2020 = ee.ImageCollection("WorldPop/GP/100m/pop")\
25
+ .filterDate("2020-01-01", "2021-01-01")
26
+
27
+ pop2020 = popdataset2020.mean().clip(california_area)
28
+
29
+ pop_params = {
30
+ 'bands': ['population'],
31
+ 'min': 1.0,
32
+ 'max': 60.0,
33
+ 'palette' : ['bdd7e7','6baed6','2171b5']
34
+ }
35
+
36
+ popdataset2001 = ee.ImageCollection("WorldPop/GP/100m/pop")\
37
+ .filterDate("2001-01-01", "2002-01-01")
38
+
39
+ pop2001 = popdataset2001.mean().clip(california_area)
40
+
41
+ # burned
42
+ burnedCollection2020 = ee.ImageCollection('MODIS/006/MCD64A1').filter(ee.Filter.date('2020-01-01', '2021-01-01'))
43
+ burned2020 = burnedCollection2020.select('BurnDate').mean().clip(california_area)
44
+ burned_params = {
45
+ 'min': 30.0,
46
+ 'max': 341.0,
47
+ 'palette':['red']
48
+ }
49
+
50
+ burnedCollection2001 = ee.ImageCollection('MODIS/006/MCD64A1').filter(ee.Filter.date('2001-01-01', '2002-01-01'))
51
+ burned2001 = burnedCollection2001.select('BurnDate').mean().clip(california_area)
52
+ burnedpop2020 = popdataset2020.map(lambda img: applyBurnedPopulationMask(img, burned2020))
53
+ burnedpop2001 = popdataset2001.map(lambda img: applyBurnedPopulationMask(img, burned2001))
54
+
55
+ impacted_pop_params = {
56
+ 'bands': ['population'],
57
+ 'min': 0.0,
58
+ 'max': 60.0,
59
+ 'palette' : ['white','bdd7e7','6baed6','2171b5']
60
+ }
61
+
62
+ # plot graph
63
+ roi = ee.Geometry.Point(-119.6, 37.4)
64
+ self.add_basemap("SATELLITE")
65
+
66
+ # num_legends = self.getLegendCount()
67
+
68
+
69
+ # legend for population
70
+ legend_dict = {
71
+ 'No population': '000000',
72
+ 'Low population':'6baed6',
73
+ 'High population': '2171b5',
74
+ 'Area with population affected by wildfires': 'ffffff',
75
+ 'Burn areas': 'ff0000'
76
+ }
77
+ self.centerObject(roi, 4)
78
+ # try:
79
+ # self.add_legend(legend_title="Population and Burn Scars", legend_elements=legend_dict)
80
+ # except Exception as e:
81
+ # print(f"Error adding legend: {e}")
82
+
83
+
84
+ landcover2 = ee.ImageCollection("NOAA/DMSP-OLS/NIGHTTIME_LIGHTS") \
85
+ .filter(ee.Filter.date('1992-01-01', '1992-12-31')).mean()
86
+ curImage = landcover2.select('stable_lights')
87
+ curImage = curImage.where(curImage.neq(1), 1)
88
+ self.add_layer(curImage,{'palette':['white']},'Background')
89
+
90
+ landcover = ee.ImageCollection('USGS/NLCD').select('landcover').filterDate("2016-01-01", "2017-01-01").first().clip(california_area)
91
+ landcover3 = ee.ImageCollection("NOAA/DMSP-OLS/NIGHTTIME_LIGHTS") \
92
+ .filter(ee.Filter.date('1992-01-01', '1992-12-31')).mean()
93
+ curImage = landcover3.select('stable_lights').clip(california_area)
94
+ curImage = curImage.updateMask(landcover.neq(11).And(landcover.neq(12)).And(landcover.neq(90)).And(landcover.neq(95)).And(landcover.neq(31)))
95
+ curImage = curImage.where(curImage.neq(1), 1)
96
+ self.add_layer(curImage,{'palette':['a4a7ab']},'California')
97
+
98
+
99
+ # population
100
+ worldPop2020 = ee.ImageCollection("WorldPop/GP/100m/pop")\
101
+ .filterDate("2020-01-01", "2020-12-01").select('population').mean().clip(california_area)
102
+
103
+ worldPop2020 = worldPop2020.updateMask(worldPop2020.gte(5))
104
+
105
+ worldPop2001 = ee.ImageCollection("WorldPop/GP/100m/pop")\
106
+ .filterDate("2001-01-01", "2002-12-01").select('population').mean().clip(california_area)
107
+
108
+ worldPop2001 = worldPop2001.updateMask(worldPop2001.gte(5))
109
+
110
+ pop_params2 = {
111
+ 'bands': ['population'],
112
+ 'min': 0.0,
113
+ 'max': 50.0,
114
+ 'palette': ['white','bdd7e7','6baed6','2171b5']
115
+ }
116
+
117
+
118
+ self.addLayer(pop2020, pop_params, "Population 2020", False)
119
+ self.addLayer(burned2020, burned_params, 'Burned Area 2020', True, 0.6)
120
+ self.addLayer(burnedpop2020, impacted_pop_params, "Area of Impacted Population 2020", False)
121
+ self.addLayer(worldPop2020, pop_params2, "Impacted Population Overlay 2020", True)
122
+
123
+ self.addLayer(pop2001, pop_params, "Population 2001", False)
124
+ self.addLayer(burned2001, burned_params, 'Burned Area 2001', False, 0.6)
125
+ self.addLayer(burnedpop2001, impacted_pop_params, "Area of Impacted Population 2001", False)
126
+ self.addLayer(worldPop2001, pop_params2, "Impacted Population Overlay 2001", False)
127
+
128
+
129
+
130
+ # time.sleep(20)
131
+ # add_legend_after_overlay(self)
132
+
133
+ @solara.component
134
+ def Page():
135
+ with solara.Column(align="center"):
136
+ markdown = """
137
+ ## California Wildfire Analysis
138
+
139
+ ### Population Density and wildfire burn area
140
+
141
+ **For this analysis we will be using [WorldPop Global Project Population Data: Estimated Residential Population per 100x100m Grid Square dataset](https://developers.google.com/earth-engine/datasets/catalog/WorldPop_GP_100m_pop#bands), [MCD64A1.061 MODIS Burned Area Monthly Global 500m (https://developers.google.com/earth-engine/datasets/catalog/MODIS_061_MCD64A1) dataset] with geemap. First, we will compute the zonal statistics to identify the countries with the largest forest area, and then plot them. Here the base tree cover imagery is taken from 2000**
142
+ #### Population and Wildfire Color Coding
143
+ - **No population**: `#000000` ![#000000](https://via.placeholder.com/15/000000/000000?text=+)
144
+ - **Low population**: `#6baed6` ![#6baed6](https://via.placeholder.com/15/6baed6/000000?text=+)
145
+ - **High population**: `#2171b5` ![#2171b5](https://via.placeholder.com/15/2171b5/000000?text=+)
146
+ - **Area with population affected by wildfires**: `#ffffff` ![#ffffff](https://via.placeholder.com/15/ffffff/000000?text=+)
147
+ - **Burn areas**: `#ff0000` ![#ff0000](https://via.placeholder.com/15/ff0000/000000?text=+)
148
+
149
+ """
150
+ solara.Markdown(markdown)
151
+
152
+ with solara.Column(style={"min-width": "500px"}):
153
+ Map.element(
154
+ center=[40, -100],
155
+ zoom=4,
156
+ height="600px",
157
+ )
158
+
159
+
160
+