示例#1
0
    def test_gnss_target(self):
        src_length = 5 * km
        src_width = 2 * km
        nstations = 100
        interp = ['nearest_neighbor', 'multilinear']
        interpolation = interp[0]

        source = gf.RectangularSource(lat=0.,
                                      lon=0.,
                                      north_shift=0.,
                                      east_shift=0.,
                                      depth=6.5 * km,
                                      width=src_width,
                                      length=src_length,
                                      dip=90.,
                                      rake=90.,
                                      strike=90.,
                                      slip=1.)

        gnss_target = gf.GNSSCampaignTarget(
            lats=(random.uniform(-.2, .2, nstations)),
            lons=(random.uniform(-.2, .2, nstations)),
            interpolation=interpolation)

        engine = gf.LocalEngine(store_dirs=[self.get_pscmp_store_dir()])
        res = engine.process(source, gnss_target, nprocs=0)

        statics = res.static_results()
        for static in statics:
            assert len(static.campaign.stations) == nstations
示例#2
0
    def get_targets(self):
        stations = self.get_stations()
        lats = num.array([s.lat for s in stations])
        lons = num.array([s.lon for s in stations])

        target = gf.GNSSCampaignTarget(lats=lats,
                                       lons=lons,
                                       store_id=self.store_id)

        return [target]
示例#3
0
    def test_new_static(self):
        from pyrocko.gf import store_ext
        benchmark.show_factor = True

        store = gf.Store(self.get_pscmp_store_dir())
        store.open()
        src_length = 2 * km
        src_width = 2 * km
        ntargets = 20

        north_shifts, east_shifts = num.meshgrid(
            num.linspace(-20 * km, 20 * km, ntargets),
            num.linspace(-20 * km, 20 * km, ntargets))

        interp = ['nearest_neighbor', 'multilinear']
        interpolation = interp[1]

        source = gf.RectangularSource(lat=0.,
                                      lon=0.,
                                      depth=5 * km,
                                      north_shift=0.,
                                      east_shift=0.,
                                      anchor='top',
                                      width=src_width,
                                      length=src_length)

        static_target = gf.GNSSCampaignTarget(
            north_shifts=north_shifts,
            east_shifts=east_shifts,
            lats=num.zeros_like(north_shifts),
            lons=num.zeros_like(north_shifts))

        targets = static_target.get_targets()

        dsource = source.discretize_basesource(store, targets[0])
        mts_arr = dsource.m6s
        delays_s = dsource.times.astype(num.float64)
        pos = 1

        scheme_desc = ['displacement.n', 'displacement.e', 'displacement.d']

        benchmark.clear()

        def run(interpolation=interp[0], nthreads=1, niter=1):
            @benchmark.labeled(' sum_statics %d cpu (%s)' %
                               (nthreads, interpolation))
            def fwd_model_seperate(interpolation=interp[0]):
                args = (store.cstore, dsource.coords5(), mts_arr,
                        static_target.coords5, 'elastic10', interpolation,
                        nthreads)

                sum_params = store_ext.make_sum_params(*args)

                out = {}

                for icomp, comp in enumerate(scheme_desc):
                    weights, irecords = sum_params[icomp]
                    out[comp] = store_ext.store_sum_static(
                        store.cstore, irecords, delays_s, weights, pos,
                        ntargets**2, nthreads)
                return out

            @benchmark.labeled('calc_statics %d cpu (%s)' %
                               (nthreads, interpolation))
            def fwd_model_unified(interpolation=interp[0]):
                out = {}
                res = store_ext.store_calc_static(store.cstore,
                                                  dsource.coords5(), mts_arr,
                                                  dsource.times,
                                                  static_target.coords5,
                                                  'elastic10', interpolation,
                                                  pos, nthreads)
                for comp, r in zip(scheme_desc, res):
                    out[comp] = r

                return out

            for _ in range(niter):
                res1 = fwd_model_seperate(interpolation)
            for _ in range(niter):
                res2 = fwd_model_unified(interpolation)

            for r1, r2 in zip(res1.values(), res2.values()):
                num.testing.assert_equal(r1, r2)

        for interpolation in interp:
            continue
            for nthreads in [1, 2, 4, 8, 0]:
                run(interpolation, nthreads)
            print(benchmark)
            benchmark.clear()

        run(interpolation, nthreads=0, niter=30)
        print(benchmark)

        def plot(displ):
            import matplotlib.pyplot as plt
            size = int(num.sqrt(displ.size))
            fig = plt.figure()
            ax = fig.gca()
            ax.imshow(displ.reshape((size, size)))
            plt.show()