def continuous_signal(time, low, high, dt): """ Continuous source-signal """ sig = (np.random.rand(time.size) * 2 - 1) tr = Trace() tr.data = sig tr.stats.delta = dt tr.stats.starttime = 0 tr.filter('bandpass', freqmin=low, freqmax=high, corners=4) tr.normalize() return tr
def arrayProcessing(self, prewhiten, method): np.random.seed(2348) geometry = np.array([[0.0, 0.0, 0.0], [-5.0, 7.0, 0.0], [5.0, 7.0, 0.0], [10.0, 0.0, 0.0], [5.0, -7.0, 0.0], [-5.0, -7.0, 0.0], [-10.0, 0.0, 0.0]]) geometry /= 100 # in km slowness = 1.3 # in s/km baz_degree = 20.0 # 0.0 > source in x direction baz = baz_degree * np.pi / 180. df = 100 # samplerate # SNR = 100. # signal to noise ratio amp = .00001 # amplitude of coherent wave length = 500 # signal length in samples coherent_wave = amp * np.random.randn(length) # time offsets in samples dt = df * slowness * (np.cos(baz) * geometry[:, 1] + np.sin(baz) * geometry[:, 0]) dt = np.round(dt) dt = dt.astype('int32') max_dt = np.max(dt) + 1 min_dt = np.min(dt) - 1 trl = list() for i in xrange(len(geometry)): tr = Trace(coherent_wave[-min_dt + dt[i]:-max_dt + dt[i]].copy()) # + amp / SNR * \ # np.random.randn(length - abs(min_dt) - abs(max_dt))) tr.stats.sampling_rate = df tr.stats.coordinates = AttribDict() tr.stats.coordinates.x = geometry[i, 0] tr.stats.coordinates.y = geometry[i, 1] tr.stats.coordinates.elevation = geometry[i, 2] # lowpass random signal to f_nyquist / 2 tr.filter("lowpass", freq=df / 4.) trl.append(tr) st = Stream(trl) stime = UTCDateTime(1970, 1, 1, 0, 0) etime = UTCDateTime(1970, 1, 1, 0, 0) + \ (length - abs(min_dt) - abs(max_dt)) / df win_len = 2. step_frac = 0.2 sll_x = -3.0 slm_x = 3.0 sll_y = -3.0 slm_y = 3.0 sl_s = 0.1 frqlow = 1.0 frqhigh = 8.0 semb_thres = -1e99 vel_thres = -1e99 args = (st, win_len, step_frac, sll_x, slm_x, sll_y, slm_y, sl_s, semb_thres, vel_thres, frqlow, frqhigh, stime, etime) kwargs = dict(prewhiten=prewhiten, coordsys='xy', verbose=False, method=method) out = array_processing(*args, **kwargs) if 0: # 1 for debugging print '\n', out[:, 1:] return out
def array_processing(self, prewhiten, method): np.random.seed(2348) geometry = np.array([[0.0, 0.0, 0.0], [-5.0, 7.0, 0.0], [5.0, 7.0, 0.0], [10.0, 0.0, 0.0], [5.0, -7.0, 0.0], [-5.0, -7.0, 0.0], [-10.0, 0.0, 0.0]]) geometry /= 100 # in km slowness = 1.3 # in s/km baz_degree = 20.0 # 0.0 > source in x direction baz = baz_degree * np.pi / 180. df = 100 # samplerate # SNR = 100. # signal to noise ratio amp = .00001 # amplitude of coherent wave length = 500 # signal length in samples coherent_wave = amp * np.random.randn(length) # time offsets in samples dt = df * slowness * (np.cos(baz) * geometry[:, 1] + np.sin(baz) * geometry[:, 0]) dt = np.round(dt) dt = dt.astype(np.int32) max_dt = np.max(dt) + 1 min_dt = np.min(dt) - 1 trl = list() for i in range(len(geometry)): tr = Trace(coherent_wave[-min_dt + dt[i]:-max_dt + dt[i]].copy()) # + amp / SNR * \ # np.random.randn(length - abs(min_dt) - abs(max_dt))) tr.stats.sampling_rate = df tr.stats.coordinates = AttribDict() tr.stats.coordinates.x = geometry[i, 0] tr.stats.coordinates.y = geometry[i, 1] tr.stats.coordinates.elevation = geometry[i, 2] # lowpass random signal to f_nyquist / 2 tr.filter("lowpass", freq=df / 4.) trl.append(tr) st = Stream(trl) stime = UTCDateTime(1970, 1, 1, 0, 0) etime = UTCDateTime(1970, 1, 1, 0, 0) + 4.0 # TODO: check why this does not work any more # (length - abs(min_dt) - abs(max_dt)) / df win_len = 2. step_frac = 0.2 sll_x = -3.0 slm_x = 3.0 sll_y = -3.0 slm_y = 3.0 sl_s = 0.1 frqlow = 1.0 frqhigh = 8.0 semb_thres = -1e99 vel_thres = -1e99 args = (st, win_len, step_frac, sll_x, slm_x, sll_y, slm_y, sl_s, semb_thres, vel_thres, frqlow, frqhigh, stime, etime) kwargs = dict(prewhiten=prewhiten, coordsys='xy', verbose=False, method=method) out = array_processing(*args, **kwargs) if False: # 1 for debugging print('\n', out[:, 1:]) return out
tr = Trace(data=x) tr.stats.station = "ABC" tr.stats.sampling_rate = 20.0 tr.stats.starttime = UTCDateTime(2014, 2, 24, 15, 0, 0) print(tr) tr.plot() # - # - Use **`tr.filter(...)`** and apply a lowpass filter with a corner frequency of 1 Hertz. # - Display the preview plot, there are a few seconds of zeros that we can cut off. # + {"tags": ["exercise"]} # + {"tags": ["solution"]} tr.filter("lowpass", freq=1) tr.plot() # - # - Use **`tr.trim(...)`** to remove some of the zeros at start and at the end # - show the preview plot again # + {"tags": ["exercise"]} # + {"tags": ["solution"]} tr.trim(tr.stats.starttime + 3, tr.stats.endtime - 5) tr.plot() # - # - Scale up the amplitudes of the trace by a factor of 500
if os.path.exists(finpc1) and os.path.getsize(finpc1) > 0: try: st = read(finpc1, starttime=t1, endtime=t2) if len(st) != 0: st.merge(method=1, fill_value=0) tc = st[0] stat = tc.stats.station chan = tc.stats.channel tc.detrend("constant") # 24h continuous trace starts 00 h 00 m 00.0s trim_fill(tc, t1, t2) tc.filter( "bandpass", freqmin=bandpass[0], freqmax=bandpass[1], zerophase=True, ) # store detrended and filtered continuous data # in a Stream stream_df += Stream(traces=[tc]) except IOError: pass if len(stream_df) >= nch_min: ntl = len(stt) amaxat = np.empty(ntl) # for each template event # md=np.empty(ntl)