Пример #1
0
def test_SKS():
    import matplotlib
    matplotlib.use('Agg')
    import numpy as np
    from obspy.core import Stream
    from obspy.signal.rotate import rotate_ne_rt
    from telewavesim import utils as ut
    from telewavesim import wiggle as wg

    modfile = resource_filename('telewavesim',
                                'examples/models/model_SKS.txt')
    wvtype = 'SV'
    npts = 3000  # Number of samples
    dt = 0.05  # Sample distance in seconds
    slow = 0.04  # Horizontal slowness (or ray parameter) in s/km
    baz = np.arange(0., 360., 10.)
    model = ut.read_model(modfile)
    t1 = ut.calc_ttime(model, slow, wvtype=wvtype)
    assert round(t1, 1) == 21.6
    trR = Stream()
    trT = Stream()
    # Loop over range of data
    for bb in baz:
        # Calculate the plane wave seismograms
        trxyz = ut.run_plane(model, slow, npts, dt, bb, wvtype=wvtype)
        # Extract East, North and Vertical
        ntr = trxyz[0]
        etr = trxyz[1]
        ztr = trxyz[2]
        # Copy to radial and transverse
        rtr = ntr.copy()
        ttr = etr.copy()
        # Rotate to radial and transverse
        rtr.data, ttr.data = rotate_ne_rt(ntr.data, etr.data, bb)
        # Append to streams
        trR.append(rtr)
        trT.append(ttr)

    # Set frequency corners in Hz
    f1 = 0.01
    f2 = 0.2
    # Filter to get wave-like traces
    trR.filter('bandpass', freqmin=f1, freqmax=f2, corners=2, zerophase=True)
    trT.filter('bandpass', freqmin=f1, freqmax=f2, corners=2, zerophase=True)
    # Plot as wiggles
    with tempfile.TemporaryDirectory() as tempdir:
        wg.pw_wiggles_baz(trR, trT, 'test', btyp='baz', scale=0.05,
                          t1=t1, tmin=0., tmax=40, save=True,
                          ftitle=join(tempdir, 'sks'),
                          wvtype='SV')
Пример #2
0
 def _synthone(self, src_lat, src_lon, dt, npts, time_init):
     """
     Synthesize single event
     """
     event_id_base = 'hiperseis:PRM/evid='
     stats = self.compute_event_stats(src_lat, src_lon, event_id_base)
     stats.pop('tt_model')
     ray_param_sec_per_km = stats['slowness'] / KM_PER_DEG
     traces_zne = run_plane(self.model,
                            ray_param_sec_per_km,
                            npts,
                            dt,
                            baz=stats['back_azimuth'])
     # Taper beginning to deal with spectral artefacts
     traces_zne.taper(0.05, side='left')
     # Synthetics here have been observed to have high noise at Nyquist freq. Filter it out.
     kernel = sig.firwin(9, 0.5)
     for tr in traces_zne:
         tr.data = sig.filtfilt(kernel, 1, tr.data)
     # end for
     # Extract time location of max Z amplitude and use as the onset time marker.
     tr_z = traces_zne.select(component='Z')[0]
     onset_marker = tr_z.times()[(tr_z.data == np.max(tr_z.data))][0]
     times_rel_mantle = tr_z.times()[0] - onset_marker
     for tr in traces_zne:
         stats['channel'] = '**' + tr.stats['channel'][-1]
         tr.stats.update(stats)
         if time_init < times_rel_mantle:
             n_leading = int((times_rel_mantle - time_init) / dt)
             data_new = np.append(np.zeros(n_leading),
                                  tr.data[:(npts - n_leading)])
             assert data_new.shape == tr.data.shape
             tr.data = data_new
         elif time_init > times_rel_mantle:
             n_trailing = int((time_init - times_rel_mantle) / dt)
             data_new = np.append(tr.data[(npts - n_trailing):],
                                  np.zeros(n_trailing))
             assert data_new.shape == tr.data.shape
             tr.data = data_new
         # end if
     # end for
     traces_zne.differentiate()
     return traces_zne
Пример #3
0
def test_Porter2011():
    import matplotlib
    matplotlib.use('Agg')
    import numpy as np
    from obspy.core import Stream
    from telewavesim import utils as ut
    from telewavesim import wiggle as wg

    modfile = resource_filename('telewavesim',
                                'examples/models/model_Porter2011.txt')
    wvtype = 'P'
    npts = 3000  # Number of samples
    dt = 0.01  # Sample distance in seconds
    slow = 0.06  # Horizontal slowness (or ray parameter) in s/km
    baz = np.arange(0., 360., 10.)
    model = ut.read_model(modfile)
    trR = Stream()
    trT = Stream()
    # Loop over range of data
    for bb in baz:
        # Calculate the plane waves seismograms
        trxyz = ut.run_plane(model, slow, npts, dt, bb, wvtype=wvtype,
                             obs=False)
        # Then the transfer functions in Z-R-T coordinate system
        tfs = ut.tf_from_xyz(trxyz, pvh=False)
        # Append to streams
        trR.append(tfs[0])
        trT.append(tfs[1])
    # Set frequency corners in Hz
    f1 = 0.01
    f2 = 1.0
    # Filter to get wave-like traces
    trR.filter('bandpass', freqmin=f1, freqmax=f2, corners=2, zerophase=True)
    trT.filter('bandpass', freqmin=f1, freqmax=f2, corners=2, zerophase=True)
    # Stack over all traces
    trR_stack, trT_stack = ut.stack_all(trR, trT, pws=True)
    # Plot as wiggles
    with tempfile.TemporaryDirectory() as tempdir:
        wg.rf_wiggles_baz(trR, trT, trR_stack, trT_stack, 'test', btyp='baz',
                          scale=1.e3, tmin=-5., tmax=8., save=True,
                          ftitle=join(tempdir, 'porter2011.png'),
                          wvtype='P')
Пример #4
0
def test_Audet2016():
    import matplotlib
    matplotlib.use('Agg')
    from obspy.core import Stream
    from obspy.signal.rotate import rotate_ne_rt
    from telewavesim import utils as ut
    from telewavesim import wiggle as wg
    modfile = resource_filename('telewavesim',
                                'examples/models/model_Audet2016.txt')
    wvtype = 'P'
    npts = 3000  # Number of samples
    dt = 0.01  # Sample distance in seconds
    dp = 2000.  # Deployment depth below sea level in meters
    c = 1.500    # P-wave velocity in salt water (km/s)
    rhof = 1027.  # Density of salt water (kg/m^3)
    slow = 0.06  # Horizontal slowness (or ray parameter) in s/km
    # Back-azimuth direction in degrees
    # (has no influence if model is isotropic)
    baz = 0.
    model = ut.read_model(modfile)
    assert list(model.rho) == [2800.0, 2800.0, 3200.0]
    t1 = ut.calc_ttime(model, slow, wvtype=wvtype)
    assert round(t1, 1) == 1.1
    trxyz = ut.run_plane(model, slow, npts, dt, baz=baz, wvtype=wvtype,
                         obs=True, dp=dp, c=c, rhof=rhof)
    tfs = ut.tf_from_xyz(trxyz, pvh=False)
    ntr = trxyz[0]  # North component
    etr = trxyz[1]  # East component
    ztr = trxyz[2]  # Vertical component
    rtr = ntr.copy()  # Radial component
    ttr = etr.copy()  # Transverse component
    rtr.data, ttr.data = rotate_ne_rt(ntr.data, etr.data, baz)
    strf = Stream(traces=[tfs[0], ztr, rtr])
    # Set frequency corners in Hz
    f1 = 0.1
    f2 = 1.0
    # Plot as wiggles
    with tempfile.TemporaryDirectory() as tempdir:
        wg.pw_wiggles_Audet2016(strf, t1=t1, tmax=10., f1=f1, f2=f2,
                                ftitle=join(tempdir, 'audet2016'),
                                scale=2.e-7, save=True)
Пример #5
0
    def _residuals(self):
        """ 
        Internal method to obtain residuals between observed and predicted
        receiver functions given the Moho depth and Vp/Vs obtained from
        the Hk stack.
        """
        from telewavesim import utils

        # Simple 1-layer model over half-space
        model = utils.Model([self.h0, 0.], [2800., 3300.], [self.vp, 8.0],
                            [self.vp / self.k0, 4.5], ['iso', 'iso'])

        # Parameters for run
        slow = [tr.stats.slow for tr in self.rfV1]
        npts = self.rfV1[0].stats.npts
        dt = self.rfV1[0].stats.delta

        trR = Stream()

        for sl in slow:
            trxyz = utils.run_plane(model, sl, npts, dt)
            tfs = utils.tf_from_xyz(trxyz,
                                    pvh=True,
                                    vp=self.vp,
                                    vs=self.vp / self.k0)
            tfs[0].data = np.fft.fftshift(tfs[0].data)
            trR.append(tfs[0])

        trR.filter('bandpass',
                   freqmin=0.05,
                   freqmax=0.5,
                   corners=2,
                   zerophase=True)

        # Get stream of residuals
        res = trR.copy()
        for i in range(len(res)):
            res[i].data = self.rfV1[i].data - trR[i].data
        return res