Beispiel #1
0
 def test_fixed_lengths(self):
     for sp_samples in [10, 15, 20]:
         sim_data = seis_sim(sp=sp_samples, flength=150)
         # Find first non-zero sample - start of P-phase
         for i, sample in enumerate(sim_data):
             if sample != 0.0:
                 start_sample = i
                 break
         # Find maximum - start of S-phase
         max_sample = np.argmax(np.abs(sim_data))
         self.assertEqual((max_sample - start_sample) - 1, sp_samples)
Beispiel #2
0
 def test_seis_sim(self):
     """
     Check that phases are put in the right place
     """
     for sp_samples in [10, 15, 20, 50]:
         sim_data = seis_sim(sp=sp_samples)
         # Find first non-zero sample - start of P-phase
         for i, sample in enumerate(sim_data):
             if sample != 0.0:
                 start_sample = i
                 break
         # Find maximum - start of S-phase
         max_sample = np.argmax(np.abs(sim_data))
         self.assertEqual((max_sample - start_sample) - 1, sp_samples)
Beispiel #3
0
    def test_plot_synth_real(self):
        from eqcorrscan.utils.synth_seis import seis_sim

        synth = Stream(Trace(seis_sim(sp=100, flength=200)))
        synth[0].stats.station = 'RJOB'
        synth[0].stats.channel = 'EHZ'
        synth[0].stats.sampling_rate = 100
        synth = synth.filter('bandpass', freqmin=2, freqmax=8)
        real = self.st.select(
           station='RJOB', channel='EHZ').detrend('simple').filter(
              'bandpass', freqmin=2, freqmax=8)
        real.trim(starttime=real[0].stats.starttime + 4.9,
                  endtime=real[0].stats.starttime + 6.9)
        fig = plot_synth_real(real_template=real, synthetic=synth,
                              size=(7, 4), show=False, return_figure=True)
        return fig
Beispiel #4
0
 def test_phaseout(self):
     sp_samples = 15
     flength = 150
     sim_data = seis_sim(sp=sp_samples, flength=flength, phaseout='S')
     self.assertEqual(len(sim_data), flength)
Beispiel #5
0
def synth_from_sfile(sfile, samp_rate, length=10.0, PS_ratio=1.68):
    """
    Function to generate a synthetic template for a given s-file

    :type path: str
    :param path: Path to the sfile
    :type samp_rate: float
    :param samp_rate: Sampling rate in Hz for template
    :type length: float
    :param length: Length of templates in seconds, defaults to 10
    :type PS_ratio: float
    :param PS_ratio: S-P ratio to use if only one pick found for station,\
            defaults to 1.68

    :returns: :class: obspy.Stream
    """
    from eqcorrscan.utils import Sfile_util
    from eqcorrscan.utils import synth_seis
    from obspy import Stream, Trace, UTCDateTime
    # Get the picks and the origin time
    picks=Sfile_util.readpicks(sfile)
    ori_time=Sfile_util.readheader(sfile).time.datetime
    # We only want P and S phases
    picks=[p for p in picks if p.phase in ['P','S']]
    # We want a list of the stations that we have picks for
    stations=list(set([p.station for p in picks]))
    # Loop through the stations
    synths=Stream()
    for station in stations:
        # Find the relevant picks
        sta_picks=[p for p in picks if p.station==station]
        if len(sta_picks) == 1:
            msg='Only '+sta_picks[0].phase+' phase picked for station '+\
                station+' will use an S-P ratio of '+str(PS_ratio)
            warnings.warn(msg)
            # Calculate the pick travel time
            tt = (sta_picks[0].time.datetime-ori_time).total_seconds()
            if sta_picks[0].phase == 'P':
                SP_time=(tt*PS_ratio)-tt
                P_pick=sta_picks[0].time.datetime
                S_pick=(UTCDateTime(P_pick)+SP_time).datetime
            else:
                SP_time=tt-(tt/PS_ratio)
                P_pick=(sta_picks[0].time-SP_time).datetime
                S_pick=sta_picks[0].time.datetime
        else:
            if len([p for p in sta_picks if p.phase=='P']) > 1:
                warnings.warn('Multiple P picks found for station '+station+\
                                ', will use earliest')
                P_pick=min([p.time for p in sta_picks if p.phase=='P'])
                channel=sta_picks[0].channel
            else:
                P_pick=[p.time for p in sta_picks if p.phase=='P'][0]
                channel=sta_picks[0].channel
            if len([p for p in sta_picks if p.phase=='S']) > 1:
                warnings.warn('Multiple S picks found for station '+station+\
                                ', will use earliest')
                S_pick=min([p.time for p in sta_picks if p.phase=='S'])
            else:
                S_pick=[p.time for p in sta_picks if p.phase=='S'][0]
            if P_pick > S_pick:
                raise ValueError('P pick is after S pick')
            SP_time=(S_pick.datetime-P_pick.datetime).total_seconds()
        # Loop through the picks available
        for p in sta_picks:
            tr=Trace(synth_seis.seis_sim(int(SP_time*samp_rate),\
                        flength=length*samp_rate, phaseout=p.phase))
            tr.stats.sampling_rate=samp_rate
            tr.stats.station=station
            tr.stats.channel=p.channel
            # Sythetics start 10 samples before P
            if p.phase in ['all', 'P']:
                tr.stats.starttime=UTCDateTime(P_pick)-(10.0/samp_rate)
            else:
                tr.stats.starttime=UTCDateTime(S_pick)-(10.0/samp_rate)
            synths+=tr
    return synths