Spaces:
Sleeping
Sleeping
Update demo2/pages/__init__.py
Browse files- demo2/pages/__init__.py +701 -701
demo2/pages/__init__.py
CHANGED
@@ -1,702 +1,702 @@
|
|
1 |
-
#%%
|
2 |
-
css = """
|
3 |
-
|
4 |
-
@font-face {
|
5 |
-
font-family: 'Open Sans';
|
6 |
-
font-style: normal;
|
7 |
-
font-weight: 400;
|
8 |
-
font-stretch: 100%;
|
9 |
-
font-display: swap;
|
10 |
-
src: url('/static/public/open-sans.regular.ttf') format('truetype');
|
11 |
-
}
|
12 |
-
|
13 |
-
@font-face {
|
14 |
-
font-family: 'Museo 900';
|
15 |
-
src: url('/static/public/Museo900-Regular.woff2') format('woff2'),
|
16 |
-
url('/static/public/Museo900-Regular.woff') format('woff');
|
17 |
-
font-weight: 900;
|
18 |
-
font-style: normal;
|
19 |
-
font-display: swap;
|
20 |
-
}
|
21 |
-
|
22 |
-
|
23 |
-
@font-face {
|
24 |
-
font-family: 'Museo 700';
|
25 |
-
src: url('/static/public/Museo700-Regular.woff2') format('woff2')
|
26 |
-
}
|
27 |
-
|
28 |
-
|
29 |
-
.v-application {
|
30 |
-
font-family: 'Open Sans'
|
31 |
-
}
|
32 |
-
|
33 |
-
.v-card__title {
|
34 |
-
padding: 2px;
|
35 |
-
font-family: 'Museo 900'
|
36 |
-
}
|
37 |
-
|
38 |
-
.v-application .ma-2 {
|
39 |
-
margin: 2px!important;
|
40 |
-
}
|
41 |
-
|
42 |
-
.leaflet-control-attribution {
|
43 |
-
display: none;
|
44 |
-
}
|
45 |
-
.v-btn__content {
|
46 |
-
font-size: 12px;
|
47 |
-
}
|
48 |
-
|
49 |
-
.v-input__control {
|
50 |
-
height: 24px
|
51 |
-
}
|
52 |
-
|
53 |
-
.jupyter-widgets.leaflet-widgets {
|
54 |
-
height: 280px;
|
55 |
-
overflow: hidden;
|
56 |
-
}
|
57 |
-
|
58 |
-
.col {
|
59 |
-
overflow: hidden;
|
60 |
-
}
|
61 |
-
|
62 |
-
.v-card__title {
|
63 |
-
font-size: 20px;
|
64 |
-
text-color: "orange";
|
65 |
-
}
|
66 |
-
|
67 |
-
label.v-label.theme--dark {
|
68 |
-
font-size: 14px;
|
69 |
-
line-height: 100%;
|
70 |
-
}
|
71 |
-
|
72 |
-
.metricdesc {
|
73 |
-
font-size: 15px;
|
74 |
-
margin-top: -30px;
|
75 |
-
text-align: center;
|
76 |
-
}
|
77 |
-
.infobox {
|
78 |
-
font-size: 14px;
|
79 |
-
line-height: 110%;
|
80 |
-
}
|
81 |
-
|
82 |
-
.infoitem {
|
83 |
-
font-size: 12px;
|
84 |
-
line-height: 110%;
|
85 |
-
}
|
86 |
-
|
87 |
-
.maintitle {
|
88 |
-
font-family: 'Museo 900';
|
89 |
-
font-size: 30px;
|
90 |
-
text-align: center;
|
91 |
-
}
|
92 |
-
|
93 |
-
"""
|
94 |
-
|
95 |
-
import solara
|
96 |
-
import pandas as pd
|
97 |
-
import geopandas as gpd
|
98 |
-
import ipyleaflet
|
99 |
-
from random import uniform
|
100 |
-
import random
|
101 |
-
import numpy as np
|
102 |
-
import json
|
103 |
-
import matplotlib.pyplot as plt
|
104 |
-
from .engine import run_engine
|
105 |
-
|
106 |
-
languages = ["EN","TR"]
|
107 |
-
lang = solara.reactive("EN")
|
108 |
-
|
109 |
-
lbl_land_use_btn = [{'EN': 'civil societies',
|
110 |
-
'TR': 'sivil toplum'},
|
111 |
-
{'EN': 'women',
|
112 |
-
'TR': 'kadınlar'},
|
113 |
-
{'EN': 'youth',
|
114 |
-
'TR': 'gençler'},]
|
115 |
-
lbl_maintitle = {'EN': 'Tomorrow\'s Cities Decision Making Simulation','TR': 'Yarının Şehirleri için Karar Verme Simülasyonu'}
|
116 |
-
lbl_earthquake= {'EN': 'Earthquake', 'TR': 'Deprem'}
|
117 |
-
lbl_flood = {'EN': 'Flood', 'TR': 'Sel'}
|
118 |
-
lbl_debris = {'EN': 'Landslide', 'TR': 'Heyelan'}
|
119 |
-
lbl_reset = {'EN': 'Reset Simulation', 'TR': 'Simülasyonu Sıfırla'}
|
120 |
-
lbl_language = {'EN': 'Language', 'TR': 'Dil'}
|
121 |
-
lbl_luf_res_high = {'EN': 'Residential (High Density)', 'TR': 'Yerlesim Alani (Yuksek Yogunluk)'}
|
122 |
-
lbl_tv0_map_title = {'EN': '1. Today\'s land use', 'TR': '1. Mevcut plan'}
|
123 |
-
lbl_density_map_title = {'EN': '2. Select the potential hazard', 'TR': '2. Olası tehlikeyi seçin'}
|
124 |
-
lbl_policy_card_title = {'EN': '4. Select three policies to make your city resillient', 'TR': '4. Şehrinizi dayanıklı hale getirmek için üç politika seçin'}
|
125 |
-
lbl_too_many_policy_selected_error = {'EN': 'You cannot select more than three policies',
|
126 |
-
'TR': 'Üçten fazla politika seçemezsiniz'}
|
127 |
-
lbl_infobox = {'EN': f'''
|
128 |
-
Our decisions directly influence our future. It is critical for a
|
129 |
-
resilient city life where the decisions at the city scale reduces the disaster risk in the future.
|
130 |
-
In this simulation, we calculate possible disaster impacts calculated with Tomorrow's Cities Decision
|
131 |
-
Support System (TCDSE). The simulation shows how earthquake and flood hazards that may occur
|
132 |
-
in an urban environment affect different urban scenarios. To use the simulation 1) Check land use 2) Select the
|
133 |
-
possible hazard 3) Select the possible city scenarios for the future 4) choose policies 5) Run and check the metrics.
|
134 |
-
''',
|
135 |
-
"TR": f'''
|
136 |
-
Aldığımız kararlar, geleceğimizi doğrudan etkilemektedir. Kent ölçeğinde alınan kararların, gelecekte afet riskini azaltacak
|
137 |
-
nitelikte olması dayanıklı bir şehir hayatı için önemlidir.
|
138 |
-
Bu simülasyonda, Yarının Şehirleri Karar Destek Sistemi (TCDSE) ile hesaplanan olası afet etkilerini hesaplıyoruz. Simülasyon,
|
139 |
-
bir kent ortamında meydana gelebilecek deprem ve sel tehlikelerinin, farklı kent senaryolarını nasıl etkilediğini gösteriyor.
|
140 |
-
Simülasyonu kullanmak için 1) Mevcut planı inceleyin 2) Olası tehlikeyi seçin 3) Geleceğe dair olası şehir senaryolarını seçin
|
141 |
-
4) Politikaları seçin 5) Çalıştırın ve metrikleri inceleyin.'''}
|
142 |
-
lbl_infobox_title = {'EN': '', 'TR': ''}
|
143 |
-
lbl_landuse_plans_title = {'EN': '3. Future land uses', 'TR': '3. Geleceğin alternatif yerleşim planlarından birini seçin'}
|
144 |
-
lbl_run_btn = {'EN': 'RUN', 'TR': 'ÇALIŞTIR'}
|
145 |
-
lbl_results_card_title = {'EN': '5. Impact metrics', 'TR': '5. Etki metrikleri'}
|
146 |
-
lbl_info1 = {'EN': 'Number of individuals<br>39058', 'TR': 'Kişi Sayısı<br>39058'}
|
147 |
-
lbl_info2 = {'EN': 'Number of households<br>10397', 'TR': 'Hane Sayısı<br>10397'}
|
148 |
-
lbl_info3 = {'EN': 'Number of buildings<br>4810', 'TR': 'Bina Sayısı<br>4810'}
|
149 |
-
lbl_info4 = {'EN': 'Number of schools<br>4', 'TR': 'Okul Sayısı<br>4'}
|
150 |
-
lbl_info5 = {'EN': 'Number of hospitals<br>1', 'TR': 'Hastane Sayısı<br>1'}
|
151 |
-
#lbl_info6 = {'EN': 'Number of green field<br>', 'TR': 'Yeşil Alan Sayısı<br>'}
|
152 |
-
|
153 |
-
hazard_types = ["earthquake", "flood", "debris"]
|
154 |
-
hazard_type_default = hazard_types[0]
|
155 |
-
hazard_type = solara.reactive("earthquake")
|
156 |
-
|
157 |
-
flood_df = gpd.read_file('hazard_flood.geojson')
|
158 |
-
debris_df = gpd.read_file('hazard_debris.geojson')
|
159 |
-
earthquake_df = gpd.read_file('hazard_earthquake.geojson')
|
160 |
-
|
161 |
-
earthquake_df_as_geo = gpd.read_file('hazard_earthquake.geojson')
|
162 |
-
print('bir',earthquake_df_as_geo.crs)
|
163 |
-
earthquake_df_as_geo = earthquake_df_as_geo.set_crs("EPSG:4326",allow_override=True)
|
164 |
-
print('iki',earthquake_df_as_geo.crs)
|
165 |
-
earthquake_df_as_geo = earthquake_df_as_geo.to_crs(32645)
|
166 |
-
print('uc',earthquake_df_as_geo.crs)
|
167 |
-
|
168 |
-
debris_df_as_geo = gpd.read_file('hazard_debris.geojson')
|
169 |
-
debris_df_as_geo = debris_df_as_geo.set_crs("EPSG:4326",allow_override=True)
|
170 |
-
debris_df_as_geo = debris_df_as_geo.to_crs("EPSG:32645")
|
171 |
-
|
172 |
-
flood_df_as_geo = gpd.read_file('hazard_flood.geojson')
|
173 |
-
flood_df_as_geo = flood_df_as_geo.set_crs("EPSG:4326",allow_override=True)
|
174 |
-
flood_df_as_geo = flood_df_as_geo.to_crs("EPSG:32645")
|
175 |
-
|
176 |
-
landuse_tv0_df = gpd.read_file('landuse_tv0.geojson')
|
177 |
-
landuse_tv50_1_df = gpd.read_file('landuse_tv50_1.geojson')
|
178 |
-
landuse_tv50_2_df = gpd.read_file('landuse_tv50_2.geojson')
|
179 |
-
landuse_tv50_3_df = gpd.read_file('landuse_tv50_3.geojson')
|
180 |
-
n_landuses = 3
|
181 |
-
|
182 |
-
luf_types = pd.unique(landuse_tv0_df['luf'])
|
183 |
-
|
184 |
-
luf_colors = dict()
|
185 |
-
for luf_label in luf_types:
|
186 |
-
if luf_label == 'Agricultural Areas':
|
187 |
-
luf_colors[luf_label] = {
|
188 |
-
'color': 'black',
|
189 |
-
'fillColor': '#ffe665',
|
190 |
-
}
|
191 |
-
elif luf_label == 'Urban Green':
|
192 |
-
luf_colors[luf_label] = {
|
193 |
-
'color': 'black',
|
194 |
-
'fillColor': '#abdda4',
|
195 |
-
}
|
196 |
-
elif luf_label == 'Public Service Areas':
|
197 |
-
luf_colors[luf_label] = {
|
198 |
-
'color': 'black',
|
199 |
-
'fillColor': '#2b83ba',
|
200 |
-
}
|
201 |
-
elif luf_label == 'Commercial Areas':
|
202 |
-
luf_colors[luf_label] = {
|
203 |
-
'color': 'black',
|
204 |
-
'fillColor': '#d42c45',
|
205 |
-
}
|
206 |
-
elif luf_label == 'Industrial Areas':
|
207 |
-
luf_colors[luf_label] = {
|
208 |
-
'color': 'black',
|
209 |
-
'fillColor': '#936ede',
|
210 |
-
}
|
211 |
-
elif luf_label == 'Residential Areas with Low Density':
|
212 |
-
luf_colors[luf_label] = {
|
213 |
-
'color': 'black',
|
214 |
-
'fillColor': '#be8750',
|
215 |
-
}
|
216 |
-
elif luf_label == 'Residential Areas with Moderate Density':
|
217 |
-
luf_colors[luf_label] = {
|
218 |
-
'color': 'black',
|
219 |
-
'fillColor': '#a97d51',
|
220 |
-
}
|
221 |
-
elif luf_label == 'Residential Areas with High Density':
|
222 |
-
luf_colors[luf_label] = {
|
223 |
-
'color': 'black',
|
224 |
-
'fillColor': '#8c541a',
|
225 |
-
}
|
226 |
-
else:
|
227 |
-
luf_colors[luf_label] = {
|
228 |
-
'color': 'black',
|
229 |
-
'fillColor': random.choice(['red', 'yellow', 'green', 'orange','blue']),
|
230 |
-
}
|
231 |
-
|
232 |
-
#
|
233 |
-
plt.switch_backend("agg")
|
234 |
-
plt.rcParams['axes.facecolor'] = '#1e1e1e'
|
235 |
-
plt.rcParams['axes.edgecolor'] = '#1e1e1e'
|
236 |
-
#plt.switch_backend('macosx')
|
237 |
-
#%matplotlib inline
|
238 |
-
# for j in range(1, n_landuses+1):
|
239 |
-
# df = eval(f'landuse_tv50_{j}_df')
|
240 |
-
# title = f'tv50_{j}'
|
241 |
-
# for i, row in df.iterrows():
|
242 |
-
# df.loc[i, 'color'] = luf_colors[row['luf']]['fillColor']
|
243 |
-
# fig, ax = plt.subplots(nrows=1, ncols=1,figsize=(4*1.3, 5*1.3))
|
244 |
-
# fig.set_tight_layout(True)
|
245 |
-
# fig.patch.set_facecolor('white')
|
246 |
-
# #fig.patch.set_alpha(0.7)
|
247 |
-
# df.plot(color=df['color'],ax=ax)
|
248 |
-
# #ax.set_title(f'{title}')
|
249 |
-
# ax.set_xticks([])
|
250 |
-
# ax.set_yticks([])
|
251 |
-
# plt.savefig(f'landuse_{title}_selected.png')
|
252 |
-
|
253 |
-
# fig, ax = plt.subplots(nrows=1, ncols=1,figsize=(4*1.3,5*1.3))
|
254 |
-
# fig.set_tight_layout(True)
|
255 |
-
# #fig.patch.set_facecolor('black')
|
256 |
-
# fig.patch.set_alpha(0.0)
|
257 |
-
# df.plot(color=df['color'],ax=ax)
|
258 |
-
# #ax.set_title(f'{title}')
|
259 |
-
# ax.set_xticks([])
|
260 |
-
# ax.set_yticks([])
|
261 |
-
# plt.savefig(f'landuse_{title}.png')
|
262 |
-
|
263 |
-
landuse_tv0_json = json.loads(landuse_tv0_df.to_json())
|
264 |
-
luf_filtered_data = solara.reactive(landuse_tv0_json)
|
265 |
-
|
266 |
-
luf_selected = solara.reactive(luf_types)
|
267 |
-
luf_type_selected = dict()
|
268 |
-
for luf_type in luf_types:
|
269 |
-
luf_type_selected[luf_type] = solara.reactive(True)
|
270 |
-
|
271 |
-
lbl_luf = dict()
|
272 |
-
for luf_label in luf_types:
|
273 |
-
if luf_label == 'Agricultural Areas':
|
274 |
-
lbl_luf[luf_label] = {'EN': 'Agricultural Areas', 'TR': 'Tarım Alanları'}
|
275 |
-
elif luf_label == 'Urban Green':
|
276 |
-
lbl_luf[luf_label] = {'EN': 'Urban Green & Recreation Areas', 'TR': 'Kentsel Yeşil/Rekreasyon Alanları'}
|
277 |
-
elif luf_label == 'Public Service Areas':
|
278 |
-
lbl_luf[luf_label] = {'EN': 'Public Service Areas', 'TR': 'Kamu Hizmet Alanları'}
|
279 |
-
elif luf_label == 'Commercial Areas':
|
280 |
-
lbl_luf[luf_label] = {'EN': 'Commercial & Mixed Use Areas', 'TR': 'Ticari/Karışık Kullanım Alanları'}
|
281 |
-
elif luf_label == 'Industrial Areas':
|
282 |
-
lbl_luf[luf_label] = {'EN': 'Industrial Areas', 'TR': 'Sanayi Alanları'}
|
283 |
-
elif luf_label == 'Residential Areas with Low Density':
|
284 |
-
lbl_luf[luf_label] = {'EN': 'Residential Areas with Low Density', 'TR': 'Düşük Yoğunluklu Konut Alanı'}
|
285 |
-
elif luf_label == 'Residential Areas with Moderate Density':
|
286 |
-
lbl_luf[luf_label] = {'EN': 'Residential Areas with Moderate Density', 'TR': 'Orta Yoğunluklu Konut Alanı'}
|
287 |
-
elif luf_label == 'Residential Areas with High Density':
|
288 |
-
lbl_luf[luf_label] = {'EN': 'Residential Areas with High Density', 'TR': 'Yüksek Yoğunluklu Konut Alanı'}
|
289 |
-
else:
|
290 |
-
lbl_luf[luf_label] = {'EN': luf_label, 'TR': '(TR)'+luf_label}
|
291 |
-
|
292 |
-
policies = [1,2,3,4,5,6]
|
293 |
-
lbl_policy = dict()
|
294 |
-
lbl_policy[1] = {'EN': 'Loans for reconstruction for minor to moderate damages',
|
295 |
-
'TR': 'Küçük ila orta dereceli hasarlar için yeniden yapılanma kredileri'}
|
296 |
-
lbl_policy[2] = {'EN': 'Knowledge sharing about disaster risk reduction in schools',
|
297 |
-
'TR': 'Devlet ve özel okullarda afet risklerinin azaltılması hakkında bilgi paylaşımı'}
|
298 |
-
lbl_policy[3] = {'EN': 'Catastrophe bond for education/health facilities',
|
299 |
-
'TR': 'Eğitim ve sağlık tesislerini yapılandırmak için afet bonosu'}
|
300 |
-
lbl_policy[4] = {'EN': 'Repair loan assistance for flooding',
|
301 |
-
'TR': 'Sel için onarım kredisi yardımı'}
|
302 |
-
lbl_policy[5] = {'EN': 'Technical assistance for debris removal in education facilities',
|
303 |
-
'TR': 'Eğitim tesislerinde enkaz kaldırma için teknik yardım'}
|
304 |
-
lbl_policy[6] = {'EN': 'Compulsory content insurance for schools and hospitals',
|
305 |
-
'TR': 'Okullar ve hastaneler için zorunlu eşya sigortası'}
|
306 |
-
#lbl_policy[7] = {'EN': 'Green resilient infrastructure (prevention) & financial support for business recovery', 'TR': 'Politika 7'}
|
307 |
-
#lbl_policy[8] = {'EN': 'Green resilient infrastructure (prevention), reinforcement of schools, hospitals & shelters, financial support for affected business & household', 'TR': 'Politika 8'}
|
308 |
-
policy_selected = dict()
|
309 |
-
for policy in policies:
|
310 |
-
policy_selected[policy] = solara.reactive(False)
|
311 |
-
last_selected_policies = solara.reactive(set())
|
312 |
-
|
313 |
-
earthquake_locs = np.array([earthquake_df.geometry.y.to_list(), earthquake_df.geometry.x.to_list(), earthquake_df.im.to_list()]).transpose().tolist()
|
314 |
-
flood_locs = np.array([flood_df.geometry.y.to_list(), flood_df.geometry.x.to_list(), flood_df.im.to_list()]).transpose().tolist()
|
315 |
-
debris_locs = np.array([debris_df.geometry.y.to_list(), debris_df.geometry.x.to_list(), debris_df.im.to_list()]).transpose().tolist()
|
316 |
-
|
317 |
-
hazard_intensities = {
|
318 |
-
"earthquake": earthquake_locs,
|
319 |
-
"flood": flood_locs,
|
320 |
-
"debris": debris_locs
|
321 |
-
}
|
322 |
-
|
323 |
-
hazard_df = {
|
324 |
-
"earthquake": earthquake_df,
|
325 |
-
"flood": flood_df,
|
326 |
-
"debris": debris_df
|
327 |
-
}
|
328 |
-
|
329 |
-
hazard_df_as_geo = {
|
330 |
-
"earthquake": earthquake_df_as_geo,
|
331 |
-
"flood": flood_df_as_geo,
|
332 |
-
"debris": debris_df_as_geo
|
333 |
-
}
|
334 |
-
|
335 |
-
zoom_default = 12
|
336 |
-
tv0_zoom = solara.reactive(zoom_default)
|
337 |
-
|
338 |
-
tv0_center_default = (32.215, 35.21)
|
339 |
-
tv0_center = solara.reactive(tv0_center_default)
|
340 |
-
print(tv0_center)
|
341 |
-
def random_color(feature):
|
342 |
-
return luf_colors[feature['properties']['luf']]
|
343 |
-
|
344 |
-
@solara.component
|
345 |
-
def TV0MAP():
|
346 |
-
selected_lufs = set()
|
347 |
-
for luf_type in luf_types:
|
348 |
-
if luf_type_selected[luf_type].value:
|
349 |
-
selected_lufs.add(luf_type)
|
350 |
-
x = {'type':landuse_tv0_json['type'] }
|
351 |
-
x['features'] = []
|
352 |
-
for f in landuse_tv0_json['features']:
|
353 |
-
if f['properties']['luf'] in selected_lufs:
|
354 |
-
x['features'].append(f)
|
355 |
-
ipyleaflet.Map.element(
|
356 |
-
zoom=tv0_zoom.value,
|
357 |
-
on_zoom=tv0_zoom.set,
|
358 |
-
max_zoom=21,
|
359 |
-
min_zoom=1,
|
360 |
-
center=tv0_center.value,
|
361 |
-
on_center=tv0_center.set,
|
362 |
-
scroll_wheel_zoom=True,
|
363 |
-
dragging=True,
|
364 |
-
double_click_zoom=False,
|
365 |
-
touch_zoom=False,
|
366 |
-
box_zoom=False,
|
367 |
-
keyboard=True,
|
368 |
-
zoom_control=False,
|
369 |
-
layers=[
|
370 |
-
ipyleaflet.basemap_to_tiles(ipyleaflet.basemaps.OpenStreetMap.Mapnik), #ipyleaflet.basemaps.Esri.WorldImagery
|
371 |
-
ipyleaflet.GeoJSON(
|
372 |
-
data=x,
|
373 |
-
style={
|
374 |
-
'opacity': 1, 'dashArray': '9', 'fillOpacity':
|
375 |
-
},
|
376 |
-
hover_style={
|
377 |
-
'color': 'white', 'dashArray': '0', 'fillOpacity': 0.
|
378 |
-
},
|
379 |
-
style_callback=random_color)
|
380 |
-
],
|
381 |
-
)
|
382 |
-
|
383 |
-
@solara.component
|
384 |
-
def DensityMap(hazard_type):
|
385 |
-
locs = hazard_intensities[hazard_type]
|
386 |
-
ipyleaflet.Map.element(
|
387 |
-
zoom=tv0_zoom.value,
|
388 |
-
max_zoom=zoom_default,
|
389 |
-
min_zoom=zoom_default,
|
390 |
-
on_zoom=tv0_zoom.set,
|
391 |
-
center=tv0_center.value,
|
392 |
-
on_center=tv0_center.set,
|
393 |
-
scroll_wheel_zoom=False,
|
394 |
-
dragging=False,
|
395 |
-
double_click_zoom=False,
|
396 |
-
touch_zoom=False,
|
397 |
-
box_zoom=False,
|
398 |
-
keyboard=False,
|
399 |
-
zoom_control=False,
|
400 |
-
layers=[
|
401 |
-
ipyleaflet.basemap_to_tiles(ipyleaflet.basemaps.Esri.WorldTopoMap),
|
402 |
-
ipyleaflet.Heatmap(
|
403 |
-
name=hazard_type,
|
404 |
-
locations=locs,
|
405 |
-
radius=10
|
406 |
-
),
|
407 |
-
],
|
408 |
-
)
|
409 |
-
|
410 |
-
run_is_allowed = solara.reactive(True)
|
411 |
-
|
412 |
-
@solara.component
|
413 |
-
def PolicyValidation():
|
414 |
-
npolicies_selected = 0
|
415 |
-
selected_policies = set()
|
416 |
-
for p in policies:
|
417 |
-
if policy_selected[p].value:
|
418 |
-
selected_policies.add(p)
|
419 |
-
npolicies_selected += 1
|
420 |
-
if npolicies_selected > 3:
|
421 |
-
print("roll-back")
|
422 |
-
solara.Warning(label=lbl_too_many_policy_selected_error[lang.value])
|
423 |
-
run_is_allowed.value = False
|
424 |
-
# Roll-back to last selection
|
425 |
-
#for p in policies:
|
426 |
-
# if p in last_selected_policies.value:
|
427 |
-
# policy_selected[p].value = True
|
428 |
-
# else:
|
429 |
-
# policy_selected[p].value = False
|
430 |
-
else:
|
431 |
-
last_selected_policies.value = selected_policies
|
432 |
-
run_is_allowed.value = True
|
433 |
-
|
434 |
-
landuseplan_selected = solara.reactive(1)
|
435 |
-
|
436 |
-
lbl_metric1 = {"EN": "Number of workers unemployed", "TR": "İşini kaybedenlerin sayısı"}
|
437 |
-
lbl_metric2 = {"EN": "Number of children with no access to education", "TR": "Okula gidemeyen çocuk sayısı"}
|
438 |
-
lbl_metric3 = {"EN": "Number of households with no access to hospital", "TR": "Hastane erişimi olmayan hane sayısı"}
|
439 |
-
lbl_metric4 = {"EN": "Number of individuals with no access to hospital", "TR": "Hastane erişimi olmayan kişi sayısı"}
|
440 |
-
lbl_metric5 = {"EN": "Number of homeless households", "TR": "İşlevsiz kalan hane sayısı"}
|
441 |
-
lbl_metric6 = {"EN": "Number of homeless individuals", "TR": "Evsiz kalan sayısı"}
|
442 |
-
lbl_metric7 = {"EN": "Population displacement", "TR": "Yer değiştirmek zorunda kalan kişi sayısı"}
|
443 |
-
|
444 |
-
metrics = {"metric1": {"desc": lbl_metric1, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
445 |
-
"metric2": {"desc": lbl_metric2, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
446 |
-
"metric3": {"desc": lbl_metric3, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
447 |
-
"metric4": {"desc": lbl_metric4, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
448 |
-
"metric5": {"desc": lbl_metric5, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
449 |
-
"metric6": {"desc": lbl_metric6, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
450 |
-
"metric7": {"desc": lbl_metric7, "value": solara.reactive(0), "max_value": solara.reactive(0)}}
|
451 |
-
|
452 |
-
@solara.component
|
453 |
-
def MetricWidget(name, description, value, max_value=10000):
|
454 |
-
value, set_value = solara.use_state_or_update(value)
|
455 |
-
max_value, set_max_value = solara.use_state_or_update(max_value)
|
456 |
-
options = {
|
457 |
-
"series": [ {
|
458 |
-
"type": 'gauge',
|
459 |
-
"min": 0,
|
460 |
-
"name": description,
|
461 |
-
"max": max(1,max_value), # workaround when max_value = 0
|
462 |
-
"startAngle": 180,
|
463 |
-
"endAngle": 0,
|
464 |
-
"progress": {"show": True, "width": 10, "itemStyle": {"color": 'red'}},
|
465 |
-
"pointer": { "show": False},
|
466 |
-
"axisLine": {"lineStyle": {"width": 10}},
|
467 |
-
"axisTick": {"show": False},
|
468 |
-
"splitLine": {"show": False},
|
469 |
-
"axisLabel": {"show": False},
|
470 |
-
"anchor": {"show": False},
|
471 |
-
"title": {"show": False},
|
472 |
-
"detail": {
|
473 |
-
"valueAnimation": True,
|
474 |
-
"offsetCenter": [0, '25%'],
|
475 |
-
"fontSize": 16,
|
476 |
-
"color": 'white'},
|
477 |
-
#"title": {"fontSize": 12},
|
478 |
-
"data": [{"value": value, "name": name}]}]}
|
479 |
-
print(f'value/max_value {value}:{max_value}')
|
480 |
-
|
481 |
-
solara.FigureEcharts(option=options, attributes={ "style": "height: 100px; width: 100px" })
|
482 |
-
|
483 |
-
@solara.component
|
484 |
-
def MetricsPanel(metrics):
|
485 |
-
'''
|
486 |
-
with solara.Columns([33,33,33]):
|
487 |
-
with solara.Column(align="center", gap="2px"):
|
488 |
-
for key in ["metric1","metric2"]:
|
489 |
-
MetricWidget(key, metrics[key]["desc"], metrics[key]["value"].value,
|
490 |
-
max_value=metrics[key]["max_value"].value)
|
491 |
-
solara.HTML(unsafe_innerHTML=metrics[key]["desc"][lang.value], classes=["metricdesc"])
|
492 |
-
with solara.Column(align="center", gap="2px"):
|
493 |
-
for key in ["metric3","metric4"]:
|
494 |
-
MetricWidget(key, metrics[key]["desc"], metrics[key]["value"].value,
|
495 |
-
max_value=metrics[key]["max_value"].value)
|
496 |
-
solara.HTML(unsafe_innerHTML=metrics[key]["desc"][lang.value], classes=["metricdesc"])
|
497 |
-
with solara.Column(align="center", gap="2px"):
|
498 |
-
for key in ["metric6","metric7"]:
|
499 |
-
MetricWidget(key, metrics[key]["desc"], metrics[key]["value"].value,
|
500 |
-
max_value=metrics[key]["max_value"].value)
|
501 |
-
solara.HTML(unsafe_innerHTML=metrics[key]["desc"][lang.value], classes=["metricdesc"])
|
502 |
-
'''
|
503 |
-
with solara.GridFixed(columns=3):
|
504 |
-
for key in ["metric2","metric4","metric7"]:
|
505 |
-
with solara.Row(justify="center"):
|
506 |
-
MetricWidget(key, metrics[key]["desc"], metrics[key]["value"].value,
|
507 |
-
max_value=metrics[key]["max_value"].value)
|
508 |
-
for key in ["metric2","metric4","metric7"]:
|
509 |
-
with solara.Row(justify="center"):
|
510 |
-
solara.HTML(unsafe_innerHTML=metrics[key]["desc"][lang.value], classes=["metricdesc"])
|
511 |
-
# for key in ["metric4","metric6","metric7"]:
|
512 |
-
# with solara.Row(justify="center"):
|
513 |
-
# MetricWidget(key,metrics[key]["desc"], metrics[key]["value"].value,
|
514 |
-
# max_value=metrics[key]["max_value"].value)
|
515 |
-
# for key in ["metric4","metric6","metric7"]:
|
516 |
-
# with solara.Row(justify="center"):
|
517 |
-
# solara.HTML(unsafe_innerHTML=metrics[key]["desc"][lang.value], classes=["metricdesc"])
|
518 |
-
|
519 |
-
|
520 |
-
def run_simulation():
|
521 |
-
print("Running simulation")
|
522 |
-
print(f"Selected landuse plans: {landuseplan_selected.value}")
|
523 |
-
selected_policies = set()
|
524 |
-
for p in policies:
|
525 |
-
if policy_selected[p].value:
|
526 |
-
selected_policies.add(p)
|
527 |
-
print(f"Selected policies: {selected_policies}")
|
528 |
-
|
529 |
-
new_metrics = run_engine(hazard_type.value,
|
530 |
-
landuseplan_selected.value,
|
531 |
-
hazard_df_as_geo[hazard_type.value],
|
532 |
-
list(selected_policies))
|
533 |
-
for key in new_metrics.keys():
|
534 |
-
metrics[key]["value"].value = new_metrics[key]["value"]
|
535 |
-
metrics[key]["max_value"].value = new_metrics[key]["max_value"]
|
536 |
-
|
537 |
-
print(metrics)
|
538 |
-
|
539 |
-
@solara.component
|
540 |
-
def LandUsePlans():
|
541 |
-
for p in policies:
|
542 |
-
if policy_selected[p].value:
|
543 |
-
print(p, 'selected')
|
544 |
-
|
545 |
-
for p in policies:
|
546 |
-
if policy_selected[p].value:
|
547 |
-
print(p, 'selected')
|
548 |
-
|
549 |
-
#with solara.Column(gap="2px"):
|
550 |
-
# with solara.Columns([2,32,32,32,2]):
|
551 |
-
# solara.HTML(unsafe_innerHTML="")
|
552 |
-
# for i in range(1, n_landuses+1):
|
553 |
-
# if landuseplan_selected.value == i:
|
554 |
-
# solara.Image(f"landuse_tv50_{i}_selected.png", width="230px")
|
555 |
-
# else:
|
556 |
-
# solara.Image(f"landuse_tv50_{i}.png",width="230px")
|
557 |
-
# solara.HTML(unsafe_innerHTML="")
|
558 |
-
# with solara.Row():
|
559 |
-
# with solara.ToggleButtonsSingle(value=landuseplan_selected):
|
560 |
-
# for i in range(0, n_landuses):
|
561 |
-
# solara.Button(lbl_land_use_btn[i][lang.value], value=i+1, text=True, style="width: 320px; height: 26px")
|
562 |
-
|
563 |
-
|
564 |
-
def landuse_1():
|
565 |
-
landuseplan_selected.value = 1
|
566 |
-
|
567 |
-
def landuse_2():
|
568 |
-
landuseplan_selected.value = 2
|
569 |
-
|
570 |
-
def landuse_3():
|
571 |
-
landuseplan_selected.value = 3
|
572 |
-
|
573 |
-
funcs = {1: landuse_1, 2: landuse_2, 3: landuse_3}
|
574 |
-
|
575 |
-
butons = []
|
576 |
-
with solara.Columns([32,32,32]):
|
577 |
-
for i in range(0, n_landuses):
|
578 |
-
with solara.Column():
|
579 |
-
if landuseplan_selected.value == i + 1:
|
580 |
-
solara.Button(lbl_land_use_btn[i][lang.value], value=i+1,
|
581 |
-
text=True, on_click=funcs[i+1], style="background-color: #545454; height: 26px")
|
582 |
-
with solara.Row(justify="center"):
|
583 |
-
solara.Image(f"landuse_tv50_{i+1}_selected.png", width="100%")
|
584 |
-
|
585 |
-
else:
|
586 |
-
solara.Button(lbl_land_use_btn[i][lang.value], value=i+1,
|
587 |
-
text=True, on_click=funcs[i+1], style="height: 26px")
|
588 |
-
with solara.Row(justify="center"):
|
589 |
-
solara.Image(f"landuse_tv50_{i+1}.png", width="100%")
|
590 |
-
|
591 |
-
@solara.component
|
592 |
-
def Page():
|
593 |
-
def reset_view():
|
594 |
-
tv0_zoom.value = zoom_default
|
595 |
-
tv0_center.value = tv0_center_default
|
596 |
-
hazard_type.value = hazard_type_default
|
597 |
-
for luf_type in luf_types:
|
598 |
-
luf_type_selected[luf_type].value = True
|
599 |
-
landuseplan_selected.value = 1
|
600 |
-
|
601 |
-
solara.Style(css)
|
602 |
-
with solara.Columns([1,98,1]):
|
603 |
-
solara.HTML(unsafe_innerHTML="")
|
604 |
-
with solara.Column():
|
605 |
-
with solara.Columns(([15,15,45,20,10]), style="display: flex; justify-content: center; align-items: center;"):
|
606 |
-
solara.HTML(unsafe_innerHTML="")
|
607 |
-
with solara.Column():
|
608 |
-
solara.Markdown("""[](https://tomorrowscities.org/)""")
|
609 |
-
#solara.Button(label=lbl_reset[lang.value], on_click=reset_view, style="height: 26px;")
|
610 |
-
solara.HTML(unsafe_innerHTML=lbl_maintitle[lang.value],classes=["maintitle"])
|
611 |
-
with solara.Column():
|
612 |
-
solara.Markdown("""[](https://urpartner.io/)""")
|
613 |
-
with solara.ToggleButtonsSingle(value=lang):
|
614 |
-
solara.Button(label="EN", value="EN", text=True,classes=["langbutton"],style="height: 26px;")
|
615 |
-
solara.Button(label="TR", value="TR", text=True,classes=["langbutton"],style="height: 26px;")
|
616 |
-
with solara.Columns([50,50]):
|
617 |
-
with solara.Column(gap="2px"):
|
618 |
-
with solara.Card(title=lbl_tv0_map_title[lang.value]):
|
619 |
-
with solara.Columns([50,25,25], classes=["mycol"]):
|
620 |
-
TV0MAP()
|
621 |
-
with solara.Column(gap="13px"):
|
622 |
-
for luf_type in luf_types:
|
623 |
-
with solara.Row():
|
624 |
-
#solara.Button(label="",
|
625 |
-
# color=luf_colors[luf_type]['fillColor'],
|
626 |
-
# classes=["lufbox"])
|
627 |
-
solara.HTML(unsafe_innerHTML=" ",
|
628 |
-
style=f"margin: 1px; background-color: {luf_colors[luf_type]['fillColor']};")
|
629 |
-
solara.HTML(unsafe_innerHTML=lbl_luf[luf_type][lang.value],
|
630 |
-
style="font-size: 12px; line-height: 100%; display: flex; justify-content: center; align-items: center;")
|
631 |
-
#solara.Checkbox(label=lbl_luf[luf_type][lang.value],value=luf_type_selected[luf_type],
|
632 |
-
# style="margin-top: 0px; line-height: 80%;")
|
633 |
-
with solara.Column(gap="20px"):
|
634 |
-
solara.HTML(unsafe_innerHTML=lbl_info1[lang.value], classes=["infoitem"])
|
635 |
-
solara.HTML(unsafe_innerHTML=lbl_info2[lang.value], classes=["infoitem"])
|
636 |
-
solara.HTML(unsafe_innerHTML=lbl_info3[lang.value], classes=["infoitem"])
|
637 |
-
solara.HTML(unsafe_innerHTML=lbl_info4[lang.value], classes=["infoitem"])
|
638 |
-
solara.HTML(unsafe_innerHTML=lbl_info5[lang.value], classes=["infoitem"])
|
639 |
-
with solara.Card(title=lbl_infobox_title[lang.value], style={"text-align": "justify"}):
|
640 |
-
solara.HTML(unsafe_innerHTML=lbl_infobox[lang.value], classes=["infobox"])
|
641 |
-
with solara.Card(title=lbl_density_map_title[lang.value]):
|
642 |
-
with solara.Columns([30,30,30]):
|
643 |
-
with solara.Column():
|
644 |
-
if hazard_type.value == "earthquake":
|
645 |
-
bgcolor = "background-color: #545454;"
|
646 |
-
else:
|
647 |
-
bgcolor = ""
|
648 |
-
with solara.Row(justify="center"):
|
649 |
-
solara.Button(lbl_earthquake[lang.value], value="earthquake", text=True, on_click=lambda: hazard_type.set("earthquake"), style=f"{bgcolor} width: 100%; height: 26px")
|
650 |
-
# DensityMap("earthquake")
|
651 |
-
with solara.Row(justify="center"):
|
652 |
-
solara.Image("/static/public/eq1.jpg")
|
653 |
-
with solara.Column():
|
654 |
-
if hazard_type.value == "flood":
|
655 |
-
bgcolor = "background-color: #545454;"
|
656 |
-
else:
|
657 |
-
bgcolor = ""
|
658 |
-
with solara.Row(justify="center"):
|
659 |
-
solara.Button(lbl_flood[lang.value], value="flood", text=True, on_click=lambda: hazard_type.set("flood"), style=f"{bgcolor} width: 100%; height: 26px")
|
660 |
-
# DensityMap("flood")
|
661 |
-
with solara.Row(justify="center"):
|
662 |
-
solara.Image("/static/public/fl1.jpg")
|
663 |
-
# with solara.Column():
|
664 |
-
# if hazard_type.value == "debris":
|
665 |
-
# bgcolor = "background-color: #545454;"
|
666 |
-
# else:
|
667 |
-
# bgcolor = ""
|
668 |
-
# with solara.Row(justify="center"):
|
669 |
-
# solara.Button(lbl_debris[lang.value], value="debris", text=True, on_click=lambda: hazard_type.set("debris"), style=f"{bgcolor} width: 200px; height: 26px")
|
670 |
-
# DensityMap("debris")
|
671 |
-
#with solara.Columns([30,30,30]):
|
672 |
-
# DensityMap("earthquake")
|
673 |
-
# DensityMap("flood")
|
674 |
-
# DensityMap("debris")
|
675 |
-
with solara.Column(gap="2px"):
|
676 |
-
with solara.Card(title=lbl_landuse_plans_title[lang.value]):
|
677 |
-
LandUsePlans()
|
678 |
-
with solara.Card(lbl_policy_card_title[lang.value]):
|
679 |
-
with solara.GridFixed(columns=1,row_gap="2px", column_gap="2px"):
|
680 |
-
for p in policies:
|
681 |
-
solara.Checkbox(label=lbl_policy[p][lang.value],value=policy_selected[p], style="font-size: 15px")
|
682 |
-
solara.Button(label=lbl_run_btn[lang.value],on_click=run_simulation, disabled=not run_is_allowed.value, style="height: 50px")
|
683 |
-
PolicyValidation()
|
684 |
-
with solara.Card(title=lbl_results_card_title[lang.value]):
|
685 |
-
MetricsPanel(metrics)
|
686 |
-
solara.HTML(unsafe_innerHTML="")
|
687 |
-
solara.Title("Tomorrow's Cities Demo")
|
688 |
-
|
689 |
-
|
690 |
-
@solara.component
|
691 |
-
def Layout(children):
|
692 |
-
# if you need the normal applayout
|
693 |
-
# layout = solara.AppLayout(children=children, style)
|
694 |
-
layout = solara.Div(children=children, style={"width": "100%", "min-height": "100vh"})
|
695 |
-
|
696 |
-
def log(*args):
|
697 |
-
print("stop doing that!")
|
698 |
-
|
699 |
-
#solara.v.use_event(layout, "contextmenu.prevent", log)
|
700 |
-
return layout
|
701 |
-
|
702 |
Page()
|
|
|
1 |
+
#%%
|
2 |
+
css = """
|
3 |
+
|
4 |
+
@font-face {
|
5 |
+
font-family: 'Open Sans';
|
6 |
+
font-style: normal;
|
7 |
+
font-weight: 400;
|
8 |
+
font-stretch: 100%;
|
9 |
+
font-display: swap;
|
10 |
+
src: url('/static/public/open-sans.regular.ttf') format('truetype');
|
11 |
+
}
|
12 |
+
|
13 |
+
@font-face {
|
14 |
+
font-family: 'Museo 900';
|
15 |
+
src: url('/static/public/Museo900-Regular.woff2') format('woff2'),
|
16 |
+
url('/static/public/Museo900-Regular.woff') format('woff');
|
17 |
+
font-weight: 900;
|
18 |
+
font-style: normal;
|
19 |
+
font-display: swap;
|
20 |
+
}
|
21 |
+
|
22 |
+
|
23 |
+
@font-face {
|
24 |
+
font-family: 'Museo 700';
|
25 |
+
src: url('/static/public/Museo700-Regular.woff2') format('woff2')
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
.v-application {
|
30 |
+
font-family: 'Open Sans'
|
31 |
+
}
|
32 |
+
|
33 |
+
.v-card__title {
|
34 |
+
padding: 2px;
|
35 |
+
font-family: 'Museo 900'
|
36 |
+
}
|
37 |
+
|
38 |
+
.v-application .ma-2 {
|
39 |
+
margin: 2px!important;
|
40 |
+
}
|
41 |
+
|
42 |
+
.leaflet-control-attribution {
|
43 |
+
display: none;
|
44 |
+
}
|
45 |
+
.v-btn__content {
|
46 |
+
font-size: 12px;
|
47 |
+
}
|
48 |
+
|
49 |
+
.v-input__control {
|
50 |
+
height: 24px
|
51 |
+
}
|
52 |
+
|
53 |
+
.jupyter-widgets.leaflet-widgets {
|
54 |
+
height: 280px;
|
55 |
+
overflow: hidden;
|
56 |
+
}
|
57 |
+
|
58 |
+
.col {
|
59 |
+
overflow: hidden;
|
60 |
+
}
|
61 |
+
|
62 |
+
.v-card__title {
|
63 |
+
font-size: 20px;
|
64 |
+
text-color: "orange";
|
65 |
+
}
|
66 |
+
|
67 |
+
label.v-label.theme--dark {
|
68 |
+
font-size: 14px;
|
69 |
+
line-height: 100%;
|
70 |
+
}
|
71 |
+
|
72 |
+
.metricdesc {
|
73 |
+
font-size: 15px;
|
74 |
+
margin-top: -30px;
|
75 |
+
text-align: center;
|
76 |
+
}
|
77 |
+
.infobox {
|
78 |
+
font-size: 14px;
|
79 |
+
line-height: 110%;
|
80 |
+
}
|
81 |
+
|
82 |
+
.infoitem {
|
83 |
+
font-size: 12px;
|
84 |
+
line-height: 110%;
|
85 |
+
}
|
86 |
+
|
87 |
+
.maintitle {
|
88 |
+
font-family: 'Museo 900';
|
89 |
+
font-size: 30px;
|
90 |
+
text-align: center;
|
91 |
+
}
|
92 |
+
|
93 |
+
"""
|
94 |
+
|
95 |
+
import solara
|
96 |
+
import pandas as pd
|
97 |
+
import geopandas as gpd
|
98 |
+
import ipyleaflet
|
99 |
+
from random import uniform
|
100 |
+
import random
|
101 |
+
import numpy as np
|
102 |
+
import json
|
103 |
+
import matplotlib.pyplot as plt
|
104 |
+
from .engine import run_engine
|
105 |
+
|
106 |
+
languages = ["EN","TR"]
|
107 |
+
lang = solara.reactive("EN")
|
108 |
+
|
109 |
+
lbl_land_use_btn = [{'EN': 'civil societies',
|
110 |
+
'TR': 'sivil toplum'},
|
111 |
+
{'EN': 'women',
|
112 |
+
'TR': 'kadınlar'},
|
113 |
+
{'EN': 'youth',
|
114 |
+
'TR': 'gençler'},]
|
115 |
+
lbl_maintitle = {'EN': 'Tomorrow\'s Cities Decision Making Simulation','TR': 'Yarının Şehirleri için Karar Verme Simülasyonu'}
|
116 |
+
lbl_earthquake= {'EN': 'Earthquake', 'TR': 'Deprem'}
|
117 |
+
lbl_flood = {'EN': 'Flood', 'TR': 'Sel'}
|
118 |
+
lbl_debris = {'EN': 'Landslide', 'TR': 'Heyelan'}
|
119 |
+
lbl_reset = {'EN': 'Reset Simulation', 'TR': 'Simülasyonu Sıfırla'}
|
120 |
+
lbl_language = {'EN': 'Language', 'TR': 'Dil'}
|
121 |
+
lbl_luf_res_high = {'EN': 'Residential (High Density)', 'TR': 'Yerlesim Alani (Yuksek Yogunluk)'}
|
122 |
+
lbl_tv0_map_title = {'EN': '1. Today\'s land use', 'TR': '1. Mevcut plan'}
|
123 |
+
lbl_density_map_title = {'EN': '2. Select the potential hazard', 'TR': '2. Olası tehlikeyi seçin'}
|
124 |
+
lbl_policy_card_title = {'EN': '4. Select three policies to make your city resillient', 'TR': '4. Şehrinizi dayanıklı hale getirmek için üç politika seçin'}
|
125 |
+
lbl_too_many_policy_selected_error = {'EN': 'You cannot select more than three policies',
|
126 |
+
'TR': 'Üçten fazla politika seçemezsiniz'}
|
127 |
+
lbl_infobox = {'EN': f'''
|
128 |
+
Our decisions directly influence our future. It is critical for a
|
129 |
+
resilient city life where the decisions at the city scale reduces the disaster risk in the future.
|
130 |
+
In this simulation, we calculate possible disaster impacts calculated with Tomorrow's Cities Decision
|
131 |
+
Support System (TCDSE). The simulation shows how earthquake and flood hazards that may occur
|
132 |
+
in an urban environment affect different urban scenarios. To use the simulation 1) Check land use 2) Select the
|
133 |
+
possible hazard 3) Select the possible city scenarios for the future 4) choose policies 5) Run and check the metrics.
|
134 |
+
''',
|
135 |
+
"TR": f'''
|
136 |
+
Aldığımız kararlar, geleceğimizi doğrudan etkilemektedir. Kent ölçeğinde alınan kararların, gelecekte afet riskini azaltacak
|
137 |
+
nitelikte olması dayanıklı bir şehir hayatı için önemlidir.
|
138 |
+
Bu simülasyonda, Yarının Şehirleri Karar Destek Sistemi (TCDSE) ile hesaplanan olası afet etkilerini hesaplıyoruz. Simülasyon,
|
139 |
+
bir kent ortamında meydana gelebilecek deprem ve sel tehlikelerinin, farklı kent senaryolarını nasıl etkilediğini gösteriyor.
|
140 |
+
Simülasyonu kullanmak için 1) Mevcut planı inceleyin 2) Olası tehlikeyi seçin 3) Geleceğe dair olası şehir senaryolarını seçin
|
141 |
+
4) Politikaları seçin 5) Çalıştırın ve metrikleri inceleyin.'''}
|
142 |
+
lbl_infobox_title = {'EN': '', 'TR': ''}
|
143 |
+
lbl_landuse_plans_title = {'EN': '3. Future land uses', 'TR': '3. Geleceğin alternatif yerleşim planlarından birini seçin'}
|
144 |
+
lbl_run_btn = {'EN': 'RUN', 'TR': 'ÇALIŞTIR'}
|
145 |
+
lbl_results_card_title = {'EN': '5. Impact metrics', 'TR': '5. Etki metrikleri'}
|
146 |
+
lbl_info1 = {'EN': 'Number of individuals<br>39058', 'TR': 'Kişi Sayısı<br>39058'}
|
147 |
+
lbl_info2 = {'EN': 'Number of households<br>10397', 'TR': 'Hane Sayısı<br>10397'}
|
148 |
+
lbl_info3 = {'EN': 'Number of buildings<br>4810', 'TR': 'Bina Sayısı<br>4810'}
|
149 |
+
lbl_info4 = {'EN': 'Number of schools<br>4', 'TR': 'Okul Sayısı<br>4'}
|
150 |
+
lbl_info5 = {'EN': 'Number of hospitals<br>1', 'TR': 'Hastane Sayısı<br>1'}
|
151 |
+
#lbl_info6 = {'EN': 'Number of green field<br>', 'TR': 'Yeşil Alan Sayısı<br>'}
|
152 |
+
|
153 |
+
hazard_types = ["earthquake", "flood", "debris"]
|
154 |
+
hazard_type_default = hazard_types[0]
|
155 |
+
hazard_type = solara.reactive("earthquake")
|
156 |
+
|
157 |
+
flood_df = gpd.read_file('hazard_flood.geojson')
|
158 |
+
debris_df = gpd.read_file('hazard_debris.geojson')
|
159 |
+
earthquake_df = gpd.read_file('hazard_earthquake.geojson')
|
160 |
+
|
161 |
+
earthquake_df_as_geo = gpd.read_file('hazard_earthquake.geojson')
|
162 |
+
print('bir',earthquake_df_as_geo.crs)
|
163 |
+
earthquake_df_as_geo = earthquake_df_as_geo.set_crs("EPSG:4326",allow_override=True)
|
164 |
+
print('iki',earthquake_df_as_geo.crs)
|
165 |
+
earthquake_df_as_geo = earthquake_df_as_geo.to_crs(32645)
|
166 |
+
print('uc',earthquake_df_as_geo.crs)
|
167 |
+
|
168 |
+
debris_df_as_geo = gpd.read_file('hazard_debris.geojson')
|
169 |
+
debris_df_as_geo = debris_df_as_geo.set_crs("EPSG:4326",allow_override=True)
|
170 |
+
debris_df_as_geo = debris_df_as_geo.to_crs("EPSG:32645")
|
171 |
+
|
172 |
+
flood_df_as_geo = gpd.read_file('hazard_flood.geojson')
|
173 |
+
flood_df_as_geo = flood_df_as_geo.set_crs("EPSG:4326",allow_override=True)
|
174 |
+
flood_df_as_geo = flood_df_as_geo.to_crs("EPSG:32645")
|
175 |
+
|
176 |
+
landuse_tv0_df = gpd.read_file('landuse_tv0.geojson')
|
177 |
+
landuse_tv50_1_df = gpd.read_file('landuse_tv50_1.geojson')
|
178 |
+
landuse_tv50_2_df = gpd.read_file('landuse_tv50_2.geojson')
|
179 |
+
landuse_tv50_3_df = gpd.read_file('landuse_tv50_3.geojson')
|
180 |
+
n_landuses = 3
|
181 |
+
|
182 |
+
luf_types = pd.unique(landuse_tv0_df['luf'])
|
183 |
+
|
184 |
+
luf_colors = dict()
|
185 |
+
for luf_label in luf_types:
|
186 |
+
if luf_label == 'Agricultural Areas':
|
187 |
+
luf_colors[luf_label] = {
|
188 |
+
'color': 'black',
|
189 |
+
'fillColor': '#ffe665',
|
190 |
+
}
|
191 |
+
elif luf_label == 'Urban Green':
|
192 |
+
luf_colors[luf_label] = {
|
193 |
+
'color': 'black',
|
194 |
+
'fillColor': '#abdda4',
|
195 |
+
}
|
196 |
+
elif luf_label == 'Public Service Areas':
|
197 |
+
luf_colors[luf_label] = {
|
198 |
+
'color': 'black',
|
199 |
+
'fillColor': '#2b83ba',
|
200 |
+
}
|
201 |
+
elif luf_label == 'Commercial Areas':
|
202 |
+
luf_colors[luf_label] = {
|
203 |
+
'color': 'black',
|
204 |
+
'fillColor': '#d42c45',
|
205 |
+
}
|
206 |
+
elif luf_label == 'Industrial Areas':
|
207 |
+
luf_colors[luf_label] = {
|
208 |
+
'color': 'black',
|
209 |
+
'fillColor': '#936ede',
|
210 |
+
}
|
211 |
+
elif luf_label == 'Residential Areas with Low Density':
|
212 |
+
luf_colors[luf_label] = {
|
213 |
+
'color': 'black',
|
214 |
+
'fillColor': '#be8750',
|
215 |
+
}
|
216 |
+
elif luf_label == 'Residential Areas with Moderate Density':
|
217 |
+
luf_colors[luf_label] = {
|
218 |
+
'color': 'black',
|
219 |
+
'fillColor': '#a97d51',
|
220 |
+
}
|
221 |
+
elif luf_label == 'Residential Areas with High Density':
|
222 |
+
luf_colors[luf_label] = {
|
223 |
+
'color': 'black',
|
224 |
+
'fillColor': '#8c541a',
|
225 |
+
}
|
226 |
+
else:
|
227 |
+
luf_colors[luf_label] = {
|
228 |
+
'color': 'black',
|
229 |
+
'fillColor': random.choice(['red', 'yellow', 'green', 'orange','blue']),
|
230 |
+
}
|
231 |
+
|
232 |
+
#
|
233 |
+
plt.switch_backend("agg")
|
234 |
+
plt.rcParams['axes.facecolor'] = '#1e1e1e'
|
235 |
+
plt.rcParams['axes.edgecolor'] = '#1e1e1e'
|
236 |
+
#plt.switch_backend('macosx')
|
237 |
+
#%matplotlib inline
|
238 |
+
# for j in range(1, n_landuses+1):
|
239 |
+
# df = eval(f'landuse_tv50_{j}_df')
|
240 |
+
# title = f'tv50_{j}'
|
241 |
+
# for i, row in df.iterrows():
|
242 |
+
# df.loc[i, 'color'] = luf_colors[row['luf']]['fillColor']
|
243 |
+
# fig, ax = plt.subplots(nrows=1, ncols=1,figsize=(4*1.3, 5*1.3))
|
244 |
+
# fig.set_tight_layout(True)
|
245 |
+
# fig.patch.set_facecolor('white')
|
246 |
+
# #fig.patch.set_alpha(0.7)
|
247 |
+
# df.plot(color=df['color'],ax=ax)
|
248 |
+
# #ax.set_title(f'{title}')
|
249 |
+
# ax.set_xticks([])
|
250 |
+
# ax.set_yticks([])
|
251 |
+
# plt.savefig(f'landuse_{title}_selected.png')
|
252 |
+
|
253 |
+
# fig, ax = plt.subplots(nrows=1, ncols=1,figsize=(4*1.3,5*1.3))
|
254 |
+
# fig.set_tight_layout(True)
|
255 |
+
# #fig.patch.set_facecolor('black')
|
256 |
+
# fig.patch.set_alpha(0.0)
|
257 |
+
# df.plot(color=df['color'],ax=ax)
|
258 |
+
# #ax.set_title(f'{title}')
|
259 |
+
# ax.set_xticks([])
|
260 |
+
# ax.set_yticks([])
|
261 |
+
# plt.savefig(f'landuse_{title}.png')
|
262 |
+
|
263 |
+
landuse_tv0_json = json.loads(landuse_tv0_df.to_json())
|
264 |
+
luf_filtered_data = solara.reactive(landuse_tv0_json)
|
265 |
+
|
266 |
+
luf_selected = solara.reactive(luf_types)
|
267 |
+
luf_type_selected = dict()
|
268 |
+
for luf_type in luf_types:
|
269 |
+
luf_type_selected[luf_type] = solara.reactive(True)
|
270 |
+
|
271 |
+
lbl_luf = dict()
|
272 |
+
for luf_label in luf_types:
|
273 |
+
if luf_label == 'Agricultural Areas':
|
274 |
+
lbl_luf[luf_label] = {'EN': 'Agricultural Areas', 'TR': 'Tarım Alanları'}
|
275 |
+
elif luf_label == 'Urban Green':
|
276 |
+
lbl_luf[luf_label] = {'EN': 'Urban Green & Recreation Areas', 'TR': 'Kentsel Yeşil/Rekreasyon Alanları'}
|
277 |
+
elif luf_label == 'Public Service Areas':
|
278 |
+
lbl_luf[luf_label] = {'EN': 'Public Service Areas', 'TR': 'Kamu Hizmet Alanları'}
|
279 |
+
elif luf_label == 'Commercial Areas':
|
280 |
+
lbl_luf[luf_label] = {'EN': 'Commercial & Mixed Use Areas', 'TR': 'Ticari/Karışık Kullanım Alanları'}
|
281 |
+
elif luf_label == 'Industrial Areas':
|
282 |
+
lbl_luf[luf_label] = {'EN': 'Industrial Areas', 'TR': 'Sanayi Alanları'}
|
283 |
+
elif luf_label == 'Residential Areas with Low Density':
|
284 |
+
lbl_luf[luf_label] = {'EN': 'Residential Areas with Low Density', 'TR': 'Düşük Yoğunluklu Konut Alanı'}
|
285 |
+
elif luf_label == 'Residential Areas with Moderate Density':
|
286 |
+
lbl_luf[luf_label] = {'EN': 'Residential Areas with Moderate Density', 'TR': 'Orta Yoğunluklu Konut Alanı'}
|
287 |
+
elif luf_label == 'Residential Areas with High Density':
|
288 |
+
lbl_luf[luf_label] = {'EN': 'Residential Areas with High Density', 'TR': 'Yüksek Yoğunluklu Konut Alanı'}
|
289 |
+
else:
|
290 |
+
lbl_luf[luf_label] = {'EN': luf_label, 'TR': '(TR)'+luf_label}
|
291 |
+
|
292 |
+
policies = [1,2,3,4,5,6]
|
293 |
+
lbl_policy = dict()
|
294 |
+
lbl_policy[1] = {'EN': 'Loans for reconstruction for minor to moderate damages',
|
295 |
+
'TR': 'Küçük ila orta dereceli hasarlar için yeniden yapılanma kredileri'}
|
296 |
+
lbl_policy[2] = {'EN': 'Knowledge sharing about disaster risk reduction in schools',
|
297 |
+
'TR': 'Devlet ve özel okullarda afet risklerinin azaltılması hakkında bilgi paylaşımı'}
|
298 |
+
lbl_policy[3] = {'EN': 'Catastrophe bond for education/health facilities',
|
299 |
+
'TR': 'Eğitim ve sağlık tesislerini yapılandırmak için afet bonosu'}
|
300 |
+
lbl_policy[4] = {'EN': 'Repair loan assistance for flooding',
|
301 |
+
'TR': 'Sel için onarım kredisi yardımı'}
|
302 |
+
lbl_policy[5] = {'EN': 'Technical assistance for debris removal in education facilities',
|
303 |
+
'TR': 'Eğitim tesislerinde enkaz kaldırma için teknik yardım'}
|
304 |
+
lbl_policy[6] = {'EN': 'Compulsory content insurance for schools and hospitals',
|
305 |
+
'TR': 'Okullar ve hastaneler için zorunlu eşya sigortası'}
|
306 |
+
#lbl_policy[7] = {'EN': 'Green resilient infrastructure (prevention) & financial support for business recovery', 'TR': 'Politika 7'}
|
307 |
+
#lbl_policy[8] = {'EN': 'Green resilient infrastructure (prevention), reinforcement of schools, hospitals & shelters, financial support for affected business & household', 'TR': 'Politika 8'}
|
308 |
+
policy_selected = dict()
|
309 |
+
for policy in policies:
|
310 |
+
policy_selected[policy] = solara.reactive(False)
|
311 |
+
last_selected_policies = solara.reactive(set())
|
312 |
+
|
313 |
+
earthquake_locs = np.array([earthquake_df.geometry.y.to_list(), earthquake_df.geometry.x.to_list(), earthquake_df.im.to_list()]).transpose().tolist()
|
314 |
+
flood_locs = np.array([flood_df.geometry.y.to_list(), flood_df.geometry.x.to_list(), flood_df.im.to_list()]).transpose().tolist()
|
315 |
+
debris_locs = np.array([debris_df.geometry.y.to_list(), debris_df.geometry.x.to_list(), debris_df.im.to_list()]).transpose().tolist()
|
316 |
+
|
317 |
+
hazard_intensities = {
|
318 |
+
"earthquake": earthquake_locs,
|
319 |
+
"flood": flood_locs,
|
320 |
+
"debris": debris_locs
|
321 |
+
}
|
322 |
+
|
323 |
+
hazard_df = {
|
324 |
+
"earthquake": earthquake_df,
|
325 |
+
"flood": flood_df,
|
326 |
+
"debris": debris_df
|
327 |
+
}
|
328 |
+
|
329 |
+
hazard_df_as_geo = {
|
330 |
+
"earthquake": earthquake_df_as_geo,
|
331 |
+
"flood": flood_df_as_geo,
|
332 |
+
"debris": debris_df_as_geo
|
333 |
+
}
|
334 |
+
|
335 |
+
zoom_default = 12
|
336 |
+
tv0_zoom = solara.reactive(zoom_default)
|
337 |
+
|
338 |
+
tv0_center_default = (32.215, 35.21)
|
339 |
+
tv0_center = solara.reactive(tv0_center_default)
|
340 |
+
print(tv0_center)
|
341 |
+
def random_color(feature):
|
342 |
+
return luf_colors[feature['properties']['luf']]
|
343 |
+
|
344 |
+
@solara.component
|
345 |
+
def TV0MAP():
|
346 |
+
selected_lufs = set()
|
347 |
+
for luf_type in luf_types:
|
348 |
+
if luf_type_selected[luf_type].value:
|
349 |
+
selected_lufs.add(luf_type)
|
350 |
+
x = {'type':landuse_tv0_json['type'] }
|
351 |
+
x['features'] = []
|
352 |
+
for f in landuse_tv0_json['features']:
|
353 |
+
if f['properties']['luf'] in selected_lufs:
|
354 |
+
x['features'].append(f)
|
355 |
+
ipyleaflet.Map.element(
|
356 |
+
zoom=tv0_zoom.value,
|
357 |
+
on_zoom=tv0_zoom.set,
|
358 |
+
max_zoom=21,
|
359 |
+
min_zoom=1,
|
360 |
+
center=tv0_center.value,
|
361 |
+
on_center=tv0_center.set,
|
362 |
+
scroll_wheel_zoom=True,
|
363 |
+
dragging=True,
|
364 |
+
double_click_zoom=False,
|
365 |
+
touch_zoom=False,
|
366 |
+
box_zoom=False,
|
367 |
+
keyboard=True,
|
368 |
+
zoom_control=False,
|
369 |
+
layers=[
|
370 |
+
ipyleaflet.basemap_to_tiles(ipyleaflet.basemaps.OpenStreetMap.Mapnik), #ipyleaflet.basemaps.Esri.WorldImagery
|
371 |
+
ipyleaflet.GeoJSON(
|
372 |
+
data=x,
|
373 |
+
style={
|
374 |
+
'opacity': 1, 'dashArray': '9', 'fillOpacity': 1, 'weight': 1
|
375 |
+
},
|
376 |
+
hover_style={
|
377 |
+
'color': 'white', 'dashArray': '0', 'fillOpacity': 0.8
|
378 |
+
},
|
379 |
+
style_callback=random_color)
|
380 |
+
],
|
381 |
+
)
|
382 |
+
|
383 |
+
@solara.component
|
384 |
+
def DensityMap(hazard_type):
|
385 |
+
locs = hazard_intensities[hazard_type]
|
386 |
+
ipyleaflet.Map.element(
|
387 |
+
zoom=tv0_zoom.value,
|
388 |
+
max_zoom=zoom_default,
|
389 |
+
min_zoom=zoom_default,
|
390 |
+
on_zoom=tv0_zoom.set,
|
391 |
+
center=tv0_center.value,
|
392 |
+
on_center=tv0_center.set,
|
393 |
+
scroll_wheel_zoom=False,
|
394 |
+
dragging=False,
|
395 |
+
double_click_zoom=False,
|
396 |
+
touch_zoom=False,
|
397 |
+
box_zoom=False,
|
398 |
+
keyboard=False,
|
399 |
+
zoom_control=False,
|
400 |
+
layers=[
|
401 |
+
ipyleaflet.basemap_to_tiles(ipyleaflet.basemaps.Esri.WorldTopoMap),
|
402 |
+
ipyleaflet.Heatmap(
|
403 |
+
name=hazard_type,
|
404 |
+
locations=locs,
|
405 |
+
radius=10
|
406 |
+
),
|
407 |
+
],
|
408 |
+
)
|
409 |
+
|
410 |
+
run_is_allowed = solara.reactive(True)
|
411 |
+
|
412 |
+
@solara.component
|
413 |
+
def PolicyValidation():
|
414 |
+
npolicies_selected = 0
|
415 |
+
selected_policies = set()
|
416 |
+
for p in policies:
|
417 |
+
if policy_selected[p].value:
|
418 |
+
selected_policies.add(p)
|
419 |
+
npolicies_selected += 1
|
420 |
+
if npolicies_selected > 3:
|
421 |
+
print("roll-back")
|
422 |
+
solara.Warning(label=lbl_too_many_policy_selected_error[lang.value])
|
423 |
+
run_is_allowed.value = False
|
424 |
+
# Roll-back to last selection
|
425 |
+
#for p in policies:
|
426 |
+
# if p in last_selected_policies.value:
|
427 |
+
# policy_selected[p].value = True
|
428 |
+
# else:
|
429 |
+
# policy_selected[p].value = False
|
430 |
+
else:
|
431 |
+
last_selected_policies.value = selected_policies
|
432 |
+
run_is_allowed.value = True
|
433 |
+
|
434 |
+
landuseplan_selected = solara.reactive(1)
|
435 |
+
|
436 |
+
lbl_metric1 = {"EN": "Number of workers unemployed", "TR": "İşini kaybedenlerin sayısı"}
|
437 |
+
lbl_metric2 = {"EN": "Number of children with no access to education", "TR": "Okula gidemeyen çocuk sayısı"}
|
438 |
+
lbl_metric3 = {"EN": "Number of households with no access to hospital", "TR": "Hastane erişimi olmayan hane sayısı"}
|
439 |
+
lbl_metric4 = {"EN": "Number of individuals with no access to hospital", "TR": "Hastane erişimi olmayan kişi sayısı"}
|
440 |
+
lbl_metric5 = {"EN": "Number of homeless households", "TR": "İşlevsiz kalan hane sayısı"}
|
441 |
+
lbl_metric6 = {"EN": "Number of homeless individuals", "TR": "Evsiz kalan sayısı"}
|
442 |
+
lbl_metric7 = {"EN": "Population displacement", "TR": "Yer değiştirmek zorunda kalan kişi sayısı"}
|
443 |
+
|
444 |
+
metrics = {"metric1": {"desc": lbl_metric1, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
445 |
+
"metric2": {"desc": lbl_metric2, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
446 |
+
"metric3": {"desc": lbl_metric3, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
447 |
+
"metric4": {"desc": lbl_metric4, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
448 |
+
"metric5": {"desc": lbl_metric5, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
449 |
+
"metric6": {"desc": lbl_metric6, "value": solara.reactive(0), "max_value": solara.reactive(0)},
|
450 |
+
"metric7": {"desc": lbl_metric7, "value": solara.reactive(0), "max_value": solara.reactive(0)}}
|
451 |
+
|
452 |
+
@solara.component
|
453 |
+
def MetricWidget(name, description, value, max_value=10000):
|
454 |
+
value, set_value = solara.use_state_or_update(value)
|
455 |
+
max_value, set_max_value = solara.use_state_or_update(max_value)
|
456 |
+
options = {
|
457 |
+
"series": [ {
|
458 |
+
"type": 'gauge',
|
459 |
+
"min": 0,
|
460 |
+
"name": description,
|
461 |
+
"max": max(1,max_value), # workaround when max_value = 0
|
462 |
+
"startAngle": 180,
|
463 |
+
"endAngle": 0,
|
464 |
+
"progress": {"show": True, "width": 10, "itemStyle": {"color": 'red'}},
|
465 |
+
"pointer": { "show": False},
|
466 |
+
"axisLine": {"lineStyle": {"width": 10}},
|
467 |
+
"axisTick": {"show": False},
|
468 |
+
"splitLine": {"show": False},
|
469 |
+
"axisLabel": {"show": False},
|
470 |
+
"anchor": {"show": False},
|
471 |
+
"title": {"show": False},
|
472 |
+
"detail": {
|
473 |
+
"valueAnimation": True,
|
474 |
+
"offsetCenter": [0, '25%'],
|
475 |
+
"fontSize": 16,
|
476 |
+
"color": 'white'},
|
477 |
+
#"title": {"fontSize": 12},
|
478 |
+
"data": [{"value": value, "name": name}]}]}
|
479 |
+
print(f'value/max_value {value}:{max_value}')
|
480 |
+
|
481 |
+
solara.FigureEcharts(option=options, attributes={ "style": "height: 100px; width: 100px" })
|
482 |
+
|
483 |
+
@solara.component
|
484 |
+
def MetricsPanel(metrics):
|
485 |
+
'''
|
486 |
+
with solara.Columns([33,33,33]):
|
487 |
+
with solara.Column(align="center", gap="2px"):
|
488 |
+
for key in ["metric1","metric2"]:
|
489 |
+
MetricWidget(key, metrics[key]["desc"], metrics[key]["value"].value,
|
490 |
+
max_value=metrics[key]["max_value"].value)
|
491 |
+
solara.HTML(unsafe_innerHTML=metrics[key]["desc"][lang.value], classes=["metricdesc"])
|
492 |
+
with solara.Column(align="center", gap="2px"):
|
493 |
+
for key in ["metric3","metric4"]:
|
494 |
+
MetricWidget(key, metrics[key]["desc"], metrics[key]["value"].value,
|
495 |
+
max_value=metrics[key]["max_value"].value)
|
496 |
+
solara.HTML(unsafe_innerHTML=metrics[key]["desc"][lang.value], classes=["metricdesc"])
|
497 |
+
with solara.Column(align="center", gap="2px"):
|
498 |
+
for key in ["metric6","metric7"]:
|
499 |
+
MetricWidget(key, metrics[key]["desc"], metrics[key]["value"].value,
|
500 |
+
max_value=metrics[key]["max_value"].value)
|
501 |
+
solara.HTML(unsafe_innerHTML=metrics[key]["desc"][lang.value], classes=["metricdesc"])
|
502 |
+
'''
|
503 |
+
with solara.GridFixed(columns=3):
|
504 |
+
for key in ["metric2","metric4","metric7"]:
|
505 |
+
with solara.Row(justify="center"):
|
506 |
+
MetricWidget(key, metrics[key]["desc"], metrics[key]["value"].value,
|
507 |
+
max_value=metrics[key]["max_value"].value)
|
508 |
+
for key in ["metric2","metric4","metric7"]:
|
509 |
+
with solara.Row(justify="center"):
|
510 |
+
solara.HTML(unsafe_innerHTML=metrics[key]["desc"][lang.value], classes=["metricdesc"])
|
511 |
+
# for key in ["metric4","metric6","metric7"]:
|
512 |
+
# with solara.Row(justify="center"):
|
513 |
+
# MetricWidget(key,metrics[key]["desc"], metrics[key]["value"].value,
|
514 |
+
# max_value=metrics[key]["max_value"].value)
|
515 |
+
# for key in ["metric4","metric6","metric7"]:
|
516 |
+
# with solara.Row(justify="center"):
|
517 |
+
# solara.HTML(unsafe_innerHTML=metrics[key]["desc"][lang.value], classes=["metricdesc"])
|
518 |
+
|
519 |
+
|
520 |
+
def run_simulation():
|
521 |
+
print("Running simulation")
|
522 |
+
print(f"Selected landuse plans: {landuseplan_selected.value}")
|
523 |
+
selected_policies = set()
|
524 |
+
for p in policies:
|
525 |
+
if policy_selected[p].value:
|
526 |
+
selected_policies.add(p)
|
527 |
+
print(f"Selected policies: {selected_policies}")
|
528 |
+
|
529 |
+
new_metrics = run_engine(hazard_type.value,
|
530 |
+
landuseplan_selected.value,
|
531 |
+
hazard_df_as_geo[hazard_type.value],
|
532 |
+
list(selected_policies))
|
533 |
+
for key in new_metrics.keys():
|
534 |
+
metrics[key]["value"].value = new_metrics[key]["value"]
|
535 |
+
metrics[key]["max_value"].value = new_metrics[key]["max_value"]
|
536 |
+
|
537 |
+
print(metrics)
|
538 |
+
|
539 |
+
@solara.component
|
540 |
+
def LandUsePlans():
|
541 |
+
for p in policies:
|
542 |
+
if policy_selected[p].value:
|
543 |
+
print(p, 'selected')
|
544 |
+
|
545 |
+
for p in policies:
|
546 |
+
if policy_selected[p].value:
|
547 |
+
print(p, 'selected')
|
548 |
+
|
549 |
+
#with solara.Column(gap="2px"):
|
550 |
+
# with solara.Columns([2,32,32,32,2]):
|
551 |
+
# solara.HTML(unsafe_innerHTML="")
|
552 |
+
# for i in range(1, n_landuses+1):
|
553 |
+
# if landuseplan_selected.value == i:
|
554 |
+
# solara.Image(f"landuse_tv50_{i}_selected.png", width="230px")
|
555 |
+
# else:
|
556 |
+
# solara.Image(f"landuse_tv50_{i}.png",width="230px")
|
557 |
+
# solara.HTML(unsafe_innerHTML="")
|
558 |
+
# with solara.Row():
|
559 |
+
# with solara.ToggleButtonsSingle(value=landuseplan_selected):
|
560 |
+
# for i in range(0, n_landuses):
|
561 |
+
# solara.Button(lbl_land_use_btn[i][lang.value], value=i+1, text=True, style="width: 320px; height: 26px")
|
562 |
+
|
563 |
+
|
564 |
+
def landuse_1():
|
565 |
+
landuseplan_selected.value = 1
|
566 |
+
|
567 |
+
def landuse_2():
|
568 |
+
landuseplan_selected.value = 2
|
569 |
+
|
570 |
+
def landuse_3():
|
571 |
+
landuseplan_selected.value = 3
|
572 |
+
|
573 |
+
funcs = {1: landuse_1, 2: landuse_2, 3: landuse_3}
|
574 |
+
|
575 |
+
butons = []
|
576 |
+
with solara.Columns([32,32,32]):
|
577 |
+
for i in range(0, n_landuses):
|
578 |
+
with solara.Column():
|
579 |
+
if landuseplan_selected.value == i + 1:
|
580 |
+
solara.Button(lbl_land_use_btn[i][lang.value], value=i+1,
|
581 |
+
text=True, on_click=funcs[i+1], style="background-color: #545454; height: 26px")
|
582 |
+
with solara.Row(justify="center"):
|
583 |
+
solara.Image(f"landuse_tv50_{i+1}_selected.png", width="100%")
|
584 |
+
|
585 |
+
else:
|
586 |
+
solara.Button(lbl_land_use_btn[i][lang.value], value=i+1,
|
587 |
+
text=True, on_click=funcs[i+1], style="height: 26px")
|
588 |
+
with solara.Row(justify="center"):
|
589 |
+
solara.Image(f"landuse_tv50_{i+1}.png", width="100%")
|
590 |
+
|
591 |
+
@solara.component
|
592 |
+
def Page():
|
593 |
+
def reset_view():
|
594 |
+
tv0_zoom.value = zoom_default
|
595 |
+
tv0_center.value = tv0_center_default
|
596 |
+
hazard_type.value = hazard_type_default
|
597 |
+
for luf_type in luf_types:
|
598 |
+
luf_type_selected[luf_type].value = True
|
599 |
+
landuseplan_selected.value = 1
|
600 |
+
|
601 |
+
solara.Style(css)
|
602 |
+
with solara.Columns([1,98,1]):
|
603 |
+
solara.HTML(unsafe_innerHTML="")
|
604 |
+
with solara.Column():
|
605 |
+
with solara.Columns(([15,15,45,20,10]), style="display: flex; justify-content: center; align-items: center;"):
|
606 |
+
solara.HTML(unsafe_innerHTML="")
|
607 |
+
with solara.Column():
|
608 |
+
solara.Markdown("""[](https://tomorrowscities.org/)""")
|
609 |
+
#solara.Button(label=lbl_reset[lang.value], on_click=reset_view, style="height: 26px;")
|
610 |
+
solara.HTML(unsafe_innerHTML=lbl_maintitle[lang.value],classes=["maintitle"])
|
611 |
+
with solara.Column():
|
612 |
+
solara.Markdown("""[](https://urpartner.io/)""")
|
613 |
+
with solara.ToggleButtonsSingle(value=lang):
|
614 |
+
solara.Button(label="EN", value="EN", text=True,classes=["langbutton"],style="height: 26px;")
|
615 |
+
solara.Button(label="TR", value="TR", text=True,classes=["langbutton"],style="height: 26px;")
|
616 |
+
with solara.Columns([50,50]):
|
617 |
+
with solara.Column(gap="2px"):
|
618 |
+
with solara.Card(title=lbl_tv0_map_title[lang.value]):
|
619 |
+
with solara.Columns([50,25,25], classes=["mycol"]):
|
620 |
+
TV0MAP()
|
621 |
+
with solara.Column(gap="13px"):
|
622 |
+
for luf_type in luf_types:
|
623 |
+
with solara.Row():
|
624 |
+
#solara.Button(label="",
|
625 |
+
# color=luf_colors[luf_type]['fillColor'],
|
626 |
+
# classes=["lufbox"])
|
627 |
+
solara.HTML(unsafe_innerHTML=" ",
|
628 |
+
style=f"margin: 1px; background-color: {luf_colors[luf_type]['fillColor']};")
|
629 |
+
solara.HTML(unsafe_innerHTML=lbl_luf[luf_type][lang.value],
|
630 |
+
style="font-size: 12px; line-height: 100%; display: flex; justify-content: center; align-items: center;")
|
631 |
+
#solara.Checkbox(label=lbl_luf[luf_type][lang.value],value=luf_type_selected[luf_type],
|
632 |
+
# style="margin-top: 0px; line-height: 80%;")
|
633 |
+
with solara.Column(gap="20px"):
|
634 |
+
solara.HTML(unsafe_innerHTML=lbl_info1[lang.value], classes=["infoitem"])
|
635 |
+
solara.HTML(unsafe_innerHTML=lbl_info2[lang.value], classes=["infoitem"])
|
636 |
+
solara.HTML(unsafe_innerHTML=lbl_info3[lang.value], classes=["infoitem"])
|
637 |
+
solara.HTML(unsafe_innerHTML=lbl_info4[lang.value], classes=["infoitem"])
|
638 |
+
solara.HTML(unsafe_innerHTML=lbl_info5[lang.value], classes=["infoitem"])
|
639 |
+
with solara.Card(title=lbl_infobox_title[lang.value], style={"text-align": "justify"}):
|
640 |
+
solara.HTML(unsafe_innerHTML=lbl_infobox[lang.value], classes=["infobox"])
|
641 |
+
with solara.Card(title=lbl_density_map_title[lang.value]):
|
642 |
+
with solara.Columns([30,30,30]):
|
643 |
+
with solara.Column():
|
644 |
+
if hazard_type.value == "earthquake":
|
645 |
+
bgcolor = "background-color: #545454;"
|
646 |
+
else:
|
647 |
+
bgcolor = ""
|
648 |
+
with solara.Row(justify="center"):
|
649 |
+
solara.Button(lbl_earthquake[lang.value], value="earthquake", text=True, on_click=lambda: hazard_type.set("earthquake"), style=f"{bgcolor} width: 100%; height: 26px")
|
650 |
+
# DensityMap("earthquake")
|
651 |
+
with solara.Row(justify="center"):
|
652 |
+
solara.Image("/static/public/eq1.jpg")
|
653 |
+
with solara.Column():
|
654 |
+
if hazard_type.value == "flood":
|
655 |
+
bgcolor = "background-color: #545454;"
|
656 |
+
else:
|
657 |
+
bgcolor = ""
|
658 |
+
with solara.Row(justify="center"):
|
659 |
+
solara.Button(lbl_flood[lang.value], value="flood", text=True, on_click=lambda: hazard_type.set("flood"), style=f"{bgcolor} width: 100%; height: 26px")
|
660 |
+
# DensityMap("flood")
|
661 |
+
with solara.Row(justify="center"):
|
662 |
+
solara.Image("/static/public/fl1.jpg")
|
663 |
+
# with solara.Column():
|
664 |
+
# if hazard_type.value == "debris":
|
665 |
+
# bgcolor = "background-color: #545454;"
|
666 |
+
# else:
|
667 |
+
# bgcolor = ""
|
668 |
+
# with solara.Row(justify="center"):
|
669 |
+
# solara.Button(lbl_debris[lang.value], value="debris", text=True, on_click=lambda: hazard_type.set("debris"), style=f"{bgcolor} width: 200px; height: 26px")
|
670 |
+
# DensityMap("debris")
|
671 |
+
#with solara.Columns([30,30,30]):
|
672 |
+
# DensityMap("earthquake")
|
673 |
+
# DensityMap("flood")
|
674 |
+
# DensityMap("debris")
|
675 |
+
with solara.Column(gap="2px"):
|
676 |
+
with solara.Card(title=lbl_landuse_plans_title[lang.value]):
|
677 |
+
LandUsePlans()
|
678 |
+
with solara.Card(lbl_policy_card_title[lang.value]):
|
679 |
+
with solara.GridFixed(columns=1,row_gap="2px", column_gap="2px"):
|
680 |
+
for p in policies:
|
681 |
+
solara.Checkbox(label=lbl_policy[p][lang.value],value=policy_selected[p], style="font-size: 15px")
|
682 |
+
solara.Button(label=lbl_run_btn[lang.value],on_click=run_simulation, disabled=not run_is_allowed.value, style="height: 50px")
|
683 |
+
PolicyValidation()
|
684 |
+
with solara.Card(title=lbl_results_card_title[lang.value]):
|
685 |
+
MetricsPanel(metrics)
|
686 |
+
solara.HTML(unsafe_innerHTML="")
|
687 |
+
solara.Title("Tomorrow's Cities Demo")
|
688 |
+
|
689 |
+
|
690 |
+
@solara.component
|
691 |
+
def Layout(children):
|
692 |
+
# if you need the normal applayout
|
693 |
+
# layout = solara.AppLayout(children=children, style)
|
694 |
+
layout = solara.Div(children=children, style={"width": "100%", "min-height": "100vh"})
|
695 |
+
|
696 |
+
def log(*args):
|
697 |
+
print("stop doing that!")
|
698 |
+
|
699 |
+
#solara.v.use_event(layout, "contextmenu.prevent", log)
|
700 |
+
return layout
|
701 |
+
|
702 |
Page()
|