예제 #1
0
파일: calc.py 프로젝트: ruthali/oq-risklib
def calc_gmfs_fast(oqparam, sitecol):
    """
    Build all the ground motion fields for the whole site collection in
    a single step.
    """
    max_dist = oqparam.maximum_distance
    correl_model = get_correl_model(oqparam)
    seed = oqparam.random_seed
    imts = get_imts(oqparam)
    [gsim] = get_gsims(oqparam)
    trunc_level = oqparam.truncation_level
    n_gmfs = oqparam.number_of_ground_motion_fields
    rupture = get_rupture(oqparam)
    res = gmf.ground_motion_fields(
        rupture,
        sitecol,
        imts,
        gsim,
        trunc_level,
        n_gmfs,
        correl_model,
        filters.rupture_site_distance_filter(max_dist),
        seed,
    )
    return {str(imt): matrix for imt, matrix in res.items()}
예제 #2
0
    def pre_execute(self):
        """
        Read the site collection and initialize GmfComputer, tags and seeds
        """
        super(ScenarioCalculator, self).pre_execute()
        trunc_level = self.oqparam.truncation_level
        correl_model = readinput.get_correl_model(self.oqparam)
        n_gmfs = self.oqparam.number_of_ground_motion_fields
        rupture = readinput.get_rupture(self.oqparam)
        self.gsims = readinput.get_gsims(self.oqparam)
        self.rlzs_assoc = readinput.get_rlzs_assoc(self.oqparam)

        # filter the sites
        self.sitecol = filters.filter_sites_by_distance_to_rupture(
            rupture, self.oqparam.maximum_distance, self.sitecol)
        if self.sitecol is None:
            raise RuntimeError(
                'All sites were filtered out! '
                'maximum_distance=%s km' % self.oqparam.maximum_distance)
        self.tags = numpy.array(
            sorted(['scenario-%010d' % i for i in range(n_gmfs)]),
            (bytes, 100))
        self.computer = GmfComputer(
            rupture, self.sitecol, self.oqparam.imtls, self.gsims,
            trunc_level, correl_model)
        rnd = random.Random(self.oqparam.random_seed)
        self.tag_seed_pairs = [(tag, rnd.randint(0, calc.MAX_INT))
                               for tag in self.tags]
        self.sescollection = [{tag: Rupture(tag, seed, rupture)
                               for tag, seed in self.tag_seed_pairs}]
예제 #3
0
def main(argv):
    """
    This provides a short summary of the GSIM models used in a hazard model and
    the required parameters necessary to define ruptures, sites and
    rupture-site distances.
    """
    #
    # get the name of the .ini file
    ini_fname = argv[0]
    #
    # read the content of the configuration file
    oqparam = readinput.get_oqparam(ini_fname)
    gmmlt = readinput.get_gsim_lt(oqparam)
    gmmlist = set(readinput.get_gsims(oqparam))
    #
    # print results
    print('\nGMPEs:')
    for tstr in gmmlist:
        print('  - ', tstr)
    ctx = ContextMaker(gmmlist)
    #
    # parameters
    print('\nRequired rupture-site distances')
    print('   ', getattr(ctx, 'REQUIRES_DISTANCES'))
    print('Required site parameters')
    print('   ', getattr(ctx, 'REQUIRES_SITES_PARAMETERS'))
    print('Required rupture parameters')
    print('   ', getattr(ctx, 'REQUIRES_RUPTURE_PARAMETERS'))
예제 #4
0
    def pre_execute(self):
        """
        Read the site collection and initialize GmfComputer, tags and seeds
        """
        super(ScenarioCalculator, self).pre_execute()
        trunc_level = self.oqparam.truncation_level
        correl_model = readinput.get_correl_model(self.oqparam)
        n_gmfs = self.oqparam.number_of_ground_motion_fields
        rupture = readinput.get_rupture(self.oqparam)
        self.gsims = readinput.get_gsims(self.oqparam)
        self.rlzs_assoc = readinput.get_rlzs_assoc(self.oqparam)

        # filter the sites
        self.sitecol = filters.filter_sites_by_distance_to_rupture(
            rupture, self.oqparam.maximum_distance, self.sitecol)
        if self.sitecol is None:
            raise RuntimeError('All sites were filtered out! '
                               'maximum_distance=%s km' %
                               self.oqparam.maximum_distance)
        self.tags = numpy.array(
            sorted(['scenario-%010d' % i for i in range(n_gmfs)]),
            (bytes, 100))
        self.computer = GmfComputer(rupture, self.sitecol, self.oqparam.imtls,
                                    self.gsims, trunc_level, correl_model)
        rnd = random.Random(self.oqparam.random_seed)
        self.tag_seed_pairs = [(tag, rnd.randint(0, calc.MAX_INT))
                               for tag in self.tags]
        self.sescollection = [{
            tag: Rupture(tag, seed, rupture)
            for tag, seed in self.tag_seed_pairs
        }]
예제 #5
0
 def pre_execute(self):
     """
     Read the site collection and initialize GmfComputer and seeds
     """
     oq = self.oqparam
     cinfo = source.CompositionInfo.fake(readinput.get_gsim_lt(oq))
     self.datastore['csm_info'] = cinfo
     if 'rupture_model' not in oq.inputs:
         logging.warn('There is no rupture_model, the calculator will just '
                      'import data without performing any calculation')
         super().pre_execute()
         return
     self.rup = readinput.get_rupture(oq)
     self.gsims = readinput.get_gsims(oq)
     self.cmaker = ContextMaker(self.gsims, oq.maximum_distance,
                                {'filter_distance': oq.filter_distance})
     super().pre_execute()
     self.datastore['oqparam'] = oq
     self.rlzs_assoc = cinfo.get_rlzs_assoc()
     E = oq.number_of_ground_motion_fields
     events = numpy.zeros(E, readinput.stored_event_dt)
     events['eid'] = numpy.arange(E)
     ebr = EBRupture(self.rup, 0, self.sitecol.sids, events)
     self.datastore['events'] = ebr.events
     rupser = calc.RuptureSerializer(self.datastore)
     rupser.save([ebr])
     rupser.close()
     self.computer = GmfComputer(ebr, self.sitecol, oq.imtls, self.cmaker,
                                 oq.truncation_level, oq.correl_model)
예제 #6
0
 def pre_execute(self):
     """
     Read the site collection and initialize GmfComputer and seeds
     """
     super(ScenarioCalculator, self).pre_execute()
     oq = self.oqparam
     gsim_lt = readinput.get_gsim_lt(oq)
     cinfo = source.CompositionInfo.fake(gsim_lt)
     self.datastore['csm_info'] = cinfo
     self.datastore['oqparam'] = oq
     self.rlzs_assoc = cinfo.get_rlzs_assoc()
     if 'rupture_model' not in oq.inputs:
         logging.warn('There is no rupture_model, the calculator will just '
                      'import data without performing any calculation')
         return
     ebr, self.sitecol = readinput.get_rupture_sitecol(oq, self.sitecol)
     self.gsims = readinput.get_gsims(oq)
     self.datastore['events'] = ebr.events
     rupser = calc.RuptureSerializer(self.datastore)
     rupser.save([ebr])
     rupser.close()
     trunc_level = oq.truncation_level
     correl_model = oq.get_correl_model()
     self.computer = GmfComputer(ebr, self.sitecol, oq.imtls,
                                 ContextMaker(self.gsims), trunc_level,
                                 correl_model)
예제 #7
0
 def pre_execute(self):
     """
     Read the site collection and initialize GmfComputer and seeds
     """
     super(ScenarioCalculator, self).pre_execute()
     oq = self.oqparam
     trunc_level = oq.truncation_level
     correl_model = oq.get_correl_model()
     rup = readinput.get_rupture(oq)
     rup.seed = self.oqparam.random_seed
     self.gsims = readinput.get_gsims(oq)
     maxdist = oq.maximum_distance['default']
     with self.monitor('filtering sites', autoflush=True):
         self.sitecol = filters.filter_sites_by_distance_to_rupture(
             rup, maxdist, self.sitecol)
     if self.sitecol is None:
         raise RuntimeError(
             'All sites were filtered out! maximum_distance=%s km' %
             maxdist)
     # eid, ses, occ, sample
     events = numpy.array(
         [(eid, 1, 1, 0)
          for eid in range(oq.number_of_ground_motion_fields)],
         calc.event_dt)
     rupture = calc.EBRupture(
         rup, self.sitecol.sids, events, 'single_rupture', 0, 0)
     self.datastore['ruptures/grp-00/0'] = rupture
     self.computer = GmfComputer(
         rupture, self.sitecol, oq.imtls, self.gsims,
         trunc_level, correl_model)
     gsim_lt = readinput.get_gsim_lt(oq)
     cinfo = source.CompositionInfo.fake(gsim_lt)
     self.datastore['csm_info'] = cinfo
     self.rlzs_assoc = cinfo.get_rlzs_assoc()
예제 #8
0
 def pre_execute(self):
     """
     Read the site collection and initialize GmfComputer, etags and seeds
     """
     super(ScenarioCalculator, self).pre_execute()
     trunc_level = self.oqparam.truncation_level
     correl_model = readinput.get_correl_model(self.oqparam)
     n_gmfs = self.oqparam.number_of_ground_motion_fields
     rupture = readinput.get_rupture(self.oqparam)
     self.gsims = readinput.get_gsims(self.oqparam)
     self.rlzs_assoc = readinput.get_rlzs_assoc(self.oqparam)
     maxdist = self.oqparam.maximum_distance['default']
     with self.monitor('filtering sites', autoflush=True):
         self.sitecol = filters.filter_sites_by_distance_to_rupture(
             rupture, maxdist, self.sitecol)
     if self.sitecol is None:
         raise RuntimeError(
             'All sites were filtered out! maximum_distance=%s km' %
             maxdist)
     self.etags = numpy.array(
         sorted(['scenario-%010d' % i for i in range(n_gmfs)]),
         (bytes, 100))
     self.computer = GmfComputer(
         rupture, self.sitecol, self.oqparam.imtls, self.gsims,
         trunc_level, correl_model)
예제 #9
0
 def pre_execute(self):
     """
     Read the site collection and initialize GmfComputer, etags and seeds
     """
     super(ScenarioCalculator, self).pre_execute()
     oq = self.oqparam
     trunc_level = oq.truncation_level
     correl_model = readinput.get_correl_model(oq)
     n_gmfs = oq.number_of_ground_motion_fields
     rupture = readinput.get_rupture(oq)
     self.gsims = readinput.get_gsims(oq)
     maxdist = oq.maximum_distance['default']
     with self.monitor('filtering sites', autoflush=True):
         self.sitecol = filters.filter_sites_by_distance_to_rupture(
             rupture, maxdist, self.sitecol)
     if self.sitecol is None:
         raise RuntimeError(
             'All sites were filtered out! maximum_distance=%s km' %
             maxdist)
     self.etags = numpy.array(
         sorted(['scenario-%010d~ses=1' % i for i in range(n_gmfs)]),
         (bytes, 100))
     self.computer = GmfComputer(rupture, self.sitecol, oq.imtls,
                                 self.gsims, trunc_level, correl_model)
     gsim_lt = readinput.get_gsim_lt(oq)
     cinfo = source.CompositionInfo.fake(gsim_lt)
     self.datastore['csm_info'] = cinfo
     self.rlzs_assoc = cinfo.get_rlzs_assoc()
예제 #10
0
 def pre_execute(self):
     self.sitecol = readinput.get_site_collection(self.oqparam)
     [self.gsim] = readinput.get_gsims(self.oqparam)
     self.imts = readinput.get_imts(self.oqparam)
     self.rupture = readinput.get_rupture(self.oqparam)
     self.etags = [  # used in the export phase
         'etag%d' % i
         for i in range(self.oqparam.number_of_ground_motion_fields)]
예제 #11
0
 def pre_execute(self):
     self.sitecol = readinput.get_site_collection(self.oqparam)
     [self.gsim] = readinput.get_gsims(self.oqparam)
     self.imts = readinput.get_imts(self.oqparam)
     self.rupture = readinput.get_rupture(self.oqparam)
     self.rupture_tags = [  # used in the export phase
         'tag%d' % i
         for i in range(self.oqparam.number_of_ground_motion_fields)]
예제 #12
0
    def _read_scenario_ruptures(self):
        oq = self.oqparam
        gsim_lt = readinput.get_gsim_lt(self.oqparam)
        G = gsim_lt.get_num_paths()
        if oq.inputs['rupture_model'].endswith('.xml'):
            ngmfs = oq.number_of_ground_motion_fields
            self.gsims = readinput.get_gsims(oq)
            self.cmaker = ContextMaker('*', self.gsims, {
                'maximum_distance': oq.maximum_distance,
                'imtls': oq.imtls
            })
            rup = readinput.get_rupture(oq)
            mesh = surface_to_array(rup.surface).transpose(1, 2, 0).flatten()
            if self.N > oq.max_sites_disagg:  # many sites, split rupture
                ebrs = [
                    EBRupture(copyobj(rup, rup_id=rup.rup_id + i),
                              0,
                              0,
                              G,
                              e0=i * G) for i in range(ngmfs)
                ]
                meshes = numpy.array([mesh] * ngmfs, object)
            else:  # keep a single rupture with a big occupation number
                ebrs = [EBRupture(rup, 0, 0, G * ngmfs, rup.rup_id)]
                meshes = numpy.array([mesh] * ngmfs, object)
            rup_array = get_rup_array(ebrs, self.srcfilter).array
            hdf5.extend(self.datastore['rupgeoms'], meshes)
        elif oq.inputs['rupture_model'].endswith('.csv'):
            aw = readinput.get_ruptures(oq.inputs['rupture_model'])
            aw.array['n_occ'] = G
            rup_array = aw.array
            hdf5.extend(self.datastore['rupgeoms'], aw.geom)

        if len(rup_array) == 0:
            raise RuntimeError(
                'There are no sites within the maximum_distance'
                ' of %s km from the rupture' %
                oq.maximum_distance(rup.tectonic_region_type, rup.mag))

        # check the number of branchsets
        branchsets = len(gsim_lt._ltnode)
        if len(rup_array) == 1 and branchsets > 1:
            raise InvalidFile(
                '%s for a scenario calculation must contain a single '
                'branchset, found %d!' % (oq.inputs['job_ini'], branchsets))

        fake = logictree.FullLogicTree.fake(gsim_lt)
        self.realizations = fake.get_realizations()
        self.datastore['full_lt'] = fake
        self.store_rlz_info({})  # store weights
        self.save_params()
        calc.RuptureImporter(self.datastore).import_rups(rup_array)
예제 #13
0
 def pre_execute(self):
     """
     Read the site collection and initialize GmfComputer and seeds
     """
     oq = self.oqparam
     cinfo = logictree.FullLogicTree.fake(readinput.get_gsim_lt(oq))
     self.realizations = cinfo.get_realizations()
     self.datastore['full_lt'] = cinfo
     if 'rupture_model' not in oq.inputs:
         logging.warning(
             'There is no rupture_model, the calculator will just '
             'import data without performing any calculation')
         super().pre_execute()
         return
     self.rup = readinput.get_rupture(oq)
     self.gsims = readinput.get_gsims(oq)
     R = len(self.gsims)
     self.cmaker = ContextMaker(
         '*', self.gsims, {
             'maximum_distance': oq.maximum_distance,
             'filter_distance': oq.filter_distance
         })
     super().pre_execute()
     self.datastore['oqparam'] = oq
     self.store_rlz_info({})
     rlzs_by_gsim = cinfo.get_rlzs_by_gsim(0)
     E = oq.number_of_ground_motion_fields
     n_occ = numpy.array([E])
     ebr = EBRupture(self.rup, 0, 0, n_occ)
     ebr.e0 = 0
     events = numpy.zeros(E * R, events_dt)
     for rlz, eids in ebr.get_eids_by_rlz(rlzs_by_gsim).items():
         events[rlz * E:rlz * E + E]['id'] = eids
         events[rlz * E:rlz * E + E]['rlz_id'] = rlz
     self.datastore['events'] = self.events = events
     rupser = calc.RuptureSerializer(self.datastore)
     rup_array = get_rup_array([ebr], self.src_filter())
     if len(rup_array) == 0:
         maxdist = oq.maximum_distance(self.rup.tectonic_region_type,
                                       self.rup.mag)
         raise RuntimeError('There are no sites within the maximum_distance'
                            ' of %s km from the rupture' % maxdist)
     rupser.save(rup_array)
     rupser.close()
     self.computer = GmfComputer(ebr, self.sitecol, oq.imtls, self.cmaker,
                                 oq.truncation_level, oq.correl_model,
                                 self.amplifier)
     M32 = (numpy.float32, len(self.oqparam.imtls))
     self.sig_eps_dt = [('eid', numpy.uint64), ('sig', M32), ('eps', M32)]
예제 #14
0
파일: calc.py 프로젝트: griffij/oq-risklib
def calc_gmfs_fast(oqparam, sitecol):
    """
    Build all the ground motion fields for the whole site collection in
    a single step.
    """
    max_dist = oqparam.maximum_distance
    correl_model = get_correl_model(oqparam)
    seed = oqparam.random_seed
    imts = get_imts(oqparam)
    [gsim] = get_gsims(oqparam)
    trunc_level = oqparam.truncation_level
    n_gmfs = oqparam.number_of_ground_motion_fields
    rupture = get_rupture(oqparam)
    res = gmf.ground_motion_fields(
        rupture, sitecol, imts, gsim, trunc_level, n_gmfs, correl_model,
        filters.rupture_site_distance_filter(max_dist), seed)
    return {str(imt): matrix for imt, matrix in res.items()}
예제 #15
0
파일: scenario.py 프로젝트: rcgee/oq-engine
 def pre_execute(self):
     """
     Read the site collection and initialize GmfComputer and seeds
     """
     super(ScenarioCalculator, self).pre_execute()
     oq = self.oqparam
     trunc_level = oq.truncation_level
     correl_model = oq.get_correl_model()
     self.datastore["rupture"] = rupture = readinput.get_rupture(oq)
     self.gsims = readinput.get_gsims(oq)
     maxdist = oq.maximum_distance["default"]
     with self.monitor("filtering sites", autoflush=True):
         self.sitecol = filters.filter_sites_by_distance_to_rupture(rupture, maxdist, self.sitecol)
     if self.sitecol is None:
         raise RuntimeError("All sites were filtered out! maximum_distance=%s km" % maxdist)
     self.computer = GmfComputer(rupture, self.sitecol, oq.imtls, self.gsims, trunc_level, correl_model)
     gsim_lt = readinput.get_gsim_lt(oq)
     cinfo = source.CompositionInfo.fake(gsim_lt)
     self.datastore["csm_info"] = cinfo
     self.rlzs_assoc = cinfo.get_rlzs_assoc()
예제 #16
0
 def pre_execute(self):
     """
     Read the site collection and initialize GmfComputer and seeds
     """
     super(ScenarioCalculator, self).pre_execute()
     oq = self.oqparam
     trunc_level = oq.truncation_level
     correl_model = oq.get_correl_model()
     ebr, self.sitecol = readinput.get_rupture_sitecol(oq, self.sitecol)
     self.gsims = readinput.get_gsims(oq)
     self.datastore['events'] = ebr.events
     rupser = calc.RuptureSerializer(self.datastore)
     rupser.save([ebr])
     rupser.close()
     self.computer = GmfComputer(ebr, self.sitecol, oq.imtls, self.gsims,
                                 trunc_level, correl_model)
     gsim_lt = readinput.get_gsim_lt(oq)
     cinfo = source.CompositionInfo.fake(gsim_lt)
     self.datastore['csm_info'] = cinfo
     self.rlzs_assoc = cinfo.get_rlzs_assoc()
예제 #17
0
    def _read_scenario_ruptures(self):
        oq = self.oqparam
        if oq.inputs['rupture_model'].endswith(('.xml', '.toml', '.txt')):
            self.gsims = readinput.get_gsims(oq)
            self.cmaker = ContextMaker(
                '*', self.gsims,
                {'maximum_distance': oq.maximum_distance,
                 'filter_distance': oq.filter_distance})
            n_occ = numpy.array([oq.number_of_ground_motion_fields])
            rup = readinput.get_rupture(oq)
            ebr = EBRupture(rup, 0, 0, n_occ)
            ebr.e0 = 0
            rup_array = get_rup_array([ebr], self.srcfilter).array
            mesh = surface_to_array(rup.surface).transpose(1, 2, 0).flatten()
            hdf5.extend(self.datastore['rupgeoms'],
                        numpy.array([mesh], object))
        elif oq.inputs['rupture_model'].endswith('.csv'):
            aw = readinput.get_ruptures(oq.inputs['rupture_model'])
            rup_array = aw.array
            hdf5.extend(self.datastore['rupgeoms'], aw.geom)

        if len(rup_array) == 0:
            raise RuntimeError(
                'There are no sites within the maximum_distance'
                ' of %s km from the rupture' % oq.maximum_distance(
                    rup.tectonic_region_type, rup.mag))

        gsim_lt = readinput.get_gsim_lt(self.oqparam)
        # check the number of branchsets
        branchsets = len(gsim_lt._ltnode)
        if len(rup_array) == 1 and branchsets > 1:
            raise InvalidFile(
                '%s for a scenario calculation must contain a single '
                'branchset, found %d!' % (oq.inputs['job_ini'], branchsets))

        fake = logictree.FullLogicTree.fake(gsim_lt)
        self.realizations = fake.get_realizations()
        self.datastore['full_lt'] = fake
        self.store_rlz_info({})  # store weights
        self.save_params()
        calc.RuptureImporter(self.datastore).import_rups(rup_array)
예제 #18
0
 def pre_execute(self):
     """
     Read the site collection and initialize GmfComputer and seeds
     """
     super(ScenarioCalculator, self).pre_execute()
     oq = self.oqparam
     trunc_level = oq.truncation_level
     correl_model = oq.get_correl_model()
     rup = readinput.get_rupture(oq)
     rup.seed = self.oqparam.random_seed
     self.gsims = readinput.get_gsims(oq)
     maxdist = oq.maximum_distance['default']
     with self.monitor('filtering sites', autoflush=True):
         self.sitecol = filters.filter_sites_by_distance_to_rupture(
             rup, maxdist, self.sitecol)
     if self.sitecol is None:
         raise RuntimeError(
             'All sites were filtered out! maximum_distance=%s km' %
             maxdist)
     # eid, ses, occ, sample
     events = numpy.zeros(oq.number_of_ground_motion_fields,
                          calc.stored_event_dt)
     events['eid'] = numpy.arange(oq.number_of_ground_motion_fields)
     rupture = calc.EBRupture(rup, self.sitecol.sids, events, 0, 0)
     rupture.sidx = 0
     rupture.eidx1 = 0
     rupture.eidx2 = len(events)
     self.datastore['sids'] = self.sitecol.sids
     self.datastore['events/grp-00'] = events
     array, nbytes = calc.RuptureSerializer.get_array_nbytes([rupture])
     self.datastore.extend('ruptures/grp-00', array, nbytes=nbytes)
     self.computer = GmfComputer(rupture, self.sitecol, oq.imtls,
                                 self.gsims, trunc_level, correl_model)
     gsim_lt = readinput.get_gsim_lt(oq)
     cinfo = source.CompositionInfo.fake(gsim_lt)
     self.datastore['csm_info'] = cinfo
     self.rlzs_assoc = cinfo.get_rlzs_assoc()