Spaces:
Runtime error
Runtime error
Commit
·
fe20df4
1
Parent(s):
2a67034
Moved flood parameters into setttings page
Browse files
tomorrowcities/backend/engine.py
CHANGED
|
@@ -8,8 +8,9 @@ from scipy.interpolate import interp1d
|
|
| 8 |
import networkx as nx
|
| 9 |
|
| 10 |
def compute_road_infra(buildings, household, individual,
|
| 11 |
-
nodes, edges, intensity, fragility, hazard,
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
DS_NO = 0
|
| 15 |
DS_SLIGHT = 1
|
|
@@ -288,7 +289,8 @@ def compute_power_infra(buildings, household, nodes,edges,intensity,fragility,ha
|
|
| 288 |
return gdf_nodes['ds'], gdf_nodes['is_damaged'], gdf_nodes['is_operational'], \
|
| 289 |
gdf_buildings['has_power'], household_w_node_id['has_power'],hospitals['has_power']
|
| 290 |
|
| 291 |
-
def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensity, df_hazard, hazard_type, policies=[]
|
|
|
|
| 292 |
|
| 293 |
if hazard_type != "landslide":
|
| 294 |
np.random.seed(seed=0)
|
|
@@ -318,8 +320,6 @@ def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensit
|
|
| 318 |
HAZARD_FLOOD = "flood"
|
| 319 |
HAZARD_DEBRIS = "debris"
|
| 320 |
|
| 321 |
-
threshold_flood = 0.2
|
| 322 |
-
threshold_flood_distance = 10
|
| 323 |
epsg = 3857
|
| 324 |
|
| 325 |
# Replace strange TypeX LRS with RCi
|
|
|
|
| 8 |
import networkx as nx
|
| 9 |
|
| 10 |
def compute_road_infra(buildings, household, individual,
|
| 11 |
+
nodes, edges, intensity, fragility, hazard,
|
| 12 |
+
road_water_height_threshold,
|
| 13 |
+
threshold_flood_distance):
|
| 14 |
|
| 15 |
DS_NO = 0
|
| 16 |
DS_SLIGHT = 1
|
|
|
|
| 289 |
return gdf_nodes['ds'], gdf_nodes['is_damaged'], gdf_nodes['is_operational'], \
|
| 290 |
gdf_buildings['has_power'], household_w_node_id['has_power'],hospitals['has_power']
|
| 291 |
|
| 292 |
+
def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensity, df_hazard, hazard_type, policies=[],
|
| 293 |
+
threshold_flood = 0.2, threshold_flood_distance = 10):
|
| 294 |
|
| 295 |
if hazard_type != "landslide":
|
| 296 |
np.random.seed(seed=0)
|
|
|
|
| 320 |
HAZARD_FLOOD = "flood"
|
| 321 |
HAZARD_DEBRIS = "debris"
|
| 322 |
|
|
|
|
|
|
|
| 323 |
epsg = 3857
|
| 324 |
|
| 325 |
# Replace strange TypeX LRS with RCi
|
tomorrowcities/pages/engine.py
CHANGED
|
@@ -22,6 +22,7 @@ import logging, sys
|
|
| 22 |
import pickle
|
| 23 |
import datetime
|
| 24 |
from .settings import storage, landslide_max_trials, revive_storage
|
|
|
|
| 25 |
from ..backend.engine import compute, compute_power_infra, compute_road_infra, calculate_metrics
|
| 26 |
from ..backend.utils import building_preprocess, identity_preprocess
|
| 27 |
from .utilities import S3FileBrowser, extension_list, extension_list_w_dots
|
|
@@ -32,7 +33,6 @@ layers = solara.reactive({
|
|
| 32 |
'hazard': solara.reactive("flood"),
|
| 33 |
'hazard_list': ["earthquake","flood","landslide"],
|
| 34 |
'datetime_analysis': datetime.datetime.utcnow(),
|
| 35 |
-
'road_water_height_threshold': solara.reactive(0.3),
|
| 36 |
'landslide_trigger_level': solara.reactive('moderate'),
|
| 37 |
'landslide_trigger_level_list': ['minor','moderate','severe'],
|
| 38 |
'dialog_message_to_be_shown': solara.reactive(None),
|
|
@@ -1048,7 +1048,6 @@ def ExecutePanel():
|
|
| 1048 |
intensity = layers.value['layers']['intensity']['data'].value
|
| 1049 |
fragility = layers.value['layers']['road fragility']['data'].value
|
| 1050 |
hazard = layers.value['hazard'].value
|
| 1051 |
-
road_water_height_threshold = layers.value['road_water_height_threshold'].value
|
| 1052 |
|
| 1053 |
edges['ds'] = 0
|
| 1054 |
edges['is_damaged'] = False
|
|
@@ -1060,7 +1059,7 @@ def ExecutePanel():
|
|
| 1060 |
ds, is_damaged, building_node_id, building_hospital_acess, household_node_id, \
|
| 1061 |
household_hospital_access, individual_facility_access = \
|
| 1062 |
compute_road_infra(buildings, household, individual, nodes, edges, intensity,
|
| 1063 |
-
fragility, hazard,
|
| 1064 |
|
| 1065 |
edges['ds'] = list(ds)
|
| 1066 |
edges['is_damaged'] = list(is_damaged)
|
|
@@ -1135,7 +1134,9 @@ def ExecutePanel():
|
|
| 1135 |
intensity,
|
| 1136 |
fragility[['expstr','susceptibility',trigger_level]].rename(columns={trigger_level:'collapse_probability'}),
|
| 1137 |
layers.value['hazard'].value,
|
| 1138 |
-
policies=policies
|
|
|
|
|
|
|
| 1139 |
else:
|
| 1140 |
df_bld_hazard = compute(
|
| 1141 |
landuse,
|
|
@@ -1144,7 +1145,9 @@ def ExecutePanel():
|
|
| 1144 |
individual,
|
| 1145 |
intensity,
|
| 1146 |
fragility if layers.value['hazard'].value == "earthquake" else vulnerability,
|
| 1147 |
-
layers.value['hazard'].value, policies=policies
|
|
|
|
|
|
|
| 1148 |
buildings['ds'] = list(df_bld_hazard['ds'])
|
| 1149 |
|
| 1150 |
return buildings
|
|
@@ -1179,7 +1182,7 @@ def ExecutePanel():
|
|
| 1179 |
raise Exception(f'Missing {missing}')
|
| 1180 |
max_trials = landslide_max_trials.value if layers.value['hazard'].value == "landslide" else 1
|
| 1181 |
for trial in range(1,max_trials+1):
|
| 1182 |
-
set_progress_message(
|
| 1183 |
if 'power' in layers.value['infra'].value:
|
| 1184 |
nodes, buildings, household = execute_power()
|
| 1185 |
layers.value['layers']['power nodes']['data'].set(nodes)
|
|
|
|
| 22 |
import pickle
|
| 23 |
import datetime
|
| 24 |
from .settings import storage, landslide_max_trials, revive_storage
|
| 25 |
+
from .settings import threshold_flood, threshold_flood_distance, threshold_road_water_height
|
| 26 |
from ..backend.engine import compute, compute_power_infra, compute_road_infra, calculate_metrics
|
| 27 |
from ..backend.utils import building_preprocess, identity_preprocess
|
| 28 |
from .utilities import S3FileBrowser, extension_list, extension_list_w_dots
|
|
|
|
| 33 |
'hazard': solara.reactive("flood"),
|
| 34 |
'hazard_list': ["earthquake","flood","landslide"],
|
| 35 |
'datetime_analysis': datetime.datetime.utcnow(),
|
|
|
|
| 36 |
'landslide_trigger_level': solara.reactive('moderate'),
|
| 37 |
'landslide_trigger_level_list': ['minor','moderate','severe'],
|
| 38 |
'dialog_message_to_be_shown': solara.reactive(None),
|
|
|
|
| 1048 |
intensity = layers.value['layers']['intensity']['data'].value
|
| 1049 |
fragility = layers.value['layers']['road fragility']['data'].value
|
| 1050 |
hazard = layers.value['hazard'].value
|
|
|
|
| 1051 |
|
| 1052 |
edges['ds'] = 0
|
| 1053 |
edges['is_damaged'] = False
|
|
|
|
| 1059 |
ds, is_damaged, building_node_id, building_hospital_acess, household_node_id, \
|
| 1060 |
household_hospital_access, individual_facility_access = \
|
| 1061 |
compute_road_infra(buildings, household, individual, nodes, edges, intensity,
|
| 1062 |
+
fragility, hazard, threshold_road_water_height.value, threshold_flood_distance.value)
|
| 1063 |
|
| 1064 |
edges['ds'] = list(ds)
|
| 1065 |
edges['is_damaged'] = list(is_damaged)
|
|
|
|
| 1134 |
intensity,
|
| 1135 |
fragility[['expstr','susceptibility',trigger_level]].rename(columns={trigger_level:'collapse_probability'}),
|
| 1136 |
layers.value['hazard'].value,
|
| 1137 |
+
policies=policies,
|
| 1138 |
+
threshold_flood = threshold_flood.value,
|
| 1139 |
+
threshold_flood_distance = threshold_flood_distance.value)
|
| 1140 |
else:
|
| 1141 |
df_bld_hazard = compute(
|
| 1142 |
landuse,
|
|
|
|
| 1145 |
individual,
|
| 1146 |
intensity,
|
| 1147 |
fragility if layers.value['hazard'].value == "earthquake" else vulnerability,
|
| 1148 |
+
layers.value['hazard'].value, policies=policies,
|
| 1149 |
+
threshold_flood = threshold_flood.value,
|
| 1150 |
+
threshold_flood_distance = threshold_flood_distance.value)
|
| 1151 |
buildings['ds'] = list(df_bld_hazard['ds'])
|
| 1152 |
|
| 1153 |
return buildings
|
|
|
|
| 1182 |
raise Exception(f'Missing {missing}')
|
| 1183 |
max_trials = landslide_max_trials.value if layers.value['hazard'].value == "landslide" else 1
|
| 1184 |
for trial in range(1,max_trials+1):
|
| 1185 |
+
set_progress_message('Running...')
|
| 1186 |
if 'power' in layers.value['infra'].value:
|
| 1187 |
nodes, buildings, household = execute_power()
|
| 1188 |
layers.value['layers']['power nodes']['data'].set(nodes)
|
tomorrowcities/pages/settings.py
CHANGED
|
@@ -87,6 +87,10 @@ def revive_storage():
|
|
| 87 |
storage = solara.reactive(revive_storage())
|
| 88 |
landslide_max_trials = solara.reactive(5)
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
def storage_control(aws_access_key_id: str, aws_secret_access_key: str, region_name: str, bucket_name: str):
|
| 91 |
storage.value = S3Storage(aws_access_key_id, aws_secret_access_key, region_name, bucket_name)
|
| 92 |
|
|
@@ -167,4 +171,22 @@ def Page(name: Optional[str] = None, page: int = 0, page_size=100):
|
|
| 167 |
solara.Error(err_message)
|
| 168 |
|
| 169 |
with solara.Card(title='Landslide Parameters',subtitle='Choose the parameters for the landslide simulation'):
|
| 170 |
-
solara.SliderInt(label='Number of Monte-Carlo Trials', value=landslide_max_trials, min=1,max=100)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
storage = solara.reactive(revive_storage())
|
| 88 |
landslide_max_trials = solara.reactive(5)
|
| 89 |
|
| 90 |
+
threshold_flood = solara.reactive(0.2)
|
| 91 |
+
threshold_flood_distance = solara.reactive(10)
|
| 92 |
+
threshold_road_water_height = solara.reactive(0.3)
|
| 93 |
+
|
| 94 |
def storage_control(aws_access_key_id: str, aws_secret_access_key: str, region_name: str, bucket_name: str):
|
| 95 |
storage.value = S3Storage(aws_access_key_id, aws_secret_access_key, region_name, bucket_name)
|
| 96 |
|
|
|
|
| 171 |
solara.Error(err_message)
|
| 172 |
|
| 173 |
with solara.Card(title='Landslide Parameters',subtitle='Choose the parameters for the landslide simulation'):
|
| 174 |
+
solara.SliderInt(label='Number of Monte-Carlo Trials', value=landslide_max_trials, min=1,max=100)
|
| 175 |
+
|
| 176 |
+
with solara.Card(title='Flood Parameters',subtitle='Choose the parameters for the flood simulations'):
|
| 177 |
+
solara.Markdown(md_text='''
|
| 178 |
+
If the relative damage obtained from the vulnerability curve is beyond
|
| 179 |
+
the flood threshold, the structure is assumed to flooded.
|
| 180 |
+
After resetting the value, please execute the simulation again to see its effect.''')
|
| 181 |
+
solara.SliderFloat(label='Flood Threshold (relative damage)', value=threshold_flood, min=0,max=1, step=0.1)
|
| 182 |
+
solara.Markdown(md_text='''
|
| 183 |
+
If the distance from a structure to the nearest flood intensity measure
|
| 184 |
+
is greater than Flood Distance, then the structure is assumed to be
|
| 185 |
+
intact from flood.
|
| 186 |
+
After resetting the value, please execute the simulation again to see its effect.''')
|
| 187 |
+
solara.SliderInt(label='Minimum Flood Distance Threshold (meters)', value=threshold_flood_distance, min=0,max=100)
|
| 188 |
+
|
| 189 |
+
solara.Markdown(md_text='''
|
| 190 |
+
If the water level is beyond this threshold then the road
|
| 191 |
+
is assumed to be flooded.''')
|
| 192 |
+
solara.SliderFloat(label='Minimum Water Level Threshold for Roads (meters)', value=threshold_road_water_height, min=0,max=1)
|