Huseyin Kaya commited on
Commit
e7f3412
·
unverified ·
2 Parent(s): 24a9defef5d52c

Merge pull request #104 from TomorrowsCities/feature_policy_8

Browse files
tomorrowcities/backend/engine.py CHANGED
@@ -443,6 +443,7 @@ def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensit
443
  earthquake_intensity_unit = 'm/s2',
444
  cdf_median_increase_in_percent = 0.20,
445
  flood_depth_reduction = 0.20,
 
446
  ):
447
 
448
  print('cdf_median_increase_in_percent',cdf_median_increase_in_percent)
@@ -567,13 +568,6 @@ def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensit
567
  idx = (gdf_building_intensity['rnd'] < 0.70) & (gdf_building_intensity['occupancy'] == 'Res')
568
  gdf_building_intensity.loc[idx,'occupancy'] = 'Agri'
569
 
570
- if 8 in policies:
571
- if hazard_type == HAZARD_FLOOD or hazard_type == HAZARD_DEBRIS:
572
- max_height = gdf_building_intensity['height'].max()
573
- idx = gdf_building_intensity['specialfac'] == 0
574
- gdf_building_intensity.loc[idx, 'height'] = gdf_building_intensity[idx]['height'].apply(lambda h: min(max_height, h+4))
575
- gdf_building_intensity['storeys'] = gdf_building_intensity['height'].apply(lambda h: str(h)+'s')
576
-
577
  if 9 in policies:
578
  if hazard_type == HAZARD_FLOOD or hazard_type == HAZARD_DEBRIS:
579
  max_height = gdf_building_intensity['height'].max()
@@ -669,12 +663,16 @@ def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensit
669
  # Increase medians *cdf_median_increase_in_percent* percent for residential buildings
670
  applied_to = (bld_eq['occupancy'] == 'Res') & ((bld_eq['freqincome'] == 'lowIncomeA') | (bld_eq['freqincome'] == 'lowIncomeB'))
671
  bld_eq.loc[applied_to, med_cols] = bld_eq.loc[applied_to, med_cols] * \
672
- ( 1 + cdf_median_increase_in_percent )
673
  if 6 in policies:
674
  # Increase medians *cdf_median_increase_in_percent* percent for residential buildings
675
  applied_to = bld_eq['occupancy']=='Res'
676
  bld_eq.loc[applied_to, med_cols] = bld_eq.loc[applied_to, med_cols] * \
677
  ( 1 + cdf_median_increase_in_percent )
 
 
 
 
678
 
679
  # Intensity measure calculation
680
  sa_list = np.array([float(x.split()[-1]) for x in bld_eq.columns if x.startswith('sa ')])
@@ -731,7 +729,11 @@ def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensit
731
  applied_to = bld_eq['occupancy'] == 'Res'
732
  bld_eq.loc[applied_to, imt_cols] = bld_eq.loc[applied_to, imt_cols] * \
733
  ( 1 - cdf_median_increase_in_percent )
734
-
 
 
 
 
735
  def computer_damage_state(row):
736
  intensity_in_g = row[row['imt_2']] / earthquake_intensity_normalization_factor
737
  prob_ds1 = np.interp(intensity_in_g, row['imls'], row['slight'])
@@ -758,7 +760,7 @@ def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensit
758
 
759
  elif hazard_type == HAZARD_FLOOD:
760
  bld_flood = gdf_building_intensity.merge(df_hazard, on='expstr', how='left')
761
-
762
  # reduce flood depth *flood_depth_reduction* cm
763
  # Effect of policies are stacked
764
  if 1 in policies:
@@ -771,6 +773,9 @@ def compute(gdf_landuse, gdf_buildings, df_household, df_individual,gdf_intensit
771
  if 6 in policies:
772
  applied_to = bld_flood['occupancy'] == 'Res'
773
  bld_flood.loc[applied_to, 'im'] = bld_flood.loc[applied_to, 'im'] - flood_depth_reduction
 
 
 
774
  bld_flood.loc[bld_flood['im'] < 0, 'im'] = 0
775
 
776
  x = np.array([0,0.5,1,1.5,2,3,4,5,6])
 
443
  earthquake_intensity_unit = 'm/s2',
444
  cdf_median_increase_in_percent = 0.20,
445
  flood_depth_reduction = 0.20,
446
+ damage_curve_suppress_factor = 0.9,
447
  ):
448
 
449
  print('cdf_median_increase_in_percent',cdf_median_increase_in_percent)
 
568
  idx = (gdf_building_intensity['rnd'] < 0.70) & (gdf_building_intensity['occupancy'] == 'Res')
569
  gdf_building_intensity.loc[idx,'occupancy'] = 'Agri'
570
 
 
 
 
 
 
 
 
571
  if 9 in policies:
572
  if hazard_type == HAZARD_FLOOD or hazard_type == HAZARD_DEBRIS:
573
  max_height = gdf_building_intensity['height'].max()
 
663
  # Increase medians *cdf_median_increase_in_percent* percent for residential buildings
664
  applied_to = (bld_eq['occupancy'] == 'Res') & ((bld_eq['freqincome'] == 'lowIncomeA') | (bld_eq['freqincome'] == 'lowIncomeB'))
665
  bld_eq.loc[applied_to, med_cols] = bld_eq.loc[applied_to, med_cols] * \
666
+ ( 1 + cdf_median_increase_in_percent )
667
  if 6 in policies:
668
  # Increase medians *cdf_median_increase_in_percent* percent for residential buildings
669
  applied_to = bld_eq['occupancy']=='Res'
670
  bld_eq.loc[applied_to, med_cols] = bld_eq.loc[applied_to, med_cols] * \
671
  ( 1 + cdf_median_increase_in_percent )
672
+ if 8 in policies:
673
+ applied_to = bld_eq['occupancy'] == 'Res'
674
+ bld_eq.loc[applied_to, med_cols] = bld_eq.loc[applied_to, med_cols] * \
675
+ ( 1 + cdf_median_increase_in_percent )
676
 
677
  # Intensity measure calculation
678
  sa_list = np.array([float(x.split()[-1]) for x in bld_eq.columns if x.startswith('sa ')])
 
729
  applied_to = bld_eq['occupancy'] == 'Res'
730
  bld_eq.loc[applied_to, imt_cols] = bld_eq.loc[applied_to, imt_cols] * \
731
  ( 1 - cdf_median_increase_in_percent )
732
+ if 8 in policies:
733
+ applied_to = bld_eq['occupancy'] == 'Res'
734
+ bld_eq.loc[applied_to, imt_cols] = bld_eq.loc[applied_to, imt_cols] * \
735
+ ( 1 - cdf_median_increase_in_percent )
736
+
737
  def computer_damage_state(row):
738
  intensity_in_g = row[row['imt_2']] / earthquake_intensity_normalization_factor
739
  prob_ds1 = np.interp(intensity_in_g, row['imls'], row['slight'])
 
760
 
761
  elif hazard_type == HAZARD_FLOOD:
762
  bld_flood = gdf_building_intensity.merge(df_hazard, on='expstr', how='left')
763
+ damage_curve_cols = ['hw0','hw0_5','hw1','hw1_5','hw2','hw3','hw4','hw5','hw6']
764
  # reduce flood depth *flood_depth_reduction* cm
765
  # Effect of policies are stacked
766
  if 1 in policies:
 
773
  if 6 in policies:
774
  applied_to = bld_flood['occupancy'] == 'Res'
775
  bld_flood.loc[applied_to, 'im'] = bld_flood.loc[applied_to, 'im'] - flood_depth_reduction
776
+ if 8 in policies:
777
+ applied_to = bld_flood['occupancy'] == 'Res'
778
+ bld_flood.loc[applied_to, damage_curve_cols] = bld_flood.loc[applied_to, damage_curve_cols] * damage_curve_suppress_factor
779
  bld_flood.loc[bld_flood['im'] < 0, 'im'] = 0
780
 
781
  x = np.array([0,0.5,1,1.5,2,3,4,5,6])
tomorrowcities/pages/engine.py CHANGED
@@ -53,6 +53,7 @@ def create_new_app_state():
53
  'cdf_median_increase_in_percent': solara.reactive(0.2),
54
  'threshold_increase_culvert_water_height': solara.reactive(0.2),
55
  'threshold_increase_road_water_height': solara.reactive(0.2),
 
56
  'flood_depth_reduction': solara.reactive(0.2),
57
  'dialog_message_to_be_shown': solara.reactive(None),
58
  'seed': solara.reactive(42),
@@ -245,15 +246,15 @@ def create_new_app_state():
245
  'selected_policies': solara.reactive([]),
246
  'policies': {
247
  '1': {'id':1, 'label': 'P1', 'description': 'Land and tenure security program', 'applied': solara.reactive(False)},
248
- '2': {'id':2, 'label': 'P2', 'description': 'State-led upgrading/retrofitting of low-income/informal housing', 'applied': solara.reactive(False)},
249
- '3': {'id':3, 'label': 'P3', 'description': 'Robust investment in WASH (water, sanitation and hygiene) and flood-control infrastructure', 'applied': solara.reactive(False)},
250
- '4': {'id':4, 'label': 'P4', 'description': 'Investments in road networks and public spaces through conventional paving', 'applied': solara.reactive(False)},
251
- '5': {'id':5, 'label': 'P5', 'description': 'Shelter Law - All low-income and informal settlements should have physical and free access to community centres and shelters', 'applied': solara.reactive(False)},
252
- '6': {'id':6, 'label': 'P6', 'description': 'Funding community-based networks in low-income areas (holistic approaches)', 'applied': solara.reactive(False)},
253
- '7': {'id':7, 'label': 'P7', 'description': 'Urban farming programs', 'applied': solara.reactive(False)},
254
- '8': {'id':8, 'label': 'P8', 'description': 'Emergency cash transfers to vulnerable households', 'applied': solara.reactive(False)},
255
- '9': {'id':9, 'label': 'P9', 'description': 'Waste collection and rivers cleaning program ', 'applied': solara.reactive(False)},
256
- '10': {'id':10, 'label': 'P10', 'description': 'Enforcement of environmental protection zones', 'applied': solara.reactive(False)},
257
  #'11': {'id':11, 'label': 'I1', 'description': 'DRR-oriented zoning and urban transformation', 'applied': solara.reactive(False)},
258
  #'12': {'id':12, 'label': 'I2', 'description': 'Increased monitoring and supervision on new constructions in terms of disaster-resilience', 'applied': solara.reactive(False)},
259
  #'13': {'id':13, 'label': 'I3', 'description': 'Taking social equality into consideration in the making of urbanisation and DRR policies', 'applied': solara.reactive(False)},
@@ -1381,6 +1382,7 @@ def ExecutePanel():
1381
  earthquake_intensity_unit = layers.value['earthquake_intensity_unit'].value
1382
  flood_depth_reduction = layers.value['flood_depth_reduction'].value
1383
  cdf_median_increase_in_percent = layers.value['cdf_median_increase_in_percent'].value
 
1384
 
1385
 
1386
  policies = [p['id'] for _, p in layers.value['policies'].items() if f"{p['label']}/{p['description']}" in layers.value['selected_policies'].value]
@@ -1410,6 +1412,7 @@ def ExecutePanel():
1410
  earthquake_intensity_unit=earthquake_intensity_unit,
1411
  cdf_median_increase_in_percent=cdf_median_increase_in_percent,
1412
  flood_depth_reduction=flood_depth_reduction,
 
1413
  )
1414
  else:
1415
  if fragility is None:
@@ -1427,6 +1430,7 @@ def ExecutePanel():
1427
  earthquake_intensity_unit=earthquake_intensity_unit,
1428
  cdf_median_increase_in_percent=cdf_median_increase_in_percent,
1429
  flood_depth_reduction=flood_depth_reduction,
 
1430
  )
1431
  buildings['ds'] = list(df_bld_hazard['ds'])
1432
  buildings['casualty'] = list(df_bld_hazard['casualty'])
@@ -1537,8 +1541,8 @@ def ExecutePanel():
1537
  if len(policies) > 0:
1538
  with solara.Column(gap="30px"):
1539
  # if at least one of the policies is selected
1540
- if bool(set({1,2,4,6}).intersection(set(policies))):
1541
- with solara.Tooltip('Effects policies 1,2,4,6. Code-level upgrade of residential buildings (percentage increase in median value of the CDF default: 0.2)'):
1542
  solara.InputFloat(label='cdf_median_increase_in_percent', value=layers.value['cdf_median_increase_in_percent'],
1543
  continuous_update=True)
1544
  if bool(set({1,2,3,6}).intersection(set(policies))):
@@ -1553,7 +1557,10 @@ def ExecutePanel():
1553
  with solara.Tooltip('Effects policies 4. Increasing water-depth threshold for roads'):
1554
  solara.InputFloat(label='threshold_increase_road_water_height', value=layers.value['threshold_increase_road_water_height'],
1555
  continuous_update=True)
1556
-
 
 
 
1557
  # The statements in this block are passed several times during thread execution
1558
  if result.error is not None:
1559
  execute_error.set(execute_error.value + str(result.error))
 
53
  'cdf_median_increase_in_percent': solara.reactive(0.2),
54
  'threshold_increase_culvert_water_height': solara.reactive(0.2),
55
  'threshold_increase_road_water_height': solara.reactive(0.2),
56
+ 'damage_curve_suppress_factor': solara.reactive(0.9),
57
  'flood_depth_reduction': solara.reactive(0.2),
58
  'dialog_message_to_be_shown': solara.reactive(None),
59
  'seed': solara.reactive(42),
 
246
  'selected_policies': solara.reactive([]),
247
  'policies': {
248
  '1': {'id':1, 'label': 'P1', 'description': 'Land and tenure security program', 'applied': solara.reactive(False)},
249
+ '2': {'id':2, 'label': 'P2', 'description': 'Housing retrofitting', 'applied': solara.reactive(False)},
250
+ '3': {'id':3, 'label': 'P3', 'description': 'Investment in water and sanitation', 'applied': solara.reactive(False)},
251
+ '4': {'id':4, 'label': 'P4', 'description': 'Investments in road networks', 'applied': solara.reactive(False)},
252
+ '5': {'id':5, 'label': 'P5', 'description': 'Access to more shelters', 'applied': solara.reactive(False)},
253
+ '6': {'id':6, 'label': 'P6', 'description': 'Funding community networks', 'applied': solara.reactive(False)},
254
+ '7': {'id':7, 'label': 'P7', 'description': 'Support for local livelihoods', 'applied': solara.reactive(False)},
255
+ '8': {'id':8, 'label': 'P8', 'description': 'Cash transfers to vulnerable groups', 'applied': solara.reactive(False)},
256
+ '9': {'id':9, 'label': 'P9', 'description': 'Waste collection and river cleaning program', 'applied': solara.reactive(False)},
257
+ '10': {'id':10, 'label': 'P10', 'description': 'Environmental protection zones', 'applied': solara.reactive(False)},
258
  #'11': {'id':11, 'label': 'I1', 'description': 'DRR-oriented zoning and urban transformation', 'applied': solara.reactive(False)},
259
  #'12': {'id':12, 'label': 'I2', 'description': 'Increased monitoring and supervision on new constructions in terms of disaster-resilience', 'applied': solara.reactive(False)},
260
  #'13': {'id':13, 'label': 'I3', 'description': 'Taking social equality into consideration in the making of urbanisation and DRR policies', 'applied': solara.reactive(False)},
 
1382
  earthquake_intensity_unit = layers.value['earthquake_intensity_unit'].value
1383
  flood_depth_reduction = layers.value['flood_depth_reduction'].value
1384
  cdf_median_increase_in_percent = layers.value['cdf_median_increase_in_percent'].value
1385
+ damage_curve_suppress_factor = layers.value['damage_curve_suppress_factor'].value
1386
 
1387
 
1388
  policies = [p['id'] for _, p in layers.value['policies'].items() if f"{p['label']}/{p['description']}" in layers.value['selected_policies'].value]
 
1412
  earthquake_intensity_unit=earthquake_intensity_unit,
1413
  cdf_median_increase_in_percent=cdf_median_increase_in_percent,
1414
  flood_depth_reduction=flood_depth_reduction,
1415
+ damage_curve_suppress_factor=damage_curve_suppress_factor
1416
  )
1417
  else:
1418
  if fragility is None:
 
1430
  earthquake_intensity_unit=earthquake_intensity_unit,
1431
  cdf_median_increase_in_percent=cdf_median_increase_in_percent,
1432
  flood_depth_reduction=flood_depth_reduction,
1433
+ damage_curve_suppress_factor=damage_curve_suppress_factor,
1434
  )
1435
  buildings['ds'] = list(df_bld_hazard['ds'])
1436
  buildings['casualty'] = list(df_bld_hazard['casualty'])
 
1541
  if len(policies) > 0:
1542
  with solara.Column(gap="30px"):
1543
  # if at least one of the policies is selected
1544
+ if bool(set({1,2,4,6,8}).intersection(set(policies))):
1545
+ with solara.Tooltip('Effects policies 1,2,4,6,8. Code-level upgrade of residential buildings (percentage increase in median value of the CDF default: 0.2)'):
1546
  solara.InputFloat(label='cdf_median_increase_in_percent', value=layers.value['cdf_median_increase_in_percent'],
1547
  continuous_update=True)
1548
  if bool(set({1,2,3,6}).intersection(set(policies))):
 
1557
  with solara.Tooltip('Effects policies 4. Increasing water-depth threshold for roads'):
1558
  solara.InputFloat(label='threshold_increase_road_water_height', value=layers.value['threshold_increase_road_water_height'],
1559
  continuous_update=True)
1560
+ if bool(set({8}).intersection(set(policies))):
1561
+ with solara.Tooltip('Effects policies 8. Suppress damage curves via multiplying this factor'):
1562
+ solara.InputFloat(label='damage_curve_suppress_factor', value=layers.value['damage_curve_suppress_factor'],
1563
+ continuous_update=True)
1564
  # The statements in this block are passed several times during thread execution
1565
  if result.error is not None:
1566
  execute_error.set(execute_error.value + str(result.error))