Example #1
0
 def agg_dicts(self, acc, result):
     """
     :param acc: accumulator dictionary
     :param result: an AccumDict with events, ruptures, gmfs and hcurves
     """
     sav_mon = self.monitor('saving gmfs')
     agg_mon = self.monitor('aggregating hcurves')
     with sav_mon:
         data = result.pop('gmfdata')
         if len(data):
             idxs = base.get_idxs(data, self.eid2idx)  # this has to be fast
             data['eid'] = idxs  # replace eid with idx
             self.datastore.extend('gmf_data/data', data)
             sig_eps = result.pop('sig_eps')
             sig_eps['eid'] = base.get_idxs(sig_eps, self.eid2idx)
             self.datastore.extend('gmf_data/sigma_epsilon', sig_eps)
             # it is important to save the number of bytes while the
             # computation is going, to see the progress
             update_nbytes(self.datastore, 'gmf_data/data', data)
             for sid, start, stop in result['indices']:
                 self.indices[sid, 0].append(start + self.offset)
                 self.indices[sid, 1].append(stop + self.offset)
             self.offset += len(data)
             if self.offset >= TWO32:
                 raise RuntimeError(
                     'The gmf_data table has more than %d rows' % TWO32)
     imtls = self.oqparam.imtls
     with agg_mon:
         for key, poes in result.get('hcurves', {}).items():
             r, sid, imt = str2rsi(key)
             array = acc[r].setdefault(sid, 0).array[imtls(imt), 0]
             array[:] = 1. - (1. - array) * (1. - poes)
     self.datastore.flush()
     return acc
Example #2
0
 def agg_dicts(self, acc, result):
     """
     :param acc: accumulator dictionary
     :param result: an AccumDict with events, ruptures, gmfs and hcurves
     """
     sav_mon = self.monitor('saving gmfs')
     agg_mon = self.monitor('aggregating hcurves')
     with sav_mon:
         data = result.pop('gmfdata')
         if len(data) == 0:
             return acc
         idxs = base.get_idxs(data, self.eid2idx)  # this has to be fast
         data['eid'] = idxs  # replace eid with idx
         self.datastore.extend('gmf_data/data', data)
         sig_eps = result.pop('sig_eps')
         sig_eps['eid'] = base.get_idxs(sig_eps, self.eid2idx)
         self.datastore.extend('gmf_data/sigma_epsilon', sig_eps)
         # it is important to save the number of bytes while the
         # computation is going, to see the progress
         update_nbytes(self.datastore, 'gmf_data/data', data)
         for sid, start, stop in result['indices']:
             self.indices[sid, 0].append(start + self.offset)
             self.indices[sid, 1].append(stop + self.offset)
         self.offset += len(data)
         if self.offset >= TWO32:
             raise RuntimeError(
                 'The gmf_data table has more than %d rows' % TWO32)
     imtls = self.oqparam.imtls
     with agg_mon:
         for key, poes in result.get('hcurves', {}).items():
             r, sid, imt = str2rsi(key)
             array = acc[r].setdefault(sid, 0).array[imtls(imt), 0]
             array[:] = 1. - (1. - array) * (1. - poes)
     sav_mon.flush()
     agg_mon.flush()
     self.datastore.flush()
     return acc