예제 #1
0
    def run(self, config):
        elements = list(config.earthmodel_1d.elements())

        if len(elements) != 2:
            raise AhfullgreenError('More than one layer in earthmodel')
        if not isinstance(elements[1], cake.HomogeneousLayer):
            raise AhfullgreenError('Layer has to be a HomogeneousLayer')

        l = elements[1].m
        vp, vs, density, qp, qs = (l.vp, l.vs, l.rho, l.qp, l.qs)
        f = (0., 0., 0.)
        m6 = config.source_mech.m6()
        ns = config.nsamples
        deltat = config.deltat
        tmin = 0.
        for i_distance, d in enumerate(config.receiver_distances):
            outx = num.zeros(ns)
            outy = num.zeros(ns)
            outz = num.zeros(ns)
            x = (d, 0.0, config.source_depth)
            add_seismogram(vp, vs, density, qp, qs, x, f, m6, 'displacement',
                           deltat, 0.0, outx, outy, outz, stf=Impulse())

            for i_comp, o in enumerate((outx, outy, outz)):
                comp = components[i_comp]
                tr = trace.Trace('', '%04i' % i_distance, '', comp,
                                tmin=tmin, ydata=o, deltat=deltat,
                                             meta=dict(distance=d,
                                                       azimuth=0.))
                self.traces.append(tr)
예제 #2
0
def make_traces(material, source_mech, deltat, norths, easts, source_depth,
                receiver_depth):

    if isinstance(source_mech, MomentTensor):
        m6 = source_mech.m6()
        f = (0., 0., 0.)
    elif isinstance(source_mech, tuple):
        m6 = (0., 0., 0., 0., 0., 0.)
        f = source_mech

    npad = 120

    traces = []
    for i_distance, (north, east) in enumerate(zip(norths, easts)):
        d3d = math.sqrt(north**2 + east**2 +
                        (receiver_depth - source_depth)**2)

        tmin = (math.floor(d3d / material.vp / deltat) - npad) * deltat
        tmax = (math.ceil(d3d / material.vs / deltat) + npad) * deltat
        ns = int(round((tmax - tmin) / deltat))

        outx = num.zeros(ns)
        outy = num.zeros(ns)
        outz = num.zeros(ns)

        x = (north, east, receiver_depth - source_depth)

        add_seismogram(material.vp,
                       material.vs,
                       material.rho,
                       material.qp,
                       material.qs,
                       x,
                       f,
                       m6,
                       'displacement',
                       deltat,
                       tmin,
                       outx,
                       outy,
                       outz,
                       stf=Impulse())

        for i_comp, o in enumerate((outx, outy, outz)):
            comp = components[i_comp]
            tr = trace.Trace('',
                             '%04i' % i_distance,
                             '',
                             comp,
                             tmin=tmin,
                             ydata=o,
                             deltat=deltat,
                             meta=dict(distance=math.sqrt(north**2 + east**2),
                                       azimuth=0.))

            traces.append(tr)

    return traces
예제 #3
0
    def test_ahfull_kiwi(self):
        setup = load(
            filename=common.test_data_file('test_ahfull_kiwi_setup.yaml'))
        trs_ref = io.load(
            common.test_data_file('test_ahfull_kiwi_traces.mseed'))

        for i, s in enumerate(setup.setups):
            d3d = math.sqrt(s.x[0]**2 + s.x[1]**2 + s.x[2]**2)

            tlen = d3d / s.vs * 2

            n = int(num.round(tlen / s.deltat))

            out_x = num.zeros(n)
            out_y = num.zeros(n)
            out_z = num.zeros(n)

            ahfullgreen.add_seismogram(s.vp, s.vs, s.density, 1000000.0,
                                       1000000.0, s.x, s.f, s.m6,
                                       'displacement', s.deltat, 0., out_x,
                                       out_y, out_z, ahfullgreen.Gauss(s.tau))

            trs = []
            for out, comp in zip([out_x, out_y, out_z], 'NED'):
                tr = trace.Trace('',
                                 'S%03i' % i,
                                 'P',
                                 comp,
                                 deltat=s.deltat,
                                 tmin=0.0,
                                 ydata=out)

                trs.append(tr)

            trs2 = []

            for cha in 'NED':

                t1 = g(trs, 'S%03i' % i, cha)
                t2 = g(trs_ref, 'S%03i' % i, cha)

                tmin = max(t1.tmin, t2.tmin)
                tmax = min(t1.tmax, t2.tmax)

                t1 = t1.chop(tmin, tmax, inplace=False)
                t2 = t2.chop(tmin, tmax, inplace=False)

                trs2.append(t2)

                d = 2.0 * num.sum((t1.ydata - t2.ydata)**2) / \
                    (num.sum(t1.ydata**2) + num.sum(t2.ydata**2))

                if d >= 0.02:
                    print(d)
                    # trace.snuffle([t1, t2])

                assert d < 0.02
    def test_ahfull_kiwi(self):
        setup = load(filename=common.test_data_file(
            'test_ahfull_kiwi_setup.yaml'))
        trs_ref = io.load(common.test_data_file(
            'test_ahfull_kiwi_traces.mseed'))

        for i, s in enumerate(setup.setups):
            d3d = math.sqrt(s.x[0]**2 + s.x[1]**2 + s.x[2]**2)

            tlen = d3d / s.vs * 2

            n = int(num.round(tlen / s.deltat))

            out_x = num.zeros(n)
            out_y = num.zeros(n)
            out_z = num.zeros(n)

            ahfullgreen.add_seismogram(
                s.vp, s.vs, s.density, 1000000.0, 1000000.0, s.x, s.f, s.m6,
                'displacement',
                s.deltat, 0.,
                out_x, out_y, out_z,
                ahfullgreen.Gauss(s.tau))

            trs = []
            for out, comp in zip([out_x, out_y, out_z], 'NED'):
                tr = trace.Trace(
                    '', 'S%03i' % i, 'P', comp,
                    deltat=s.deltat, tmin=0.0, ydata=out)

                trs.append(tr)

            trs2 = []

            for cha in 'NED':

                t1 = g(trs, 'S%03i' % i, cha)
                t2 = g(trs_ref, 'S%03i' % i, cha)

                tmin = max(t1.tmin, t2.tmin)
                tmax = min(t1.tmax, t2.tmax)

                t1 = t1.chop(tmin, tmax, inplace=False)
                t2 = t2.chop(tmin, tmax, inplace=False)

                trs2.append(t2)

                d = 2.0 * num.sum((t1.ydata - t2.ydata)**2) / \
                    (num.sum(t1.ydata**2) + num.sum(t2.ydata**2))

                if d >= 0.02:
                    print(d)
                    # trace.snuffle([t1, t2])

                assert d < 0.02
예제 #5
0
    def run(self, config):
        elements = list(config.earthmodel_1d.elements())

        if len(elements) != 2:
            raise AhfullgreenError('More than one layer in earthmodel')
        if not isinstance(elements[1], cake.HomogeneousLayer):
            raise AhfullgreenError('Layer has to be a HomogeneousLayer')

        l = elements[1].m
        vp, vs, density, qp, qs = (l.vp, l.vs, l.rho, l.qp, l.qs)
        f = (0., 0., 0.)
        m6 = config.source_mech.m6()
        ns = config.nsamples
        deltat = config.deltat
        tmin = 0.
        for i_distance, d in enumerate(config.receiver_distances):
            outx = num.zeros(ns)
            outy = num.zeros(ns)
            outz = num.zeros(ns)
            x = (d, 0.0, config.source_depth)
            add_seismogram(vp,
                           vs,
                           density,
                           qp,
                           qs,
                           x,
                           f,
                           m6,
                           'displacement',
                           deltat,
                           0.0,
                           outx,
                           outy,
                           outz,
                           stf=Impulse())

            for i_comp, o in enumerate((outx, outy, outz)):
                comp = components[i_comp]
                tr = trace.Trace('',
                                 '%04i' % i_distance,
                                 '',
                                 comp,
                                 tmin=tmin,
                                 ydata=o,
                                 deltat=deltat,
                                 meta=dict(distance=d, azimuth=0.))

                self.traces.append(tr)
def make_traces(material, source_mech, deltat, norths, easts,
                source_depth, receiver_depth):

    if isinstance(source_mech, MomentTensor):
        m6 = source_mech.m6()
        f = (0., 0., 0.)
    elif isinstance(source_mech, tuple):
        m6 = (0., 0., 0., 0., 0., 0.)
        f = source_mech

    npad = 120

    traces = []
    for i_distance, (north, east) in enumerate(zip(norths, easts)):
        d3d = math.sqrt(
            north**2 + east**2 + (receiver_depth - source_depth)**2)

        tmin = (math.floor(d3d / material.vp / deltat) - npad) * deltat
        tmax = (math.ceil(d3d / material.vs / deltat) + npad) * deltat
        ns = int(round((tmax - tmin) / deltat))

        outx = num.zeros(ns)
        outy = num.zeros(ns)
        outz = num.zeros(ns)

        x = (north, east, receiver_depth-source_depth)

        add_seismogram(
            material.vp, material.vs, material.rho, material.qp, material.qs,
            x, f, m6, 'displacement',
            deltat, tmin, outx, outy, outz,
            stf=Impulse())

        for i_comp, o in enumerate((outx, outy, outz)):
            comp = components[i_comp]
            tr = trace.Trace('', '%04i' % i_distance, '', comp,
                             tmin=tmin, ydata=o, deltat=deltat,
                             meta=dict(
                                 distance=math.sqrt(north**2 + east**2),
                                 azimuth=0.))

            traces.append(tr)

    return traces
예제 #7
0
파일: test_gf.py 프로젝트: shineusn/pyrocko
def make_traces_homogeneous(dsource, receiver, material, deltat, net, sta,
                            loc):

    comps = ['displacement.n', 'displacement.e', 'displacement.d']
    npad = 120

    dists = dsource.distances_to(receiver)

    dists = dsource.distances_to(receiver)
    azis, _ = dsource.azibazis_to(receiver)

    norths = dists * num.cos(azis * d2r)
    easts = dists * num.sin(azis * d2r)

    ddepths = receiver.depth - dsource.depths

    d3ds = num.sqrt(norths**2 + easts**2 + ddepths**2)
    times = dsource.times
    toff = math.floor(num.min(times) / deltat) * deltat

    tmin = num.min(
        (num.floor(times + d3ds / material.vp / deltat) - npad) * deltat)
    tmax = num.max(
        (num.ceil(times + d3ds / material.vs / deltat) + npad) * deltat)

    ns = int(round((tmax - tmin) / deltat))

    outx = num.zeros(ns)
    outy = num.zeros(ns)
    outz = num.zeros(ns)

    traces = []
    for ielement in xrange(dsource.nelements):
        x = (norths[ielement], easts[ielement], ddepths[ielement])

        if isinstance(dsource, gf.DiscretizedMTSource):
            m6 = dsource.m6s[ielement, :]
            f = (0., 0., 0.)
        elif isinstance(dsource, gf.DiscretizedSFSource):
            m6 = (0., 0., 0., 0., 0., 0.)
            f = dsource.forces[ielement, :]
        elif isinstance(dsource, gf.DiscretizedExplosionSource):
            m0 = dsource.m0s[ielement]
            m6 = (m0, m0, m0, 0., 0., 0.)
            f = (0., 0., 0.)
        else:
            assert False

        ahfullgreen.add_seismogram(material.vp,
                                   material.vs,
                                   material.rho,
                                   material.qp,
                                   material.qs,
                                   x,
                                   f,
                                   m6,
                                   'displacement',
                                   deltat,
                                   tmin - (times[ielement] - toff),
                                   outx,
                                   outy,
                                   outz,
                                   stf=ahfullgreen.Impulse())

    for comp, o in zip(comps, (outx, outy, outz)):
        tr = trace.Trace(net,
                         sta,
                         loc,
                         comp,
                         tmin=tmin + toff,
                         ydata=o,
                         deltat=deltat)

        traces.append(tr)

    return traces
예제 #8
0
    def call(self):
        '''Main work routine of the snuffling.'''
        self.cleanup()
        olat = 0.
        olon = 0.
        f = (0., 0., 0.)
        deltat = 1./self.fsampling
        if self.stf == 'Gauss':
            stf = Gauss(self.tau)
        elif self.stf == 'Impulse':
            stf = Impulse()

        viewer = self.get_viewer()
        event = viewer.get_active_event()
        if event:
            event, stations = self.get_active_event_and_stations(missing='warn')
        else:
            event = model.Event(lat=olat, lon=olon)
            stations = []

        if not stations:
            s = model.Station(lat=olat, lon=olon, station='AFG')
            stations = [s]
            viewer.add_stations(stations)

        source = gf.DCSource(
            time=event.time+self.time,
            lat=event.lat,
            lon=event.lon,
            north_shift=self.north_km*km,
            east_shift=self.east_km*km,
            depth=self.depth_km*km,
            magnitude=moment_tensor.moment_to_magnitude(self.moment),
            strike=self.strike,
            dip=self.dip,
            rake=self.rake)

        source.regularize()

        m = EventMarker(source.pyrocko_event())
        self.add_marker(m)

        targets = []

        mt = moment_tensor.MomentTensor(
            strike=source.strike,
            dip=source.dip,
            rake=source.rake,
            moment=self.moment)

        traces = []
        for station in stations:
            xyz = (self.north_km*km, self.east_km*km, self.depth_km*km)
            r = num.sqrt(xyz[0]**2 + xyz[1]**2 + xyz[2]**2)
            ns = math.ceil(r/self.vs/1.6)*2
            outx = num.zeros(int(ns))
            outy = num.zeros(int(ns))
            outz = num.zeros(int(ns))
            nsl = station.nsl()
            quantity = self.quantity.split()[0].lower()
            add_seismogram(
                self.vp*km, self.vs*km, self.density, self.qp, self.qs, xyz, f,
                mt.m6(), quantity, deltat, 0., outx, outy, outz,
                stf=stf, want_near=self.want_near,
                want_intermediate=self.want_intermediate,
                want_far=self.want_far)

            for channel, out in zip('NEZ', [outx, outy, outz]):
                tr = trace.Trace('', station.station, '', channel, deltat=deltat,
                                 tmin=source.time, ydata=out)
                traces.append(tr)
        self.add_traces(traces)
예제 #9
0
def _make_traces_homogeneous(
        dsource, receiver, material, deltat, net, sta, loc):

    comps = ['displacement.n', 'displacement.e', 'displacement.d']
    npad = 120

    dists = dsource.distances_to(receiver)

    dists = dsource.distances_to(receiver)
    azis, _ = dsource.azibazis_to(receiver)

    norths = dists * num.cos(azis*d2r)
    easts = dists * num.sin(azis*d2r)

    ddepths = receiver.depth - dsource.depths

    d3ds = num.sqrt(norths**2 + easts**2 + ddepths**2)
    times = dsource.times
    toff = math.floor(num.min(times) / deltat) * deltat

    tmin = num.min(
        (num.floor(times + d3ds / material.vp / deltat) - npad) * deltat)
    tmax = num.max(
        (num.ceil(times + d3ds / material.vs / deltat) + npad) * deltat)

    ns = int(round((tmax - tmin) / deltat))

    outx = num.zeros(ns)
    outy = num.zeros(ns)
    outz = num.zeros(ns)

    traces = []
    for ielement in range(dsource.nelements):
        x = (norths[ielement], easts[ielement], ddepths[ielement])

        if isinstance(dsource, gf.DiscretizedMTSource):
            m6 = dsource.m6s[ielement, :]
            f = (0., 0., 0.)
        elif isinstance(dsource, gf.DiscretizedSFSource):
            m6 = (0., 0., 0., 0., 0., 0.)
            f = dsource.forces[ielement, :]
        elif isinstance(dsource, gf.DiscretizedExplosionSource):
            m0 = dsource.m0s[ielement]
            m6 = (m0, m0, m0, 0., 0., 0.)
            f = (0., 0., 0.)
        else:
            assert False

        ahfullgreen.add_seismogram(
            material.vp, material.vs, material.rho, material.qp, material.qs,
            x, f, m6, 'displacement',
            deltat, tmin - (times[ielement] - toff), outx, outy, outz,
            stf=ahfullgreen.Impulse())

    for comp, o in zip(comps, (outx, outy, outz)):
        tr = trace.Trace(
            net, sta, loc, comp,
            tmin=tmin + toff, ydata=o, deltat=deltat)

        traces.append(tr)

    return traces