def build_slip_list_node(slip_list): """ :param slip_list: an array of shape (N, 2) with columns (slip, weight) :returns: a hypoList node containing N slip nodes """ sliplist = LiteralNode('slipList', {}) for row in slip_list: sliplist.append(LiteralNode('slip', dict(weight=row[1]), row[0])) return sliplist
def build_slip_list_node(slip_list): """ :param slip_list: an array of shape (N, 2) with columns (slip, weight) :returns: a hypoList node containing N slip nodes """ sliplist = LiteralNode('slipList', {}) for row in slip_list: sliplist.append( LiteralNode('slip', dict(weight=row[1]), row[0])) return sliplist
def build_hypo_list_node(hypo_list): """ :param hypo_list: an array of shape (N, 3) with columns (alongStrike, downDip, weight) :returns: a hypoList node containing N hypo nodes """ hypolist = LiteralNode('hypoList', {}) for row in hypo_list: n = LiteralNode( 'hypo', dict(alongStrike=row[0], downDip=row[1], weight=row[2])) hypolist.append(n) return hypolist
def convert_fragility_model_04(node, fname, fmcounter=itertools.count(1)): """ :param node: an :class:`openquake.commonib.node.LiteralNode` in NRML 0.4 :param fname: path of the fragility file :returns: an :class:`openquake.commonib.node.LiteralNode` in NRML 0.5 """ convert_type = {"lognormal": "logncdf"} new = LiteralNode('fragilityModel', dict(assetCategory='building', lossCategory='structural', id='fm_%d_converted_from_NRML_04' % next(fmcounter))) with context(fname, node): fmt = node['format'] descr = ~node.description limit_states = ~node.limitStates new.append(LiteralNode('description', {}, descr)) new.append((LiteralNode('limitStates', {}, ' '.join(limit_states)))) for ffs in node[2:]: IML = ffs.IML # NB: noDamageLimit = None is different than zero nodamage = ffs.attrib.get('noDamageLimit') ff = LiteralNode('fragilityFunction', {'format': fmt}) ff['id'] = ~ffs.taxonomy ff['shape'] = convert_type[ffs.attrib.get('type', 'lognormal')] if fmt == 'continuous': with context(fname, IML): ff.append(LiteralNode('imls', dict(imt=IML['IMT'], minIML=IML['minIML'], maxIML=IML['maxIML'], noDamageLimit=nodamage))) for ffc in ffs[2:]: with context(fname, ffc): ls = ffc['ls'] param = ffc.params with context(fname, param): m, s = param['mean'], param['stddev'] ff.append(LiteralNode('params', dict(ls=ls, mean=m, stddev=s))) else: # discrete with context(fname, IML): imls = ' '.join(map(str, (~IML)[1])) attr = dict(imt=IML['IMT']) if nodamage is not None: attr['noDamageLimit'] = nodamage ff.append(LiteralNode('imls', attr, imls)) for ffd in ffs[2:]: ls = ffd['ls'] with context(fname, ffd): poes = ' '.join(map(str, ~ffd.poEs)) ff.append(LiteralNode('poes', dict(ls=ls), poes)) new.append(ff) return new