Spaces:
Runtime error
Runtime error
Commit
·
27dd195
1
Parent(s):
de6fbca
Integrated road network analysis into metric3
Browse filesUsing hospital_access attribute in household layer
is used to update metric3.
tomorrowcities/backend/engine.py
CHANGED
|
@@ -496,9 +496,10 @@ def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensit
|
|
| 496 |
return bld_hazard
|
| 497 |
|
| 498 |
|
| 499 |
-
def calculate_metrics(gdf_buildings, df_household, df_individual, hazard_type, policies=[],capacity=1.0):
|
| 500 |
# only use necessary columns
|
| 501 |
-
bld_hazard = gdf_buildings[['bldid','ds','expstr','occupancy','storeys',
|
|
|
|
| 502 |
|
| 503 |
# Find the damage state of the building that the household is in
|
| 504 |
df_household_bld = df_household.merge(bld_hazard[['bldid','ds']], on='bldid', how='left',validate='many_to_one')
|
|
@@ -582,7 +583,10 @@ def calculate_metrics(gdf_buildings, df_household, df_individual, hazard_type, p
|
|
| 582 |
df_metric2['metric2'] = df_metric2['metric2'].fillna(0).astype(int)
|
| 583 |
|
| 584 |
# metric 3 number of households in each building with no access to hospitals
|
| 585 |
-
|
|
|
|
|
|
|
|
|
|
| 586 |
'bldid',as_index=False).agg({'hhid':'count'})
|
| 587 |
|
| 588 |
df_metric3 = bld_hazard.merge(df_hospitals_per_household,how='left',left_on='bldid',right_on='bldid')[['bldid','nhouse','hhid']]
|
|
|
|
| 496 |
return bld_hazard
|
| 497 |
|
| 498 |
|
| 499 |
+
def calculate_metrics(gdf_buildings, df_household, df_individual, infra, hazard_type, policies=[],capacity=1.0):
|
| 500 |
# only use necessary columns
|
| 501 |
+
bld_hazard = gdf_buildings[['bldid','ds','expstr','occupancy','storeys',
|
| 502 |
+
'code_level','material','nhouse','residents','hospital_access']]
|
| 503 |
|
| 504 |
# Find the damage state of the building that the household is in
|
| 505 |
df_household_bld = df_household.merge(bld_hazard[['bldid','ds']], on='bldid', how='left',validate='many_to_one')
|
|
|
|
| 583 |
df_metric2['metric2'] = df_metric2['metric2'].fillna(0).astype(int)
|
| 584 |
|
| 585 |
# metric 3 number of households in each building with no access to hospitals
|
| 586 |
+
metric3_index = df_hospitals['ds'] > thresholds['metric3']
|
| 587 |
+
if 'road' in infra:
|
| 588 |
+
metric3_index = (metric3_index) | (df_hospitals['hospital_access'] == False)
|
| 589 |
+
df_hospitals_per_household = df_hospitals[metric3_index].groupby(
|
| 590 |
'bldid',as_index=False).agg({'hhid':'count'})
|
| 591 |
|
| 592 |
df_metric3 = bld_hazard.merge(df_hospitals_per_household,how='left',left_on='bldid',right_on='bldid')[['bldid','nhouse','hhid']]
|
tomorrowcities/pages/engine.py
CHANGED
|
@@ -989,7 +989,7 @@ def ExecutePanel():
|
|
| 989 |
print(buildings.head())
|
| 990 |
print('number of damaged roads/bridges',len(edges[edges['is_damaged']]))
|
| 991 |
|
| 992 |
-
return edges, buildings
|
| 993 |
|
| 994 |
def execute_power():
|
| 995 |
nodes = layers.value['layers']['power nodes']['data'].value
|
|
@@ -1039,6 +1039,14 @@ def ExecutePanel():
|
|
| 1039 |
layers.value['hazard'].value,policies=policies)
|
| 1040 |
buildings['ds'] = list(df_bld_hazard['ds'])
|
| 1041 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1042 |
implementation_capacity_score = layers.value['implementation_capacity_score'].value
|
| 1043 |
if implementation_capacity_score == 'medium':
|
| 1044 |
capacity = 1.25
|
|
@@ -1047,8 +1055,8 @@ def ExecutePanel():
|
|
| 1047 |
else:
|
| 1048 |
capacity = 1
|
| 1049 |
computed_metrics, df_metrics = calculate_metrics(buildings, household,
|
| 1050 |
-
individual, layers.value['
|
| 1051 |
-
|
| 1052 |
print(computed_metrics)
|
| 1053 |
for metric in df_metrics.keys():
|
| 1054 |
buildings[metric] = list(df_metrics[metric][metric])
|
|
@@ -1056,6 +1064,7 @@ def ExecutePanel():
|
|
| 1056 |
layers.value['metrics'][metric]['max_value'] = computed_metrics[metric]['max_value']
|
| 1057 |
return buildings
|
| 1058 |
|
|
|
|
| 1059 |
if execute_counter > 0 :
|
| 1060 |
is_ready, missing = is_ready_to_run(layers.value['infra'].value, layers.value['hazard'].value)
|
| 1061 |
if not is_ready:
|
|
@@ -1065,14 +1074,17 @@ def ExecutePanel():
|
|
| 1065 |
nodes = execute_power()
|
| 1066 |
layers.value['layers']['power nodes']['data'].set(nodes)
|
| 1067 |
if 'road' in layers.value['infra'].value:
|
| 1068 |
-
edges, buildings = execute_road()
|
| 1069 |
layers.value['layers']['road edges']['data'].set(edges)
|
| 1070 |
layers.value['layers']['building']['data'].set(buildings)
|
| 1071 |
-
|
| 1072 |
if 'building' in layers.value['infra'].value:
|
| 1073 |
buildings = execute_building()
|
| 1074 |
layers.value['layers']['building']['data'].set(buildings)
|
| 1075 |
|
|
|
|
|
|
|
|
|
|
| 1076 |
# trigger render event
|
| 1077 |
layers.value['render_count'].set(layers.value['render_count'].value + 1)
|
| 1078 |
if 'power' in layers.value['infra'].value:
|
|
|
|
| 989 |
print(buildings.head())
|
| 990 |
print('number of damaged roads/bridges',len(edges[edges['is_damaged']]))
|
| 991 |
|
| 992 |
+
return edges, buildings, household
|
| 993 |
|
| 994 |
def execute_power():
|
| 995 |
nodes = layers.value['layers']['power nodes']['data'].value
|
|
|
|
| 1039 |
layers.value['hazard'].value,policies=policies)
|
| 1040 |
buildings['ds'] = list(df_bld_hazard['ds'])
|
| 1041 |
|
| 1042 |
+
return buildings
|
| 1043 |
+
|
| 1044 |
+
def execute_metric():
|
| 1045 |
+
buildings = layers.value['layers']['building']['data'].value
|
| 1046 |
+
household = layers.value['layers']['household']['data'].value
|
| 1047 |
+
individual = layers.value['layers']['individual']['data'].value
|
| 1048 |
+
policies = [p['id'] for _, p in layers.value['policies'].items() if f"{p['label']}/{p['description']}" in layers.value['selected_policies'].value]
|
| 1049 |
+
|
| 1050 |
implementation_capacity_score = layers.value['implementation_capacity_score'].value
|
| 1051 |
if implementation_capacity_score == 'medium':
|
| 1052 |
capacity = 1.25
|
|
|
|
| 1055 |
else:
|
| 1056 |
capacity = 1
|
| 1057 |
computed_metrics, df_metrics = calculate_metrics(buildings, household,
|
| 1058 |
+
individual, layers.value['infra'].value,
|
| 1059 |
+
layers.value['hazard'].value, policies=policies,capacity=capacity)
|
| 1060 |
print(computed_metrics)
|
| 1061 |
for metric in df_metrics.keys():
|
| 1062 |
buildings[metric] = list(df_metrics[metric][metric])
|
|
|
|
| 1064 |
layers.value['metrics'][metric]['max_value'] = computed_metrics[metric]['max_value']
|
| 1065 |
return buildings
|
| 1066 |
|
| 1067 |
+
|
| 1068 |
if execute_counter > 0 :
|
| 1069 |
is_ready, missing = is_ready_to_run(layers.value['infra'].value, layers.value['hazard'].value)
|
| 1070 |
if not is_ready:
|
|
|
|
| 1074 |
nodes = execute_power()
|
| 1075 |
layers.value['layers']['power nodes']['data'].set(nodes)
|
| 1076 |
if 'road' in layers.value['infra'].value:
|
| 1077 |
+
edges, buildings, household = execute_road()
|
| 1078 |
layers.value['layers']['road edges']['data'].set(edges)
|
| 1079 |
layers.value['layers']['building']['data'].set(buildings)
|
| 1080 |
+
layers.value['layers']['household']['data'].set(household)
|
| 1081 |
if 'building' in layers.value['infra'].value:
|
| 1082 |
buildings = execute_building()
|
| 1083 |
layers.value['layers']['building']['data'].set(buildings)
|
| 1084 |
|
| 1085 |
+
buildings = execute_metric()
|
| 1086 |
+
layers.value['layers']['building']['data'].set(buildings)
|
| 1087 |
+
|
| 1088 |
# trigger render event
|
| 1089 |
layers.value['render_count'].set(layers.value['render_count'].value + 1)
|
| 1090 |
if 'power' in layers.value['infra'].value:
|