Ejemplo n.º 1
0
 def gen_args(self, monitor):
     """
     Generate a task for each branch
     """
     oq = self.oqparam
     allargs = []  # it is better to return a list; if there is single
     # branch then `parallel.Starmap` will run the task in core
     rlzs_by_gsim = self.csm.info.get_rlzs_by_gsim_grp()
     ufilter = UcerfFilter(self.sitecol, self.oqparam.maximum_distance)
     for sm_id in range(len(self.csm.source_models)):
         ssm = self.csm.get_model(sm_id)
         [sm] = ssm.source_models
         srcs = ssm.get_sources()
         for ses_idx in range(1, oq.ses_per_logic_tree_path + 1):
             ses_seeds = [(ses_idx, oq.ses_seed + ses_idx)]
             param = dict(ses_seeds=ses_seeds,
                          samples=sm.samples,
                          oqparam=oq,
                          save_ruptures=oq.save_ruptures,
                          filter_distance=oq.filter_distance,
                          gmf=oq.ground_motion_fields,
                          min_iml=self.get_min_iml(oq))
             allargs.append(
                 (srcs, ufilter, rlzs_by_gsim[sm_id], param, monitor))
     return allargs
Ejemplo n.º 2
0
    def gen_args(self):
        """
        Yield the arguments required by build_ruptures, i.e. the
        source models, the asset collection, the riskmodel and others.
        """
        oq = self.oqparam
        self.L = len(self.riskmodel.lti)
        self.I = oq.insured_losses + 1
        min_iml = self.get_min_iml(oq)
        elt_dt = numpy.dtype([('eid', U64), ('rlzi', U16),
                              ('loss', (F32, (self.L, )))])
        monitor = self.monitor('compute_losses')
        src_filter = UcerfFilter(self.sitecol.complete, oq.maximum_distance)

        for sm in self.csm.source_models:
            if sm.samples > 1:
                logging.warn('Sampling in ucerf_risk is untested')
            ssm = self.csm.get_model(sm.ordinal)
            for ses_idx in range(1, oq.ses_per_logic_tree_path + 1):
                param = dict(ses_seeds=[(ses_idx, oq.ses_seed + ses_idx)],
                             samples=sm.samples,
                             assetcol=self.assetcol,
                             save_ruptures=False,
                             ses_ratio=oq.ses_ratio,
                             avg_losses=oq.avg_losses,
                             elt_dt=elt_dt,
                             min_iml=min_iml,
                             oqparam=oq,
                             insured_losses=oq.insured_losses)
                yield ssm, src_filter, param, self.riskmodel, monitor
Ejemplo n.º 3
0
 def pre_execute(self):
     super().pre_execute()
     self.src_filter = UcerfFilter(
         self.sitecol, self.oqparam.maximum_distance)
     for sm in self.csm.source_models:  # one branch at the time
         [grp] = sm.src_groups
         for src in grp:
             self.csm.infos[src.source_id] = source.SourceInfo(src)
             grp.tot_ruptures += src.num_ruptures
Ejemplo n.º 4
0
 def src_filter(self):
     """
     :returns: a SourceFilter/UcerfFilter
     """
     oq = self.oqparam
     self.hdf5cache = self.datastore.hdf5cache()
     sitecol = self.sitecol.complete if self.sitecol else None
     if 'ucerf' in oq.calculation_mode:
         return UcerfFilter(sitecol, oq.maximum_distance, self.hdf5cache)
     return SourceFilter(sitecol, oq.maximum_distance, self.hdf5cache)
Ejemplo n.º 5
0
 def pre_execute(self):
     super().pre_execute()
     self.src_filter = UcerfFilter(self.sitecol,
                                   self.oqparam.maximum_distance)
     for sm in self.csm.source_models:  # one branch at the time
         [grp] = sm.src_groups
         ucerf = grp.sources[0].orig
         logging.info('Getting background sources from %s', ucerf.source_id)
         grp.sources.extend(ucerf.get_background_sources(self.src_filter))
         for src in grp:
             self.csm.infos[src.source_id] = source.SourceInfo(src)
             grp.tot_ruptures += src.num_ruptures
Ejemplo n.º 6
0
 def src_filter(self):
     """
     :returns: a SourceFilter/UcerfFilter
     """
     oq = self.oqparam
     if getattr(self, 'sitecol', None):
         sitecol = self.sitecol.complete
     else:  # can happen to the ruptures-only calculator
         sitecol = None
     if oq.is_ucerf():
         return UcerfFilter(sitecol, oq.maximum_distance)
     return SourceFilter(sitecol, oq.maximum_distance)
Ejemplo n.º 7
0
 def src_filter(self, filename=None):
     """
     :returns: a SourceFilter/UcerfFilter
     """
     oq = self.oqparam
     if getattr(self, 'sitecol', None):
         sitecol = self.sitecol.complete
     else:  # can happen to the ruptures-only calculator
         sitecol = None
         filename = None
     if 'ucerf' in oq.calculation_mode:
         return UcerfFilter(sitecol, oq.maximum_distance, filename)
     return SourceFilter(sitecol, oq.maximum_distance, filename)
Ejemplo n.º 8
0
 def from_sources(self, param):
     """
     Generate a task for each branch
     """
     oq = self.oqparam
     allargs = []  # it is better to return a list; if there is single
     # branch then `parallel.Starmap` will run the task in core
     rlzs_by_gsim = self.csm.info.get_rlzs_by_gsim_grp()
     ufilter = UcerfFilter(self.sitecol, self.oqparam.maximum_distance)
     for sm_id in range(len(self.csm.source_models)):
         ssm = self.csm.get_model(sm_id)
         [sm] = ssm.source_models
         srcs = ssm.get_sources()
         for ses_idx in range(oq.ses_per_logic_tree_path):
             param = param.copy()
             param['ses_seeds'] = [(ses_idx, oq.ses_seed + ses_idx + 1)]
             allargs.append((srcs, ufilter, rlzs_by_gsim[sm_id], param))
     return allargs
Ejemplo n.º 9
0
 def pre_execute(self):
     """
     parse the logic tree and source model input
     """
     logging.warn('%s is still experimental', self.__class__.__name__)
     oq = self.oqparam
     self.read_risk_data()  # read the site collection
     self.csm = readinput.get_composite_source_model(oq)
     self.csm.src_filter = UcerfFilter(self.sitecol, oq.maximum_distance)
     logging.info('Found %d source model logic tree branches',
                  len(self.csm.source_models))
     self.datastore['sitecol'] = self.sitecol
     self.datastore['csm_info'] = self.csm_info = self.csm.info
     self.rlzs_assoc = self.csm_info.get_rlzs_assoc()
     self.infos = []
     self.eid = collections.Counter()  # sm_id -> event_id
     self.sm_by_grp = self.csm_info.get_sm_by_grp()
     if not self.oqparam.imtls:
         raise ValueError('Missing intensity_measure_types!')
     self.rupser = calc.RuptureSerializer(self.datastore)
     self.precomputed_gmfs = False
Ejemplo n.º 10
0
 def filter_csm(self):
     return UcerfFilter(
         self.sitecol, self.oqparam.maximum_distance), self.csm