Exemple #1
0
 def _update_pmap(self, ctxs, pmap=None):
     # compute PoEs and update pmap
     if pmap is None:  # for src_indep
         pmap = self.pmap
     for rup, r_sites, dctx in ctxs:
         # this must be fast since it is inside an inner loop
         with self.gmf_mon:
             mean_std = base.get_mean_std(  # shape (2, N, M, G)
                 r_sites, rup, dctx, self.imts, self.gsims)
         with self.poe_mon:
             ll = self.loglevels
             poes = base.get_poes(mean_std, ll, self.trunclevel, self.gsims)
             for g, gsim in enumerate(self.gsims):
                 for m, imt in enumerate(ll):
                     if hasattr(gsim, 'weight') and gsim.weight[imt] == 0:
                         # set by the engine when parsing the gsim logictree
                         # when 0 ignore the gsim: see _build_trts_branches
                         poes[:, ll(imt), g] = 0
         with self.pne_mon:
             # pnes and poes of shape (N, L, G)
             pnes = rup.get_probability_no_exceedance(poes)
             for grp_id in rup.grp_ids:
                 p = pmap[grp_id]
                 if self.rup_indep:
                     for sid, pne in zip(r_sites.sids, pnes):
                         p.setdefault(sid, 1.).array *= pne
                 else:  # rup_mutex
                     for sid, pne in zip(r_sites.sids, pnes):
                         p.setdefault(sid,
                                      0.).array += (1. - pne) * rup.weight
Exemple #2
0
    def _update_pmap(self, ctxs, pmap=None):
        # compute PoEs and update pmap
        if pmap is None:  # for src_indep
            pmap = self.pmap
        rup_indep = self.rup_indep
        for ctx in ctxs:
            # this must be fast since it is inside an inner loop
            with self.gmf_mon:
                # shape (2, N, M, G)
                mean_std = ctx.get_mean_std(self.imts, self.gsims)
            with self.poe_mon:
                ll = self.loglevels
                af = self.cmaker.af
                if af:
                    [sitecode] = ctx.sites['ampcode']  # single-site only
                else:
                    sitecode = None
                poes = base.get_poes(mean_std, ll, self.trunclevel, self.gsims,
                                     af, ctx.mag, sitecode, ctx.rrup)
                for g, gsim in enumerate(self.gsims):
                    for m, imt in enumerate(ll):
                        if hasattr(gsim, 'weight') and gsim.weight[imt] == 0:
                            # set by the engine when parsing the gsim logictree
                            # when 0 ignore the gsim: see _build_trts_branches
                            poes[:, ll(imt), g] = 0

            with self.pne_mon:
                # pnes and poes of shape (N, L, G)
                pnes = ctx.get_probability_no_exceedance(poes)
                for sid, pne in zip(ctx.sids, pnes):
                    probs = pmap.setdefault(sid, rup_indep).array
                    if rup_indep:
                        probs *= pne
                    else:  # rup_mutex
                        probs += (1. - pne) * ctx.weight
Exemple #3
0
 def _make_pnes(self, rupture, mean_std):
     ll = self.loglevels
     poes = base.get_poes(mean_std, ll, self.trunclevel, self.gsims)
     for g, gsim in enumerate(self.gsims):
         for m, imt in enumerate(ll):
             if hasattr(gsim, 'weight') and gsim.weight[imt] == 0:
                 # set by the engine when parsing the gsim logictree;
                 # when 0 ignore the gsim: see _build_trts_branches
                 poes[:, ll(imt), g] = 0
     return rupture.get_probability_no_exceedance(poes)
Exemple #4
0
 def _sids_poes(self, rup, r_sites, dctx, srcid):
     # return sids and poes of shape (N, L, G)
     # NB: this must be fast since it is inside an inner loop
     with self.gmf_mon:
         mean_std = base.get_mean_std(  # shape (2, N, M, G)
             r_sites, rup, dctx, self.imts, self.gsims)
     with self.poe_mon:
         ll = self.loglevels
         poes = base.get_poes(mean_std, ll, self.trunclevel, self.gsims)
         for g, gsim in enumerate(self.gsims):
             for m, imt in enumerate(ll):
                 if hasattr(gsim, 'weight') and gsim.weight[imt] == 0:
                     # set by the engine when parsing the gsim logictree;
                     # when 0 ignore the gsim: see _build_trts_branches
                     poes[:, ll(imt), g] = 0
         return r_sites.sids, poes
Exemple #5
0
def make_pmap(ctxs, gsims, imtls, trunclevel, investigation_time):
    RuptureContext.temporal_occurrence_model = PoissonTOM(investigation_time)
    # easy case of independent ruptures, useful for debugging
    imts = [from_string(im) for im in imtls]
    loglevels = DictArray(imtls)
    for imt, imls in imtls.items():
        if imt != 'MMI':
            loglevels[imt] = numpy.log(imls)
    pmap = ProbabilityMap(len(loglevels.array), len(gsims))
    for ctx in ctxs:
        mean_std = ctx.get_mean_std(imts, gsims)  # shape (2, N, M, G)
        poes = base.get_poes(mean_std, loglevels, trunclevel, gsims, None,
                             ctx.mag, None, ctx.rrup)  # (N, L, G)
        pnes = ctx.get_probability_no_exceedance(poes)
        for sid, pne in zip(ctx.sids, pnes):
            pmap.setdefault(sid, 1.).array *= pne
    return ~pmap