Example #1
0
    def dummy_homogeneous_store(self):
        mod = cake.LayeredModel.from_scanlines(
            cake.read_nd_model_str('''
0 6 3.46  3.0  1000 500
20 6 3.46  3.0  1000 500
'''.lstrip()))

        if self._dummy_homogeneous_store is None:

            conf = gf.ConfigTypeA(
                id='empty_homogeneous',
                source_depth_min=0.,
                source_depth_max=20*km,
                source_depth_delta=10*km,
                distance_min=1000*km,
                distance_max=2000*km,
                distance_delta=10*km,
                sample_rate=2.0,
                ncomponents=10,
                earthmodel_1d=mod)

            store_dir = mkdtemp(prefix='gfstore')
            self.tempdirs.append(store_dir)

            gf.Store.create(store_dir, config=conf)
            self._dummy_homogeneous_store = gf.Store(store_dir)

        return self._dummy_homogeneous_store
Example #2
0
    def _create_psgrn_pscmp_store(self):
        mod = cake.LayeredModel.from_scanlines(cake.read_nd_model_str('''
 0. 5.8 3.46 2.6 1264. 600.
 20. 5.8 3.46 2.6 1264. 600.
 20. 6.5 3.85 2.9 1283. 600.
 35. 6.5 3.85 2.9 1283. 600.
mantle
 35. 8.04 4.48 3.58 1449. 600.
 77.5 8.045 4.49 3.5 1445. 600.
 77.5 8.045 4.49 3.5 180.6 75.
 120. 8.05 4.5 3.427 180. 75.
 120. 8.05 4.5 3.427 182.6 76.06
 165. 8.175 4.509 3.371 188.7 76.55
 210. 8.301 4.518 3.324 201. 79.4
 210. 8.3 4.52 3.321 336.9 133.3
 410. 9.03 4.871 3.504 376.5 146.1
 410. 9.36 5.08 3.929 414.1 162.7
 660. 10.2 5.611 3.918 428.5 172.9
 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip()))

        store_dir = mkdtemp(prefix='gfstore')
        self.tempdirs.append(store_dir)
        store_id = 'psgrn_pscmp_test'
        version = '2008a'

        c = psgrn_pscmp.PsGrnPsCmpConfig()
        c.psgrn_config.sampling_interval = 1.
        c.psgrn_config.version = version
        c.pscmp_config.version = version

        config = gf.meta.ConfigTypeA(
            id=store_id,
            ncomponents=10,
            sample_rate=1./(3600. * 24.),
            receiver_depth=0.*km,
            source_depth_min=0.*km,
            source_depth_max=20.*km,
            source_depth_delta=0.25*km,
            distance_min=0.*km,
            distance_max=40.*km,
            distance_delta=0.25*km,
            modelling_code_id='psgrn_pscmp.%s' % version,
            earthmodel_1d=mod,
            tabulated_phases=[])
        config.validate()

        gf.store.Store.create_editables(
            store_dir, config=config, extra={'psgrn_pscmp': c})

        store = gf.store.Store(store_dir, 'r')
        store.close()

        psgrn_pscmp.build(store_dir, nworkers=4)
        return store_dir
Example #3
0
    def _create_qseis_store(self):
        mod = cake.LayeredModel.from_scanlines(cake.read_nd_model_str('''
 0. 5.8 3.46 2.6 1264. 600.
 20. 5.8 3.46 2.6 1264. 600.
 20. 6.5 3.85 2.9 1283. 600.
 35. 6.5 3.85 2.9 1283. 600.'''.lstrip()))
        store_dir = mkdtemp(prefix='gfstore')
        self.tempdirs.append(store_dir)

        qsconf = qseis.QSeisConfig()
        qsconf.qseis_version = '2006a'

        qsconf.time_region = (
            gf.meta.Timing('0'),
            gf.meta.Timing('end+100'))

        qsconf.cut = (
            gf.meta.Timing('0'),
            gf.meta.Timing('end+100'))

        qsconf.wavelet_duration_samples = 0.001
        qsconf.sw_flat_earth_transform = 0

        config = gf.meta.ConfigTypeA(
            id='qseis_test',
            ncomponents=10,
            sample_rate=0.25,
            receiver_depth=0.*km,
            source_depth_min=2.5*km,
            source_depth_max=10*km,
            source_depth_delta=2.5*km,
            distance_min=0*km,
            distance_max=20*km,
            distance_delta=2.5*km,
            modelling_code_id='qseis.2006a',
            earthmodel_1d=mod,
            tabulated_phases=[
                gf.meta.TPDef(
                    id='begin',
                    definition='p,P,p\\,P\\'),
                gf.meta.TPDef(
                    id='end',
                    definition='2.5'),
            ])

        config.validate()
        gf.store.Store.create_editables(
            store_dir, config=config, extra={'qseis': qsconf})

        store = gf.store.Store(store_dir, 'r')
        store.make_ttt()
        store.close()
        qseis.build(store_dir, nworkers=1)
        return store_dir
    def test_fomosto_vs_psgrn_pscmp(self):

        mod = cake.LayeredModel.from_scanlines(cake.read_nd_model_str('''
 0. 5.8 3.46 2.6 1264. 600.
 20. 5.8 3.46 2.6 1264. 600.
 20. 6.5 3.85 2.9 1283. 600.
 35. 6.5 3.85 2.9 1283. 600.
mantle
 35. 8.04 4.48 3.58 1449. 600.
 77.5 8.045 4.49 3.5 1445. 600.
 77.5 8.045 4.49 3.5 180.6 75.
 120. 8.05 4.5 3.427 180. 75.
 120. 8.05 4.5 3.427 182.6 76.06
 165. 8.175 4.509 3.371 188.7 76.55
 210. 8.301 4.518 3.324 201. 79.4
 210. 8.3 4.52 3.321 336.9 133.3
 410. 9.03 4.871 3.504 376.5 146.1
 410. 9.36 5.08 3.929 414.1 162.7
 660. 10.2 5.611 3.918 428.5 172.9
 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip()))

        store_dir = mkdtemp(prefix='gfstore')
        self.tempdirs.append(store_dir)
        store_id = 'psgrn_pscmp_test'

        version = '2008a'

        c = psgrn_pscmp.PsGrnPsCmpConfig()
        c.psgrn_config.sampling_interval = 1.
        c.psgrn_config.version = version
        c.pscmp_config.version = version

        config = gf.meta.ConfigTypeA(
            id=store_id,
            ncomponents=10,
            sample_rate=1. / (3600. * 24.),
            receiver_depth=0. * km,
            source_depth_min=0. * km,
            source_depth_max=5. * km,
            source_depth_delta=0.1 * km,
            distance_min=0. * km,
            distance_max=40. * km,
            distance_delta=0.1 * km,
            modelling_code_id='psgrn_pscmp.%s' % version,
            earthmodel_1d=mod,
            tabulated_phases=[])

        config.validate()
        gf.store.Store.create_editables(
            store_dir, config=config, extra={'psgrn_pscmp': c})

        store = gf.store.Store(store_dir, 'r')
        store.close()

        # build store
        try:
            psgrn_pscmp.build(store_dir, nworkers=1)
        except psgrn_pscmp.PsCmpError as e:
            if str(e).find('could not start psgrn/pscmp') != -1:
                logger.warn('psgrn/pscmp not installed; '
                            'skipping test_pyrocko_gf_vs_pscmp')
                return
            else:
                raise

        origin = gf.Location(
            lat=10.,
            lon=-15.)

        # test GF store
        TestRF = dict(
            lat=origin.lat,
            lon=origin.lon,
            depth=2. * km,
            width=2. * km,
            length=5. * km,
            rake=90., dip=45., strike=45.,
            slip=1.)

        source = gf.RectangularSource(**TestRF)

        neast = 40
        nnorth = 40

        N, E = num.meshgrid(num.linspace(-20. * km, 20. * km, nnorth),
                            num.linspace(-20. * km, 20. * km, neast))

        starget = gf.StaticTarget(
            lats=num.array([origin.lat] * N.size),
            lons=num.array([origin.lon] * N.size),
            north_shifts=N.flatten(),
            east_shifts=E.flatten(),
            interpolation='nearest_neighbor')
        engine = gf.LocalEngine(store_dirs=[store_dir])
        t0 = time()
        r = engine.process(source, starget)
        t1 = time()
        logger.info('pyrocko stacking time %f' % (t1 - t0))
        un_fomosto = r.static_results()[0].result['displacement.n']
        ue_fomosto = r.static_results()[0].result['displacement.e']
        ud_fomosto = r.static_results()[0].result['displacement.d']

        # test against direct pscmp output
        lats, lons = ortd.ne_to_latlon(
            origin.lat, origin.lon, N.flatten(), E.flatten())
        pscmp_sources = [psgrn_pscmp.PsCmpRectangularSource(**TestRF)]

        cc = c.pscmp_config
        cc.observation = psgrn_pscmp.PsCmpScatter(lats=lats, lons=lons)

        cc.rectangular_source_patches = pscmp_sources

        ccf = psgrn_pscmp.PsCmpConfigFull(**cc.items())
        ccf.psgrn_outdir = os.path.join(store_dir, c.gf_outdir) + '/'

        t2 = time()
        runner = psgrn_pscmp.PsCmpRunner(keep_tmp=False)
        runner.run(ccf)
        ps2du = runner.get_results(component='displ')[0]
        t3 = time()
        logger.info('pscmp stacking time %f' % (t3 - t2))

        un_pscmp = ps2du[:, 0]
        ue_pscmp = ps2du[:, 1]
        ud_pscmp = ps2du[:, 2]

        num.testing.assert_allclose(un_fomosto, un_pscmp, atol=0.002)
        num.testing.assert_allclose(ue_fomosto, ue_pscmp, atol=0.002)
        num.testing.assert_allclose(ud_fomosto, ud_pscmp, atol=0.002)
Example #5
0
    def test_pyrocko_gf_vs_qseis(self):

        mod = cake.LayeredModel.from_scanlines(cake.read_nd_model_str('''
 0. 5.8 3.46 2.6 1264. 600.
 20. 5.8 3.46 2.6 1264. 600.
 20. 6.5 3.85 2.9 1283. 600.
 35. 6.5 3.85 2.9 1283. 600.
mantle
 35. 8.04 4.48 3.58 1449. 600.
 77.5 8.045 4.49 3.5 1445. 600.
 77.5 8.045 4.49 3.5 180.6 75.
 120. 8.05 4.5 3.427 180. 75.
 120. 8.05 4.5 3.427 182.6 76.06
 165. 8.175 4.509 3.371 188.7 76.55
 210. 8.301 4.518 3.324 201. 79.4
 210. 8.3 4.52 3.321 336.9 133.3
 410. 9.03 4.871 3.504 376.5 146.1
 410. 9.36 5.08 3.929 414.1 162.7
 660. 10.2 5.611 3.918 428.5 172.9
 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip()))

        store_dir = mkdtemp(prefix='gfstore')
        self.tempdirs.append(store_dir)

        qsconf = qseis.QSeisConfig()
        qsconf.qseis_version = '2006a'

        qsconf.time_region = (
            gf.meta.Timing('0'),
            gf.meta.Timing('end+100'))

        qsconf.cut = (
            gf.meta.Timing('0'),
            gf.meta.Timing('end+100'))

        qsconf.wavelet_duration_samples = 0.001
        qsconf.sw_flat_earth_transform = 0

        config = gf.meta.ConfigTypeA(
            id='qseis_test',
            ncomponents=10,
            sample_rate=0.25,
            receiver_depth=0.*km,
            source_depth_min=10*km,
            source_depth_max=10*km,
            source_depth_delta=1*km,
            distance_min=550*km,
            distance_max=560*km,
            distance_delta=1*km,
            modelling_code_id='qseis.2006a',
            earthmodel_1d=mod,
            tabulated_phases=[
                gf.meta.TPDef(
                    id='begin',
                    definition='p,P,p\\,P\\'),
                gf.meta.TPDef(
                    id='end',
                    definition='2.5'),
            ])

        config.validate()
        gf.store.Store.create_editables(
            store_dir, config=config, extra={'qseis': qsconf})

        store = gf.store.Store(store_dir, 'r')
        store.make_ttt()
        store.close()

        try:
            qseis.build(store_dir, nworkers=1)
        except qseis.QSeisError, e:
            if str(e).find('could not start qseis') != -1:
                logger.warn('qseis not installed; '
                            'skipping test_pyrocko_gf_vs_qseis')
                return
            else:
                raise
    def test_pyrocko_report_with_gf_and_qseis(self):

        mod = cake.LayeredModel.from_scanlines(cake.read_nd_model_str('''
 0. 5.8 3.46 2.6 1264. 600.
 20. 5.8 3.46 2.6 1264. 600.
 20. 6.5 3.85 2.9 1283. 600.
 35. 6.5 3.85 2.9 1283. 600.
mantle
 35. 8.04 4.48 3.58 1449. 600.
 77.5 8.045 4.49 3.5 1445. 600.
 77.5 8.045 4.49 3.5 180.6 75.
 120. 8.05 4.5 3.427 180. 75.
 120. 8.05 4.5 3.427 182.6 76.06
 165. 8.175 4.509 3.371 188.7 76.55
 210. 8.301 4.518 3.324 201. 79.4
 210. 8.3 4.52 3.321 336.9 133.3
 410. 9.03 4.871 3.504 376.5 146.1
 410. 9.36 5.08 3.929 414.1 162.7
 660. 10.2 5.611 3.918 428.5 172.9
 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip()))

        store_dir = mkdtemp(prefix='gft_')
        self.tempdirs.append(store_dir)

        qsconf = qseis.QSeisConfig()
        qsconf.qseis_version = '2006a'

        qsconf.time_region = (
            gf.meta.Timing('0'),
            gf.meta.Timing('end+100'))

        qsconf.cut = (
            gf.meta.Timing('0'),
            gf.meta.Timing('end+100'))

        qsconf.wavelet_duration_samples = 0.001
        qsconf.sw_flat_earth_transform = 0

        config = gf.meta.ConfigTypeA(
            id='gft_test',
            ncomponents=10,
            sample_rate=0.25,
            receiver_depth=0.*km,
            source_depth_min=10*km,
            source_depth_max=10*km,
            source_depth_delta=1*km,
            distance_min=550*km,
            distance_max=560*km,
            distance_delta=1*km,
            modelling_code_id='qseis.2006a',
            earthmodel_1d=mod,
            tabulated_phases=[
                gf.meta.TPDef(
                    id='begin',
                    definition='p,P,p\\,P\\'),
                gf.meta.TPDef(
                    id='end',
                    definition='2.5'),
            ])

        config.validate()
        gf.store.Store.create_editables(
            store_dir, config=config, extra={'qseis': qsconf})

        store = gf.store.Store(store_dir, 'r')
        store.make_ttt()
        store.close()

        try:
            qseis.build(store_dir, nworkers=1)
        except qseis.QSeisError as e:
            if str(e).find('could not start qseis') != -1:
                logger.warn('qseis not installed; '
                            'skipping test_pyrocko_gf_vs_qseis')
                return
            else:
                raise

        gft = gftest(store_dir, sensor_count=2, pdf_dir=store_dir,
                     plot_velocity=True, rel_lowpass_frequency=(1. / 110),
                     rel_highpass_frequency=(1. / 16), output_format='html')

        src = gft.createSource('DC', None, 45., 90., 180.)
        sen = gft.createSensors(strike=0., codes=('', 'STA', '', 'Z'),
                                azimuth=0., dip=-90.)
        gft.trace_configs = [[src, sen]]
        gft.createDisplacementTraces()
        gft.createVelocityTraces()
        gft.applyFrequencyFilters()
        gft.getPhaseArrivals()
        gft.createOutputDoc()
    def _test_homogeneous_scenario(
            self,
            config_type_class,
            component_scheme,
            discretized_source_class):

        if config_type_class.short_type == 'C' \
                or component_scheme.startswith('poro'):

            assert False

        store_id = 'homogeneous_%s_%s' % (
            config_type_class.short_type, component_scheme)

        vp = 5.8 * km
        vs = 3.46 * km

        mod = cake.LayeredModel.from_scanlines(cake.read_nd_model_str('''
  0. %(vp)g %(vs)g 2.6 1264. 600.
 20. %(vp)g %(vs)g 2.6 1264. 600.'''.lstrip() % dict(vp=vp/km, vs=vs/km)))

        store_type = config_type_class.short_type
        params = dict(
            id=store_id,
            sample_rate=1000.,
            modelling_code_id='ahfullgreen',
            component_scheme=component_scheme,
            earthmodel_1d=mod)

        if store_type in ('A', 'B'):
            params.update(
                source_depth_min=1.*km,
                source_depth_max=2.*km,
                source_depth_delta=0.5*km,
                distance_min=4.*km,
                distance_max=6.*km,
                distance_delta=0.5*km)

        if store_type == 'A':
            params.update(
                receiver_depth=3.*km)

        if store_type == 'B':
            params.update(
                receiver_depth_min=2.*km,
                receiver_depth_max=3.*km,
                receiver_depth_delta=0.5*km)

        if store_type == 'C':
            params.update(
                source_depth_min=1.*km,
                source_depth_max=2.*km,
                source_depth_delta=0.5*km,
                source_east_shift_min=1.*km,
                source_east_shift_max=2.*km,
                source_east_shift_delta=0.5*km,
                source_north_shift_min=2.*km,
                source_north_shift_max=3.*km,
                source_north_shift_delta=0.5*km)

        config = config_type_class(**params)

        config.validate()

        store_dir = mkdtemp(prefix=store_id)
        self.tempdirs.append(store_dir)

        gf.store.Store.create_editables(store_dir, config=config)

        store = gf.store.Store(store_dir, 'r')
        store.make_ttt()
        store.close()

        fomosto_ahfullgreen.build(store_dir, nworkers=1)

        store = gf.store.Store(store_dir, 'r')

        dsource_type = discretized_source_class.__name__

        params = {}
        if dsource_type == 'DiscretizedMTSource':
            params.update(
                m6s=num.array([
                    [1., 2., 3., 4., 5., 6.],
                    [1., 2., 3., 4., 5., 6.]]))
        elif dsource_type == 'DiscretizedExplosionSource':
            params.update(
                m0s=num.array([2., 2.]))
        elif dsource_type == 'DiscretizedSFSource':
            params.update(
                forces=num.array([[1., 2., 3.], [1., 2., 3.]]))
        elif dsource_type == 'DiscretizedPorePressureSource':
            params.update(
                pp=num.array([3., 3.]))

        snorth = 2.0*km
        seast = 2.0*km
        sdepth = 1.0*km
        rnorth = snorth + 3.*km
        reast = seast + 4.*km
        rdepth = 3.0*km

        t0 = 10.0 * store.config.deltat

        dsource = discretized_source_class(
            times=num.array([t0, t0+5.*store.config.deltat]),
            north_shifts=num.array([snorth, snorth]),
            east_shifts=num.array([seast, seast]),
            depths=num.array([sdepth, sdepth]),
            **params)

        receiver = gf.Receiver(
            north_shift=rnorth,
            east_shift=reast,
            depth=rdepth)

        components = gf.component_scheme_to_description[
            component_scheme].provided_components

        for seismogram in (store.seismogram, store.seismogram_old):
            for interpolation in ('nearest_neighbor', 'multilinear'):
                trs1 = []
                for component, gtr in seismogram(
                        dsource, receiver, components,
                        interpolation=interpolation).items():

                    tr = gtr.to_trace('', 'STA', '', component)
                    trs1.append(tr)

                trs2 = _make_traces_homogeneous(
                    dsource, receiver,
                    store.config.earthmodel_1d.require_homogeneous(),
                    store.config.deltat, '', 'STA', 'a')

                tmin = max(tr.tmin for tr in trs1+trs2)
                tmax = min(tr.tmax for tr in trs1+trs2)
                for tr in trs1+trs2:
                    tr.chop(tmin, tmax)

                assert tr.data_len() > 2

                trs1.sort(key=lambda tr: tr.channel)
                trs2.sort(key=lambda tr: tr.channel)

                denom = 0.0
                for t1, t2 in zip(trs1, trs2):
                    assert t1.channel == t2.channel
                    denom += num.sum(t1.ydata**2) + num.sum(t2.ydata**2)

                ds = []
                for t1, t2 in zip(trs1, trs2):
                    ds.append(2.0 * num.sum((t1.ydata - t2.ydata)**2) / denom)

                ds = num.array(ds)

                if component_scheme == 'elastic8':
                    limit = 1e-2
                else:
                    limit = 1e-6

                if not num.all(ds < limit):
                    print(ds)
                    trace.snuffle(trs1+trs2)

                assert num.all(ds < limit)
Example #8
0
    def test_fomosto_vs_psgrn_pscmp(self):

        mod = cake.LayeredModel.from_scanlines(
            cake.read_nd_model_str('''
 0. 5.8 3.46 2.6 1264. 600.
 20. 5.8 3.46 2.6 1264. 600.
 20. 6.5 3.85 2.9 1283. 600.
 35. 6.5 3.85 2.9 1283. 600.
mantle
 35. 8.04 4.48 3.58 1449. 600.
 77.5 8.045 4.49 3.5 1445. 600.
 77.5 8.045 4.49 3.5 180.6 75.
 120. 8.05 4.5 3.427 180. 75.
 120. 8.05 4.5 3.427 182.6 76.06
 165. 8.175 4.509 3.371 188.7 76.55
 210. 8.301 4.518 3.324 201. 79.4
 210. 8.3 4.52 3.321 336.9 133.3
 410. 9.03 4.871 3.504 376.5 146.1
 410. 9.36 5.08 3.929 414.1 162.7
 660. 10.2 5.611 3.918 428.5 172.9
 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip()))

        store_dir = mkdtemp(prefix='gfstore')
        self.tempdirs.append(store_dir)
        store_id = 'psgrn_pscmp_test'

        version = '2008a'

        c = psgrn_pscmp.PsGrnPsCmpConfig()
        c.psgrn_config.sampling_interval = 1.
        c.psgrn_config.version = version
        c.pscmp_config.version = version

        config = gf.meta.ConfigTypeA(id=store_id,
                                     ncomponents=10,
                                     sample_rate=1. / (3600. * 24.),
                                     receiver_depth=0. * km,
                                     source_depth_min=0. * km,
                                     source_depth_max=5. * km,
                                     source_depth_delta=0.1 * km,
                                     distance_min=0. * km,
                                     distance_max=40. * km,
                                     distance_delta=0.1 * km,
                                     modelling_code_id='psgrn_pscmp.%s' %
                                     version,
                                     earthmodel_1d=mod,
                                     tabulated_phases=[])

        config.validate()
        gf.store.Store.create_editables(store_dir,
                                        config=config,
                                        extra={'psgrn_pscmp': c})

        store = gf.store.Store(store_dir, 'r')
        store.close()

        # build store
        try:
            psgrn_pscmp.build(store_dir, nworkers=1)
        except psgrn_pscmp.PsCmpError as e:
            if str(e).find('could not start psgrn/pscmp') != -1:
                logger.warn('psgrn/pscmp not installed; '
                            'skipping test_pyrocko_gf_vs_pscmp')
                return
            else:
                raise

        origin = gf.Location(lat=10., lon=-15.)

        # test GF store
        TestRF = dict(lat=origin.lat,
                      lon=origin.lon,
                      depth=2. * km,
                      width=2. * km,
                      length=5. * km,
                      rake=90.,
                      dip=45.,
                      strike=45.,
                      slip=1.)

        source = gf.RectangularSource(**TestRF)

        neast = 40
        nnorth = 40

        N, E = num.meshgrid(num.linspace(-20. * km, 20. * km, nnorth),
                            num.linspace(-20. * km, 20. * km, neast))

        starget = gf.StaticTarget(lats=num.array([origin.lat] * N.size),
                                  lons=num.array([origin.lon] * N.size),
                                  north_shifts=N.flatten(),
                                  east_shifts=E.flatten(),
                                  interpolation='nearest_neighbor')
        engine = gf.LocalEngine(store_dirs=[store_dir])
        t0 = time()
        r = engine.process(source, starget)
        t1 = time()
        logger.info('pyrocko stacking time %f' % (t1 - t0))
        un_fomosto = r.static_results()[0].result['displacement.n']
        ue_fomosto = r.static_results()[0].result['displacement.e']
        ud_fomosto = r.static_results()[0].result['displacement.d']

        # test against direct pscmp output
        lats, lons = ortd.ne_to_latlon(origin.lat, origin.lon, N.flatten(),
                                       E.flatten())
        pscmp_sources = [psgrn_pscmp.PsCmpRectangularSource(**TestRF)]

        cc = c.pscmp_config
        cc.observation = psgrn_pscmp.PsCmpScatter(lats=lats, lons=lons)

        cc.rectangular_source_patches = pscmp_sources

        ccf = psgrn_pscmp.PsCmpConfigFull(**cc.items())
        ccf.psgrn_outdir = os.path.join(store_dir, c.gf_outdir) + '/'

        t2 = time()
        runner = psgrn_pscmp.PsCmpRunner(keep_tmp=False)
        runner.run(ccf)
        ps2du = runner.get_results(component='displ')[0]
        t3 = time()
        logger.info('pscmp stacking time %f' % (t3 - t2))

        un_pscmp = ps2du[:, 0]
        ue_pscmp = ps2du[:, 1]
        ud_pscmp = ps2du[:, 2]

        num.testing.assert_allclose(un_fomosto, un_pscmp, atol=0.002)
        num.testing.assert_allclose(ue_fomosto, ue_pscmp, atol=0.002)
        num.testing.assert_allclose(ud_fomosto, ud_pscmp, atol=0.002)
    def test_pyrocko_gf_vs_qseis2d(self):

        mod = cake.LayeredModel.from_scanlines(cake.read_nd_model_str('''
 0. 5.8 3.46 2.6 1264. 600.
 20. 5.8 3.46 2.6 1264. 600.
 20. 6.5 3.85 2.9 1283. 600.
 35. 6.5 3.85 2.9 1283. 600.
mantle
 35. 8.04 4.48 3.58 1449. 600.
 77.5 8.045 4.49 3.5 1445. 600.
 77.5 8.045 4.49 3.5 180.6 75.
 120. 8.05 4.5 3.427 180. 75.
 120. 8.05 4.5 3.427 182.6 76.06
 165. 8.175 4.509 3.371 188.7 76.55
 210. 8.301 4.518 3.324 201. 79.4
 210. 8.3 4.52 3.321 336.9 133.3
 410. 9.03 4.871 3.504 376.5 146.1
 410. 9.36 5.08 3.929 414.1 162.7
 660. 10.2 5.611 3.918 428.5 172.9
 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip()))

        receiver_mod = cake.LayeredModel.from_scanlines(
                                    cake.read_nd_model_str('''
 0. 5.8 3.46 2.6 1264. 600.
 20. 5.8 3.46 2.6 1264. 600.
 20. 6.5 3.85 2.9 1283. 600.
 35. 6.5 3.85 2.9 1283. 600.
'''.lstrip()))

        q2_store_dir = mkdtemp(prefix='gfstore')
        q_store_dir = mkdtemp(prefix='gfstore')
        self.tempdirs.append(q2_store_dir)
        self.tempdirs.append(q_store_dir)

        # qseis2d
        q2conf = qseis2d.QSeis2dConfig()
        q2conf.gf_directory = os.path.join(q2_store_dir, 'qseisS_green')

        qss = q2conf.qseis_s_config
        qss.receiver_basement_depth = 35.
        qss.calc_slowness_window = 0
        qss.slowness_window = slowness_window

        q2conf.time_region = (
            gf.meta.Timing('0'),
            gf.meta.Timing('end+100'))

        q2conf.cut = (
            gf.meta.Timing('0'),
            gf.meta.Timing('end+100'))

        qss.sw_flat_earth_transform = 0

        config_q2 = gf.meta.ConfigTypeA(
            id='qseis2d_test_q2',
            ncomponents=10,
            sample_rate=0.25,
            receiver_depth=0. * km,
            source_depth_min=10. * km,
            source_depth_max=10. * km,
            source_depth_delta=1. * km,
            distance_min=5528. * km,
            distance_max=5532. * km,
            distance_delta=1. * km,
            modelling_code_id='qseis2d',
            earthmodel_1d=mod,
            earthmodel_receiver_1d=receiver_mod,
            tabulated_phases=[
                gf.meta.TPDef(
                    id='begin',
                    definition='p,P,p\\,P\\'),
                gf.meta.TPDef(
                    id='end',
                    definition='2.5'),
            ])

        config_q2.validate()
        gf.store.Store.create_editables(
            q2_store_dir, config=config_q2, extra={'qseis2d': q2conf})

        store = gf.store.Store(q2_store_dir, 'r')
        store.make_ttt()
        store.close()

        # build store
        try:
            qseis2d.build(q2_store_dir, nworkers=1)
        except qseis2d.QSeis2dError as e:
            if str(e).find('could not start qseis2d') != -1:
                logger.warn('qseis2d not installed; '
                            'skipping test_pyrocko_qseis_vs_qseis2d')
                logger.warn(e)
                return
            else:
                raise

        # qseis
        config_q = copy.deepcopy(config_q2)
        config_q.id = 'qseis2d_test_q'
        config_q.modelling_code_id = 'qseis.2006a'

        qconf = qseis.QSeisConfig()
        qconf.qseis_version = '2006a'

        qconf.slowness_window = slowness_window

        qconf.time_region = (
            gf.meta.Timing('0'),
            gf.meta.Timing('end+100'))

        qconf.cut = (
            gf.meta.Timing('0'),
            gf.meta.Timing('end+100'))

        qconf.sw_flat_earth_transform = 0

        config_q.validate()
        gf.store.Store.create_editables(
            q_store_dir, config=config_q, extra={'qseis': qconf})

        store = gf.store.Store(q_store_dir, 'r')
        store.make_ttt()
        store.close()

        # build store
        try:
            qseis.build(q_store_dir, nworkers=1)
        except qseis.QSeisError as e:
            if str(e).find('could not start qseis') != -1:
                logger.warn('qseis not installed; '
                            'skipping test_pyrocko_qseis_vs_qseis2d')
                logger.warn(e)
                return
            else:
                raise

        # forward model
        source = gf.MTSource(
            lat=0.,
            lon=0.,
            depth=10. * km)

        source.m6 = tuple(random.random() * 2. - 1. for x in range(6))

        azi = 0.    # QSeis2d only takes one receiver without azimuth variable
        dist = 5530. * km

        dnorth = dist * math.cos(azi * d2r)
        deast = dist * math.sin(azi * d2r)

        targets_q = []
        targets_q2 = []
        for cha in 'rtz':
            target_q2 = gf.Target(
                quantity='displacement',
                codes=('', '0000', 'Q2', cha),
                north_shift=dnorth,
                east_shift=deast,
                store_id='qseis2d_test_q2')

            dist = source.distance_to(target_q2)
            azi, bazi = source.azibazi_to(target_q2)

            if cha == 'r':
                target_q2.azimuth = bazi + 180.
                target_q2.dip = 0.
            elif cha == 't':
                target_q2.azimuth = bazi - 90.
                target_q2.dip = 0.
            elif cha == 'z':
                target_q2.azimuth = 0.
                target_q2.dip = 90.

            target_q = copy.deepcopy(target_q2)
            target_q.store_id = 'qseis2d_test_q'
            target_q.codes = ('', '0000', 'Q', cha)
            targets_q2.append(target_q2)
            targets_q.append(target_q)

        targets = targets_q + targets_q2
        engine = gf.LocalEngine(store_dirs=[q2_store_dir, q_store_dir])
        response = engine.process(source, targets)

        qtrcs = []
        q2trcs = []
        for s, target, trc in response.iter_results():
            if target.codes[2] == 'Q':
                qtrcs.append(trc)
            else:
                q2trcs.append(trc)

        for q, q2 in zip(qtrcs, q2trcs):
            num.testing.assert_allclose(q.ydata, q2.ydata, atol=4e-24)
Example #10
0
        def regularize_extra(self, val):
            if isinstance(val, basestring):
                val = cake.LayeredModel.from_scanlines(
                    cake.read_nd_model_str(val))

            return val
Example #11
0
    def test_pyrocko_gf_vs_qseis2d(self):

        mod = cake.LayeredModel.from_scanlines(
            cake.read_nd_model_str('''
 0. 5.8 3.46 2.6 1264. 600.
 20. 5.8 3.46 2.6 1264. 600.
 20. 6.5 3.85 2.9 1283. 600.
 35. 6.5 3.85 2.9 1283. 600.
mantle
 35. 8.04 4.48 3.58 1449. 600.
 77.5 8.045 4.49 3.5 1445. 600.
 77.5 8.045 4.49 3.5 180.6 75.
 120. 8.05 4.5 3.427 180. 75.
 120. 8.05 4.5 3.427 182.6 76.06
 165. 8.175 4.509 3.371 188.7 76.55
 210. 8.301 4.518 3.324 201. 79.4
 210. 8.3 4.52 3.321 336.9 133.3
 410. 9.03 4.871 3.504 376.5 146.1
 410. 9.36 5.08 3.929 414.1 162.7
 660. 10.2 5.611 3.918 428.5 172.9
 660. 10.79 5.965 4.229 1349. 549.6'''.lstrip()))

        receiver_mod = cake.LayeredModel.from_scanlines(
            cake.read_nd_model_str('''
 0. 5.8 3.46 2.6 1264. 600.
 20. 5.8 3.46 2.6 1264. 600.
 20. 6.5 3.85 2.9 1283. 600.
 35. 6.5 3.85 2.9 1283. 600.
'''.lstrip()))

        q2_store_dir = mkdtemp(prefix='gfstore')
        q_store_dir = mkdtemp(prefix='gfstore')
        self.tempdirs.append(q2_store_dir)
        self.tempdirs.append(q_store_dir)

        # qseis2d
        q2conf = qseis2d.QSeis2dConfig()
        q2conf.gf_directory = os.path.join(q2_store_dir, 'qseisS_green')

        qss = q2conf.qseis_s_config
        qss.receiver_basement_depth = 35.
        qss.calc_slowness_window = 0
        qss.slowness_window = slowness_window

        q2conf.time_region = (gf.meta.Timing('0'), gf.meta.Timing('end+100'))

        q2conf.cut = (gf.meta.Timing('0'), gf.meta.Timing('end+100'))

        qss.sw_flat_earth_transform = 0

        config_q2 = gf.meta.ConfigTypeA(id='qseis2d_test_q2',
                                        ncomponents=10,
                                        sample_rate=0.25,
                                        receiver_depth=0. * km,
                                        source_depth_min=10. * km,
                                        source_depth_max=10. * km,
                                        source_depth_delta=1. * km,
                                        distance_min=5528. * km,
                                        distance_max=5532. * km,
                                        distance_delta=1. * km,
                                        modelling_code_id='qseis2d',
                                        earthmodel_1d=mod,
                                        earthmodel_receiver_1d=receiver_mod,
                                        tabulated_phases=[
                                            gf.meta.TPDef(
                                                id='begin',
                                                definition='p,P,p\\,P\\'),
                                            gf.meta.TPDef(id='end',
                                                          definition='2.5'),
                                        ])

        config_q2.validate()
        gf.store.Store.create_editables(q2_store_dir,
                                        config=config_q2,
                                        extra={'qseis2d': q2conf})

        store = gf.store.Store(q2_store_dir, 'r')
        store.make_ttt()
        store.close()

        # build store
        try:
            qseis2d.build(q2_store_dir, nworkers=1)
        except qseis2d.QSeis2dError, e:
            if str(e).find('could not start qseis2d') != -1:
                logger.warn('qseis2d not installed; '
                            'skipping test_pyrocko_qseis_vs_qseis2d')
                return
            else:
                raise