Esempio n. 1
0
    def iter_ruptures(self, fromidx=0, untilidx=None, **kwargs):
        """
        An iterator for the ruptures.

        :param fromidx: start
        :param untilidx: stop
        """
        # check
        if 'sections' not in self.__dict__:
            raise RuntimeError('You forgot to call set_sections in %s!' % self)

        # iter on the ruptures
        untilidx = len(self.mags) if untilidx is None else untilidx
        s = self.sections
        for i in range(fromidx, untilidx):
            idxs = self.rupture_idxs[i]
            if len(idxs) == 1:
                sfc = self.sections[idxs[0]].surface
            else:
                sfc = MultiSurface([s[idx].surface for idx in idxs])
            rake = self.rakes[i]
            hypo = self.sections[idxs[0]].surface.get_middle_point()
            yield NonParametricProbabilisticRupture(self.mags[i], rake,
                                                    self.tectonic_region_type,
                                                    hypo, sfc, self.pmfs[i])
Esempio n. 2
0
 def fromdict(self, dic, weights=None):
     """
     Populate a GriddedSource with ruptures
     """
     assert not self.data, '%s is not empty' % self
     i = 0
     for mag, rake, hp, probs, (start, stop) in zip(dic['magnitude'],
                                                    dic['rake'],
                                                    dic['hypocenter'],
                                                    dic['probs_occur'],
                                                    dic['slice']):
         mesh = Mesh(dic['mesh3d'][start:stop, 0],
                     dic['mesh3d'][start:stop, 1], dic['mesh3d'][start:stop,
                                                                 2])
         surface = GriddedSurface(mesh)
         pmf = PMF([(prob, i) for i, prob in enumerate(probs)])
         hypocenter = Point(hp[0], hp[1], hp[2])
         rup = NonParametricProbabilisticRupture(
             mag,
             rake,
             self.tectonic_region_type,
             hypocenter,
             surface,
             pmf,
             weight=None if weights is None else weights[i])
         self.data.append((rup, pmf))
         i += 1
Esempio n. 3
0
 def __fromh5__(self, dic, attrs):
     vars(self).update(attrs)
     self.data = []
     for mag, rake, hp, probs, points in zip(
             dic['magnitude'], dic['rake'], dic['hypocenter'],
             dic['probs_occur'], dic['points']):
         mesh = Mesh(points[0], points[1], points[2])
         surface = GriddedSurface(mesh)
         pmf = PMF([(prob, i) for i, prob in enumerate(probs)])
         hypocenter = Point(hp['lon'], hp['lat'], hp['depth'])
         rup = NonParametricProbabilisticRupture(
             mag, rake, self.tectonic_region_type, hypocenter, surface, pmf)
         self.data.append((rup, pmf))
    def iter_ruptures(self):
        """
        Get a generator object that yields probabilistic ruptures the source
        consists of.

        :returns:
            Generator of instances of :class:
            `~openquake.hazardlib.source.rupture.NonParametricProbabilisticRupture`.
        """
        for rup, pmf in self.data:
            yield NonParametricProbabilisticRupture(
                rup.mag, rup.rake, self.tectonic_region_type, rup.hypocenter,
                rup.surface, pmf)
Esempio n. 5
0
 def few_ruptures(self):
     """
     Fast version of iter_ruptures used in estimate_weight
     """
     for i, (rup, pmf) in enumerate(self.data):
         if i % 25 == 0 and rup.mag >= self.min_mag:
             yield NonParametricProbabilisticRupture(
                 rup.mag,
                 rup.rake,
                 self.tectonic_region_type,
                 rup.hypocenter,
                 rup.surface,
                 pmf,
                 weight=rup.weight)
Esempio n. 6
0
 def few_ruptures(self):
     """
     Fast version of iter_ruptures used in estimate_weight
     """
     s = self.sections
     for i in range(0, len(self.mags), BLOCKSIZE // 5):
         idxs = self.rupture_idxs[i]
         if len(idxs) == 1:
             sfc = self.sections[idxs[0]].surface
         else:
             sfc = MultiSurface([s[idx].surface for idx in idxs])
         rake = self.rakes[i]
         hypo = self.sections[idxs[0]].surface.get_middle_point()
         yield NonParametricProbabilisticRupture(
             self.mags[i], rake, self.tectonic_region_type, hypo, sfc,
             self.pmfs[i])
Esempio n. 7
0
    def iter_ruptures(self, **kwargs):
        """
        Get a generator object that yields probabilistic ruptures the source
        consists of.

        :returns:
            Generator of instances of :class:`openquake.hazardlib.source.
            rupture.NonParametricProbabilisticRupture`.
        """
        for rup, pmf in self.data:
            if rup.mag >= self.min_mag:
                yield NonParametricProbabilisticRupture(
                    rup.mag,
                    rup.rake,
                    self.tectonic_region_type,
                    rup.hypocenter,
                    rup.surface,
                    pmf,
                    weight=rup.weight,
                    source_id=self.source_id,
                    source_name=self.name)