def make(self, src, sites, pmap): """ :param src: a hazardlib source :param s_sites: the sites affected by it :returns: the probability map generated by the source """ with self.cmaker.mon('iter_ruptures', measuremem=False): self.mag_rups = [(mag, list(rups)) for mag, rups in itertools.groupby( src.iter_ruptures(shift_hypo=self.shift_hypo), key=operator.attrgetter('mag'))] rupdata = RupData(self.cmaker) totrups, numrups, nsites = 0, 0, 0 L, G = len(self.imtls.array), len(self.gsims) poemap = ProbabilityMap(L, G) dists = [] for rups, sites, mdist in self._gen_rups_sites(src, sites): if mdist is not None: dists.append(mdist) with self.ctx_mon: ctxs = self.cmaker.make_ctxs(rups, sites, mdist) if ctxs: totrups += len(ctxs) ctxs = self.collapse(ctxs) numrups += len(ctxs) for rup, r_sites, dctx in ctxs: if self.fewsites: # store rupdata rupdata.add(rup, src.id, r_sites, dctx) sids, poes = self._sids_poes(rup, r_sites, dctx, src.id) with self.pne_mon: pnes = rup.get_probability_no_exceedance(poes) if self.rup_indep: for sid, pne in zip(sids, pnes): poemap.setdefault(sid, self.rup_indep).array *= pne else: for sid, pne in zip(sids, pnes): poemap.setdefault( sid, self.rup_indep).array += (1. - pne) * rup.weight nsites += len(sids) poemap.totrups = totrups poemap.numrups = numrups poemap.nsites = nsites poemap.maxdist = numpy.mean(dists) if dists else None poemap.data = rupdata.data self._update(pmap, poemap, src) return poemap
def get_pmap(self, src, s_sites, rup_indep=True): """ :param src: a hazardlib source :param s_sites: the sites affected by it :returns: the probability map generated by the source """ imts = self.imts fewsites = len(s_sites.complete) <= self.max_sites_disagg rupdata = RupData(self) nrups, nsites = 0, 0 L, G = len(self.imtls.array), len(self.gsims) poemap = ProbabilityMap(L, G) dists = [] for rup, sites, maxdist in self._gen_rup_sites(src, s_sites): if maxdist is not None: dists.append(maxdist) try: with self.ctx_mon: r_sites, dctx = self.make_contexts(sites, rup, maxdist) except FarAwayRupture: continue with self.gmf_mon: mean_std = base.get_mean_std( # shape (2, N, M, G) r_sites, rup, dctx, imts, self.gsims) with self.poe_mon: pairs = zip(r_sites.sids, self._make_pnes(rup, mean_std)) with self.pne_mon: if rup_indep: for sid, pne in pairs: poemap.setdefault(sid, rup_indep).array *= pne else: for sid, pne in pairs: poemap.setdefault(sid, rup_indep).array += ( 1.-pne) * rup.weight nrups += 1 nsites += len(r_sites) if fewsites: # store rupdata rupdata.add(rup, src.id, r_sites, dctx) poemap.nrups = nrups poemap.nsites = nsites poemap.maxdist = numpy.mean(dists) if dists else None poemap.data = rupdata.data return poemap
def make(self): """ :param src: a hazardlib source :param s_sites: the sites affected by it :returns: the probability map generated by the source """ totrups, numrups, nsites = 0, 0, 0 L, G = len(self.imtls.array), len(self.gsims) poemap = ProbabilityMap(L, G) dists = [] for rups, sites, mdist in self._gen_rups_sites(): if mdist is not None: dists.append(mdist) with self.ctx_mon: ctxs = self.cmaker.make_ctxs(rups, sites, mdist) if ctxs: totrups += len(ctxs) ctxs = self.collapse(ctxs) numrups += len(ctxs) for rup, r_sites, dctx in ctxs: sids, poes = self._sids_poes(rup, r_sites, dctx) with self.pne_mon: pnes = rup.get_probability_no_exceedance(poes) if self.rup_indep: for sid, pne in zip(sids, pnes): poemap.setdefault(sid, self.rup_indep).array *= pne else: for sid, pne in zip(sids, pnes): poemap.setdefault( sid, self.rup_indep).array += (1. - pne) * rup.weight nsites += len(sids) poemap.totrups = totrups poemap.numrups = numrups poemap.nsites = nsites poemap.maxdist = numpy.mean(dists) if dists else None poemap.data = self.rupdata.data return poemap