hkayabilisim commited on
Commit
06f2c34
·
1 Parent(s): 26dcc22

feat: redefine population displacement (metric7)

Browse files

An individual is assumed to be displaced when any of the following conditions hold:

At least X of the following assets either suffer direct damage, cannot be reached via the
transportation network (applies to all except residential buildings), or have no electricity:

- the individual's residence, workplace, school, or associated hospital

where X is the population displacement consensus which can be adjusted in the settings with a default value of 2.

With this redefinition, metric7 (population displacement) is much lower than when
calculated with the old definition. (Old definition is simply the new one with consensis=1)

tomorrowcities/backend/engine.py CHANGED
@@ -747,7 +747,7 @@ def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensit
747
  return bld_hazard
748
 
749
 
750
- def calculate_metrics(gdf_buildings, df_household, df_individual, infra, hazard_type, policies=[],capacity=1.0):
751
  # Very handy temporary attributes showin if an individual is associated with a facility
752
  # and lost access to facility
753
  df_individual['has_facility'] = df_individual['indivfacid'].apply(lambda x: x > -1)
@@ -788,7 +788,7 @@ def calculate_metrics(gdf_buildings, df_household, df_individual, infra, hazard_
788
  .merge(df_workers[['individ','ds','has_power']].rename(columns={'ds':'ds_workplace','has_power':'workplace_power'}),on='individ', how='left')\
789
  .merge(df_students[['individ','ds','has_power']].rename(columns={'ds':'ds_school','has_power':'school_power'}), on='individ', how='left')\
790
  .merge(df_indiv_household[['individ','ds','hospital_access','hospital_has_power']].rename(columns={'ds':'ds_household'}), on='individ',how='left')\
791
- .merge(df_household[['hhid','bldid']],on='hhid',how='left')
792
 
793
  DS_NO = 0
794
  DS_SLIGHT = 1
@@ -900,17 +900,20 @@ def calculate_metrics(gdf_buildings, df_household, df_individual, infra, hazard_
900
 
901
  # metric 7 the number of displaced individuals in each building
902
  # more info: an individual is displaced if at least of the conditions below hold
903
- metric7_index = (df_displaced_indiv['ds_household'] > thresholds['metric6']) |\
904
- (df_displaced_indiv['ds_school'] > thresholds['metric2']) |\
905
- (df_displaced_indiv['ds_workplace'] > thresholds['metric1']) |\
906
- (df_displaced_indiv['ds_hospital'] > thresholds['metric4'])
 
907
  if 'road' in infra:
908
- metric7_index = (metric7_index) | (df_displaced_indiv['hospital_access'] == False)
909
- metric7_index = (metric7_index) | (df_displaced_indiv['lost_facility_access'] == True)
 
 
910
  if 'power' in infra:
911
- metric7_index = (metric7_index) | (df_displaced_indiv['hospital_has_power'] == False)
912
- metric7_index = (metric7_index) | (df_displaced_indiv['workplace_power'] == False)
913
- metric7_index = (metric7_index) | (df_displaced_indiv['school_power'] == False)
914
  df_disp_per_bld = df_displaced_indiv[metric7_index]\
915
  .groupby('bldid',as_index=False)\
916
  .agg({'individ':'count'})
 
747
  return bld_hazard
748
 
749
 
750
+ def calculate_metrics(gdf_buildings, df_household, df_individual, infra, hazard_type, population_displacement_consensus, policies=[],capacity=1.0):
751
  # Very handy temporary attributes showin if an individual is associated with a facility
752
  # and lost access to facility
753
  df_individual['has_facility'] = df_individual['indivfacid'].apply(lambda x: x > -1)
 
788
  .merge(df_workers[['individ','ds','has_power']].rename(columns={'ds':'ds_workplace','has_power':'workplace_power'}),on='individ', how='left')\
789
  .merge(df_students[['individ','ds','has_power']].rename(columns={'ds':'ds_school','has_power':'school_power'}), on='individ', how='left')\
790
  .merge(df_indiv_household[['individ','ds','hospital_access','hospital_has_power']].rename(columns={'ds':'ds_household'}), on='individ',how='left')\
791
+ .merge(df_household[['hhid','bldid','has_power']].rename(columns={'has_power':'household_power'}),on='hhid',how='left')
792
 
793
  DS_NO = 0
794
  DS_SLIGHT = 1
 
900
 
901
  # metric 7 the number of displaced individuals in each building
902
  # more info: an individual is displaced if at least of the conditions below hold
903
+ print('population_displacement_consensus', population_displacement_consensus)
904
+ # direct damage
905
+ metric7_index = (df_displaced_indiv[['ds_household','ds_school','ds_workplace','ds_hospital']] \
906
+ > [thresholds['metric6'],thresholds['metric2'],thresholds['metric1'],thresholds['metric4']]).sum(axis=1) >= population_displacement_consensus
907
+ # inaccebility
908
  if 'road' in infra:
909
+ inaccesibility_index = (df_displaced_indiv[['hospital_access','lost_facility_access']] \
910
+ == [False,True]).sum(axis=1) >= population_displacement_consensus
911
+ metric7_index = (metric7_index) | (inaccesibility_index)
912
+ # power loss
913
  if 'power' in infra:
914
+ power_loss_index = (df_displaced_indiv[['household_power','hospital_has_power','workplace_power','school_power']] \
915
+ == [False,False,False,False]).sum(axis=1) >= population_displacement_consensus
916
+ metric7_index = (metric7_index) | (power_loss_index)
917
  df_disp_per_bld = df_displaced_indiv[metric7_index]\
918
  .groupby('bldid',as_index=False)\
919
  .agg({'individ':'count'})
tomorrowcities/pages/engine.py CHANGED
@@ -22,7 +22,8 @@ import logging, sys
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, threshold_culvert_water_height, preserve_edge_directions
 
26
  from ..backend.engine import compute, compute_power_infra, compute_road_infra, calculate_metrics, generate_exposure
27
  from ..backend.utils import building_preprocess, identity_preprocess, ParameterFile
28
  from .utilities import S3FileBrowser, extension_list, extension_list_w_dots
@@ -1229,7 +1230,8 @@ def ExecutePanel():
1229
  # capacity = 1
1230
  computed_metrics, df_metrics = calculate_metrics(buildings, household,
1231
  individual, layers.value['infra'].value,
1232
- layers.value['hazard'].value, policies=policies,capacity=1)
 
1233
  print(computed_metrics)
1234
  for metric in df_metrics.keys():
1235
  buildings[metric] = list(df_metrics[metric][metric])
 
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, threshold_culvert_water_height, preserve_edge_directions,\
26
+ population_displacement_consensus
27
  from ..backend.engine import compute, compute_power_infra, compute_road_infra, calculate_metrics, generate_exposure
28
  from ..backend.utils import building_preprocess, identity_preprocess, ParameterFile
29
  from .utilities import S3FileBrowser, extension_list, extension_list_w_dots
 
1230
  # capacity = 1
1231
  computed_metrics, df_metrics = calculate_metrics(buildings, household,
1232
  individual, layers.value['infra'].value,
1233
+ layers.value['hazard'].value, population_displacement_consensus.value,
1234
+ policies=policies,capacity=1)
1235
  print(computed_metrics)
1236
  for metric in df_metrics.keys():
1237
  buildings[metric] = list(df_metrics[metric][metric])
tomorrowcities/pages/settings.py CHANGED
@@ -24,6 +24,7 @@ threshold_flood_distance = solara.reactive(10)
24
  threshold_road_water_height = solara.reactive(0.3)
25
  threshold_culvert_water_height = solara.reactive(1.5)
26
  preserve_edge_directions = solara.reactive(False)
 
27
 
28
  def storage_control(aws_access_key_id: str, aws_secret_access_key: str, region_name: str, bucket_name: str):
29
  storage.value = S3Storage(aws_access_key_id, aws_secret_access_key, region_name, bucket_name)
@@ -106,6 +107,10 @@ def Page(name: Optional[str] = None, page: int = 0, page_size=100):
106
  if err_message != '':
107
  solara.Error(err_message)
108
 
 
 
 
 
109
  with solara.Card(title='Connectivity Parameters',subtitle='Parameters effecting connectivity analysis in road/power networks'):
110
  solara.Checkbox(label='Preserve directions in graph edges', value=preserve_edge_directions)
111
 
 
24
  threshold_road_water_height = solara.reactive(0.3)
25
  threshold_culvert_water_height = solara.reactive(1.5)
26
  preserve_edge_directions = solara.reactive(False)
27
+ population_displacement_consensus = solara.reactive(2)
28
 
29
  def storage_control(aws_access_key_id: str, aws_secret_access_key: str, region_name: str, bucket_name: str):
30
  storage.value = S3Storage(aws_access_key_id, aws_secret_access_key, region_name, bucket_name)
 
107
  if err_message != '':
108
  solara.Error(err_message)
109
 
110
+ with solara.Card(title='Metric-related Parameters',
111
+ subtitle='Minimum number of direct damage, inaccessibility or power lost should be observed to claim a population displacement.'):
112
+ solara.Select(label='population displacement consensus', values=[1,2,3,4], value=population_displacement_consensus)
113
+
114
  with solara.Card(title='Connectivity Parameters',subtitle='Parameters effecting connectivity analysis in road/power networks'):
115
  solara.Checkbox(label='Preserve directions in graph edges', value=preserve_edge_directions)
116