Skip to content

Commit

Permalink
Use DLassessment calculate_demand to read demand in auto_pop
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyan1214 committed Nov 26, 2024
1 parent a0e64f6 commit ad5c9d0
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions pelicun/resources/auto/Hazus_Earthquake_IM.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import pandas as pd

import pelicun
import pelicun.file_io
from pelicun.assessment import DLCalculationAssessment

ap_design_level = {1940: 'LC', 1975: 'MC', 2100: 'HC'}
# original:
Expand Down Expand Up @@ -409,26 +409,40 @@ def getHAZUSBridgeSlightDamageModifier(hazus_class, aim):
return None
demand_path = Path(aim['DL']['Demands']['DemandFilePath']).resolve()
sample_size = int(aim['DL']['Demands']['SampleSize'])
raw_demands = pd.read_csv(demand_path, index_col=0)
demands = pelicun.file_io.load_data(raw_demands)
edp_types = demands.columns.get_level_values(1)
length_unit = aim['GeneralInformation']['units']['length']
coupled_demands = aim['Applications']['DL']['ApplicationData']['coupled_EDP']
assessment = DLCalculationAssessment(config_options=None)
assessment.calculate_demand(
demand_path=demand_path,
collapse_limits=None,
length_unit=length_unit,
demand_calibration=None,
sample_size=sample_size,
demand_cloning=None,
residual_drift_inference=None,
coupled_demands=coupled_demands,
)
demand_sample, _ = assessment.demand.save_sample(
save_units=True
)
edp_types = demand_sample.columns.get_level_values(level='type')
if (edp_types == 'SA_0.3').sum() != 1:
msg = (
'The demand file does not contain the required EDP type SA_0.3'
' or contains multiple instances of it.'
)
raise ValueError(msg)
sa_0p3 = demands.loc[ # noqa: PD011
:, demands.columns.get_level_values(1) == 'SA_0.3'
sa_0p3 = demand_sample.loc[ # noqa: PD011
:, demand_sample.columns.get_level_values(level='type') == 'SA_0.3'
].values.flatten()
if (edp_types == 'SA_1.0').sum() != 1:
msg = (
'The demand file does not contain the required EDP type SA_1.0'
' or contains multiple instances of it.'
)
raise ValueError(msg)
sa_1p0 = demands.loc[ # noqa: PD011
:, demands.columns.get_level_values(1) == 'SA_1.0'
sa_1p0 = demand_sample.loc[ # noqa: PD011
:, demand_sample.columns.get_level_values(level='type') == 'SA_1.0'
].values.flatten()

ratio = 2.5 * sa_1p0 / sa_0p3
Expand Down

0 comments on commit ad5c9d0

Please sign in to comment.