Skip to content

DamageRatioExporter#

DamageRatioExporter collects component-level damage-ratio records during a Monte Carlo damage-probability run and exports iteration-averaged CSV tables. Use it directly for custom post-processing, or let DamageProbabilityCalculation create it when Config.EXPORT_DETAILED_DAMAGE_RATIOS=True.

Inputs#

Constructor inputs:

Input Type Units or indexing
building_type int CHEERSafe building type id.
cindex int Public component configuration id; 1-based.
collected_data list[dict] Optional existing records. Defaults to an empty list.

collect_detailed_ratios() expects a computed DamageRatioCalculation object with total, explicit wind, implicit wind, and implicit flood damage-ratio values available. Damage ratios are unitless fractions.

add_record() takes zero-based wind-orientation, wind-speed, and flood-depth indices plus the Monte Carlo iteration number.

Outputs And Returns#

Method Returns Side effects
collect_detailed_ratios(damage_ratios) dict[str, float] with standardized damage-ratio columns. None.
add_record(...) None Appends one record to collected_data.
aggregate_and_save_to_csv(output_dir=None) CSV path, or "" when there is no data. Writes DetailedDR_m{building_type}_c{cindex}_iter{NUM_OF_ITERATIONS}.csv.
clear() None Clears collected_data.

CSV rows are grouped by m, c, wind_orientation_index, wind_speed_index, and flood_depth_index; damage-ratio columns are averaged over iteration.

Configuration Behavior#

DamageRatioExporter does not load datasets and is not gated by Config.AUTO_LOAD_DATASETS or Config.AUTO_EXECUTE_METHODS. It uses Config.OUTPUTS_PATH as the default output directory and Config.NUM_OF_ITERATIONS in the file name.

Minimal Examples#

Automatic use through the main workflow:

from cheersafe.config import Config

Config.EXPORT_DETAILED_DAMAGE_RATIOS = True
# Run DamageProbabilityCalculation.get_average_damage_probability().
# DetailedDR_m{m}_c{c}_iter{NUM_OF_ITERATIONS}.csv files are written.

Manual aggregation:

from cheersafe.damage_probability_calculation import DamageRatioExporter

exporter = DamageRatioExporter(building_type=1, cindex=1)
exporter.add_record(
    wind_orientation_index=0,
    wind_speed_index=0,
    flood_depth_index=0,
    iteration=0,
    detailed_ratios={
        "dr_total": 0.0,
        "dr_explicit": 0.0,
        "dr_implicit": 0.0,
        "dr_exp_wind_RC": 0.0,
        "dr_exp_wind_RS": 0.0,
        "dr_exp_wind_RWC": 0.0,
        "dr_exp_wind_O": 0.0,
        "dr_exp_wind_W": 0.0,
        "dr_imp_wind_I": 0.0,
        "dr_imp_wind_E": 0.0,
        "dr_imp_wind_M": 0.0,
        "dr_imp_wind_P": 0.0,
        "dr_imp_flood": 0.0,
    },
)
csv_path = exporter.aggregate_and_save_to_csv()
exporter.clear()