Exemplo n.º 1
0
def create_gf_store(mod, path, name="model"):
    store_dir = path+"/"+name+"/"
    qsconf = qseis.QSeisConfig()
    qsconf.qseis_version = '2006a'

    qsconf.time_region = (
        gf.meta.Timing('{stored:begin}-5'),
        gf.meta.Timing('{stored:end}+20'))

    qsconf.cut = (
        gf.meta.Timing('{stored:begin}-5'),
        gf.meta.Timing('{stored:end}+20'))

    qsconf.wavelet_duration_samples = 0.001
    qsconf.sw_flat_earth_transform = 0

    config = gf.meta.ConfigTypeA(
        id='qseis_%s' %name,
        sample_rate=100,
        receiver_depth=0.*km,
        source_depth_min=0*km,
        source_depth_max=15*km,
        source_depth_delta=0.4*km,
        distance_min=0.5,
        distance_max=40*km,
        distance_delta=0.4*km,
        modelling_code_id='qseis.2006a',
        earthmodel_1d=mod,
        tabulated_phases=[
            gf.meta.TPDef(
                id='any_P',
                definition='p,P'),
            gf.meta.TPDef(
                id='end',
                definition='1.5'),
            gf.meta.TPDef(
                id='begin',
                definition='10'),
        ])

    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
Exemplo n.º 2
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
Exemplo n.º 3
0
    def test_pyrocko_gf_vs_qseis(self):
        random.seed(2017)

        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',
                                     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

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

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

        azi = random.random() * 365.
        dist = 553. * km

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

        targets = []
        for cha in 'rtz':
            target = gf.Target(quantity='displacement',
                               codes=('', '0000', 'PG', cha),
                               north_shift=dnorth,
                               east_shift=deast,
                               depth=config.receiver_depth,
                               store_id='qseis_test')

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

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

            targets.append(target)

        runner = qseis.QSeisRunner()
        conf = qseis.QSeisConfigFull()
        conf.qseis_version = '2006a'
        conf.receiver_distances = [dist / km]
        conf.receiver_azimuths = [azi]
        conf.source_depth = source.depth / km
        conf.time_start = 0.0
        conf.time_window = 508.
        conf.time_reduction_velocity = 0.0
        conf.nsamples = 128
        conf.source_mech = qseis.QSeisSourceMechMT(mnn=source.mnn,
                                                   mee=source.mee,
                                                   mdd=source.mdd,
                                                   mne=source.mne,
                                                   mnd=source.mnd,
                                                   med=source.med)
        conf.earthmodel_1d = mod

        conf.sw_flat_earth_transform = 0

        runner.run(conf)

        trs = runner.get_traces()
        for tr in trs:
            tr.shift(-config.deltat)
            tr.snap(interpolate=True)
            tr.lowpass(4, 0.05)
            tr.highpass(4, 0.01)

        engine = gf.LocalEngine(store_dirs=[store_dir])

        def process_wrap(nthreads=0):
            @benchmark.labeled('pyrocko.gf.process (nthreads-%d)' % nthreads)
            def process(nthreads):
                return engine.process(source, targets, nthreads=nthreads)\
                    .pyrocko_traces()

            return process(nthreads)

        for nthreads in range(1, cpu_count() + 1):
            trs2 = process_wrap(nthreads)
        # print benchmark

        for tr in trs2:
            tr.snap(interpolate=True)
            tr.lowpass(4, 0.05)
            tr.highpass(4, 0.01)

        # trace.snuffle(trs+trs2)

        for cha in 'rtz':
            t1 = g(trs, cha)
            t2 = g(trs2, cha)
            tmin = max(t1.tmin, t2.tmin)
            tmax = min(t1.tmax, t2.tmax)
            t1.chop(tmin, tmax)
            t2.chop(tmin, tmax)
            d = 2.0 * num.sum((t1.ydata - t2.ydata)**2) / \
                (num.sum(t1.ydata**2) + num.sum(t2.ydata**2))

            assert d < 0.05
Exemplo n.º 4
0
    def test_qseis_vs_ahfull(self):
        random.seed(23)

        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_id_qseis = 'homogeneous_qseis'
        store_id_ahfull = 'homogeneous_ahfull'

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

        textra = 5.0

        qsconf.time_region = (gf.meta.Timing('{vel:%g}-%g' %
                                             (vp / km, textra)),
                              gf.meta.Timing('{vel:%g}+%g' %
                                             (vs / km, textra)))

        qsconf.cut = (gf.meta.Timing('{vel:%g}-%g' % (vp / km, textra)),
                      gf.meta.Timing('{vel:%g}+%g' % (vs / km, textra)))

        qsconf.relevel_with_fade_in = True

        qsconf.fade = (gf.meta.Timing('{vel:%g}-%g' % (vp / km, textra)),
                       gf.meta.Timing('{vel:%g}-%g' % (vp / km, 0.)),
                       gf.meta.Timing('{vel:%g}+%g' % (vs / km, 0.)),
                       gf.meta.Timing('{vel:%g}+%g' % (vs / km, textra)))

        qsconf.wavelet_duration_samples = 0.001
        qsconf.sw_flat_earth_transform = 0
        qsconf.filter_surface_effects = 1
        qsconf.wavenumber_sampling = 5.
        qsconf.aliasing_suppression_factor = 0.01

        sample_rate = 10.

        config = gf.meta.ConfigTypeA(
            id=store_id_qseis,
            sample_rate=sample_rate,
            receiver_depth=0. * km,
            source_depth_min=1. * km,
            source_depth_max=19 * km,
            source_depth_delta=6. * km,
            distance_min=2. * km,
            distance_max=20 * km,
            distance_delta=2 * 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='s,S,s\\,S\\'),
            ])

        config.validate()

        store_dir_qseis = mkdtemp(prefix=store_id_qseis)
        self.tempdirs.append(store_dir_qseis)

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

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

        try:
            qseis.build(store_dir_qseis, 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

        config = gf.meta.ConfigTypeA(
            id=store_id_ahfull,
            sample_rate=sample_rate,
            receiver_depth=0. * km,
            source_depth_min=1. * km,
            source_depth_max=19 * km,
            source_depth_delta=6. * km,
            distance_min=2. * km,
            distance_max=20 * km,
            distance_delta=2 * km,
            modelling_code_id='ahfullgreen',
            earthmodel_1d=mod,
            tabulated_phases=[
                gf.meta.TPDef(id='begin', definition='p,P,p\\,P\\'),
                gf.meta.TPDef(id='end', definition='s,S,s\\,S\\'),
            ])

        config.validate()

        store_dir_ahfull = mkdtemp(prefix=store_id_qseis)
        self.tempdirs.append(store_dir_ahfull)

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

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

        ahfullgreen.build(store_dir_ahfull, nworkers=1)

        sdepth = rand(config.source_depth_min, config.source_depth_max)
        sdepth = round(
            (sdepth - config.source_depth_min)
            / config.source_depth_delta) * config.source_depth_delta \
            + config.source_depth_min

        source = gf.MTSource(lat=0., lon=0., depth=sdepth)

        source.m6 = tuple(rand(-1., 1.) for x in range(6))

        for ii in range(5):
            azi = random.random() * 365.
            dist = rand(config.distance_min, config.distance_max)
            dist = round(dist / config.distance_delta) * config.distance_delta

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

            targets = []
            for cha in 'rtz':
                target = gf.Target(quantity='displacement',
                                   codes=('', '0000', 'PG', cha),
                                   north_shift=dnorth,
                                   east_shift=deast,
                                   depth=config.receiver_depth,
                                   store_id=store_id_ahfull)

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

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

                targets.append(target)

            runner = qseis.QSeisRunner()
            conf = qseis.QSeisConfigFull()
            conf.qseis_version = '2006a'
            conf.receiver_distances = [dist / km]
            conf.receiver_azimuths = [azi]
            conf.receiver_depth = config.receiver_depth / km
            conf.source_depth = source.depth / km

            distance_3d_max = math.sqrt(config.distance_max**2 +
                                        (config.source_depth_max -
                                         config.source_depth_min)**2)

            nsamples = trace.nextpow2(
                int(
                    math.ceil(distance_3d_max / vs * 2.0 + 2. * textra) *
                    config.sample_rate))

            conf.time_start = -textra
            conf.time_window = (nsamples - 1) / config.sample_rate
            conf.time_reduction_velocity = 0.0
            conf.nsamples = nsamples
            conf.source_mech = qseis.QSeisSourceMechMT(mnn=source.mnn,
                                                       mee=source.mee,
                                                       mdd=source.mdd,
                                                       mne=source.mne,
                                                       mnd=source.mnd,
                                                       med=source.med)
            conf.earthmodel_1d = mod

            conf.sw_flat_earth_transform = 0
            conf.filter_surface_effects = 1
            conf.wavenumber_sampling = 10.
            conf.wavelet_duration_samples = 0.001
            conf.aliasing_suppression_factor = 0.01

            conf.validate()

            runner.run(conf)

            trs = runner.get_traces()
            for tr in trs:
                pass
                tr.lowpass(4, config.sample_rate / 8., demean=False)
                tr.highpass(4, config.sample_rate / 80.)

            engine = gf.LocalEngine(
                store_dirs=[store_dir_ahfull, store_dir_qseis])

            trs2 = engine.process(source, targets).pyrocko_traces()
            for tr in trs2:
                tr.shift(config.deltat)
                tr.lowpass(4, config.sample_rate / 8., demean=False)
                tr.highpass(4, config.sample_rate / 80.)

            # trace.snuffle(trs+trs2)

            tmin = store.t('{vel:%g}' %
                           (vp / km), source, target) - textra * 0.2
            tmax = store.t('{vel:%g}' %
                           (vs / km), source, target) + textra * 0.2

            for tr in trs + trs2:
                tr.chop(tmin, tmax)

            denom = 0.0
            for cha in 'rtz':
                t1 = g(trs, cha)
                t2 = g(trs2, cha)
                denom += num.sum(t1.ydata**2) + num.sum(t2.ydata**2)

            ds = []
            for cha in 'rtz':
                t1 = g(trs, cha)
                t2 = g(trs2, cha)
                ds.append(2.0 * num.sum((t1.ydata - t2.ydata)**2) / denom)

            ds = num.array(ds)

            # if not num.all(ds < 0.05):
            #    trace.snuffle(trs+trs2)

            assert num.all(ds < 0.05)
Exemplo n.º 5
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.
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=0 * km,
                                     source_depth_max=10 * km,
                                     source_depth_delta=1 * 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
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
    def test_qseis_vs_ahfull(self):
        random.seed(23)

        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_id_qseis = 'homogeneous_qseis'
        store_id_ahfull = 'homogeneous_ahfull'

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

        textra = 5.0

        qsconf.time_region = (gf.meta.Timing('{vel:%g}-%g' %
                                             (vp / km, textra)),
                              gf.meta.Timing('{vel:%g}+%g' %
                                             (vs / km, textra)))

        qsconf.cut = (gf.meta.Timing('{vel:%g}-%g' % (vp / km, textra)),
                      gf.meta.Timing('{vel:%g}+%g' % (vs / km, textra)))

        qsconf.relevel_with_fade_in = True

        qsconf.fade = (gf.meta.Timing('{vel:%g}-%g' % (vp / km, textra)),
                       gf.meta.Timing('{vel:%g}-%g' % (vp / km, 0.)),
                       gf.meta.Timing('{vel:%g}+%g' % (vs / km, 0.)),
                       gf.meta.Timing('{vel:%g}+%g' % (vs / km, textra)))

        qsconf.wavelet_duration_samples = 0.001
        qsconf.sw_flat_earth_transform = 0
        qsconf.filter_surface_effects = 1
        qsconf.wavenumber_sampling = 5.
        qsconf.aliasing_suppression_factor = 0.01

        sample_rate = 10.

        config = gf.meta.ConfigTypeA(
            id=store_id_qseis,
            sample_rate=sample_rate,
            receiver_depth=0. * km,
            source_depth_min=1. * km,
            source_depth_max=19 * km,
            source_depth_delta=6. * km,
            distance_min=2. * km,
            distance_max=20 * km,
            distance_delta=2 * 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='s,S,s\\,S\\'),
            ])

        config.validate()

        store_dir_qseis = mkdtemp(prefix=store_id_qseis)
        self.tempdirs.append(store_dir_qseis)

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

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

        try:
            qseis.build(store_dir_qseis, 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
Exemplo n.º 8
0
def propose_stores(distances,
                   models,
                   superdir,
                   source_depth_min=0.,
                   source_depth_max=15.,
                   source_depth_delta=1.,
                   sample_rate=10.,
                   force=False,
                   numdists=2,
                   run_ttt=False,
                   simplify=False,
                   phases=['P'],
                   classic=True,
                   distance_delta_max=None):
    ''' Propose a fomosto store configuration for P-pP Array beam forming.
    :param event: Event instance
    :param superdir: where to create the store (default, current directory)
    :param source_depth_min: minimum source depth (default 0)
    :param source_depth_max: maximum source deoth (default 15)
    :param source_depth_delta: increment
    :param sample_rate: in Hz
    :param force_overwrite: overwrite potentially existent store
    :param run_ttt: generate travel time tables right away'''

    modelling_code_id = 'qseis.2006a'

    configs = []
    if classic:
        define_method = cake.PhaseDef
    else:
        define_method = cake.PhaseDef.classic

    wanted = [define_method(ph) for ph in phases]

    global_model = cake.load_model()
    remake_dir(superdir, force)
    for (station_id, key_station, key_event), (dist_min,
                                               dist_max) in distances.items():

        configid = '%s_%s_%s' % (station_id, key_station, key_event)
        distance_delta = dist_max - dist_min
        if distance_delta_max is not None:
            while distance_delta > distance_delta_max:
                distance_delta /= 2.
        config = ConfigTypeA(id=configid,
                             source_depth_min=source_depth_min * km,
                             source_depth_max=source_depth_max * km,
                             source_depth_delta=source_depth_delta * km,
                             distance_min=dist_min,
                             distance_max=dist_max,
                             distance_delta=distance_delta,
                             sample_rate=sample_rate,
                             ncomponents=10)

        station_crust = models[key_station]
        config.earthmodel_receiver_1d = cake.LayeredModel.from_scanlines(
            cake.from_crust2x2_profile(station_crust))

        config.earthmodel_1d = global_model.replaced_crust(
            crust2_profile=models[key_event])

        if simplify:
            config.earthmodel_1d = config.earthmodel_1d.simplify(
                max_rel_error=0.002)
        adjust_earthmodel_receiver_depth(config)
        configs.append(config)
        dest_dir = pjoin(superdir, config.id)
        remake_dir(dest_dir, force)
        logger.info('Created store: %s' % dest_dir)

        mean_z = num.mean((config.source_depth_min, config.source_depth_max))
        mean_dist = num.mean((config.distance_min, config.distance_max))
        arrivals = config.earthmodel_1d.arrivals(
            phases=wanted, distances=[mean_dist * cake.m2d], zstart=mean_z)
        if len(arrivals) == 0:
            logger.warning(
                NoRay('d: %s, z: %s, %s phases: %s' %
                      (mean_dist * cake.m2d, mean_z,
                       'classic' if classic else '', "|".join(phases))))
            slow = 0.1
            slowness_taper = (0., 0., 1.3 * slow, 1.5 * slow)
            z_turn = num.max(config.earthmodel_1d.profile('z'))
        else:
            slow = arrivals[0].p / (cake.r2d * cake.d2m / km)
            slowness_taper = (0.3 * slow, 0.5 * slow, 1.5 * slow, 1.7 * slow)
            z_turn = num.max(arrivals[0].zxt_path_subdivided()[0])

        zmax = max(z_turn * 1.1,
                   config.earthmodel_receiver_1d.profile('z')[-1])

        config.earthmodel_1d = config.earthmodel_1d.extract(depth_max=zmax)
        begin_phase_defs = 'P,P\\,PP'
        if model_has_cmb(config.earthmodel_1d):
            begin_phase_defs += ',Pv_(cmb)p'
        config.modelling_code_id = modelling_code_id
        config.tabulated_phases = [
            TPDef(id='begin', definition=begin_phase_defs),
            TPDef(id='end', definition='2.5'),
            TPDef(id='PP', definition='PP'),
            TPDef(id='P', definition='P')
        ]

        qs = qseis.QSeisConfig()
        qs.qseis_version = config.modelling_code_id.split('.')[1]
        half_lapse_time = 55
        qs.time_region = (Timing('begin-%s' % (half_lapse_time * 1.1)),
                          Timing('begin+%s' % (half_lapse_time * 1.1)))
        qs.cut = (Timing('begin-%s' % half_lapse_time),
                  Timing('begin+%s' % half_lapse_time))
        qs.slowness_window = slowness_taper
        qs.wavelet_duration_samples = 0.001
        qs.sw_flat_earth_transform = 1
        qs.filter_shallow_paths = 1
        qs.filter_shallow_paths_depth = float(z_turn * 0.2)
        qs.sw_algorithm = 1
        Store.create_editables(dest_dir, config=config, extra={'qseis': qs})
        if run_ttt:
            st = Store(dest_dir)
            st.make_ttt()

    config_ids = [c.id for c in configs]
    return config_ids
Exemplo n.º 9
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.
 660. 8.04 4.48 3.58 1449. 600.
 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.1,
                                        receiver_depth=0. * km,
                                        source_depth_min=10. * km,
                                        source_depth_max=10. * km,
                                        source_depth_delta=1. * km,
                                        distance_min=5529. * km,
                                        distance_max=5531. * 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-23)
Exemplo n.º 10
0
class GFQSeis2dTestCase(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)
        self.tempdirs = []

    def __del__(self):
        import shutil

        for d in self.tempdirs:
            shutil.rmtree(d)

    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

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

        qconf = qseis.QSeisConfig()

        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, e:
            if str(e).find('could not start qseis') != -1:
                logger.warn('qseis not installed; '
                            'skipping test_pyrocko_qseis_vs_qseis2d')
                return
            else:
                raise