Example #1
0
 def get_getter(self, kind, sid):
     """
     :param kind: 'poe' or 'gmf'
     :param sid: a site ID
     :returns: a PmapGetter or GmfDataGetter
     """
     if (self.oqparam.hazard_calculation_id and
             'gmf_data' not in self.datastore):
         # 'gmf_data' in self.datastore happens for ShakeMap calculations
         self.datastore.parent.close()  # make sure it is closed
         dstore = self.datastore.parent
     else:
         dstore = self.datastore
     if kind == 'poe':  # hcurves, shape (R, N)
         ws = [rlz.weight for rlz in self.rlzs_assoc.realizations]
         getter = getters.PmapGetter(dstore, ws, [sid])
     else:  # gmf
         getter = getters.GmfDataGetter(dstore, [sid], self.R)
         if len(dstore['gmf_data/data']) == 0:
             raise RuntimeError(
                 'There are no GMFs available: perhaps you set '
                 'ground_motion_fields=False or a large minimum_intensity')
     if (self.oqparam.calculation_mode not in
             'event_based_damage scenario_damage scenario_risk'
             and dstore is self.datastore):
         # hack to make h5py happy; I could not get this to work with
         # the SWMR mode
         getter.init()
     return getter
Example #2
0
 def get_getter(self, kind, sid):
     """
     :param kind: 'poe' or 'gmf'
     :param sid: a site ID
     :returns: a PmapGetter or GmfDataGetter
     """
     hdf5cache = getattr(self, 'hdf5cache', None)
     if hdf5cache:
         dstore = hdf5cache
     elif (self.oqparam.hazard_calculation_id and
           'gmf_data' not in self.datastore):
         # 'gmf_data' in self.datastore happens for ShakeMap calculations
         self.datastore.parent.close()  # make sure it is closed
         dstore = self.datastore.parent
     else:
         dstore = self.datastore
     if kind == 'poe':  # hcurves, shape (R, N)
         by_grp = self.rlzs_assoc.by_grp()
         ws = [rlz.weight for rlz in self.rlzs_assoc.realizations]
         getter = getters.PmapGetter(dstore, by_grp, ws, [sid])
     else:  # gmf
         getter = getters.GmfDataGetter(dstore, [sid], self.R)
     if dstore is self.datastore:
         getter.init()
     return getter
Example #3
0
 def _gen_riskinputs_gmf(self, dstore):
     if 'gmf_data' not in dstore:  # needed for case_shakemap
         dstore.close()
         dstore = self.datastore
     if 'gmf_data' not in dstore:
         raise InvalidFile('Did you forget gmfs_csv in %s?' %
                           self.oqparam.inputs['job_ini'])
     with self.monitor('reading GMFs'):
         rlzs = dstore['events']['rlz_id']
         gmf_df = dstore.read_df('gmf_data', 'sid')
         by_sid = dict(list(gmf_df.groupby(gmf_df.index)))
     logging.info('Grouped the GMFs by site ID')
     for sid, assets in enumerate(self.assetcol.assets_by_site()):
         if len(assets) == 0:
             continue
         try:
             df = by_sid[sid]
         except KeyError:
             getter = getters.ZeroGetter(sid, rlzs, self.R)
         else:
             df['rlzs'] = rlzs[df.eid.to_numpy()]
             getter = getters.GmfDataGetter(sid, df, len(rlzs), self.R)
         if len(dstore['gmf_data/gmv_0']) == 0:
             raise RuntimeError(
                 'There are no GMFs available: perhaps you did set '
                 'ground_motion_fields=False or a large minimum_intensity')
         for block in general.block_splitter(
                 assets, self.oqparam.assets_per_site_limit):
             yield riskinput.RiskInput(sid, getter, numpy.array(block))
         if len(block) >= TWO16:
             logging.error('There are %d assets on site #%d!', len(block),
                           sid)
Example #4
0
 def _gen_riskinputs(self, kind, eps, num_events):
     rinfo_dt = numpy.dtype([('sid', U16), ('num_assets', U16)])
     rinfo = []
     assets_by_site = self.assetcol.assets_by_site()
     dstore = self.can_read_parent() or self.datastore
     for sid, assets in enumerate(assets_by_site):
         if len(assets) == 0:
             continue
         # build the riskinputs
         if kind == 'poe':  # hcurves, shape (R, N)
             getter = getters.PmapGetter(dstore, self.rlzs_assoc, [sid])
             getter.num_rlzs = self.R
         else:  # gmf
             getter = getters.GmfDataGetter(dstore, [sid], self.R)
         if dstore is self.datastore:
             # read the hazard data in the controller node
             getter.init()
         else:
             # the datastore must be closed to avoid the HDF5 fork bug
             assert dstore.hdf5 == (), '%s is not closed!' % dstore
         for block in general.block_splitter(
                 assets, self.oqparam.assets_per_site_limit):
             # dictionary of epsilons for the reduced assets
             reduced_eps = {ass.ordinal: eps[ass.ordinal]
                            for ass in block
                            if eps is not None and len(eps)}
             yield riskinput.RiskInput(getter, [block], reduced_eps)
         rinfo.append((sid, len(block)))
         if len(block) >= TWO16:
             logging.error('There are %d assets on site #%d!',
                           len(block), sid)
     self.datastore['riskinput_info'] = numpy.array(rinfo, rinfo_dt)