Exemplo n.º 1
0
 def test_create_default(self):
     d = mkdtemp(prefix='gfstore')
     self.tempdirs.append(d)
     ahfullgreen.init(d, None)
     store = gf.Store(d)
     store.make_ttt()
     ahfullgreen.build(d)
Exemplo n.º 2
0
    def setUpClass(cls):
        cls.cwd = os.getcwd()

        cls.serve_dir = tempfile.mkdtemp(prefix='pyrocko')

        ahfullgreen.init(cls.serve_dir, None)
        cls.store = store.Store(cls.serve_dir, 'r')
        cls.store.make_ttt()
        cls.store_id = cls.store.config.id
        ahfullgreen.build(cls.serve_dir)

        cls.dl_dir = tempfile.mkdtemp(prefix='pyrocko')
        os.chdir(cls.dl_dir)
Exemplo n.º 3
0
    def setUpClass(cls):
        cls.cwd = os.getcwd()

        cls.serve_dir = tempfile.mkdtemp(prefix='pyrocko')

        ahfullgreen.init(cls.serve_dir, None)
        cls.store = store.Store(cls.serve_dir, 'r')
        cls.store.make_ttt()
        cls.store_id = cls.store.config.id
        ahfullgreen.build(cls.serve_dir)

        cls.dl_dir = tempfile.mkdtemp(prefix='pyrocko')
        os.chdir(cls.dl_dir)
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 _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).iteritems():

                    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)
Exemplo n.º 6
0
                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 xrange(6))

        for ii in xrange(5):
            azi = random.random() * 365.
            dist = rand(config.distance_min, config.distance_max)
            dist = round(dist / config.distance_delta) * config.distance_delta
Exemplo n.º 7
0
    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)