def test_evalresp(self, plot=False): resp_fpath = common.test_data_file('test2.resp') freqs = num.logspace(num.log10(0.001), num.log10(10.), num=1000) transfer = evalresp.evalresp( sta_list='BSEG', cha_list='BHZ', net_code='GR', locid='', instant=util.str_to_time('2012-01-01 00:00:00'), freqs=freqs, units='DIS', file=resp_fpath, rtype='CS')[0][4] pz_fpath = common.test_data_file('test2.sacpz') zeros, poles, constant = pz.read_sac_zpk(pz_fpath) resp = trace.PoleZeroResponse(zeros, poles, constant) transfer2 = resp.evaluate(freqs) if plot: plot_tfs(freqs, [transfer, transfer2]) assert numeq(transfer, transfer2, 1e-4)
def test_conversions(self): from pyrocko import model from pyrocko.fdsn import station, resp, enhanced_sacpz t = util.str_to_time('2014-01-01 00:00:00') codes = 'GE', 'EIL', '', 'BHZ' resp_fpath = common.test_data_file('test1.resp') stations = [ model.Station(*codes[:3], lat=29.669901, lon=34.951199, elevation=210.0, depth=0.0) ] sx_resp = resp.make_stationxml(stations, resp.iload_filename(resp_fpath)) pr_sx_resp = sx_resp.get_pyrocko_response(codes, time=t, fake_input_units='M/S') pr_evresp = trace.Evalresp(resp_fpath, nslc_id=codes, target='vel', time=t) sacpz_fpath = common.test_data_file('test1.sacpz') sx_sacpz = enhanced_sacpz.make_stationxml( enhanced_sacpz.iload_filename(sacpz_fpath)) pr_sx_sacpz = sx_sacpz.get_pyrocko_response(codes, time=t, fake_input_units='M/S') pr_sacpz = trace.PoleZeroResponse(*pz.read_sac_zpk(sacpz_fpath)) try: pr_sacpz.zeros.remove(0.0j) except ValueError: pr_sacpz.poles.append(0.0j) sxml_geofon_fpath = common.test_data_file('test1.stationxml') sx_geofon = station.load_xml(filename=sxml_geofon_fpath) pr_sx_geofon = sx_geofon.get_pyrocko_response(codes, time=t, fake_input_units='M/S') sxml_iris_fpath = common.test_data_file('test2.stationxml') sx_iris = station.load_xml(filename=sxml_iris_fpath) pr_sx_iris = sx_iris.get_pyrocko_response(codes, time=t, fake_input_units='M/S') freqs = num.logspace(num.log10(0.001), num.log10(1.0), num=1000) tf_ref = pr_evresp.evaluate(freqs) for pr in [ pr_sx_resp, pr_sx_sacpz, pr_sacpz, pr_sx_geofon, pr_sx_iris ]: tf = pr.evaluate(freqs) # plot_tfs(freqs, [tf_ref, tf]) assert cnumeqrel(tf_ref, tf, 0.01)
def test_ahfull_kiwi(self): setup = load(filename=common.test_data_file( 'test_ahfull_kiwi_setup.yaml')) trs_ref = io.load(common.test_data_file( 'test_ahfull_kiwi_traces.mseed')) for i, s in enumerate(setup.setups): d3d = math.sqrt(s.x[0]**2 + s.x[1]**2 + s.x[2]**2) tlen = d3d / s.vs * 2 n = int(num.round(tlen / s.deltat)) out_x = num.zeros(n) out_y = num.zeros(n) out_z = num.zeros(n) ahfullgreen.add_seismogram( s.vp, s.vs, s.density, 1000000.0, 1000000.0, s.x, s.f, s.m6, 'displacement', s.deltat, 0., out_x, out_y, out_z, ahfullgreen.Gauss(s.tau)) trs = [] for out, comp in zip([out_x, out_y, out_z], 'NED'): tr = trace.Trace( '', 'S%03i' % i, 'P', comp, deltat=s.deltat, tmin=0.0, ydata=out) trs.append(tr) trs2 = [] for cha in 'NED': t1 = g(trs, 'S%03i' % i, cha) t2 = g(trs_ref, 'S%03i' % i, cha) tmin = max(t1.tmin, t2.tmin) tmax = min(t1.tmax, t2.tmax) t1 = t1.chop(tmin, tmax, inplace=False) t2 = t2.chop(tmin, tmax, inplace=False) trs2.append(t2) d = 2.0 * num.sum((t1.ydata - t2.ydata)**2) / \ (num.sum(t1.ydata**2) + num.sum(t2.ydata**2)) if d >= 0.02: print d # trace.snuffle([t1, t2]) assert d < 0.02
def test_conversions(self): from pyrocko import model from pyrocko.fdsn import station, resp, enhanced_sacpz t = util.str_to_time('2014-01-01 00:00:00') codes = 'GE', 'EIL', '', 'BHZ' resp_fpath = common.test_data_file('test1.resp') stations = [model.Station( *codes[:3], lat=29.669901, lon=34.951199, elevation=210.0, depth=0.0)] sx_resp = resp.make_stationxml( stations, resp.iload_filename(resp_fpath)) pr_sx_resp = sx_resp.get_pyrocko_response( codes, time=t, fake_input_units='M/S') pr_evresp = trace.Evalresp( resp_fpath, nslc_id=codes, target='vel', time=t) sacpz_fpath = common.test_data_file('test1.sacpz') sx_sacpz = enhanced_sacpz.make_stationxml( enhanced_sacpz.iload_filename(sacpz_fpath)) pr_sx_sacpz = sx_sacpz.get_pyrocko_response( codes, time=t, fake_input_units='M/S') pr_sacpz = trace.PoleZeroResponse(*pz.read_sac_zpk(sacpz_fpath)) try: pr_sacpz.zeros.remove(0.0j) except ValueError: pr_sacpz.poles.append(0.0j) sxml_geofon_fpath = common.test_data_file('test1.stationxml') sx_geofon = station.load_xml(filename=sxml_geofon_fpath) pr_sx_geofon = sx_geofon.get_pyrocko_response( codes, time=t, fake_input_units='M/S') sxml_iris_fpath = common.test_data_file('test2.stationxml') sx_iris = station.load_xml(filename=sxml_iris_fpath) pr_sx_iris = sx_iris.get_pyrocko_response( codes, time=t, fake_input_units='M/S') freqs = num.logspace(num.log10(0.001), num.log10(1.0), num=1000) tf_ref = pr_evresp.evaluate(freqs) for pr in [pr_sx_resp, pr_sx_sacpz, pr_sacpz, pr_sx_geofon, pr_sx_iris]: tf = pr.evaluate(freqs) # plot_tfs(freqs, [tf_ref, tf]) assert cnumeqrel(tf_ref, tf, 0.01)
def test_interpolate_or_not(self): fpath = common.test_data_file('test2.cube') trs = {} for imode in ('off', 'sinc'): trs[imode] = list(datacube.iload(fpath, interpolation=imode)) for tr in trs[imode]: tr.set_codes(location='i=%s' % imode) import pylab as lab for cha in ['p0', 'p1', 'p2']: t1 = [tr for tr in trs['off'] if tr.channel == cha][0] t2 = [tr for tr in trs['sinc'] if tr.channel == cha][0] it = 0 nt = min(t1.ydata.size, t2.ydata.size) dd = [] nb = int(600. / t1.deltat) while it < nt: y1 = t1.ydata[it:it+nb] y2 = t2.ydata[it:it+nb] dd.append( abs(num.mean(y1) - num.mean(y2))) assert dd[-1] < 1.0 it += nb t = num.arange(len(dd))*600. d = num.array(dd)
def test_read_samples(self): ok = False for fn in ['geeil.iris.xml', 'geeil.geofon.xml']: fpath = common.test_data_file(fn) x = fdsn_station.load_xml(filename=fpath) for network in x.network_list: assert network.code == 'GE' for station in network.station_list: assert station.code == 'EIL' for channel in station.channel_list: assert channel.code[:2] == 'BH' for stage in channel.response.stage_list: ok = True assert ok pstations = x.get_pyrocko_stations() assert len(pstations) in (3, 4) for s in x.get_pyrocko_stations(): assert len(s.get_channels()) == 3 assert len( x.get_pyrocko_stations(time=stt('2010-01-15 10:00:00'))) == 1 new = fdsn_station.FDSNStationXML.from_pyrocko_stations(pstations) assert len(new.get_pyrocko_stations()) in (3, 4) for s in new.get_pyrocko_stations(): assert len(s.get_channels()) == 3
def test_interpolate_or_not(self): fpath = common.test_data_file('test2.cube') trs = {} for imode in ('off', 'sinc'): trs[imode] = list(datacube.iload(fpath, interpolation=imode)) for tr in trs[imode]: tr.set_codes(location='i=%s' % imode) import pylab as lab for cha in ['p0', 'p1', 'p2']: t1 = [tr for tr in trs['off'] if tr.channel == cha][0] t2 = [tr for tr in trs['sinc'] if tr.channel == cha][0] it = 0 nt = min(t1.ydata.size, t2.ydata.size) dd = [] nb = int(600. / t1.deltat) while it < nt: y1 = t1.ydata[it:it + nb] y2 = t2.ydata[it:it + nb] dd.append(abs(num.mean(y1) - num.mean(y2))) assert dd[-1] < 1.0 it += nb t = num.arange(len(dd)) * 600. d = num.array(dd)
def testReadSEGY(self): fpath = common.test_data_file('test2.segy') i = 0 for tr in io.load(fpath, format='segy'): assert tr.meta['orfield_num'] == 1111 i += 1 assert i == 24
def test_read(self): fpath = common.test_data_file('test.quakeml') qml = quakeml.QuakeML.load_xml(filename=fpath) events = qml.get_pyrocko_events() assert len(events) == 1 e = events[0] assert e.lon == -116.9945 assert e.lat == 33.986 assert e.depth == 17300 assert e.time == util.stt("1999-04-02 17:05:10.500")
def testReadSUDS(self): fpath = common.test_data_file('test.suds') i = 0 for tr in io.load(fpath, format='detect'): i += 1 assert i == 251 stations = suds.load_stations(fpath) assert len(stations) == 91
def test_load(self): fpath = common.test_data_file('test1.cube') traces_h = io.load(fpath, getdata=False, format='detect') traces_d = io.load(fpath, getdata=True, format='detect') mimas = [(30572, 87358), (46168, 80639), (53107, 73119)] for tr_h, tr_d, (mi, ma) in zip(traces_h, traces_d, mimas): assert tr_h.tmin == tr_d.tmin assert tr_h.tmax == tr_d.tmax assert tr_d.ydata.min() == mi assert tr_d.ydata.max() == ma
def test_response_plot(self): for fn, format in [('test1.resp', 'resp'), ('test1.sacpz', 'sacpz')]: fpath_resp = common.test_data_file(fn) fname = 'test_response_plot_%s.png' % fn fpath_png = self.fpath(fname) resps, labels = response_plot.load_response_information( fpath_resp, format) labels = [lab[len(fpath_resp) + 1:] or 'dummy' for lab in labels] response_plot.plot(responses=resps, labels=labels, filename=fpath_png, dpi=50) self.compare_with_ref(fname, 0.01)
def setUpClass(cls): ''' Create a reusable snuffler instance for all tests cases. ''' super(GUITest, cls).setUpClass() cls.snuffler = Snuffler() # noqa fpath = common.test_data_file('test2.mseed') p = make_pile(fpath, show_progress=False) cls.win = SnufflerWindow(pile=p) cls.pile_viewer = cls.win.pile_viewer pv = cls.pile_viewer cls.main_control_defaults = dict( highpass_control=pv.highpass_control.get_value(), lowpass_control=pv.lowpass_control.get_value(), gain_control=pv.gain_control.get_value(), rot_control=pv.rot_control.get_value())
def test_load(self): fpath = common.test_data_file('test1.cube') traces_h = io.load(fpath, getdata=False, format='detect') traces_d = io.load(fpath, getdata=True, format='detect') mimas = [ (30572, 87358), (46168, 80639), (53107, 73119)] for tr_h, tr_d, (mi, ma) in zip(traces_h, traces_d, mimas): assert tr_h.tmin == tr_d.tmin assert tr_h.tmax == tr_d.tmax assert tr_d.ydata.min() == mi assert tr_d.ydata.max() == ma
def test_load_partial(self): fpath = common.test_data_file('test2.cube') f = open(fpath, 'r') header, da1, gps_tags, nsamples, bookmarks = datacube_ext.load( f.fileno(), 2, 0, -1, None) for ioff in (0, 10, 1040000, 1048576, 2000000, 1000000): f.seek(0) header, da2, gps_tags, nsamples, _ = datacube_ext.load( f.fileno(), 2, ioff, 10, None) f.seek(0) header, da3, gps_tags, nsamples, _ = datacube_ext.load( f.fileno(), 2, ioff, 10, bookmarks) for a1, a2, a3 in zip(da1, da2, da3): assert num.all(a1[ioff:ioff + 10] == a2) and num.all(a2 == a3) f.close()
def test_load_partial(self): fpath = common.test_data_file('test2.cube') f = open(fpath, 'r') header, da1, gps_tags, nsamples, bookmarks = datacube_ext.load( f.fileno(), 2, 0, -1, None) for ioff in (0, 10, 1040000, 1048576, 2000000, 1000000): f.seek(0) header, da2, gps_tags, nsamples, _ = datacube_ext.load( f.fileno(), 2, ioff, 10, None) f.seek(0) header, da3, gps_tags, nsamples, _ = datacube_ext.load( f.fileno(), 2, ioff, 10, bookmarks) for a1, a2, a3 in zip(da1, da2, da3): assert num.all(a1[ioff:ioff+10] == a2) and num.all(a2 == a3) f.close()
def test_read_write(self): fns = [ 'test.iris.channel.ims', 'test.iris.response.ims', 'test.iris.station.ims', 'test.iris.waveform-nodata.ims', 'test.norsar.gse2' ] fpaths = [] for fn in fns: fpath = common.test_data_file(fn) fpaths.append(fpath) for sec in ims.iload(fpaths): if isinstance(sec, ims.WID2Section): tr = sec.pyrocko_trace() s = ims.dump_string(ims.iload(fpaths)) for sec in ims.iload_string(s): if isinstance(sec, ims.WID2Section): tr = sec.pyrocko_trace()
def benchmark_load(self): mode = {0: 'get time range', 1: 'get gps only', 2: 'get samples'} fpath = common.test_data_file('test2.cube') for irep in range(2): for loadflag in (0, 1, 2): f = open(fpath, 'r') t0 = time.time() header, data_arrays, gps_tags, nsamples, bookmarks = \ datacube_ext.load(f.fileno(), loadflag, 0, -1, None) f.close() t1 = time.time() print '%s: %10.3f' % (mode[loadflag], t1 - t0) t0 = time.time() trs = io.load(fpath, format='datacube') t1 = time.time() print 'with interpolation: %10.3f' % (t1 - t0) del trs
def setUpClass(cls): ''' Create a reusable snuffler instance for all tests cases. ''' super(GUITest, cls).setUpClass() if no_gui: # nosetests runs this even when class is has @skip return cls.snuffler = Snuffler() # noqa fpath = common.test_data_file('test2.mseed') p = make_pile(fpath, show_progress=False) cls.win = SnufflerWindow(pile=p) cls.pile_viewer = cls.win.pile_viewer cls.viewer = cls.win.pile_viewer.viewer pv = cls.pile_viewer cls.main_control_defaults = dict( highpass_control=pv.highpass_control.get_value(), lowpass_control=pv.lowpass_control.get_value(), gain_control=pv.gain_control.get_value(), rot_control=pv.rot_control.get_value())
def test_read_write(self): fns = [ 'test.iris.channel.ims', 'test.iris.response.ims', 'test.iris.station.ims', 'test.iris.waveform-nodata.ims', 'test.norsar.gse2'] fpaths = [] for fn in fns: fpath = common.test_data_file(fn) fpaths.append(fpath) for sec in ims.iload(fpaths): if isinstance(sec, ims.WID2Section): tr = sec.pyrocko_trace() s = ims.dump_string(ims.iload(fpaths)) for sec in ims.iload_string(s): if isinstance(sec, ims.WID2Section): tr = sec.pyrocko_trace()
def test_read_samples(self): ok = False for fn in ["geeil.iris.xml", "geeil.geofon.xml"]: fpath = common.test_data_file(fn) x = fdsn_station.load_xml(filename=fpath) for network in x.network_list: assert network.code == "GE" for station in network.station_list: assert station.code == "EIL" for channel in station.channel_list: assert channel.code[:2] == "BH" for stage in channel.response.stage_list: ok = True assert ok assert len(x.get_pyrocko_stations()) in (3, 4) for s in x.get_pyrocko_stations(): assert len(s.get_channels()) == 3 assert len(x.get_pyrocko_stations(time=stt("2010-01-15 10:00:00"))) == 1
def benchmark_load(self): mode = { 0: 'get time range', 1: 'get gps only', 2: 'get samples'} fpath = common.test_data_file('test2.cube') for irep in range(2): for loadflag in (0, 1, 2): f = open(fpath, 'r') t0 = time.time() header, data_arrays, gps_tags, nsamples, bookmarks = \ datacube_ext.load(f.fileno(), loadflag, 0, -1, None) f.close() t1 = time.time() print '%s: %10.3f' % (mode[loadflag], t1 - t0) t0 = time.time() trs = io.load(fpath, format='datacube') t1 = time.time() print 'with interpolation: %10.3f' % (t1 - t0) del trs
def test_read_big(self): for site in ['iris']: fpath = common.test_data_file('%s_1014-01-01_all.xml' % site) fdsn.station.load_xml(filename=fpath)
def testReadSac(self): fpath = common.test_data_file('test1.sac') tr = io.load(fpath, format='sac')[0] assert tr.meta['cmpaz'] == 0.0 assert tr.meta['cmpinc'] == 0.0
def testMSeedDetect(self): fpath = common.test_data_file('test2.mseed') io.load(fpath, format='detect')
def fpath_ref(self, fn): try: return common.test_data_file(fn) except util.DownloadError: return common.test_data_file_no_download(fn)
def test_read_big(self): for site in ['iris']: fpath = common.test_data_file('%s_1014-01-01_all.xml' % site) fdsn_station.load_xml(filename=fpath)