def test_raw_input_client(): """edge_test.RawInputClient_test.test_raw_input_client()""" network = "NT" station = "BOU" channel = "MVH" location = "R0" data = [0, 1, 2, 3, 4, 5] starttime = UTCDateTime("2019-12-01") trace = Trace( numpy.array(data, dtype=numpy.float64), Stats({ "channel": channel, "delta": 60.0, "location": location, "network": network, "npts": len(data), "starttime": starttime, "station": station, }), ) client = MockRawInputClient( tag="tag", host="host", port="port", station=station, channel=channel, location=location, network=network, ) trace_send = EdgeFactory()._convert_trace_to_int(trace.copy()) client.send_trace("minute", trace_send) # verify data was sent assert_equal(len(client.last_send), 1)
def test_slice_noStarttimeOrEndtime(self): """ Tests the slicing of trace objects with no starttime or endtime provided. Compares results against the equivalent trim() operation """ tr_orig = Trace(data=np.arange(10, dtype='int32')) tr = tr_orig.copy() # two time points outside the trace and two inside t1 = tr.stats.starttime - 2 t2 = tr.stats.starttime + 2 t3 = tr.stats.endtime - 3 t4 = tr.stats.endtime + 2 # test 1: only removing data at left side tr_trim = tr_orig.copy() tr_trim.trim(starttime=t2) self.assertEqual(tr_trim, tr.slice(starttime=t2)) self.assertEqual(tr_trim, tr.slice(starttime=t2, endtime=t4)) # test 2: only removing data at right side tr_trim = tr_orig.copy() tr_trim.trim(endtime=t3) self.assertEqual(tr_trim, tr.slice(endtime=t3)) self.assertEqual(tr_trim, tr.slice(starttime=t1, endtime=t3)) # test 3: not removing data at all tr_trim = tr_orig.copy() tr_trim.trim(starttime=t1, endtime=t4) self.assertEqual(tr_trim, tr.slice()) self.assertEqual(tr_trim, tr.slice(starttime=t1)) self.assertEqual(tr_trim, tr.slice(endtime=t4)) self.assertEqual(tr_trim, tr.slice(starttime=t1, endtime=t4)) tr_trim.trim() self.assertEqual(tr_trim, tr.slice()) self.assertEqual(tr_trim, tr.slice(starttime=t1)) self.assertEqual(tr_trim, tr.slice(endtime=t4)) self.assertEqual(tr_trim, tr.slice(starttime=t1, endtime=t4)) # test 4: removing data at left and right side tr_trim = tr_orig.copy() tr_trim.trim(starttime=t2, endtime=t3) self.assertEqual(tr_trim, tr.slice(t2, t3)) self.assertEqual(tr_trim, tr.slice(starttime=t2, endtime=t3)) # test 5: no data left after operation tr_trim = tr_orig.copy() tr_trim.trim(starttime=t4) self.assertEqual(tr_trim, tr.slice(starttime=t4)) self.assertEqual(tr_trim, tr.slice(starttime=t4, endtime=t4 + 1))
import numpy as np from obspy.core import Trace, UTCDateTime x = np.zeros(200) x[100] = 1 tr = Trace(x) tr.stats.network = "XX" tr.stats.station = "SDFD1" print tr print "showing original trace" tr.plot() tr.stats.sampling_rate = 20 tr.stats.starttime = UTCDateTime(2011, 2, 21, 8) print tr tr.plot() tr.filter("lowpass", freq=1) print "showing filtered trace" tr.plot() tr.trim(tr.stats.starttime + 4.5, tr.stats.endtime - 2) print "showing trimmed trace" tr.plot() tr.data = tr.data * 500 tr2 = tr.copy() tr2.data = tr2.data + np.random.randn(len(tr2)) tr2.stats.station = "SDFD2" print tr2 print "showing trace with gaussian noise added" tr2.plot()
#Processing each channel to prevent memory error reguarding matplotilb for x in ['X', 'Y', 'Z']: statsx = { 'network': 'TW', 'station': 'RASPI', 'location': '00', 'channel': 'BH' + x, 'npts': length, 'sampling_rate': sampling_rate, 'mseed': { 'dataquality': 'D' }, 'starttime': starttime } Xt = Trace(data=data[x], header=statsx) Xt_filt = Xt.copy() Xt_filt.filter('lowpass', freq=20.0, corners=2, zerophase=True) stream = Stream(traces=[Xt_filt]) stream.plot(type='dayplot', outfile='dayplotFilter' + x + '.png', size=size, events=events) stream = Stream(traces=[Xt]) stream.plot(type='dayplot', outfile='dayplot' + x + '.png', size=size, events=events) #Remove all the download and generated files os.system('rm -rf /root/earthquaketemp') os.system(