def export_damage_taxon(ekey, dstore): loss_types = dstore.get_attr('composite_risk_model', 'loss_types') damage_states = dstore.get_attr('composite_risk_model', 'damage_states') rlzs = dstore['rlzs_assoc'].realizations dmg_by_taxon = dstore['dmg_by_taxon'] # shape (T, L, R) taxonomies = dstore['assetcol/taxonomies'] dmg_states = [DmgState(s, i) for i, s in enumerate(damage_states)] D = len(dmg_states) T, R = dmg_by_taxon.shape L = len(loss_types) fnames = [] for l, r in itertools.product(range(L), range(R)): lt = loss_types[l] rlz = rlzs[r] suffix = '' if L == 1 and R == 1 else '-gsimltp_%s_%s' % (rlz.uid, lt) dd_taxo = [] for t in range(T): dist = dmg_by_taxon[t, r][lt] for ds in range(D): dd_taxo.append( DmgDistPerTaxonomy(taxonomies[t], dmg_states[ds], dist['mean'][ds], dist['stddev'][ds])) f = export_dmg_xml(('dmg_dist_per_taxonomy', 'xml'), dstore, dmg_states, dd_taxo, suffix) fnames.extend(sum(f.values(), [])) return sorted(fnames)
def export_damage_total(ekey, dstore): loss_types = dstore.get_attr('composite_risk_model', 'loss_types') damage_states = dstore.get_attr('composite_risk_model', 'damage_states') rlzs = dstore['rlzs_assoc'].realizations dmg_total = dstore['dmg_total'] R, = dmg_total.shape L = len(loss_types) dmg_states = [DmgState(s, i) for i, s in enumerate(damage_states)] D = len(dmg_states) fnames = [] for l, r in itertools.product(range(L), range(R)): lt = loss_types[l] rlz = rlzs[r] suffix = '' if L == 1 and R == 1 else '-gsimltp_%s_%s' % (rlz.uid, lt) dd_total = [] for ds in range(D): dist = dmg_total[r][lt] dd_total.append( DmgDistTotal(dmg_states[ds], dist['mean'][ds], dist['stddev'][ds])) f = export_dmg_xml(('dmg_dist_total', 'xml'), dstore, dmg_states, dd_total, suffix) fnames.extend(sum(f.values(), [])) return sorted(fnames)
def export_damage_taxon(ekey, dstore): riskmodel = dstore['riskmodel'] rlzs = dstore['rlzs_assoc'].realizations dmg_by_taxon = dstore['dmg_by_taxon'] # shape (T, L, R) taxonomies = dstore['taxonomies'] dmg_states = [ DmgState(s, i) for i, s in enumerate(riskmodel.damage_states) ] T, L, R = dmg_by_taxon.shape fnames = [] for l, r in itertools.product(range(L), range(R)): lt = riskmodel.loss_types[l] rlz = rlzs[r] suffix = '' if L == 1 and R == 1 else '-gsimltp_%s_%s' % (rlz.uid, lt) dd_taxo = [] for t in range(T): dist = dmg_by_taxon[t, l, r] for dmg_state in dmg_states: ds = dmg_state.dmg_state dd_taxo.append( DmgDistPerTaxonomy(taxonomies[t], dmg_state, dist['mean'][ds], dist['stddev'][ds])) f = export_dmg_xml(('dmg_dist_per_taxonomy', 'xml'), dstore.export_dir, dmg_states, dd_taxo, suffix) fnames.extend(sum(f.values(), [])) return sorted(fnames)
def export_damage_total(ekey, dstore): riskmodel = dstore['riskmodel'] rlzs = dstore['rlzs_assoc'].realizations dmg_total = dstore['dmg_total'] L, R = dmg_total.shape dmg_states = [ DmgState(s, i) for i, s in enumerate(riskmodel.damage_states) ] fnames = [] for l, r in itertools.product(range(L), range(R)): lt = riskmodel.loss_types[l] rlz = rlzs[r] suffix = '' if L == 1 and R == 1 else '-gsimltp_%s_%s' % (rlz.uid, lt) dd_total = [] for dmg_state in dmg_states: dist = dmg_total[l, r] ds = dmg_state.dmg_state dd_total.append( DmgDistTotal(dmg_state, dist['mean'][ds], dist['stddev'][ds])) f = export_dmg_xml(('dmg_dist_total', 'xml'), dstore.export_dir, dmg_states, dd_total, suffix) fnames.extend(sum(f.values(), [])) return sorted(fnames)
def export_damage(ekey, dstore): """ :param ekey: export key, i.e. a pair (datastore key, fmt) :param dstore: datastore object """ oqparam = dstore['oqparam'] riskmodel = dstore['riskmodel'] rlzs = dstore['rlzs_assoc'].realizations damages_by_key = dstore['damages_by_key'] assetcol = dstore['assetcol'] sitemesh = dstore['sitemesh'] assetno = dict((ref, i) for i, ref in enumerate(assetcol['asset_ref'])) dmg_states = [ DmgState(s, i) for i, s in enumerate(riskmodel.damage_states) ] fnames = [] for i in sorted(damages_by_key): rlz = rlzs[i] result = damages_by_key[i] dd_taxo = [] dd_asset = [] shape = oqparam.number_of_ground_motion_fields, len(dmg_states) totals = numpy.zeros(shape) # R x D matrix for (key_type, key), values in result.items(): if key_type == 'taxonomy': # values are fractions, R x D matrix totals += values means, stds = scientific.mean_std(values) for dmg_state, mean, std in zip(dmg_states, means, stds): dd_taxo.append( DmgDistPerTaxonomy(key, dmg_state, mean, std)) elif key_type == 'asset': means, stddevs = values point = sitemesh[assetcol[assetno[key]]['site_id']] site = Site(point['lon'], point['lat']) for dmg_state, mean, std in zip(dmg_states, means, stddevs): dd_asset.append( DmgDistPerAsset(ExposureData(key, site), dmg_state, mean, std)) dd_total = [] for dmg_state, total in zip(dmg_states, totals.T): mean, std = scientific.mean_std(total) dd_total.append(DmgDistTotal(dmg_state, mean, std)) suffix = '' if rlz.uid == '*' else '-gsimltp_%s' % rlz.uid f1 = export_dmg_xml(('dmg_dist_per_asset', 'xml'), oqparam.export_dir, dmg_states, dd_asset, suffix) f2 = export_dmg_xml(('dmg_dist_per_taxonomy', 'xml'), oqparam.export_dir, dmg_states, dd_taxo, suffix) f3 = export_dmg_xml(('dmg_dist_total', 'xml'), oqparam.export_dir, dmg_states, dd_total, suffix) max_damage = dmg_states[-1] # the collapse map is extracted from the damage distribution per asset # (dda) by taking the value corresponding to the maximum damage collapse_map = [dda for dda in dd_asset if dda.dmg_state == max_damage] f4 = export_dmg_xml(('collapse_map', 'xml'), oqparam.export_dir, dmg_states, collapse_map, suffix) fnames.extend(sum((f1 + f2 + f3 + f4).values(), [])) return sorted(fnames)
def export_classical_damage_csv(ekey, dstore): damages_by_rlz = dstore['damages_by_rlz'] rlzs = dstore['rlzs_assoc'].realizations damage_states = dstore['riskmodel'].damage_states dmg_states = [DmgState(s, i) for i, s in enumerate(damage_states)] fnames = [] for rlz in rlzs: damages = damages_by_rlz[rlz.ordinal] fname = 'damage_%d.csv' % rlz.ordinal fnames.append( _export_classical_damage_csv(dstore, fname, dmg_states, damages)) return fnames
def export_classical_damage_csv(ekey, dstore): """ :param ekey: export key, i.e. a pair (datastore key, fmt) :param dstore: datastore object """ damages_by_rlz = dstore['damages_by_rlz'] rlzs = dstore['rlzs_assoc'].realizations damage_states = dstore['riskmodel'].damage_states dmg_states = [DmgState(s, i) for i, s in enumerate(damage_states)] fnames = [] for rlz in rlzs: damages = damages_by_rlz[rlz.ordinal] fname = 'damage_%d.csv' % rlz.ordinal fnames.append( _export_classical_damage_csv(dstore.export_dir, fname, dmg_states, damages)) return fnames
def export_damage(ekey, dstore): riskmodel = dstore['riskmodel'] rlzs = dstore['rlzs_assoc'].realizations dmg_by_asset = dstore['dmg_by_asset'] # shape (N, L, R) assetcol = dstore['assetcol'] sitemesh = dstore['sitemesh'] dmg_states = [ DmgState(s, i) for i, s in enumerate(riskmodel.damage_states) ] D = len(dmg_states) N, R = dmg_by_asset.shape L = len(riskmodel.loss_types) fnames = [] for l, r in itertools.product(range(L), range(R)): lt = riskmodel.loss_types[l] rlz = rlzs[r] suffix = '' if L == 1 and R == 1 else '-gsimltp_%s_%s' % (rlz.uid, lt) dd_asset = [] for n in range(N): aref = assetcol[n]['asset_ref'] dist = dmg_by_asset[n, r][lt] point = sitemesh[assetcol[n]['site_id']] site = Site(point['lon'], point['lat']) for ds in range(D): dd_asset.append( DmgDistPerAsset(ExposureData(aref, site), dmg_states[ds], dist['mean'][ds], dist['stddev'][ds])) f1 = export_dmg_xml(('dmg_dist_per_asset', 'xml'), dstore, dmg_states, dd_asset, suffix) max_damage = dmg_states[-1] # the collapse map is extracted from the damage distribution per asset # (dda) by taking the value corresponding to the maximum damage collapse_map = [dda for dda in dd_asset if dda.dmg_state == max_damage] f2 = export_dmg_xml(('collapse_map', 'xml'), dstore, dmg_states, collapse_map, suffix) fnames.extend(sum((f1 + f2).values(), [])) return sorted(fnames)
def export_damage(ekey, dstore): loss_types = dstore.get_attr('composite_risk_model', 'loss_types') damage_states = dstore.get_attr('composite_risk_model', 'damage_states') rlzs = dstore['csm_info'].get_rlzs_assoc().realizations dmg_by_asset = dstore['dmg_by_asset'] # shape (N, L, R) assetcol = dstore['assetcol/array'].value aref = dstore['asset_refs'].value dmg_states = [DmgState(s, i) for i, s in enumerate(damage_states)] D = len(dmg_states) N, R = dmg_by_asset.shape L = len(loss_types) fnames = [] for l, r in itertools.product(range(L), range(R)): lt = loss_types[l] rlz = rlzs[r] suffix = '' if L == 1 and R == 1 else '-gsimltp_%s_%s' % (rlz.uid, lt) dd_asset = [] for n, ass in enumerate(assetcol): assref = aref[ass['idx']] dist = dmg_by_asset[n, r][lt] site = Site(ass['lon'], ass['lat']) for ds in range(D): dd_asset.append( DmgDistPerAsset(ExposureData(assref, site), dmg_states[ds], dist['mean'][ds], dist['stddev'][ds])) f1 = export_dmg_xml(('dmg_dist_per_asset', 'xml'), dstore, dmg_states, dd_asset, suffix) max_damage = dmg_states[-1] # the collapse map is extracted from the damage distribution per asset # (dda) by taking the value corresponding to the maximum damage collapse_map = [dda for dda in dd_asset if dda.dmg_state == max_damage] f2 = export_dmg_xml(('collapse_map', 'xml'), dstore, dmg_states, collapse_map, suffix) fnames.extend(sum((f1 + f2).values(), [])) return sorted(fnames)