Skip to content

Commit

Permalink
Add test for detla aai_agg
Browse files Browse the repository at this point in the history
  • Loading branch information
Chahan Kropf committed Nov 4, 2022
1 parent 50d4733 commit 2f7ecad
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions climada/engine/unsequa/test/test_unsequa.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from climada.entity.entity_def import Entity
from climada.entity import Exposures
from climada.hazard import Hazard
from climada.engine import ImpactCalc
from climada.engine.unsequa import InputVar, CalcImpact, UncOutput, CalcCostBenefit, CalcDeltaImpact

from climada.util.constants import EXP_DEMO_H5, HAZ_DEMO_H5, ENT_DEMO_TODAY, ENT_DEMO_FUTURE
Expand Down Expand Up @@ -358,10 +359,23 @@ def test_calc_uncertainty_pass(self):
haz = haz_dem()
haz2 = haz_dem()
haz2.intensity *=2
unc_calc = CalcDeltaImpact(exp_unc, impf_unc, haz, exp_dem(), impf_dem(), haz2)
unc_data = unc_calc.make_sample( N=2)
unc_calc = CalcDeltaImpact(exp_unc, impf_dem(), haz, exp_dem(), impf_unc, haz2)
unc_data = unc_calc.make_sample(N=1)
unc_data = unc_calc.uncertainty(unc_data, calc_eai_exp=False, calc_at_event=False)

for [x_exp, x_paa, x_mdd], delta_aai_aag in zip(unc_data.samples_df.values, unc_data.aai_agg_unc_df.values):
exp1 = exp_unc.evaluate(x_exp=x_exp)
exp2 = exp_dem()
impf1 = impf_dem()
impf2 = impf_unc.evaluate(x_paa=x_paa, x_mdd=x_mdd)
haz1 = haz

imp1 = ImpactCalc(exp1, impf1, haz1).impact()
imp2 = ImpactCalc(exp2, impf2, haz2).impact()

self.assertAlmostEqual(imp2.aai_agg - imp1.aai_agg, delta_aai_aag)


self.assertEqual(unc_data.unit, exp_dem().value_unit)
self.assertListEqual(unc_calc.rp, [5, 10, 20, 50, 100, 250])
self.assertEqual(unc_calc.calc_eai_exp, False)
Expand Down Expand Up @@ -844,7 +858,7 @@ def test_calc_sensitivity_pass(self):
if __name__ == "__main__":
TESTS = unittest.TestLoader().loadTestsFromTestCase(TestInputVar)
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCalcDelta))
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestOutput))
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCalcImpact))
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCalcCostBenefit))
#TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestOutput))
#TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCalcImpact))
#TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCalcCostBenefit))
unittest.TextTestRunner(verbosity=2).run(TESTS)

0 comments on commit 2f7ecad

Please sign in to comment.