コード例 #1
0
def sta_lta_div (trace, nsta, nlta):
    from obspy import Trace
    import numpy as np

    station = trace.stats.station
    npts = trace.stats.npts
    srt = trace.stats.sampling_rate

    S1 = nlta
    L1 = L2 = S2 = 0
    stlt = np.zeros(npts)
    max = trace.data.argmax()

    while S2 < max:
        S2 = S1 + nsta
        L2 = (S1 + S2) // 2
        L1 = L2 - nlta
        norm1 = np.mean (trace.data[S1:S2] ** 2) ** 2
        norm2 = np.mean (trace.data[L1:L2] ** 2) ** 2
        StaLta = np.round(norm1 / norm2, 3)
        stlt[S1:S2] = StaLta
        S1 += nsta

    data = Trace (data=stlt, header=trace.stats)
    data.taper (max_percentage = 0.1)    
    max = data.data.argmax()
    return max
コード例 #2
0
def _taper_stream(tr: obspy.Trace, taper_buffer: float) -> obspy.Trace:
    """Taper the stream, return new stream"""
    start = tr.stats.starttime
    end = tr.stats.endtime
    dur = end - start
    buffer = taper_buffer
    tr.taper(type="hann", max_percentage=0.05, max_length=dur * buffer)
    return tr
コード例 #3
0
 def test_taper(self):
     """
     Test taper method of trace
     """
     data = np.ones(10)
     tr = Trace(data=data)
     tr.taper()
     for i in range(len(data)):
         self.assertTrue(tr.data[i] <= 1.)
         self.assertTrue(tr.data[i] >= 0.)
コード例 #4
0
ファイル: test_trace.py プロジェクト: CSchwarz1234/obspy
 def test_taper(self):
     """
     Test taper method of trace
     """
     data = np.ones(10)
     tr = Trace(data=data)
     tr.taper()
     for i in range(len(data)):
         self.assertTrue(tr.data[i] <= 1.)
         self.assertTrue(tr.data[i] >= 0.)
コード例 #5
0
        f_in.seek( ns * nbytes_station + nc * nbytes_trace + nbytes_stationname  +\
         8 + ntimesteps * size_of_float + 12 )

        #for nt in range(ntimesteps):
        #    values[nt] = np.fromfile(f_in,dtype=dtype_output,count=1)
        values = np.fromfile(f_in, dtype=dtype_output, count=ntimesteps)

        tr = Trace(data=values)

        # Filter and downsample
        # Since the same filter will be applied to all synthetics consistently, non-zero-phase should be okay
        # ToDo: Think about whether zerophase would be better

        # taper first
        #ToDo: Discuss with Andreas whether this tapering makes sense!
        tr.taper(type='cosine', max_percentage=0.001)
        tr.data = sosfilt(sos, tr.data)
        tr.stats.sampling_rate = fs_old
        tr.interpolate(fs_new)

        # Differentiate
        if output_quantity == 'VEL' or output_quantity == 'ACC':
            tr.differentiate()
            if output_quantity == 'ACC':
                tr.differentiate()

        # Remove the extra time that specfem added
        tr.trim(starttime=tr.stats.starttime + offset_seconds)

        # Set data type
        tr.data = tr.data.astype(dtype_output)
コード例 #6
0
 def __tapper(data, max_percentage=0.05):
     tr = Trace(data)
     tr.taper(max_percentage=max_percentage, type='blackman')
     return tr.data
コード例 #7
0
ファイル: parse_specfem_output.py プロジェクト: lermert/noisi
  8 + ntimesteps * size_of_float + 12 )
 
 #for nt in range(ntimesteps):
 #    values[nt] = np.fromfile(f_in,dtype=dtype_output,count=1)
 values = np.fromfile(f_in,dtype=dtype_output,count=ntimesteps)
 
 tr = Trace(data=values)
 
 
 # Filter and downsample
 # Since the same filter will be applied to all synthetics consistently, non-zero-phase should be okay
 # ToDo: Think about whether zerophase would be better
 
 # taper first
 #ToDo: Discuss with Andreas whether this tapering makes sense!
 tr.taper(type='cosine',max_percentage=0.001)
 tr.data = sosfilt(sos,tr.data)
 tr.stats.sampling_rate = fs_old
 tr.interpolate(fs_new)
 
 # Differentiate
 if output_quantity == 'VEL' or output_quantity == 'ACC':
     tr.differentiate()
     if output_quantity == 'ACC':
         tr.differentiate()
 
 
 # Remove the extra time that specfem added
 tr.trim(starttime = tr.stats.starttime+offset_seconds)
 
 # Set data type