Beispiel #1
0
 def gen_computers(self, mon):
     """
     Yield a GmfComputer instance for each non-discarded rupture
     """
     trt = self.rupgetter.trt
     with mon:
         proxies = self.rupgetter.get_proxies()
     for proxy in proxies:
         with mon:
             ebr = proxy.to_ebr(trt)
             sids = self.srcfilter.close_sids(proxy, trt)
             if len(sids) == 0:  # filtered away
                 continue
             sitecol = self.sitecol.filtered(sids)
             try:
                 computer = gmf.GmfComputer(
                     ebr, sitecol, self.cmaker,
                     self.oqparam.truncation_level, self.correl_model,
                     self.amplifier, self.sec_perils)
             except FarAwayRupture:
                 continue
             # due to numeric errors ruptures within the maximum_distance
             # when written, can be outside when read; I found a case with
             # a distance of 99.9996936 km over a maximum distance of 100 km
         yield computer
Beispiel #2
0
 def test1rup(self):
     param = dict(rupture_model_file=RUP_XML,
                  number_of_ground_motion_fields=10,
                  gsim='AtkinsonBoore2006',
                  ses_seed=42,
                  sites=[(0, 1), (0, 0)],
                  reference_vs30_value="760",
                  maximum_distance=IntegrationDistance.new('200'),
                  imtls={'PGA': [0]})
     inp = read_input(param)
     [grp] = inp.groups
     [ebr] = grp
     cmaker = inp.cmakerdict[grp.trt]
     gc = gmf.GmfComputer(ebr, inp.sitecol, cmaker)
     gmfdata = gc.compute_all()
     self.assertIn('sid', gmfdata)
     self.assertIn('eid', gmfdata)
     self.assertIn('rlz', gmfdata)
     self.assertIn('gmv_0', gmfdata)
Beispiel #3
0
def export_gmf_scenario_npz(ekey, dstore):
    oq = dstore['oqparam']
    dic = {}
    fname = dstore.export_path('%s.%s' % ekey)
    if 'scenario' in oq.calculation_mode:
        # compute the GMFs on the fly from the stored rupture
        # NB: for visualization purposes we want to export the full mesh
        # of points, including the ones outside the maximum distance
        # NB2: in the future, I want to add a sitecol output, then the
        # visualization of the mesh will be possibile even without the GMFs;
        # in the future, here we will change
        # sitemesh = get_mesh(dstore['sitecol'], complete=False)
        sitecol = dstore['sitecol'].complete
        sitemesh = get_mesh(sitecol)
        rlzs_assoc = dstore['csm_info'].get_rlzs_assoc()
        gsims = rlzs_assoc.gsims_by_grp_id[0]  # there is a single grp_id
        E = oq.number_of_ground_motion_fields
        correl_model = oq.get_correl_model()
        [ebrupture] = calc.get_ruptures(dstore, 0)
        computer = gmf.GmfComputer(
            ebrupture, sitecol, oq.imtls,
            gsims, oq.truncation_level, correl_model)
        gmf_dt = numpy.dtype([(imt, (F32, (E,))) for imt in oq.imtls])
        imts = list(oq.imtls)
        for gsim in gsims:
            arr = computer.compute(gsim, E, oq.random_seed)
            I, S, E = arr.shape  # #IMTs, #sites, #events
            gmfa = numpy.zeros(S, gmf_dt)
            for imti, imt in enumerate(imts):
                gmfa[imt] = arr[imti]
            dic[str(gsim)] = util.compose_arrays(sitemesh, gmfa)
    elif 'event_based' in oq.calculation_mode:
        dic['sitemesh'] = get_mesh(dstore['sitecol'])
        for grp in sorted(dstore['gmf_data']):
            data_by_rlzi = group_array(dstore['gmf_data/' + grp].value, 'rlzi')
            for rlzi in data_by_rlzi:
                dic['rlz-%03d' % rlzi] = data_by_rlzi[rlzi]
    else:  # nothing to export
        return []
    savez(fname, **dic)
    return [fname]