@@ -67,9 +67,9 @@ def get_risk_files(inputs):
67
67
rfs ['fragility/structural' ] = inputs [
68
68
'structural_fragility' ] = inputs [key ]
69
69
del inputs ['fragility' ]
70
- elif key .endswith (('_fragility' , '_vulnerability' )):
70
+ elif key .endswith (('_fragility' , '_vulnerability' , '_vulnerability_retrofitted' )):
71
71
match = RISK_TYPE_REGEX .match (key )
72
- if match and 'retrofitted' not in key :
72
+ if match :
73
73
rfs ['%s/%s' % (match .group (2 ), match .group (1 ))] = inputs [key ]
74
74
elif match is None :
75
75
raise ValueError ('Invalid key in %s: %s_file' % (job_ini , key ))
@@ -135,45 +135,38 @@ def groupby_id(self):
135
135
return {riskid : group_by_lt (rfs ) for riskid , rfs in ddic .items ()}
136
136
137
137
138
- def get_risk_functions (oqparam , kind = 'vulnerability fragility '
139
- 'vulnerability_retrofitted' ):
138
+ def get_risk_functions (oqparam ):
140
139
"""
141
140
:param oqparam:
142
141
an OqParam instance
143
- :param kind:
144
- a space-separated string with the kinds of risk models to read
145
142
:returns:
146
143
a list of risk functions
147
144
"""
148
- kinds = kind . split ()
145
+ job_ini = oqparam . inputs [ 'job_ini' ]
149
146
rmodels = AccumDict ()
150
- for kind in kinds :
151
- for key in sorted (oqparam .inputs ):
152
- mo = re .match ('(occupants|%s)_%s$' % (LTYPE_REGEX , kind ), key )
153
- if mo :
154
- loss_type = mo .group (1 ) # the cost_type in the key
155
- # can be occupants, structural, nonstructural, ...
156
- rmodel = nrml .to_python (oqparam .inputs [key ])
157
- if len (rmodel ) == 0 :
158
- raise InvalidFile ('%s is empty!' % oqparam .inputs [key ])
159
- rmodels [loss_type , kind ] = rmodel
160
- if rmodel .lossCategory is None : # NRML 0.4
161
- continue
162
- cost_type = str (rmodel .lossCategory )
163
- rmodel_kind = rmodel .__class__ .__name__
164
- kind_ = kind .replace ('_retrofitted' , '' ) # strip retrofitted
165
- if not rmodel_kind .lower ().startswith (kind_ ):
166
- raise ValueError (
167
- 'Error in the file "%s_file=%s": is '
168
- 'of kind %s, expected %s' % (
169
- key , oqparam .inputs [key ], rmodel_kind ,
170
- kind .capitalize () + 'Model' ))
171
- if cost_type != loss_type :
172
- raise ValueError (
173
- 'Error in the file "%s_file=%s": lossCategory is of '
174
- 'type "%s", expected "%s"' %
175
- (key , oqparam .inputs [key ],
176
- rmodel .lossCategory , loss_type ))
147
+ for key , fname in get_risk_files (oqparam .inputs ).items ():
148
+ kind , loss_type = key .split ('/' ) # ex. vulnerability/structural
149
+ rmodel = nrml .to_python (fname )
150
+ if len (rmodel ) == 0 :
151
+ raise InvalidFile (f'{ job_ini } : { fname } is empty!' )
152
+ rmodels [loss_type , kind ] = rmodel
153
+ if rmodel .lossCategory is None : # NRML 0.4
154
+ continue
155
+ cost_type = str (rmodel .lossCategory )
156
+ rmodel_kind = rmodel .__class__ .__name__
157
+ kind_ = kind .replace ('_retrofitted' , '' ) # strip retrofitted
158
+ if not rmodel_kind .lower ().startswith (kind_ ):
159
+ raise ValueError (
160
+ 'Error in the file "%s_file=%s": is '
161
+ 'of kind %s, expected %s' % (
162
+ key , oqparam .inputs [key ], rmodel_kind ,
163
+ kind .capitalize () + 'Model' ))
164
+ if cost_type != loss_type :
165
+ raise ValueError (
166
+ 'Error in the file "%s_file=%s": lossCategory is of '
167
+ 'type "%s", expected "%s"' %
168
+ (key , oqparam .inputs [key ],
169
+ rmodel .lossCategory , loss_type ))
177
170
cl_risk = oqparam .calculation_mode in ('classical' , 'classical_risk' )
178
171
rlist = RiskFuncList ()
179
172
rlist .limit_states = []
0 commit comments