示例#1
0
 def test_missing_waveform_id(self):
     from obspy import read
     from eqcorrscan.core.template_gen import from_meta_file
     import os
     testing_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                 'test_data')
     quakeml = os.path.join(testing_path,
                            '20130901T041115_missingwavid.xml')
     st = read(os.path.join(testing_path, 'WAV', 'TEST_',
                            '2013-09-01-0410-35.DFDPC_024_00'))
     templates = from_meta_file(meta_file=quakeml, st=st, lowcut=2.0,
                                highcut=9.0, samp_rate=20.0, filt_order=3,
                                length=2, prepick=0.1, swin='S')
     self.assertEqual(len(templates), 1)
示例#2
0
        if std.count() < 3: # want 3 or more waveforms for templates
            print('skipping event not enough good waveforms')
            
        else:         
            std.sort(['starttime'])
            std.merge(fill_value="interpolate")
            st1=std.copy()
            
            start = UTCDateTime(year = yr, julday = days)
            end = start + 86400
            st_filter=st1.trim(starttime=start, endtime=end)
        
#            print('GENERATING TEMPLATE FOR ' + str(start) +   ' SAVING AS MINISEED FILES & PLOTS ARE SAVED TO FOLDER.')
            # template matching
            template = template_gen.from_meta_file(meta_file = new_catalog, st = st_filter,
                                                   lowcut = 3, highcut = 10, filt_order = 4, samp_rate = 25,
                                                   prepick = 0.15, length = 4.6, swin = 'P',
                                                   parallel = True)
            
            if len(template[0]) < 3:
                print('Skipping template -- %i picks & %i WF in template' % (n_picks[i], len(template[0])))
                
            else:
    #            stats = trace.Stats()
                template[0].sort(['starttime'])
                timestamp = template[0][0].stats.starttime
                end_template = template[0][0].stats.endtime
                
                # make plots
                stplot = std.copy()
                stplot = stplot.trim(starttime = timestamp - 5, 
                                     endtime= end_template + 5)
示例#3
0
 def test_all_phase_methods(self):
     sfile = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          'test_data', 'REA', 'TEST_',
                          '01-0411-15L.S201309')
     catalog = read_events(sfile)
     p_stations = list(
         set([
             pick.waveform_id.station_code for pick in catalog[0].picks
             if pick.phase_hint == 'P'
         ]))
     s_stations = list(
         set([
             pick.waveform_id.station_code for pick in catalog[0].picks
             if pick.phase_hint == 'S'
         ]))
     st = read(
         os.path.join(os.path.dirname(os.path.abspath(__file__)),
                      'test_data', 'WAV', 'TEST_',
                      '2013-09-01-0410-35.DFDPC_024_00'))
     templates = from_meta_file(meta_file=sfile,
                                st=st,
                                lowcut=2,
                                highcut=20,
                                samp_rate=100,
                                filt_order=4,
                                length=6,
                                prepick=0.2,
                                swin='P_all')
     self.assertEqual(len(templates), 1)
     self.assertEqual(len(templates[0]), len(p_stations) * 3)
     for tr in templates[0]:
         pick = [
             p for p in catalog[0].picks
             if p.waveform_id.station_code == tr.stats.station
             and p.phase_hint.upper() == 'P'
         ][0]
         print(tr)
         print(pick)
         self.assertLess(abs(tr.stats.starttime - (pick.time - 0.2)),
                         tr.stats.delta)
     templates = from_meta_file(meta_file=sfile,
                                st=st,
                                lowcut=2,
                                highcut=20,
                                samp_rate=100,
                                filt_order=4,
                                length=6,
                                prepick=0.2,
                                swin='S_all')
     self.assertEqual(len(templates), 1)
     self.assertEqual(len(templates[0]), len(s_stations) * 3)
     for tr in templates[0]:
         pick = [
             p for p in catalog[0].picks
             if p.waveform_id.station_code == tr.stats.station
             and p.phase_hint.upper() == 'S'
         ][0]
         print(tr)
         print(pick)
         self.assertLess(abs(tr.stats.starttime - (pick.time - 0.2)),
                         tr.stats.delta)
示例#4
0
 def setUpClass(cls):
     cls.testing_path = os.path.join(
         os.path.abspath(os.path.dirname(__file__)), 'test_data', 'REA',
         'TEST_')
     cls.wave_path = os.path.join(
         os.path.abspath(os.path.dirname(__file__)), 'test_data', 'WAV',
         'TEST_')
     key_dict = [{
         'name': 'template',
         'sfile': '21-1412-02L.S201309'
     }, {
         'name': 'detection',
         'sfile': '21-1759-04L.S201309'
     }, {
         'name': 'template_spicks',
         'sfile': '18-2120-53L.S201309'
     }, {
         'name': 'detection_spicks',
         'sfile': '18-2350-08L.S201309'
     }]
     for item in key_dict:
         st = read(
             os.path.join(
                 cls.wave_path,
                 readwavename(os.path.join(cls.testing_path,
                                           item['sfile']))[0]))
         for tr in st:
             tr.stats.channel = tr.stats.channel[0] + tr.stats.channel[-1]
         item.update({
             'st': st,
             'sfile': os.path.join(cls.testing_path, item['sfile'])
         })
         setattr(
             cls, item['name'],
             from_meta_file(meta_file=item['sfile'],
                            lowcut=5,
                            highcut=15,
                            samp_rate=40,
                            filt_order=4,
                            length=3,
                            swin='all',
                            prepick=0.05,
                            st=item['st'])[0])
     detection_event = read_events(
         os.path.join(cls.testing_path, '21-1759-04L.S201309'))[0]
     detection_spicks_event = read_events(
         os.path.join(cls.testing_path, '18-2350-07L.S201309'))[0]
     cls.detections = [
         Detection(detect_time=detection_event.origins[0].time,
                   detect_val=2.0,
                   no_chans=5,
                   threshold=1.9,
                   typeofdet='corr',
                   event=detection_event,
                   template_name='test_template',
                   threshold_type='MAD',
                   threshold_input=8.0),
         Detection(detect_time=detection_spicks_event.origins[0].time,
                   detect_val=2.0,
                   no_chans=5,
                   threshold=1.9,
                   typeofdet='corr',
                   event=detection_spicks_event,
                   template_name='test_template',
                   threshold_type='MAD',
                   threshold_input=8.0)
     ]
     tstart = min(tr.stats.starttime for tr in cls.template)
     cls.delays = {}
     for tr in cls.template:
         cls.delays.update({
             tr.stats.station + '.' + tr.stats.channel:
             tr.stats.starttime - tstart
         })
     warnings.simplefilter("always")