Skip to content

Commit b42e4fb

Browse files
committed
refactoring
1 parent 569964f commit b42e4fb

File tree

8 files changed

+479
-131
lines changed

8 files changed

+479
-131
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*.pyc
22
*.DS_Store
3+
\#*\#
4+
last_test_run.log
5+
.coverage

pylintrc

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
[MASTER]
2+
3+
# Specify a configuration file.
4+
#rcfile=
5+
6+
# Python code to execute, usually for sys.path manipulation such as
7+
# pygtk.require().
8+
#init-hook=
9+
init-hook=import sys; sys.path.append('/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/')
10+
11+
# Profiled execution.
12+
profile=no
13+
14+
# Add <file or directory> to the black list. It should be a base name, not a
15+
# path. You may set this option multiple times.
16+
ignore=CVS
17+
18+
# Pickle collected data for later comparisons.
19+
persistent=yes
20+
21+
# List of plugins (as comma separated values of python modules names) to load,
22+
# usually to register additional checkers.
23+
load-plugins=
24+
25+
26+
[MESSAGES CONTROL]
27+
28+
# Enable the message, report, category or checker with the given id(s). You can
29+
# either give multiple identifier separated by comma (,) or put this option
30+
# multiple time.
31+
#enable=
32+
33+
# Disable the message, report, category or checker with the given id(s). You
34+
# can either give multiple identifier separated by comma (,) or put this option
35+
# multiple time.
36+
#disable=
37+
38+
39+
[REPORTS]
40+
41+
# Set the output format. Available formats are text, parseable, colorized, msvs
42+
# (visual studio) and html
43+
output-format=text
44+
45+
# Include message's id in output
46+
include-ids=yes
47+
48+
# Put messages in a separate file for each module / package specified on the
49+
# command line instead of printing them on stdout. Reports (if any) will be
50+
# written in a file name "pylint_global.[txt|html]".
51+
files-output=no
52+
53+
# Tells whether to display a full report or only the messages
54+
reports=yes
55+
56+
# Python expression which should return a note less than 10 (10 is the highest
57+
# note). You have access to the variables errors warning, statement which
58+
# respectively contain the number of errors / warnings messages and the total
59+
# number of statements analyzed. This is used by the global evaluation report
60+
# (R0004).
61+
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
62+
63+
# Add a comment according to your evaluation note. This is used by the global
64+
# evaluation report (R0004).
65+
comment=no
66+
67+
68+
[BASIC]
69+
70+
# Variable names can be 1 to 31 characters long, with lowercase and underscores
71+
variable-rgx=[a-z_][a-z0-9_]{0,30}$
72+
73+
# Argument names can be 2 to 31 characters long, with lowercase and underscores
74+
argument-rgx=[a-z_][a-z0-9_]{1,30}$
75+
76+
# Method names should be at least 3 characters long
77+
# and be lowecased with underscores
78+
method-rgx=[a-z_][a-z0-9_]{2,50}$
79+
80+
# Module names matching nova-* are ok (files in bin/)
81+
#module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|(nova-[a-z0-9_-]+))$
82+
83+
# Don't require docstrings on tests.
84+
no-docstring-rgx=((__.*__)|([tT]est.*)|setUp|tearDown)$
85+
86+
87+
88+
[FORMAT]
89+
90+
# Maximum number of characters on a single line.
91+
max-line-length=100
92+
93+
# Maximum number of lines in a module
94+
max-module-lines=1000
95+
96+
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
97+
# tab).
98+
indent-string=' '
99+
100+
101+
[MISCELLANEOUS]
102+
103+
# List of note tags to take in consideration, separated by a comma.
104+
notes=FIXME,XXX,TODO
105+
106+
107+
[SIMILARITIES]
108+
109+
# Minimum lines number of a similarity.
110+
min-similarity-lines=4
111+
112+
# Ignore comments when computing similarities.
113+
ignore-comments=yes
114+
115+
# Ignore docstrings when computing similarities.
116+
ignore-docstrings=yes
117+
118+
119+
[TYPECHECK]
120+
121+
# Tells whether missing members accessed in mixin class should be ignored. A
122+
# mixin class is detected if its name ends with "mixin" (case insensitive).
123+
#ignore-mixin-members=yes
124+
125+
# List of classes names for which member attributes should not be checked
126+
# (useful for classes with attributes dynamically set).
127+
ignored-classes=SQLObject
128+
129+
# When zope mode is activated, add a predefined set of Zope acquired attributes
130+
# to generated-members.
131+
zope=no
132+
133+
# List of members which are set dynamically and missed by pylint inference
134+
# system, and so shouldn't trigger E0201 when accessed.
135+
generated-members=REQUEST,acl_users,aq_parent
136+
137+
138+
[VARIABLES]
139+
140+
# Tells whether we should check for unused import in __init__ files.
141+
init-import=no
142+
143+
# A regular expression matching names used for dummy variables (i.e. not used).
144+
dummy-variables-rgx=_|dummy
145+
146+
# List of additional names supposed to be defined in builtins. Remember that
147+
# you should avoid to define new builtins when possible.
148+
additional-builtins=
149+
150+
151+
[CLASSES]
152+
153+
# List of interface methods to ignore, separated by a comma. This is used for
154+
# instance to not check methods defines in Zope's Interface base class.
155+
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
156+
157+
# List of method names used to declare (i.e. assign) instance attributes.
158+
defining-attr-methods=__init__,__new__,setUp
159+
160+
161+
[DESIGN]
162+
163+
# Maximum number of arguments for function / method
164+
max-args=5
165+
166+
# Argument names that match this expression will be ignored. Default to name
167+
# with leading underscore
168+
ignored-argument-names=_.*
169+
170+
# Maximum number of locals for function / method body
171+
max-locals=15
172+
173+
# Maximum number of return / yield for function / method body
174+
max-returns=6
175+
176+
# Maximum number of branch for function / method body
177+
max-branchs=12
178+
179+
# Maximum number of statements in function / method body
180+
max-statements=50
181+
182+
# Maximum number of parents for a class (see R0901).
183+
max-parents=7
184+
185+
# Maximum number of attributes for a class (see R0902).
186+
max-attributes=7
187+
188+
# Minimum number of public methods for a class (see R0903).
189+
min-public-methods=0
190+
191+
# Maximum number of public methods for a class (see R0904).
192+
max-public-methods=20
193+
194+
195+
[IMPORTS]
196+
197+
# Deprecated modules which should not be used, separated by a comma
198+
deprecated-modules=regsub,string,TERMIOS,Bastion,rexec
199+
200+
# Create a graph of every (i.e. internal and external) dependencies in the
201+
# given file (report RP0402 must not be disabled)
202+
import-graph=import-graph.png
203+
204+
# Create a graph of external dependencies in the given file (report RP0402 must
205+
# not be disabled)
206+
ext-import-graph=ext-graph.png
207+
208+
# Create a graph of internal dependencies in the given file (report RP0402 must
209+
# not be disabled)
210+
int-import-graph=int-graph.png
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# coding=utf-8
2+
# Copyright (c) 2010-2012, GEM Foundation.
3+
#
4+
# OpenQuake is free software: you can redistribute it and/or modify it
5+
# under the terms of the GNU Affero General Public License as published
6+
# by the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# OpenQuake is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Affero General Public License
15+
# along with OpenQuake. If not, see <http://www.gnu.org/licenses/>.
16+
17+
18+
from scipy.stats import lognorm
19+
from scipy.interpolate import interp1d
20+
import math
21+
22+
23+
def poe(fragility_function, iml):
24+
"""
25+
Compute the Probability of Exceedance (PoE) for the given
26+
Intensity Measure Level (IML).
27+
"""
28+
if fragility_function.is_discrete:
29+
return poe_discrete(fragility_function, iml)
30+
else:
31+
return poe_continuous(fragility_function, iml)
32+
33+
34+
def poe_discrete(fragility_function, iml):
35+
fm = fragility_function.fragility_model
36+
37+
highest_iml = fm.imls[-1]
38+
no_damage_limit = fm.no_damage_limit
39+
40+
# when the intensity measure level is above
41+
# the range, we use the highest one
42+
if iml > highest_iml:
43+
iml = highest_iml
44+
45+
imls = [no_damage_limit] + fm.imls
46+
poes = [0.0] + fragility_function.poes
47+
48+
return interp1d(imls, poes)(iml)
49+
50+
51+
def poe_continuous(fragility_function, iml):
52+
variance = fragility_function.stddev ** 2.0
53+
sigma = math.sqrt(math.log(
54+
(variance / fragility_function.mean ** 2.0) + 1.0))
55+
56+
mu = fragility_function.mean ** 2.0 / math.sqrt(
57+
variance + fragility_function.mean ** 2.0)
58+
59+
return lognorm.cdf(iml, sigma, scale=mu)
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# coding=utf-8
2+
# Copyright (c) 2010-2012, GEM Foundation.
3+
#
4+
# OpenQuake is free software: you can redistribute it and/or modify it
5+
# under the terms of the GNU Affero General Public License as published
6+
# by the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# OpenQuake is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Affero General Public License
15+
# along with OpenQuake. If not, see <http://www.gnu.org/licenses/>.
16+
17+
18+
NO_DAMAGE_STATE = "no_damage"
19+
20+
21+
def damage_states(fragility_model):
22+
"""
23+
Return the damage states from the given limit states.
24+
25+
For N limit states in the fragility model, we always
26+
define N+1 damage states. The first damage state
27+
should always be 'no_damage'.
28+
29+
:param fragility_model A Fragility Model object which support a
30+
property `lss` containing an iterator over limit states
31+
"""
32+
33+
dmg_states = list(fragility_model.lss)
34+
dmg_states.insert(0, NO_DAMAGE_STATE)
35+
36+
return dmg_states
37+
38+
39+
def no_damage(fragility_model, gmv):
40+
"""
41+
There is no damage when ground motions values are less
42+
than the first iml or when the no damage limit value
43+
is greater than the ground motions value.
44+
"""
45+
46+
discrete = fragility_model.format == "discrete"
47+
no_damage_limit = fragility_model.no_damage_limit is not None
48+
49+
return ((discrete and not no_damage_limit and
50+
gmv < fragility_model.imls[0]) or
51+
(discrete and no_damage_limit and
52+
gmv < fragility_model.no_damage_limit))

0 commit comments

Comments
 (0)