Exemplo n.º 1
0
 def get_background_sources(self):
     """
     Turn the background model of a given branch into a set of point sources
     """
     background_sids = self.get_background_sids()
     with h5py.File(self.source_file, "r") as hdf5:
         grid_loc = "/".join(["Grid", self.ukey["grid_key"]])
         # for instance Grid/FM0_0_MEANFS_MEANMSR_MeanRates
         mags = hdf5[grid_loc + "/Magnitude"][()]
         mmax = hdf5[grid_loc + "/MMax"][background_sids]
         rates = hdf5[grid_loc + "/RateArray"][background_sids, :]
         locations = hdf5["Grid/Locations"][background_sids, :]
         sources = []
         for i, bg_idx in enumerate(background_sids):
             src_id = "_".join([self.ukey["grid_key"], str(bg_idx)])
             src_name = "|".join([self.ukey["total_key"], str(bg_idx)])
             mag_idx = (self.min_mag <= mags) & (mags < mmax[i])
             src_mags = mags[mag_idx]
             src_mfd = EvenlyDiscretizedMFD(src_mags[0],
                                            src_mags[1] - src_mags[0],
                                            rates[i, mag_idx].tolist())
             ps = PointSource(src_id, src_name, self.tectonic_region_type,
                              src_mfd, self.mesh_spacing, self.msr,
                              self.aspect, self.tom, self.usd, self.lsd,
                              Point(locations[i, 0],
                                    locations[i, 1]), self.npd, self.hdd)
             ps.checksum = zlib.adler32(pickle.dumps(vars(ps), protocol=4))
             ps._wkt = ps.wkt()
             ps.id = self.id
             ps.et_id = self.et_id
             ps.num_ruptures = ps.count_ruptures()
             ps.nsites = 1  # anything <> 0 goes
             sources.append(ps)
     return sources
Exemplo n.º 2
0
    def get_background_sources(self, sample_factor=None):
        """
        Turn the background model of a given branch into a set of point sources

        :param sample_factor:
            Used to reduce the sources if OQ_SAMPLE_SOURCES is set
        """
        background_sids = self.get_background_sids()
        if sample_factor is not None:  # hack for use in the mosaic
            background_sids = random_filter(
                background_sids, sample_factor, seed=42)
        with h5py.File(self.source_file, "r") as hdf5:
            grid_loc = "/".join(["Grid", self.idx_set["grid_key"]])
            # for instance Grid/FM0_0_MEANFS_MEANMSR_MeanRates
            mags = hdf5[grid_loc + "/Magnitude"][()]
            mmax = hdf5[grid_loc + "/MMax"][background_sids]
            rates = hdf5[grid_loc + "/RateArray"][background_sids, :]
            locations = hdf5["Grid/Locations"][background_sids, :]
            sources = []
            for i, bg_idx in enumerate(background_sids):
                src_id = "_".join([self.idx_set["grid_key"], str(bg_idx)])
                src_name = "|".join([self.idx_set["total_key"], str(bg_idx)])
                mag_idx = (self.min_mag <= mags) & (mags < mmax[i])
                src_mags = mags[mag_idx]
                src_mfd = EvenlyDiscretizedMFD(
                    src_mags[0],
                    src_mags[1] - src_mags[0],
                    rates[i, mag_idx].tolist())
                ps = PointSource(
                    src_id, src_name, self.tectonic_region_type, src_mfd,
                    self.mesh_spacing, self.msr, self.aspect, self.tom,
                    self.usd, self.lsd,
                    Point(locations[i, 0], locations[i, 1]),
                    self.npd, self.hdd)
                ps.checksum = zlib.adler32(pickle.dumps(vars(ps), protocol=4))
                ps._wkt = ps.wkt()
                ps.id = self.id
                ps.grp_id = self.grp_id
                ps.num_ruptures = ps.count_ruptures()
                sources.append(ps)
        return sources