Skip to content

DamageProbabilityAnalysis#

DamageProbabilityAnalysis is the convenience class that combines vulnerability and fragility analysis for one (building_type, resistance_type) pair. Use it when you want both curve families and optional saved plots or JSON output.

Inputs#

Inputs are inherited from FragilityCalculator:

Input Default Notes
prob_ds_file_path aggregated pickle in Outputs/ Must contain (building_type, resistance_type) as a key.
building_type 1 Building type key m.
resistance_type 1 Resistance/configuration key c, 1-based.
wind_scale_lines [74, 95, 110, 130, 157] Plot guide lines in mph.
ds_thresholds [0.03, 0.09, 0.22, 0.46] Damage-ratio thresholds.
output_dir Outputs Directory used by save_analysis_results().

The required file dependencies are the aggregated probability pickle plus Inputs/WindSpeed.json, Inputs/FloodDepth.json, and Inputs/DamageState.json.

Outputs And Returns#

Method Returns Side effects
generate_analysis() Dictionary with vulnerability_curve and fragility_curves. None.
save_analysis_results(file_name=None) Path to saved JSON file. Writes JSON under output_dir.
plot_analysis_results(save_path=None) List of two matplotlib figures. Shows plots and optionally writes PNG files.

When AUTO_EXECUTE_METHODS=True, inherited attributes expected_damage_ratio, vulnerability_curve, and fragility_curves are available immediately after construction.

Configuration Behavior#

AUTO_LOAD_DATASETS=True loads all required data during construction. AUTO_LOAD_DATASETS=False requires manual calls to load_prob_damage_states(), load_wind_speed(), load_flood_depth(), and load_damage_state().

AUTO_EXECUTE_METHODS=True computes both vulnerability and fragility outputs during construction through the parent classes. With False, compute and assign outputs manually before calling generate_analysis() or save/plot helpers.

Minimal Examples#

Automatic:

from cheersafe.config import Config
from cheersafe.damage_probability_analysis import DamageProbabilityAnalysis

Config.AUTO_LOAD_DATASETS = True
Config.AUTO_EXECUTE_METHODS = True

analysis = DamageProbabilityAnalysis(
    building_type=1,
    resistance_type=1,
    prob_ds_file_path="Outputs/ProbDS_wfd_dictMaxIter50_aggregated.pkl",
)
summary = analysis.generate_analysis()
json_path = analysis.save_analysis_results()

Manual control:

from cheersafe.config import Config
from cheersafe.damage_probability_analysis import DamageProbabilityAnalysis

Config.AUTO_LOAD_DATASETS = False
Config.AUTO_EXECUTE_METHODS = False

analysis = DamageProbabilityAnalysis(
    building_type=1,
    resistance_type=1,
    prob_ds_file_path="Outputs/ProbDS_wfd_dictMaxIter50_aggregated.pkl",
)
analysis.load_prob_damage_states()
analysis.load_wind_speed()
analysis.load_flood_depth()
analysis.load_damage_state()
analysis.expected_damage_ratio, analysis.vulnerability_curve = (
    analysis.calculate_vulnerability_curve()
)
analysis.fragility_curves = analysis.calculate_fragility_curves()
summary = analysis.generate_analysis()