def test_download_various_methods(self): """ Will download data from server and store in various databases, then create templates using the various methods. """ client = Client('GEONET') # get the events catalog = Catalog() data_stream = client._download( 'http://quakeml.geonet.org.nz/quakeml/1.2/2016p008194') data_stream.seek(0, 0) catalog += read_events(data_stream, format="quakeml") data_stream.close() # Select 3 channels to use and download sta_chans = [(pick.waveform_id.station_code, pick.waveform_id.channel_code) for pick in catalog[0].picks[0:3]] t1 = UTCDateTime(catalog[0].origins[0].time.date) t2 = t1 + 86400 bulk = [('NZ', sta_chan[0], '*', sta_chan[1], t1, t2) for sta_chan in sta_chans] continuous_st = client.get_waveforms_bulk(bulk) continuous_st.merge(fill_value=0) # Test multi_template_gen templates = multi_template_gen(catalog, continuous_st, length=3) self.assertEqual(len(templates), 1) # Test without an event templates = multi_template_gen(Catalog(), continuous_st, length=3) self.assertEqual(len(templates), 0)
def test_download_various_methods(self): """ Will download data from server and store in various databases, then create templates using the various methods. """ client = Client('GEONET') # get the events catalog = Catalog() data_stream = client._download( 'http://quakeml.geonet.org.nz/quakeml/1.2/2016p008194') data_stream.seek(0, 0) catalog += read_events(data_stream, format="quakeml") data_stream.close() # Select 3 channels to use and download sta_chans = [(pick.waveform_id.station_code, pick.waveform_id.channel_code) for pick in catalog[0].picks[0:3]] t1 = UTCDateTime(catalog[0].origins[0].time.date) t2 = t1 + 86400 bulk = [('NZ', sta_chan[0], '*', sta_chan[1], t1, t2) for sta_chan in sta_chans] continuous_st = client.get_waveforms_bulk(bulk) continuous_st.merge(fill_value=0) # Test multi_template_gen templates = multi_template_gen(catalog, continuous_st, length=3) self.assertEqual(len(templates), 1) # Test without an event templates = multi_template_gen(Catalog(), continuous_st, length=3) self.assertEqual(len(templates), 0) # Test from contbase method sfile = eventtosfile(catalog[0], 'TEST', 'L', '.', 'None', overwrite=True) os.makedirs(catalog[0].origins[0].time.date.strftime('Y%Y')) os.makedirs(catalog[0].origins[0].time.date.strftime('Y%Y' + os.sep + 'R%j.01')) for tr in continuous_st: tr.write(catalog[0].origins[0].time.date.strftime('Y%Y' + os.sep + 'R%j.01') + os.sep + tr.stats.station + '.' + tr.stats.network + '.' + tr.stats.location + '.' + tr.stats.channel + tr.stats.starttime.strftime('%Y.%j'), format='MSEED') template = from_contbase(sfile, contbase_list=[('.', 'Yyyyy/Rjjj.01', 'NZ')], lowcut=1.0, highcut=5.0, samp_rate=20, filt_order=4, length=3, prepick=0.5, swin='all') self.assertTrue(isinstance(template, Stream)) shutil.rmtree(continuous_st[0].stats.starttime.strftime('Y%Y'))
# st += ynst.select(station='DOC') # st += ynst.select(station='XUW') st.simulate(paz_remove=paz, paz_simulate=paz_1hz) st.detrend() # st.filter('bandpass', freqmin=20, freqmax=30,corners=4) st = pre_processing.shortproc(st, lowcut=2, highcut=9, filt_order=18, samp_rate=100, starttime=st[0].stats.starttime, endtime=st[0].stats.endtime) st = Stream(st) templates = multi_template_gen(catalog, st, 5.19, plot=True) #t = UTCDateTime("2014-08-03T08:30:19.095000") #st = st.slice(t-10, t+36000) #st.plot() for t in templates: print(t) t.write('template.ms', format="MSEED") # for tr in t: # #print(tr.stats.network) # #print(tr.stats.station) # #print(tr.stats.channel) # if tr.stats.channel == 'BZ': # tr.stats.channel = 'BHZ'