Skip to content

Commit 5b01c13

Browse files
committed
updated tests and copyright license
1 parent 86dd922 commit 5b01c13

24 files changed

+117
-59
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
last_test_run.log
66
.coverage
77
*.png
8-
.ropeproject
8+
.ropeproject
9+
*~
10+
*_flymake.py

qa_tests/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

qa_tests/bcr_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

qa_tests/classical_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

qa_tests/event_based_test.py

+91-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License
@@ -19,6 +19,8 @@
1919
import collections
2020
import unittest
2121
import numpy
22+
import random
23+
import itertools
2224

2325
from risklib import api
2426
from risklib import scientific
@@ -110,18 +112,19 @@
110112
],
111113

112114
expected_poes=[
113-
[1., 0.947368, 0.894737, 0.842105, 0.789474, 0.736842, 0.684211,
114-
0.631579, 0.578947, 0.526316, 0.473684, 0.421053, 0.368421,
115-
0.315789, 0.263158, 0.210526, 0.157895, 0.105263, 0.052632, 0.],
116-
[1., 0.98063792, 0.96127585, 0.94191377, 0.9225517,
117-
0.90318962, 0.88382754, 0.86446547, 0.84510339, 0.82574132,
118-
0.80637924, 0.78701717, 0.76765509, 0.74829301, 0.72893094,
119-
0.70956886, 0.69020679, 0.67084471, 0.65148263, 0.63212056],
120-
[1., 0.947368, 0.894737, 0.842105, 0.789474, 0.736842,
121-
0.684211, 0.631579, 0.578947, 0.526316, 0.473684, 0.421053,
122-
0.368421, 0.315789, 0.263158, 0.210526, 0.157895, 0.105263,
123-
0.052632, 0.],
124-
],
115+
[1., 0.94736842, 0.89473684, 0.84210526,
116+
0.78947368, 0.7368421, 0.68421052, 0.63157895, 0.57894737, 0.52631579,
117+
0.47368421, 0.42105263, 0.36842105, 0.31578947, 0.26315789,
118+
0.21052632, 0.15789474, 0.10526316, 0.05263158, 0.],
119+
[1., 0.98063792,
120+
0.96127585, 0.94191377, 0.9225517, 0.90318962, 0.88382754,
121+
0.86446547, 0.84510339, 0.82574132, 0.80637924, 0.78701717,
122+
0.76765509, 0.74829301, 0.72893094, 0.70956886, 0.69020679,
123+
0.67084471, 0.65148263, 0.63212056],
124+
[1., 0.947368, 0.894737,
125+
0.842105, 0.789474, 0.736842, 0.684211, 0.631579, 0.578947,
126+
0.526316, 0.473684, 0.421053, 0.368421, 0.315789, 0.263158,
127+
0.210526, 0.157895, 0.105263, 0.052632, 0.], ],
125128

126129
expected_losses=numpy.array([
127130
[40.5835007, 70.37142354, 81.78761801, 94.22512956,
@@ -147,9 +150,53 @@
147150

148151
class EventBasedTestCase(unittest.TestCase):
149152

150-
def assert_allclose(self, expected, actual):
151-
return numpy.testing.assert_allclose(
152-
expected, actual, atol=0.0, rtol=0.05)
153+
def test_mean_based_with_no_correlation(self):
154+
# This is a regression test. Data has not been checked
155+
vf = (
156+
scientific.VulnerabilityFunction(
157+
[0.001, 0.2, 0.3, 0.5, 0.7], [0.01, 0.1, 0.2, 0.4, 0.8],
158+
[0.01, 0.02, 0.02, 0.01, 0.03], "LN"))
159+
calc = api.ProbabilisticEventBased(
160+
vf, 30, 120, seed=1, correlation=0, curve_resolution=4)
161+
162+
outputs = calc([scientific.Asset(1000), scientific.Asset(2000)],
163+
[[10, 20, 30, 40, 50], [1, 2, 3, 4, 5]])
164+
165+
numpy.testing.assert_allclose(
166+
[0.80732874, 0.82524302, 0.8401855, 0.84260182],
167+
outputs[0].loss_ratio_curve.abscissae)
168+
169+
def test_mean_based_with_partial_correlation(self):
170+
# This is a regression test. Data has not been checked
171+
vf = (
172+
scientific.VulnerabilityFunction(
173+
[0.001, 0.2, 0.3, 0.5, 0.7], [0.01, 0.1, 0.2, 0.4, 0.8],
174+
[0.01, 0.02, 0.02, 0.01, 0.03], "LN"))
175+
calc = api.ProbabilisticEventBased(
176+
vf, 30, 120, seed=1, correlation=0.5, curve_resolution=4)
177+
178+
outputs = calc([scientific.Asset(1000), scientific.Asset(2000)],
179+
[[10, 20, 30, 40, 50], [1, 2, 3, 4, 5]])
180+
181+
numpy.testing.assert_allclose(
182+
[0.77366888, 0.79923542, 0.81229682, 0.82383648],
183+
outputs[0].loss_ratio_curve.abscissae)
184+
185+
def test_mean_based_with_perfect_correlation(self):
186+
# This is a regression test. Data has not been checked
187+
vf = (
188+
scientific.VulnerabilityFunction(
189+
[0.001, 0.2, 0.3, 0.5, 0.7], [0.01, 0.1, 0.2, 0.4, 0.8],
190+
[0.01, 0.02, 0.02, 0.01, 0.03], "LN"))
191+
calc = api.ProbabilisticEventBased(
192+
vf, 30, 120, seed=1, correlation=1, curve_resolution=4)
193+
194+
outputs = calc([scientific.Asset(1000), scientific.Asset(2000)],
195+
[[10, 20, 30, 40, 50], [1, 2, 3, 4, 5]])
196+
197+
numpy.testing.assert_allclose(
198+
[0.76161603, 0.78226872, 0.79620137, 0.81240868],
199+
outputs[0].loss_ratio_curve.abscissae)
153200

154201
def test_mean_based(self):
155202
vulnerability_function_rm = (
@@ -181,16 +228,19 @@ def test_mean_based(self):
181228
asset_output.conditional_losses[CONDITIONAL_LOSS_POES],
182229
delta=0.05 * mb.expected_loss_map[i])
183230

184-
self.assert_allclose(mb.expected_poes,
185-
asset_output.loss_ratio_curve.ordinates)
231+
numpy.testing.assert_allclose(
232+
mb.expected_poes, asset_output.loss_ratio_curve.ordinates,
233+
rtol=10E-4)
186234

187-
self.assert_allclose(mb.expected_poes,
188-
asset_output.loss_curve.ordinates)
235+
numpy.testing.assert_allclose(
236+
mb.expected_poes, asset_output.loss_curve.ordinates,
237+
rtol=10E-4)
189238

190-
self.assert_allclose(mb.expected_losses[i],
191-
asset_output.loss_curve.abscissae)
239+
numpy.testing.assert_allclose(
240+
mb.expected_losses[i], asset_output.loss_curve.abscissae,
241+
rtol=10E-4)
192242

193-
self.assert_allclose(
243+
numpy.testing.assert_allclose(
194244
mb.expected_losses[2] / mb.input_models_asset[2].value,
195245
asset_output_rc.loss_ratio_curve.abscissae)
196246

@@ -199,18 +249,22 @@ def test_mean_based(self):
199249
asset_output_rc.conditional_losses[CONDITIONAL_LOSS_POES],
200250
delta=0.05 * mb.expected_loss_map[2])
201251

202-
self.assert_allclose(mb.expected_poes,
203-
asset_output_rc.loss_ratio_curve.ordinates)
252+
numpy.testing.assert_allclose(
253+
mb.expected_poes, asset_output_rc.loss_ratio_curve.ordinates,
254+
rtol=10E-4)
204255

205-
self.assert_allclose(mb.expected_poes,
206-
asset_output_rc.loss_curve.ordinates)
256+
numpy.testing.assert_allclose(
257+
mb.expected_poes, asset_output_rc.loss_curve.ordinates,
258+
rtol=10E-4)
207259

208-
self.assert_allclose(mb.expected_losses[2],
209-
asset_output_rc.loss_curve.abscissae)
260+
numpy.testing.assert_allclose(
261+
mb.expected_losses[2], asset_output_rc.loss_curve.abscissae,
262+
rtol=10E-5)
210263

211-
self.assert_allclose(
264+
numpy.testing.assert_allclose(
212265
mb.expected_losses[2] / mb.input_models_asset[2].value,
213-
asset_output_rc.loss_ratio_curve.abscissae)
266+
asset_output_rc.loss_ratio_curve.abscissae,
267+
rtol=10E-5)
214268

215269
def test_insured_loss_mean_based(self):
216270
vulnerability_function_rm = (
@@ -235,10 +289,12 @@ def test_insured_loss_mean_based(self):
235289
asset_output_rc = calculator_rc([il.input_models_asset[2]], [gmf[2]])
236290

237291
for i, asset_output in enumerate(asset_output_rm + asset_output_rc):
238-
self.assert_allclose(
292+
numpy.testing.assert_allclose(
239293
il.expected_poes[i],
240-
asset_output.insured_losses.ordinates)
294+
asset_output.insured_losses.ordinates,
295+
rtol=10E-5)
241296

242-
self.assert_allclose(
297+
numpy.testing.assert_allclose(
243298
il.expected_losses[i],
244-
asset_output.insured_losses.abscissae)
299+
asset_output.insured_losses.abscissae,
300+
rtol=10E-5)

qa_tests/scenario_damage_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

qa_tests/scenario_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

risklib/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

risklib/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

risklib/curve.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

risklib/models/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

risklib/scientific.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
# Copyright (c) 2010-2012, GEM Foundation.
3+
# Copyright (c) 2010-2013, GEM Foundation.
44
#
55
# OpenQuake Risklib is free software: you can redistribute it and/or
66
# modify it under the terms of the GNU Affero General Public License

risklib/tests/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

risklib/tests/api_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

risklib/tests/benefit_cost_ratio_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2010-2012, GEM Foundation.
1+
# Copyright (c) 2010-2013, GEM Foundation.
22
#
33
# OpenQuake Risklib is free software: you can redistribute it and/or
44
# modify it under the terms of the GNU Affero General Public License

risklib/tests/classical_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2010-2012, GEM Foundation.
1+
# Copyright (c) 2010-2013, GEM Foundation.
22
#
33
# OpenQuake Risklib is free software: you can redistribute it and/or
44
# modify it under the terms of the GNU Affero General Public License

risklib/tests/curve_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# vim: tabstop=4 shiftwidth=4 softtabstop=4
33

4-
# Copyright (c) 2010-2012, GEM Foundation.
4+
# Copyright (c) 2010-2013, GEM Foundation.
55
#
66
# OpenQuake Risklib is free software: you can redistribute it and/or
77
# modify it under the terms of the GNU Affero General Public License

risklib/tests/event_based_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

risklib/tests/range_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

risklib/tests/scenario_damage_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2010-2012, GEM Foundation.
1+
# Copyright (c) 2010-2013, GEM Foundation.
22
#
33
# OpenQuake Risklib is free software: you can redistribute it and/or
44
# modify it under the terms of the GNU Affero General Public License

risklib/tests/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2010-2012, GEM Foundation.
2+
# Copyright (c) 2010-2013, GEM Foundation.
33
#
44
# OpenQuake Risklib is free software: you can redistribute it and/or
55
# modify it under the terms of the GNU Affero General Public License

risklib/tests/vulnerability_function_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# vim: tabstop=4 shiftwidth=4 softtabstop=4
33

4-
# Copyright (c) 2010-2012, GEM Foundation.
4+
# Copyright (c) 2010-2013, GEM Foundation.
55
#
66
# OpenQuake Risklib is free software: you can redistribute it and/or
77
# modify it under the terms of the GNU Affero General Public License

risklib/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
# Copyright (c) 2010-2012, GEM Foundation.
3+
# Copyright (c) 2010-2013, GEM Foundation.
44
#
55
# OpenQuake Risklib is free software: you can redistribute it and/or
66
# modify it under the terms of the GNU Affero General Public License

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# oq-risklib: The Risk Library
2-
# Copyright (C) 2012 GEM Foundation
2+
# Copyright (C) 2013 GEM Foundation
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU Affero General Public License as
@@ -19,7 +19,7 @@
1919
Comments, suggestions and criticisms from the community are always
2020
very welcome.
2121
22-
Copyright (C) 2012 GEM Foundation.
22+
Copyright (C) 2013 GEM Foundation.
2323
"""
2424
from setuptools import setup, find_packages
2525

0 commit comments

Comments
 (0)