Skip to content

DamageProbabilityProvider#

DamageProbabilityProvider loads the damage-state probability library and returns the expected damage ratio for one building type, one resistance configuration and one (wind speed, flood depth) pair. In the current chain it is the source of the damage library for LookupTableBuilder and the reference kernel behind the joint wind-flood surface used by combine_mode="joint". Use it directly for small queries.

Inputs#

Input Default Shape Units or indexing
damage_state_path Inputs/DamageState.json [50, 2] damage-state id, damage ratio.
wind_speed_path Inputs/WindSpeed.json [25, 3] id, mph, m/s; lookup uses column 2.
flood_depth_path Inputs/FloodDepth.json [136, 3] id, inches, meters; lookup uses column 2.
prob_ds_file_path aggregate pickle in Config.OUTPUTS_PATH dict[(m, c), array] Keys use building type and 1-based c.
legacy_dir legacy output folder individual files Fallback path when a key is absent from the dictionary.

Method inputs:

Method Inputs
load_damage_state_probabilities(m, c) m building type, c 1-based resistance/configuration id.
calculate_damage_ratio(wind_speed, flood_depth, m, c) Wind speed in m/s and flood depth in metres (column 2 of the runtime grids), plus (m, c).

Outputs And Returns#

Method Returns Side effects
load_damage_state_probabilities(m, c) ProbDS_wfd array [wind, flood, damage_state]. May read fallback file; returns a zero array if unavailable.
calculate_damage_ratio(...) Unitless expected damage ratio sum_d p_d DR_d at the first wind and flood bins at or above the query. None beyond fallback loading.

The bin selection is the ceil convention of BuildingLossEstimator; the lookup tables built by LookupTableBuilder equal calculate_damage_ratio evaluated at the table knots with the other hazard at zero.

Configuration Behavior#

This class loads damage states, wind speeds, flood depths and the probability dictionary during __post_init__ regardless of Config.AUTO_LOAD_DATASETS, and does not use Config.AUTO_EXECUTE_METHODS. Config.NUM_OF_ITERATIONS names the default aggregate file when prob_ds_file_path is not provided. BaseLossEstimation creates a provider from its own path fields unless one is injected through damage_provider.

Minimal Examples#

Direct query:

from cheersafe.loss_estimation import DamageProbabilityProvider

provider = DamageProbabilityProvider(
    prob_ds_file_path="Outputs/ProbDS_wfd_dictMaxIter3000_aggregated.pkl"
)
ratio = provider.calculate_damage_ratio(35.0, 0.0, m=1, c=1)

Injecting a provider into the loss chain:

from cheersafe.loss_estimation import DamageProbabilityProvider, LookupTableBuilder

provider = DamageProbabilityProvider(
    prob_ds_file_path="Outputs/ProbDS_wfd_dictMaxIter3000_aggregated.pkl"
)
builder = LookupTableBuilder(damage_provider=provider)
print(builder.wind_lookup.shape, builder.flood_lookup.shape)