Пример #1
0
    def execute(self):
        """
        Run the calculator and aggregate the results
        """
        if self.oqparam.number_of_logic_tree_samples:
            logging.warn('The event based risk calculator with sampling is '
                         'EXPERIMENTAL, UNTESTED and SLOW')
        if self.oqparam.ground_motion_fields:
            logging.warn('To store the ground motion fields change '
                         'calculation_mode = event_based')
        if self.oqparam.hazard_curves_from_gmfs:
            logging.warn('To compute the hazard curves change '
                         'calculation_mode = event_based')

        if 'all_loss_ratios' in self.datastore:
            EbrPostCalculator(self).run(close=False)
            return

        self.csm_info = self.datastore['csm_info']
        with self.monitor('reading ruptures', autoflush=True):
            ruptures_by_grp = (self.precalc.result if self.precalc else
                               event_based.get_ruptures_by_grp(
                                   self.datastore.parent))
            # the ordering of the ruptures is essential for repeatibility
            for grp in ruptures_by_grp:
                ruptures_by_grp[grp].sort(key=operator.attrgetter('serial'))
        num_rlzs = 0
        allres = []
        source_models = self.csm_info.source_models
        self.sm_by_grp = self.csm_info.get_sm_by_grp()
        for i, args in enumerate(self.gen_args(ruptures_by_grp)):
            ires = self.start_tasks(*args)
            allres.append(ires)
            ires.rlz_slice = slice(num_rlzs, num_rlzs + ires.num_rlzs)
            num_rlzs += ires.num_rlzs
            for sg in source_models[i].src_groups:
                sg.eff_ruptures = ires.num_ruptures.get(sg.id, 0)
        num_events = self.save_results(allres, num_rlzs)
        return num_events  # {sm_id: #events}
Пример #2
0
    def execute(self):
        """
        Run the calculator and aggregate the results
        """
        if self.oqparam.ground_motion_fields:
            logging.warn('To store the ground motion fields change '
                         'calculation_mode = event_based')
        if self.oqparam.hazard_curves_from_gmfs:
            logging.warn('To compute the hazard curves change '
                         'calculation_mode = event_based')

        ruptures_by_grp = (
            self.precalc.result if self.precalc
            else event_based.get_ruptures_by_grp(self.datastore.parent))
        # the ordering of the ruptures is essential for repeatibility
        for grp in ruptures_by_grp:
            ruptures_by_grp[grp].sort(key=operator.attrgetter('serial'))
        num_rlzs = 0
        allres = []
        source_models = self.csm.info.source_models
        self.sm_by_grp = self.csm.info.get_sm_by_grp()
        for i, args in enumerate(self.gen_args(ruptures_by_grp)):
            smap, attrs = self.build_starmap(*args)
            res = smap.submit_all()
            vars(res).update(attrs)
            allres.append(res)
            res.rlz_slice = slice(num_rlzs, num_rlzs + res.num_rlzs)
            num_rlzs += res.num_rlzs
            for sg in source_models[i].src_groups:
                sg.eff_ruptures = res.num_ruptures.get(sg.id, 0)
        self.datastore['csm_info'] = self.csm.info
        self.datastore.flush()  # when killing the computation
        # the csm_info arrays were stored but not the attributes;
        # adding the .flush() solved the issue
        num_events = self.save_results(allres, num_rlzs)
        self.save_data_transfer(parallel.IterResult.sum(allres))
        return num_events