Ejemplo n.º 1
0
 def post_execute(self, dummy):
     oq = self.oqparam
     size = self.datastore.getsize('agg_loss_table')
     logging.info('Building aggregated curves from %s of agg_loss_table',
                  general.humansize(size))
     builder = get_loss_builder(self.datastore)
     alt_df = self.datastore.read_df('agg_loss_table')
     del alt_df['event_id']
     dic = general.AccumDict(accum=[])
     columns = sorted(
         set(alt_df.columns) - {'agg_id', 'loss_id', 'variance'})
     periods = [0] + list(builder.return_periods)
     for (agg_id,
          loss_id), df in alt_df.groupby([alt_df.agg_id, alt_df.loss_id]):
         tots = [df[col].sum() * oq.time_ratio for col in columns]
         curves = [
             builder.build_curve(df[col].to_numpy()) for col in columns
         ]
         for p, period in enumerate(periods):
             dic['agg_id'].append(agg_id)
             dic['loss_id'].append(loss_id)
             dic['return_period'].append(period)
             if p == 0:
                 for col, tot in zip(columns, tots):
                     dic[col].append(tot)
             else:
                 for col, curve in zip(columns, curves):
                     dic[col].append(curve[p - 1])
     fix_dtype(dic, U16, ['agg_id'])
     fix_dtype(dic, U8, ['loss_id'])
     fix_dtype(dic, U32, ['return_period'])
     fix_dtype(dic, F32, columns)
     ls = ' '.join(self.crmodel.damage_states[1:])
     self.datastore.create_df('aggcurves', dic.items(), limit_states=ls)
Ejemplo n.º 2
0
 def __init__(self, dstore):
     self.dstore = dstore
     self.oq = dstore['oqparam']
     try:
         self.builder = get_loss_builder(dstore)
     except KeyError:  # no 'events' for non event_based_risk
         pass
     self.assetcol = dstore['assetcol']
     arefs = [decode(aref) for aref in self.assetcol.asset_refs]
     self.str2asset = dict(zip(arefs, self.assetcol))
     self.asset_refs = arefs
     self.loss_types = dstore.get_attr('risk_model', 'loss_types')
     self.R = dstore['csm_info'].get_num_rlzs()
Ejemplo n.º 3
0
 def execute(self):
     """
     Compute risk from GMFs or ruptures depending on what is stored
     """
     self.builder = get_loss_builder(self.datastore)  # check
     eids = self.datastore['gmf_data/eid'][:]
     logging.info('Processing {:_d} rows of gmf_data'.format(len(eids)))
     self.dmgcsq = zero_dmgcsq(self.assetcol, self.crmodel)
     self.datastore.swmr_on()
     smap = parallel.Starmap(event_based_damage,
                             self.gen_args(eids),
                             h5=self.datastore.hdf5)
     smap.monitor.save('assets', self.assetcol.to_dframe())
     smap.monitor.save('crmodel', self.crmodel)
     return smap.reduce(self.combine)