Пример #1
0
 def test_rfstats(self):
     stats = rfstats(station=self.station, event=self.event, pp_depth=100.)
     for head in _HEADERS:
         if head not in _HEADERS_NOT_BY_RFSTATS:
             self.assertIn(head, stats)
     # event is exactly north from station and around 66.7 degrees away
     self.assertTrue(abs(stats.distance - 66.7) < 1.)
     self.assertTrue(abs(stats.back_azimuth % 360.) < 0.1)
     self.assertTrue(abs(stats.slowness - 6.4) < 0.1)
     # test issue 7
     event = self.event.copy()
     event.preferred_origin_id = None
     event.origins = []
     with self.assertRaisesRegex(ValueError, 'No origin'):
         stats = rfstats(station=self.station, event=event, pp_depth=100.)
     event = self.event.copy()
     event.preferred_magnitude_id = None
     event.magnitudes = []
     with self.assertRaisesRegex(ValueError, 'No magnitude'):
         stats = rfstats(station=self.station, event=event, pp_depth=100.)
     event = self.event.copy()
     del event.origins[0].latitude
     with self.assertRaisesRegex(ValueError, 'No origin'):
         stats = rfstats(station=self.station, event=event, pp_depth=100.)
     event = self.event.copy()
     del event.origins[0].depth
     with self.assertRaisesRegex(ValueError, 'No origin'):
         stats = rfstats(station=self.station, event=event, pp_depth=100.)
def get_eq_waveforms(station_list, sta_inv, eq_cat, filt_kws=None, **kwargs):
    """
    
    :param station_list: list of stations to retrieve data from
    :param sta_inv: obspy network inventory object containing station information
    :param eq_cat: obspy inventory object containing earthquake catalog
    
    """
    ev_cnt = 0
    for stat in station_list:
        op_stat = get_station_info(stat, sta_inv, xml=True)
        stat_dict = get_station_info(stat, sta_inv)    
        for i, event in enumerate(eq_cat):        
            cat_id = event.resource_id
            test_id = str(cat_id).split("=")[1].split("&")[0]
            print("\nSearching for event {0} at station {1}".format(test_id, stat))
            waveforms = read_passive(op_stat, event, filt_kws=filt_kws, **kwargs)
            if waveforms != None:
                if len(waveforms) == 3:
                    #print(len(waveforms))
                    if ev_cnt == 0:
                        #op_stream = waveforms
                        eq_stream = rf.RFStream(waveforms)
                        #print kwargs
                        if 'phase_list' in kwargs:
                            phase = kwargs['phase_list'][0]
                        else:
                            phase = 'P'
                            
                        stats = rf.rfstats(station=stat_dict, event=event, phase=phase, dist_range=(30,90))
                        for tr in eq_stream:
                            tr.stats.update(stats)
                    else:
                        #op_stream += waveforms
                        temp_stream = rf.RFStream(waveforms)
                        stats = rf.rfstats(station=stat_dict, event=event, phase=phase, dist_range=(30,90))                        
                        #print(stats)
                        #print(stat_dict, event)
                        if stats == None:
                            print("No rfstats calculated... skipping event")
                            continue
                        else:
                            for tr in temp_stream:
                                tr.stats.update(stats)
                            eq_stream.extend(temp_stream)
                    ev_cnt += 1
                else:
                    print("Imported stream does not have 3 traces ({0})... skipping event".format(len(waveforms)))
    
    if ev_cnt != 0:
        return eq_stream
    else:
        print("No earthquake waveforms found...")
        return None
Пример #3
0
 def test_polarity_R_component(self):
     """issue #4"""
     stream = read_rf()
     rfstats(stream)
     stream.filter('bandpass', freqmin=0.5, freqmax=2)
     stream.trim2(10, 110, reftime='starttime')
     stream.rf(rotate='NE->RT')
     for tr in stream.select(component='R'):
         onset = tr.stats.onset - tr.stats.starttime
         dt = tr.stats.delta
         self.assertAlmostEqual(tr.data.argmax() * dt - onset, 0,
                                delta=0.01)
Пример #4
0
 def test_polarity_R_component(self):
     """issue #4"""
     stream = read_rf()
     rfstats(stream)
     stream.filter('bandpass', freqmin=0.5, freqmax=2)
     stream.trim2(10, 110, reftime='starttime')
     stream.rf(rotate='NE->RT')
     for tr in stream.select(component='R'):
         onset = tr.stats.onset - tr.stats.starttime
         dt = tr.stats.delta
         self.assertAlmostEqual(tr.data.argmax() * dt - onset, 0,
                                delta=0.01)
Пример #5
0
 def test_rfstats(self):
     stats = rfstats(station=self.station, event=self.event)
     for head in HEADERS:
         self.assertIn(head, stats)
     # event is exactly north from station and around 66.7 degrees away
     self.assertTrue(abs(stats.distance - 66.7) < 1.)
     self.assertTrue(abs(stats.back_azimuth % 360.) < 0.1)
     self.assertTrue(abs(stats.slowness - 6.4) < 0.1)
Пример #6
0
 def test_rfstats(self):
     stats = rfstats(station=self.station, event=self.event, pp_depth=100.)
     for head in HEADERS:
         self.assertIn(head, stats)
     # event is exactly north from station and around 66.7 degrees away
     self.assertTrue(abs(stats.distance - 66.7) < 1.)
     self.assertTrue(abs(stats.back_azimuth % 360.) < 0.1)
     self.assertTrue(abs(stats.slowness - 6.4) < 0.1)