Skip to content

Commit fd868bf

Browse files
committed
add tests to impact function
unit tests for set_step_ImpF unit tests for set_sigmoid_ImpF
1 parent 6f6df11 commit fd868bf

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

climada/entity/impact_funcs/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def set_sigmoid_ImpF(self, sig_mid, sig_shape, sig_max,
159159
""" Sigmoid type impact function hinging on three parameter. This type
160160
of impact function is very flexible for any sort of study/resolution.
161161
Parameters can be thought of as intercept (sig_mid), slope (sig_shape)
162-
and top (sig_max) of a sigmoid.
162+
and top (sig_max) of a sigmoid. More precisely, sig_mid refers to the
163+
intensity value where MDD equals 50% of sig_max.
163164
164165
For more information: https://en.wikipedia.org/wiki/Logistic_function
165166

climada/entity/impact_funcs/test/test_base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ def test_calc_mdr_pass(self):
3535
imp_fun.mdd = np.arange(0, 1, 0.1)
3636
new_inten = 17.2
3737
self.assertEqual(imp_fun.calc_mdr(new_inten), 0.029583999999999996)
38+
39+
def test_set_step(self):
40+
"""Check default impact function: step function"""
41+
imp_fun = ImpactFunc()
42+
imp_fun.set_step_ImpF(5, 0, 10)
43+
self.assertTrue(np.array_equal(imp_fun.paa, np.ones(4)))
44+
self.assertTrue(np.array_equal(imp_fun.mdd, np.array([0, 0, 1, 1])))
45+
self.assertTrue(np.array_equal(imp_fun.intensity, np.array([0, 5, 5, 10])))
46+
47+
def test_set_sigmoid(self):
48+
"""Check default impact function: sigmoid function"""
49+
imp_fun = ImpactFunc()
50+
imp_fun.set_sigmoid_ImpF(50., 2., 1.0, 0, 100)
51+
self.assertTrue(np.array_equal(imp_fun.paa, np.ones(20)))
52+
self.assertEqual(imp_fun.mdd[10], 0.5)
53+
self.assertEqual(imp_fun.mdd[-1], 1.0)
54+
self.assertTrue(np.array_equal(imp_fun.intensity, np.arange(0, 100, 5)))
3855

3956
# Execute Tests
4057
if __name__ == "__main__":

0 commit comments

Comments
 (0)