From ef6bfb46180d913147d6a2f050aa8b03c65535f9 Mon Sep 17 00:00:00 2001 From: EglantineGiraud Date: Thu, 2 Nov 2023 12:38:51 +0100 Subject: [PATCH] Onboarding World Resources Institute's thermal power plant physical climate vulnerability factors Onboarding World Resources Institute's thermal power plant physical climate vulnerability factors Signed-off-by: EglantineGiraud --- .../thermal_power_generation_models.py | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/physrisk/vulnerability_models/thermal_power_generation_models.py b/src/physrisk/vulnerability_models/thermal_power_generation_models.py index 91112e84..14129235 100644 --- a/src/physrisk/vulnerability_models/thermal_power_generation_models.py +++ b/src/physrisk/vulnerability_models/thermal_power_generation_models.py @@ -104,16 +104,16 @@ def get_distributions( assert isinstance(response_baseline, HazardEventDataResponse) baseline_curve = ExceedanceCurve(1.0 / response_baseline.return_periods, response_baseline.intensities) - inundation_protection_level = ( + protection_depth = ( 0.0 if len(response_baseline.intensities) == 0 else baseline_curve.get_value(1.0 / asset.get_inundation_protection_return_period()) ) intensity_curve = ExceedanceCurve(1.0 / response_scenario.return_periods, response_scenario.intensities) - if intensity_curve.values[0] < inundation_protection_level: - if inundation_protection_level < intensity_curve.values[-1]: - intensity_curve = intensity_curve.add_value_point(inundation_protection_level) + if intensity_curve.values[0] < protection_depth: + if protection_depth < intensity_curve.values[-1]: + intensity_curve = intensity_curve.add_value_point(protection_depth) intensities, probs = intensity_curve.get_probability_bins() probs = np.insert(probs, 0, intensity_curve.probs[0]) @@ -129,14 +129,20 @@ def get_distributions( elif asset.turbine in self.vuln_curves_by_type: curves = self.vuln_curves_by_type[asset.turbine] - impacts = [ - np.max([np.interp(intensity, curve.intensity, curve.impact_mean) for curve in curves]) - if inundation_protection_level < intensity and 0 < len(curves) - else 0.0 - for intensity in intensities - ] + if 0 < len(curves): + impacts = [ + np.max([np.interp(intensity, curve.intensity, curve.impact_mean) for curve in curves]) + for intensity in intensities + ] + else: + impacts = [0.0 for _ in intensities] + + # keep all bins, but make use of vulnerability matrix to apply protection level + # for improved performance we could truncate (and treat identity matrix as a special case) + # but this general version allows model uncertainties to be added + protection = np.where(protection_depth < intensities, 1.0, 0.0) - vul = VulnerabilityDistrib(self.hazard_type, intensities, impacts, np.eye(len(impacts))) + vul = VulnerabilityDistrib(self.hazard_type, intensities, impacts, np.diag(protection)) event = HazardEventDistrib(self.hazard_type, intensities, probs) return vul, event