hkayabilisim commited on
Commit
3cd1622
·
1 Parent(s): 4fc0ad0

Added implementation capacity score

Browse files
tomorrowcities/backend/engine.py CHANGED
@@ -334,9 +334,9 @@ def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensit
334
  return bld_hazard
335
 
336
 
337
- def calculate_metrics(gdf_buildings, df_household, df_individual, hazard_type, policies=[]):
338
  # only use necessary columns
339
- bld_hazard = gdf_buildings[['bldid','ds','expstr']]
340
  bld_hazard[['material','code_level','storeys','occupancy']] = \
341
  bld_hazard['expstr'].str.split('+',expand=True).copy()
342
  #bld_hazard['occupancy'] = bld_hazard['occupancy'].astype('category')
@@ -400,8 +400,10 @@ def calculate_metrics(gdf_buildings, df_household, df_individual, hazard_type, p
400
  df_household[['hhid','bldid']],on='hhid',how='left').groupby(
401
  'bldid',as_index=False).agg({'individ':'count'})
402
 
403
- df_metric1 = bld_hazard.merge(df_workers_per_building,how='left',left_on='bldid',right_on = 'bldid')[['bldid','individ']]
404
  df_metric1.rename(columns={'individ':'metric1'}, inplace=True)
 
 
405
  df_metric1['metric1'] = df_metric1['metric1'].fillna(0).astype(int)
406
 
407
  # metric 2 number of students in each building with no access to schools
@@ -409,40 +411,50 @@ def calculate_metrics(gdf_buildings, df_household, df_individual, hazard_type, p
409
  df_household[['hhid','bldid']],on='hhid',how='left').groupby(
410
  'bldid',as_index=False).agg({'individ':'count'})
411
 
412
- df_metric2 = bld_hazard.merge(df_students_per_building,how='left',left_on='bldid',right_on = 'bldid')[['bldid','individ']]
413
  df_metric2.rename(columns={'individ':'metric2'}, inplace=True)
 
 
414
  df_metric2['metric2'] = df_metric2['metric2'].fillna(0).astype(int)
415
 
416
  # metric 3 number of households in each building with no access to hospitals
417
  df_hospitals_per_household = df_hospitals[df_hospitals['ds'] > thresholds['metric3']].groupby(
418
  'bldid',as_index=False).agg({'hhid':'count'})
419
 
420
- df_metric3 = bld_hazard.merge(df_hospitals_per_household,how='left',left_on='bldid',right_on='bldid')[['bldid','hhid']]
421
  df_metric3.rename(columns={'hhid':'metric3'}, inplace=True)
 
 
422
  df_metric3['metric3'] = df_metric3['metric3'].fillna(0).astype(int)
423
 
424
  # metric 4 number of individuals in each building with no access to hospitals
425
  df_hospitals_per_individual = df_hospitals[df_hospitals['ds'] > thresholds['metric4']].groupby(
426
  'bldid',as_index=False).agg({'nind':'sum'})
427
 
428
- df_metric4 = bld_hazard.merge(df_hospitals_per_individual,how='left',left_on='bldid',right_on='bldid')[['bldid','nind']]
429
  df_metric4.rename(columns={'nind':'metric4'}, inplace=True)
 
 
430
  df_metric4['metric4'] = df_metric4['metric4'].fillna(0).astype(int)
431
 
432
  # metric 5 number of damaged households in each building
433
  df_homeless_households = df_household_bld[df_household_bld['ds'] > thresholds['metric5']].groupby(
434
  'bldid',as_index=False).agg({'hhid':'count'})
435
 
436
- df_metric5 = bld_hazard.merge(df_homeless_households,how='left',left_on='bldid',right_on='bldid')[['bldid','hhid']]
437
  df_metric5.rename(columns={'hhid':'metric5'}, inplace=True)
 
 
438
  df_metric5['metric5'] = df_metric5['metric5'].fillna(0).astype(int)
439
 
440
  # metric 6 number of homeless individuals in each building
441
  df_homeless_individuals = df_household_bld[df_household_bld['ds'] > thresholds['metric6']].groupby(
442
  'bldid',as_index=False).agg({'nind':'sum'})
443
 
444
- df_metric6 = bld_hazard.merge(df_homeless_individuals,how='left',left_on='bldid',right_on='bldid')[['bldid','nind']]
445
  df_metric6.rename(columns={'nind':'metric6'}, inplace=True)
 
 
446
  df_metric6['metric6'] = df_metric6['metric6'].fillna(0).astype(int)
447
 
448
  # metric 7 the number of displaced individuals in each building
@@ -454,8 +466,10 @@ def calculate_metrics(gdf_buildings, df_household, df_individual, hazard_type, p
454
  .groupby('bldid',as_index=False)\
455
  .agg({'individ':'count'})
456
 
457
- df_metric7 = bld_hazard.merge(df_disp_per_bld,how='left',left_on='bldid',right_on='bldid')[['bldid','individ']]
458
  df_metric7.rename(columns={'individ':'metric7'}, inplace=True)
 
 
459
  df_metric7['metric7'] = df_metric7['metric7'].fillna(0).astype(int)
460
 
461
 
 
334
  return bld_hazard
335
 
336
 
337
+ def calculate_metrics(gdf_buildings, df_household, df_individual, hazard_type, policies=[],capacity=1.0):
338
  # only use necessary columns
339
+ bld_hazard = gdf_buildings[['bldid','ds','expstr','nhouse','residents']]
340
  bld_hazard[['material','code_level','storeys','occupancy']] = \
341
  bld_hazard['expstr'].str.split('+',expand=True).copy()
342
  #bld_hazard['occupancy'] = bld_hazard['occupancy'].astype('category')
 
400
  df_household[['hhid','bldid']],on='hhid',how='left').groupby(
401
  'bldid',as_index=False).agg({'individ':'count'})
402
 
403
+ df_metric1 = bld_hazard.merge(df_workers_per_building,how='left',left_on='bldid',right_on = 'bldid')[['bldid','residents','individ']]
404
  df_metric1.rename(columns={'individ':'metric1'}, inplace=True)
405
+ df_metric1['metric1'] = (df_metric1['metric1'].fillna(0) * capacity).astype(int)
406
+ df_metric1['metric1'] = df_metric1[['residents','metric1']].min(axis=1)
407
  df_metric1['metric1'] = df_metric1['metric1'].fillna(0).astype(int)
408
 
409
  # metric 2 number of students in each building with no access to schools
 
411
  df_household[['hhid','bldid']],on='hhid',how='left').groupby(
412
  'bldid',as_index=False).agg({'individ':'count'})
413
 
414
+ df_metric2 = bld_hazard.merge(df_students_per_building,how='left',left_on='bldid',right_on = 'bldid')[['bldid','residents','individ']]
415
  df_metric2.rename(columns={'individ':'metric2'}, inplace=True)
416
+ df_metric2['metric2'] = (df_metric2['metric2'].fillna(0) * capacity).astype(int)
417
+ df_metric2['metric2'] = df_metric2[['residents','metric2']].min(axis=1)
418
  df_metric2['metric2'] = df_metric2['metric2'].fillna(0).astype(int)
419
 
420
  # metric 3 number of households in each building with no access to hospitals
421
  df_hospitals_per_household = df_hospitals[df_hospitals['ds'] > thresholds['metric3']].groupby(
422
  'bldid',as_index=False).agg({'hhid':'count'})
423
 
424
+ df_metric3 = bld_hazard.merge(df_hospitals_per_household,how='left',left_on='bldid',right_on='bldid')[['bldid','nhouse','hhid']]
425
  df_metric3.rename(columns={'hhid':'metric3'}, inplace=True)
426
+ df_metric3['metric3'] = (df_metric3['metric3'].fillna(0) * capacity).astype(int)
427
+ df_metric3['metric3'] = df_metric3[['nhouse','metric3']].min(axis=1)
428
  df_metric3['metric3'] = df_metric3['metric3'].fillna(0).astype(int)
429
 
430
  # metric 4 number of individuals in each building with no access to hospitals
431
  df_hospitals_per_individual = df_hospitals[df_hospitals['ds'] > thresholds['metric4']].groupby(
432
  'bldid',as_index=False).agg({'nind':'sum'})
433
 
434
+ df_metric4 = bld_hazard.merge(df_hospitals_per_individual,how='left',left_on='bldid',right_on='bldid')[['bldid','residents','nind']]
435
  df_metric4.rename(columns={'nind':'metric4'}, inplace=True)
436
+ df_metric4['metric4'] = (df_metric4['metric4'].fillna(0) * capacity).astype(int)
437
+ df_metric4['metric4'] = df_metric4[['residents','metric4']].min(axis=1)
438
  df_metric4['metric4'] = df_metric4['metric4'].fillna(0).astype(int)
439
 
440
  # metric 5 number of damaged households in each building
441
  df_homeless_households = df_household_bld[df_household_bld['ds'] > thresholds['metric5']].groupby(
442
  'bldid',as_index=False).agg({'hhid':'count'})
443
 
444
+ df_metric5 = bld_hazard.merge(df_homeless_households,how='left',left_on='bldid',right_on='bldid')[['bldid','nhouse','hhid']]
445
  df_metric5.rename(columns={'hhid':'metric5'}, inplace=True)
446
+ df_metric5['metric5'] = (df_metric5['metric5'].fillna(0) * capacity).astype(int)
447
+ df_metric5['metric5'] = df_metric5[['nhouse','metric5']].min(axis=1)
448
  df_metric5['metric5'] = df_metric5['metric5'].fillna(0).astype(int)
449
 
450
  # metric 6 number of homeless individuals in each building
451
  df_homeless_individuals = df_household_bld[df_household_bld['ds'] > thresholds['metric6']].groupby(
452
  'bldid',as_index=False).agg({'nind':'sum'})
453
 
454
+ df_metric6 = bld_hazard.merge(df_homeless_individuals,how='left',left_on='bldid',right_on='bldid')[['bldid','residents','nind']]
455
  df_metric6.rename(columns={'nind':'metric6'}, inplace=True)
456
+ df_metric6['metric6'] = (df_metric6['metric6'].fillna(0) * capacity).astype(int)
457
+ df_metric6['metric6'] = df_metric6[['residents','metric6']].min(axis=1)
458
  df_metric6['metric6'] = df_metric6['metric6'].fillna(0).astype(int)
459
 
460
  # metric 7 the number of displaced individuals in each building
 
466
  .groupby('bldid',as_index=False)\
467
  .agg({'individ':'count'})
468
 
469
+ df_metric7 = bld_hazard.merge(df_disp_per_bld,how='left',left_on='bldid',right_on='bldid')[['bldid','residents','individ']]
470
  df_metric7.rename(columns={'individ':'metric7'}, inplace=True)
471
+ df_metric7['metric7'] = (df_metric7['metric7'].fillna(0) * capacity).astype(int)
472
+ df_metric7['metric7'] = df_metric7[['residents','metric7']].min(axis=1)
473
  df_metric7['metric7'] = df_metric7['metric7'].fillna(0).astype(int)
474
 
475
 
tomorrowcities/content/articles/policies.md CHANGED
@@ -46,13 +46,13 @@ the damage curve value for special facilities by increasing the height of the st
46
  ### Policy 5: Shelter Law - All low-income and informal settlements should have physical and free access to community centres and shelters
47
  Expected outcome: Social Vulnerability reduction - reducing the effects of displacement and other issues such as food insecurity.
48
  Concerns: Implementation/Enforcement – evidence that some shelters remain unfunded or little effective despite their physical existence
49
- In implementation, we filter residential buildings in low income regions, and slight increase the height levels.
50
 
51
  ### Policy 6: Funding community-based networks in low-income areas (holistic approaches)
52
  Expected outcome: Social Vulnerability reduction - meeting diverse emergency needs
53
  Concerns: Implementation/Enforcement – funds could not be available as soon as hazards hit, decreasing their effectivity. Not certain how groups would allocate funding.
54
  Implementation: filter non
55
- In implementation, we filter commercial buildings in low income regions, and slight increase the height levels.
56
 
57
  ### Policy 7: Urban farming programs
58
  Expected outcome: Exposure Reduction - reserve of % of land to urban farming (by residents) in hazard-prone areas. Social Vulnerability reduction due to improved food security.
 
46
  ### Policy 5: Shelter Law - All low-income and informal settlements should have physical and free access to community centres and shelters
47
  Expected outcome: Social Vulnerability reduction - reducing the effects of displacement and other issues such as food insecurity.
48
  Concerns: Implementation/Enforcement – evidence that some shelters remain unfunded or little effective despite their physical existence
49
+ In implementation, we filter residential buildings in low income regions, and slightly increase the height levels.
50
 
51
  ### Policy 6: Funding community-based networks in low-income areas (holistic approaches)
52
  Expected outcome: Social Vulnerability reduction - meeting diverse emergency needs
53
  Concerns: Implementation/Enforcement – funds could not be available as soon as hazards hit, decreasing their effectivity. Not certain how groups would allocate funding.
54
  Implementation: filter non
55
+ In implementation, we filter commercial buildings in low income regions, and slightly increase the height levels.
56
 
57
  ### Policy 7: Urban farming programs
58
  Expected outcome: Exposure Reduction - reserve of % of land to urban farming (by residents) in hazard-prone areas. Social Vulnerability reduction due to improved food security.
tomorrowcities/content/articles/welcome.md CHANGED
@@ -15,6 +15,8 @@ category:
15
  TCDSE is a web application designed to conduct computational tasks to generate information needed for decision mechanisms in designing future cities. The web application, which will be referred as TCDSE for short, contains a computational engine capable of executing several hazard scenarios on different exposure datasets and infrastructures.
16
 
17
  ## What is New?
 
 
18
  ### New policies
19
  * Eight new policies are added. See their definitions [here](/docs/policies)
20
  * New info related to flood damage assessment is added [here](/docs/flood)
 
15
  TCDSE is a web application designed to conduct computational tasks to generate information needed for decision mechanisms in designing future cities. The web application, which will be referred as TCDSE for short, contains a computational engine capable of executing several hazard scenarios on different exposure datasets and infrastructures.
16
 
17
  ## What is New?
18
+ Implementation Capacity Score is added. If medium or low is selected, then building-level metrics is increased by 25% and 50%, respectively. If high is selected, there is no change in the metrics.
19
+
20
  ### New policies
21
  * Eight new policies are added. See their definitions [here](/docs/policies)
22
  * New info related to flood damage assessment is added [here](/docs/flood)
tomorrowcities/pages/engine.py CHANGED
@@ -122,6 +122,7 @@ layers = solara.reactive({
122
  '9': {'id':9, 'label': 'P9', 'description': 'Waste collection and rivers cleaning program ', 'applied': solara.reactive(False)},
123
  '10': {'id':10, 'label': 'P10', 'description': 'Enforcement of environmental protection zones', 'applied': solara.reactive(False)},
124
  },
 
125
  'metrics': {
126
  "metric1": {"desc": "Number of workers unemployed", "value": 0, "max_value": 100},
127
  "metric2": {"desc": "Number of children with no access to education", "value": 0, "max_value": 100},
@@ -487,7 +488,16 @@ def ExecutePanel():
487
  fragility if hazard == "earthquake" else vulnerability,
488
  hazard,policies=policies)
489
  buildings['ds'] = list(df_bld_hazard['ds'])
490
- computed_metrics, df_metrics = calculate_metrics(buildings, household, individual, hazard, policies=policies)
 
 
 
 
 
 
 
 
 
491
 
492
  print(computed_metrics)
493
  for metric in df_metrics.keys():
@@ -521,11 +531,19 @@ def ExecutePanel():
521
  # Execute the thread only when the depencency is changed
522
  result = solara.use_thread(execute_engine, dependencies=[execute_counter])
523
 
524
- with solara.Row(justify="center"):
525
- solara.ToggleButtonsMultiple(value=infra, on_value=set_infra, values=["building","power"])
526
- with solara.Row(justify="center"):
527
- solara.ToggleButtonsSingle(value=hazard, on_value=set_hazard, values=["earthquake","flood"])
528
-
 
 
 
 
 
 
 
 
529
  PolicyPanel()
530
  solara.ProgressLinear(value=False)
531
  solara.Button("Calculate", on_click=on_click, outlined=True,
 
122
  '9': {'id':9, 'label': 'P9', 'description': 'Waste collection and rivers cleaning program ', 'applied': solara.reactive(False)},
123
  '10': {'id':10, 'label': 'P10', 'description': 'Enforcement of environmental protection zones', 'applied': solara.reactive(False)},
124
  },
125
+ 'implementation_capacity_score': solara.reactive("high"),
126
  'metrics': {
127
  "metric1": {"desc": "Number of workers unemployed", "value": 0, "max_value": 100},
128
  "metric2": {"desc": "Number of children with no access to education", "value": 0, "max_value": 100},
 
488
  fragility if hazard == "earthquake" else vulnerability,
489
  hazard,policies=policies)
490
  buildings['ds'] = list(df_bld_hazard['ds'])
491
+
492
+ implementation_capacity_score = layers.value['implementation_capacity_score'].value
493
+ if implementation_capacity_score == 'medium':
494
+ capacity = 1.25
495
+ elif implementation_capacity_score == 'low':
496
+ capacity = 1.50
497
+ else:
498
+ capacity = 1
499
+ computed_metrics, df_metrics = calculate_metrics(buildings, household,
500
+ individual, hazard, policies=policies,capacity=capacity)
501
 
502
  print(computed_metrics)
503
  for metric in df_metrics.keys():
 
531
  # Execute the thread only when the depencency is changed
532
  result = solara.use_thread(execute_engine, dependencies=[execute_counter])
533
 
534
+ with solara.GridFixed(columns=2):
535
+ solara.Text("Infrastructure Type")
536
+ with solara.Row(justify="right"):
537
+ solara.ToggleButtonsMultiple(value=infra, on_value=set_infra, values=["building","power"])
538
+ solara.Text("Hazard")
539
+ with solara.Row(justify="right"):
540
+ solara.ToggleButtonsSingle(value=hazard, on_value=set_hazard, values=["earthquake","flood"])
541
+ with solara.Tooltip("Building-level metrics will be increased by 25% and 50% for medium and low"):
542
+ solara.Text("Implementation Capacity Score")
543
+ with solara.Row(justify="right"):
544
+ solara.ToggleButtonsSingle(value=layers.value['implementation_capacity_score'].value,
545
+ values=['low','medium','high'],
546
+ on_value=layers.value['implementation_capacity_score'].set)
547
  PolicyPanel()
548
  solara.ProgressLinear(value=False)
549
  solara.Button("Calculate", on_click=on_click, outlined=True,