当前位置: 首页>>代码示例>>Python>>正文


Python AccumDict.limit_states方法代码示例

本文整理汇总了Python中openquake.baselib.general.AccumDict.limit_states方法的典型用法代码示例。如果您正苦于以下问题:Python AccumDict.limit_states方法的具体用法?Python AccumDict.limit_states怎么用?Python AccumDict.limit_states使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openquake.baselib.general.AccumDict的用法示例。


在下文中一共展示了AccumDict.limit_states方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read

# 需要导入模块: from openquake.baselib.general import AccumDict [as 别名]
# 或者: from openquake.baselib.general.AccumDict import limit_states [as 别名]
 def read(cls, dstore):
     """
     :param dstore: a DataStore instance
     :returns: a :class:`CompositeRiskModel` instance
     """
     oqparam = dstore['oqparam']
     crm = dstore.getitem('risk_model')
     riskdict = AccumDict(accum={})
     riskdict.limit_states = crm.attrs['limit_states']
     for quoted_id, rm in crm.items():
         riskid = unquote_plus(quoted_id)
         for lt_kind in rm:
             lt, kind = lt_kind.rsplit('-', 1)
             rf = dstore['risk_model/%s/%s' % (quoted_id, lt_kind)]
             if kind == 'consequence':
                 riskdict[riskid][lt, kind] = rf
             elif kind == 'fragility':  # rf is a FragilityFunctionList
                 try:
                     rf = rf.build(
                         riskdict.limit_states,
                         oqparam.continuous_fragility_discretization,
                         oqparam.steps_per_interval)
                 except ValueError as err:
                     raise ValueError('%s: %s' % (riskid, err))
                 riskdict[riskid][lt, kind] = rf
             else:  # rf is a vulnerability function
                 rf.init()
                 if lt.endswith('_retrofitted'):
                     # strip _retrofitted, since len('_retrofitted') = 12
                     riskdict[riskid][
                         lt[:-12], 'vulnerability_retrofitted'] = rf
                 else:
                     riskdict[riskid][lt, 'vulnerability'] = rf
     return CompositeRiskModel(oqparam, riskdict)
开发者ID:digitalsatori,项目名称:oq-engine,代码行数:36,代码来源:riskinput.py

示例2: get_risk_models

# 需要导入模块: from openquake.baselib.general import AccumDict [as 别名]
# 或者: from openquake.baselib.general.AccumDict import limit_states [as 别名]
def get_risk_models(oqparam, kind='vulnerability fragility consequence '
                    'vulnerability_retrofitted'):
    """
    :param oqparam:
        an OqParam instance
    :param kind:
        a space-separated string with the kinds of risk models to read
    :returns:
        a dictionary riskid -> loss_type, kind -> function
    """
    kinds = kind.split()
    rmodels = AccumDict()
    for kind in kinds:
        for key in sorted(oqparam.inputs):
            mo = re.match('(occupants|%s)_%s$' % (COST_TYPE_REGEX, kind), key)
            if mo:
                loss_type = mo.group(1)  # the cost_type in the key
                # can be occupants, structural, nonstructural, ...
                rmodel = nrml.to_python(oqparam.inputs[key])
                if len(rmodel) == 0:
                    raise InvalidFile('%s is empty!' % oqparam.inputs[key])
                rmodels[loss_type, kind] = rmodel
                if rmodel.lossCategory is None:  # NRML 0.4
                    continue
                cost_type = str(rmodel.lossCategory)
                rmodel_kind = rmodel.__class__.__name__
                kind_ = kind.replace('_retrofitted', '')  # strip retrofitted
                if not rmodel_kind.lower().startswith(kind_):
                    raise ValueError(
                        'Error in the file "%s_file=%s": is '
                        'of kind %s, expected %s' % (
                            key, oqparam.inputs[key], rmodel_kind,
                            kind.capitalize() + 'Model'))
                if cost_type != loss_type:
                    raise ValueError(
                        'Error in the file "%s_file=%s": lossCategory is of '
                        'type "%s", expected "%s"' %
                        (key, oqparam.inputs[key],
                         rmodel.lossCategory, loss_type))
    rdict = AccumDict(accum={})
    rdict.limit_states = []
    for (loss_type, kind), rm in sorted(rmodels.items()):
        if kind == 'fragility':
            # build a copy of the FragilityModel with different IM levels
            newfm = rm.build(oqparam.continuous_fragility_discretization,
                             oqparam.steps_per_interval)
            for (imt, riskid), ffl in sorted(newfm.items()):
                if not rdict.limit_states:
                    rdict.limit_states.extend(rm.limitStates)
                # we are rejecting the case of loss types with different
                # limit states; this may change in the future
                assert rdict.limit_states == rm.limitStates, (
                    rdict.limit_states, rm.limitStates)
                rdict[riskid][loss_type, kind] = ffl
                # TODO: see if it is possible to remove the attribute
                # below, used in classical_damage
                ffl.steps_per_interval = oqparam.steps_per_interval
        elif kind == 'consequence':
            for riskid, cf in sorted(rm.items()):
                rdict[riskid][loss_type, kind] = cf
        else:  # vulnerability, vulnerability_retrofitted
            cl_risk = oqparam.calculation_mode in (
                'classical', 'classical_risk')
            # only for classical_risk reduce the loss_ratios
            # to make sure they are strictly increasing
            for (imt, riskid), rf in sorted(rm.items()):
                rdict[riskid][loss_type, kind] = (
                    rf.strictly_increasing() if cl_risk else rf)
    return rdict
开发者ID:digitalsatori,项目名称:oq-engine,代码行数:71,代码来源:riskmodels.py


注:本文中的openquake.baselib.general.AccumDict.limit_states方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。