def to_node(self): node = Node('discreteVulnerabilitySet', dict( vulnerabilitySetID=self['vulnerabilitySetID'], assetCategory=self['assetCategory'], lossCategory=self['lossCategory'])) node.append(Node('IML', dict(IMT=self['IMT']))) return node
def to_node(self): """ Build a full discrete fragility node from CSV """ tset = self.tableset frag = tset.tableFragilityDiscrete[0].to_node() ffs_node = record.nodedict(tset.tableFFSetDiscrete) nodamage = float(ffs_node['noDamageLimit']) \ if 'noDamageLimit' in ffs_node else None frag.nodes.extend(ffs_node.values()) for (ls, ordinal), data in groupby(tset.tableFFDataDiscrete, ['limitState', 'ffs_ordinal']): data = list(data) # check that we can instantiate a FragilityFunction in risklib if nodamage: scientific.FragilityFunctionDiscrete( [nodamage] + [rec.iml for rec in data], [0.0] + [rec.poe for rec in data], nodamage) else: scientific.FragilityFunctionDiscrete([rec.iml for rec in data], [rec.poe for rec in data], nodamage) imls = ' '.join(rec['iml'] for rec in data) ffs_node[(ordinal, )].IML.text = imls poes = ' '.join(rec['poe'] for rec in data) n = Node('ffd', dict(ls=ls)) n.append(Node('poEs', text=poes)) ffs_node[(ordinal, )].append(n) return frag
def to_node(self): node = Node('discreteVulnerability', dict(vulnerabilityFunctionID=self[1], probabilisticDistribution=self[2])) node.append(Node('lossRatio')) node.append(Node('coefficientsVariation')) return node
def to_node(self): """ Build a full discrete fragility node from CSV """ tset = self.tableset frag = tset.tableFragilityDiscrete[0].to_node() ffs_node = record.nodedict(tset.tableFFSetDiscrete) nodamage = float(ffs_node['noDamageLimit']) \ if 'noDamageLimit' in ffs_node else None frag.nodes.extend(ffs_node.values()) for (ls, ordinal), data in groupby( tset.tableFFDataDiscrete, ['limitState', 'ffs_ordinal']): data = list(data) # check that we can instantiate a FragilityFunction in risklib if nodamage: scientific.FragilityFunctionDiscrete( [nodamage] + [rec.iml for rec in data], [0.0] + [rec.poe for rec in data], nodamage) else: scientific.FragilityFunctionDiscrete( [rec.iml for rec in data], [rec.poe for rec in data], nodamage) imls = ' '.join(rec['iml'] for rec in data) ffs_node[(ordinal,)].IML.text = imls poes = ' '.join(rec['poe'] for rec in data) n = Node('ffd', dict(ls=ls)) n.append(Node('poEs', text=poes)) ffs_node[(ordinal,)].append(n) return frag
def to_node(self): node = Node( 'discreteVulnerabilitySet', dict(vulnerabilitySetID=self['vulnerabilitySetID'], assetCategory=self['assetCategory'], lossCategory=self['lossCategory'])) node.append(Node('IML', dict(IMT=self['IMT']))) return node
def to_node(self): node = Node('ffs') ndl = self[2] if ndl: node['noDamageLimit'] = ndl node.append(Node('taxonomy', text=self[1])) node.append(Node('IML', dict(IMT=self[3], imlUnit=self[4]))) return node
def to_node(self): node = Node('ffs') node.append(Node('taxonomy', text=self[1])) ndl = self[2] if ndl: node['noDamageLimit'] = ndl typ = self[3] if typ: node['type'] = typ node.append(Node('IML', dict(IMT=self[4], imlUnit=self[5], minIML=self[6], maxIML=self[7]))) return node
def build_node(self, tables): """ Build a gmfSet node from a list of tables. """ assert len(tables) > 1 gmfcoll = Node('gmfSet') for table in tables: md = table.metadata gmf = node_copy(md.gmf) for record in table: gmf.append(Node('node', record)) gmfcoll.append(gmf) return gmfcoll
def to_node(self): """ Build a Node object containing a full exposure from a set of CSV files. For population exposure the CSV has a form like id,taxonomy,lon,lat,number asset_01,IT-PV,9.15000,45.16667,7 asset_02,IT-CE,9.15333,45.12200,7 whereas for building has a form like id,taxonomy,lon,lat,number,area,cost__value,..., occupancy__day asset_01,RC/DMRF-D/LR,9.15000,45.16667,7,120,40,.5,...,20 asset_02,RC/DMRF-D/HR,9.15333,45.12200,7,119,40,,,...,20 asset_03,RC/DMRF-D/LR,9.14777,45.17999,5,118,,...,,5 with a variable number of columns depending on the metadata. """ t = self.tableset exp = t.tableExposure[0].to_node() if exp['category'] == 'buildings': cost_types = [c.name for c in t.tableCostType] exp.conversions.costTypes.nodes = [ c.to_node() for c in t.tableCostType ] else: cost_types = [] area_type = t.tableExposure[0].area_type area_unit = t.tableExposure[0].area_unit if area_type and area_unit: # insert after the description node exp.nodes.insert( 1, Node('conversions', {}, nodes=[ Node('area', { 'type': area_type, 'unit': area_unit }) ])) if t.tableOccupancy: # extract the occupancies corresponding to the first asset _asset_ref, occupancies = groupby(t.tableOccupancy, ['asset_ref']).next() periods = sorted(occ.period for occ in occupancies) else: periods = [] exp.assets.nodes = self._assetgenerator(t.tableAsset, cost_types, periods) return exp
def to_node(self): node = Node( 'discreteVulnerability', dict(vulnerabilityFunctionID=self['vulnerabilityFunctionID'], probabilisticDistribution=self['probabilisticDistribution'])) node.append(Node('lossRatio')) node.append(Node('coefficientsVariation')) return node
def to_node(self): attr = dict(id=self['asset_ref'], taxonomy=self['taxonomy'], number=self['number']) if self['area']: attr['area'] = self['area'] return Node('asset', attr)
def to_node(self): attr = dict(name=self['name'], type=self['type'], unit=self['unit']) if self['retrofittedType']: attr['retrofittedType'] = self['retrofittedType'] if self['retrofittedUnit']: attr['retrofittedUnit'] = self['retrofittedUnit'] return Node('costType', attr)
def _to_node(self): """ Add to a gmfset node all the data from a file GmfData.csv of the form:: stochasticEventSetId,imtStr,ruptureId,lon,lat,gmv 1,SA(0.025),,0.0,0.0,0.2 1,SA(0.025),,1.0,0.0,1.4 1,SA(0.025),,0.0,1.0,0.6 1,PGA,,0.0,0.0,0.2 1,PGA,,1.0,0.0,1.4 1,PGA,,0.0,1.0,0.6 The rows are grouped by ses, imt, rupture. """ tset = self.tableset gmfset_node = record.nodedict(tset.tableGmfSet) for (ses, imt, rupture), rows in groupby( tset.tableGmfData, ['stochasticEventSetId', 'imtStr', 'ruptureId']): if imt.startswith('SA'): attr = dict(IMT='SA', saPeriod=imt[3:-1], saDamping='5') else: attr = dict(IMT=imt) if rupture: attr['ruptureId'] = rupture nodes = [records.GmfData(*r).to_node() for r in rows] gmfset_node[(ses, )].append(Node('gmf', attr, nodes=nodes)) return gmfset_node
def to_node(self): dic = {} if self['stochasticEventSetId'] != '0': dic['stochasticEventSetId'] = self['stochasticEventSetId'] if self[1]: dic['investigationTime'] = self['investigationTime'] return Node('gmfSet', dic)
def to_node(self): tset = self.tableset dvs_node = record.nodedict(tset.tableDiscreteVulnerabilitySet) dvf_node = record.nodedict(tset.tableDiscreteVulnerability) for (set_id, vf_id), group in groupby( tset.tableDiscreteVulnerabilityData, ['vulnerabilitySetID', 'vulnerabilityFunctionID']): dvf = dvf_node[set_id, vf_id] imt = dvs_node[(set_id, )].IML['IMT'] coeffs = [] ratios = [] imls = [] for row in group: imls.append(row['IML']) coeffs.append(row['coefficientsVariation']) ratios.append(row['lossRatio']) # check that we can instantiate a VulnerabilityFunction in risklib scientific.VulnerabilityFunction(imt, map(float, imls), map(float, ratios), map(float, coeffs)) dvf.lossRatio.text = ' '.join(ratios) dvf.coefficientsVariation.text = ' '.join(coeffs) dvs_node[(set_id, )].append(dvf) dvs_node[(set_id, )].IML.text = ' '.join(imls) return Node('vulnerabilityModel', nodes=dvs_node.values())
def to_node(self): node = Node('ffs') ndl = self['noDamageLimit'] if ndl: node['noDamageLimit'] = ndl node.append(Node('taxonomy', text=self['taxonomy'])) node.append(Node('IML', dict(IMT=self['IMT'], imlUnit=self['imlUnit']))) return node
def to_node(self): imt = self['imtStr'] if imt.startswith('SA'): attr = dict(IMT='SA', saPeriod=imt[3:-1], saDamping='5.0') else: attr = dict(IMT=imt) rup = self['ruptureId'] if rup: attr['ruptureId'] = rup return Node('gmf', attr)
def build_tables(self): """ Yield a table for each Fragility Function Set (ffs) keyed by the ordinal of the set, starting from 1. Here is an example of a table for a discrete model:: IML,minor,moderate,severe,collapse 7,0.0,0.0,0.0,0.0 8,0.09,0.00,0.00,0.00 9,0.56,0.04,0.00,0.00 Here is an example for a continuous model:: param,slight,moderate,extensive,complete mean,11.19,27.98,48.05,108.9 stddev,8.27,20.677,42.49,123.7 """ node = self.node format = node['format'] limitStates = node.limitStates.text.split() for i, ffs in enumerate(node.getnodes('ffs'), 1): md = Node('fragilityModel', node.attrib, nodes=[node.description, node.limitStates]) if format == 'discrete': matrix = [ffs.IML.text.split()] # data in transposed form for ls, ffd in zip(limitStates, ffs.getnodes('ffd')): assert ls == ffd['ls'], 'Expected %s, got %s' % ( ls, ffd['ls']) matrix.append(ffd.poEs.text.split()) elif format == 'continuous': matrix = ['mean stddev'.split()] for ls, ffc in zip(limitStates, ffs.getnodes('ffc')): assert ls == ffc['ls'], 'Expected %s, got %s' % ( ls, ffc['ls']) matrix.append([ffc.params['mean'], ffc.params['stddev']]) else: raise ValueError('Invalid format %r' % format) md.append(Node('ffs', ffs.attrib)) md.ffs.append(ffs.taxonomy) md.ffs.append(Node('IML', ffs.IML.attrib)) # append the two nodes taxonomy and IML yield Table(str(i), md, zip(*matrix))
def to_node(self): """ Build a full continuous fragility node from CSV """ tset = self.tableset frag = tset.tableFragilityContinuous[0].to_node() ffs_node = record.nodedict(tset.tableFFSetContinuous) frag.nodes.extend(ffs_node.values()) for (ls, ordinal), data in groupby(tset.tableFFDataContinuous, ['limitState', 'ffs_ordinal']): data = list(data) n = Node('ffc', dict(ls=ls)) param = dict(row[2:] for row in data) # param, value # check that we can instantiate a FragilityFunction in risklib scientific.FragilityFunctionContinuous(float(param['mean']), float(param['stddev'])) n.append(Node('params', param)) ffs_node[(ordinal, )].append(n) return frag
def to_node(self): """ Build a full continuous fragility node from CSV """ tset = self.tableset frag = tset.tableFragilityContinuous[0].to_node() ffs_node = record.nodedict(tset.tableFFSetContinuous) frag.nodes.extend(ffs_node.values()) for (ls, ordinal), data in groupby( tset.tableFFDataContinuous, ['limitState', 'ffs_ordinal']): data = list(data) n = Node('ffc', dict(ls=ls)) param = dict(row[2:] for row in data) # param, value # check that we can instantiate a FragilityFunction in risklib scientific.FragilityFunctionContinuous( float(param['mean']), float(param['stddev'])) n.append(Node('params', param)) ffs_node[(ordinal,)].append(n) return frag
def _assetgenerator(self, assets, costtypes, periods): """ Convert assets into asset nodes. :param assets: asset records :param costtypes: the valid cost types :param periods: the valid periods :returns: an iterable over Node objects describing exposure assets """ # each asset contains the subnodes location, costs and occupancies loc_dict = record.nodedict(self.tableset.tableLocation) cost_dict = record.nodedict(self.tableset.tableCost) occ_dict = record.nodedict(self.tableset.tableOccupancy) for asset in assets: ref = asset['asset_ref'] nodes = [] location = loc_dict[(asset['location_id'], )] nodes.append(location) costnodes = [] for ctype in costtypes: cost = cost_dict.get((ref, ctype)) if cost is not None: costnodes.append(cost) if costnodes: nodes.append(Node('costs', {}, nodes=costnodes)) occupancynodes = [] for period in periods: occupancy = occ_dict.get((ref, period)) if occupancy is not None: occupancynodes.append(occupancy) if occupancynodes: nodes.append(Node('occupancies', {}, nodes=occupancynodes)) assetnode = asset.to_node() assetnode.nodes = nodes yield assetnode
def build_tables(self): """ Yield a table for each gmf node. The table has a form like lon,lat,gmv 0.0,0.0,0.2 1.0,0.0,1.4 0.0,1.0,0.6 """ node = self.node for gmfset in node.getnodes('gmfSet'): for gmf in gmfset.getnodes('gmf'): rup = gmf['ruptureId'] imt = gmf['IMT'] if imt == 'SA': imt += '(%s)' % gmf['saPeriod'] metadata = Node('gmfCollection', node.attrib) gs = Node('gmfSet', gmfset.attrib, nodes=[Node('gmf', gmf.attrib)]) metadata.append(gs) data = ((n['lon'], n['lat'], n['gmv']) for n in gmf) yield Table(imt + ',' + rup, metadata, data)
def to_node(self): node = Node('ffs') node.append(Node('taxonomy', text=self['taxonomy'])) ndl = self['noDamageLimit'] if ndl: node['noDamageLimit'] = ndl typ = self['type'] if typ: node['type'] = typ node.append( Node( 'IML', dict(IMT=self['IMT'], imlUnit=self['imlUnit'], minIML=self['minIML'], maxIML=self['maxIML']))) return node
def build_tables(self): """ Yield a single table object. For population exposure a table has a form like id,taxonomy,lon,lat,number asset_01,IT-PV,9.15000,45.16667,7 asset_02,IT-CE,9.15333,45.12200,7 whereas for building has a form like id,taxonomy,lon,lat,number,area,cost.value,..., occupancy.day asset_01,RC/DMRF-D/LR,9.15000,45.16667,7,120,40,.5,...,20 asset_02,RC/DMRF-D/HR,9.15333,45.12200,7,119,40,,,...,20 asset_03,RC/DMRF-D/LR,9.14777,45.17999,5,118,,...,,5 with a variable number of columns depending on the metadata. """ node = self.node metadata = Node('exposureModel', node.attrib, nodes=[node.description]) if node['category'] == 'population': data = ([asset['id'], asset['taxonomy'], asset.location['lon'], asset.location['lat'], asset['number']] for asset in node.assets) elif node['category'] == 'buildings': metadata.append(node.conversions) costcolumns = getcostcolumns(node.conversions.costTypes) data = ([asset['id'], asset['taxonomy'], asset.location['lon'], asset.location['lat'], asset['number'], asset['area']] + getcosts(asset, costcolumns) + getoccupancies(asset) for asset in node.assets) metadata.append(Node('assets')) yield Table('', metadata, data)
def to_node(self): """ Here are two examples: <cost type="structural" value="150000" deductible=".1" insuranceLimit="0.8" retrofitted="109876"/> <cost type="non_structural" value="25000" deductible=".09" insuranceLimit="0.82"/> """ node = Node('cost', dict(type=self['type'], value=self['value'])) if self['retrofitted']: node['retrofitted'] = self['retrofitted'] if self['deductible']: node['deductible'] = self['deductible'] if self['insurance_limit']: node['insuranceLimit'] = self['insurance_limit'] return node
def build_node(self, tables): """ Build a gmfCollection node from a list of tables. """ assert len(tables) >= 1 md = tables[0].metadata gmfcoll = Node('gmfCollection', dict( sourceModelTreePath=md.attrib['sourceModelTreePath'], gsimTreePath=md.attrib['gsimTreePath'])) def get_ses_id(table): return table.metadata.gmfSet.attrib['stochasticEventSetId'] for ses_id, tablegroup in itertools.groupby(tables, get_ses_id): tablelist = list(tablegroup) gmfset = Node('gmfSet', tablelist[0].metadata.gmfSet.attrib) for table in tablelist: gmf = Node('gmf', table.metadata.gmfSet.gmf.attrib, nodes=[Node('node', record) for record in table]) gmfset.append(gmf) gmfcoll.append(gmfset) return gmfcoll
def to_node(self): node = Node('exposureModel', dict( id=self[0], category=self[1], taxonomySource=self[2])) node.append(Node('description', text=self[3])) if node['category'] == 'buildings': conv = Node('conversions') conv.append(Node('area', dict(type=self[4], unit=self[5]))) conv.append(Node('costTypes')) conv.append(Node('deductible', dict(isAbsolute=self[6]))) conv.append(Node('insuranceLimit', dict(isAbsolute=self[7]))) node.append(conv) node.append(Node('assets')) return node
def to_node(self): return Node('location', dict(lon=self['lon'], lat=self['lat']))
def to_node(self): node = Node( 'exposureModel', dict(id=self['id'], category=self['category'], taxonomySource=self['taxonomySource'])) node.append(Node('description', text=self['description'])) if node['category'] == 'buildings': conv = Node('conversions') conv.append( Node('area', dict(type=self['area_type'], unit=self['area_unit']))) conv.append(Node('costTypes')) conv.append( Node('deductible', dict(isAbsolute=self['deductible_is_absolute']))) conv.append( Node('insuranceLimit', dict(isAbsolute=self['insurance_limit_is_absolute']))) node.append(conv) node.append(Node('assets')) return node
def to_node(self): node = Node('fragilityModel', dict(format=self['format'])) node.append(Node('description', text=self['description'])) node.append(Node('limitStates', text=self['limitStates'])) return node
def to_node(self): return Node('occupancy', dict(period=self['period'], occupants=self['occupants']))
def set_list_item(node, i, value): numbers = node.text.split() numbers[i] = value node.text = ' '.join(numbers) VSET = dict(enumerate('vulnerabilitySetID assetCategory lossCategory IMT' .split())) VFN = dict(enumerate('vulnerabilityFunctionID probabilisticDistribution' .split())) IMLS = dict(enumerate('imls lossRatio coefficientsVariation'.split())) DVSET_NODE = Node('discreteVulnerabilitySet', dict( assetCategory="population", lossCategory="fatalities", vulnerabilitySetID="XXX")) DVSET_NODE.append(Node('IML', text='')) VFN_NODE = Node('discreteVulnerability', dict( probabilisticDistribution="LN", vulnerabilityFunctionID="XX")) VFN_NODE.append(Node('lossRatio', text='')) VFN_NODE.append(Node('coefficientsVariation', text='')) class MainWindow(Ui_InputToolWindow, QtGui.QMainWindow): def __init__(self, inputdir): QtGui.QMainWindow.__init__(self) self.inputdir = inputdir self.setupUi(self)
def to_node(self): node = Node('exposureModel', dict( id=self['id'], category=self['category'], taxonomySource=self['taxonomySource'])) node.append(Node('description', text=self['description'])) if node['category'] == 'buildings': conv = Node('conversions') conv.append(Node('area', dict(type=self['area_type'], unit=self['area_unit']))) conv.append(Node('costTypes')) conv.append(Node('deductible', dict( isAbsolute=self['deductible_is_absolute']))) conv.append(Node('insuranceLimit', dict( isAbsolute=self['insurance_limit_is_absolute']))) node.append(conv) node.append(Node('assets')) return node
def to_node(self): return Node( 'gmfCollection', dict(sourceModelTreePath=self['sourceModelTreePath'], gsimTreePath=self['gsimTreePath']))
def to_node(self): return Node('node', dict(lon=self['lon'], lat=self['lat'], gmv=self['gmv']))