def get_LBz(day): from obspy.clients.earthworm import Client from obspy import UTCDateTime from obspy import Stream year1 = 2014 month1 = 11 day1 = 24 hour1 = 0 minute1 = 0 second1 = 0 num = 6 #%% LB01 try: sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.112.23', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 + day * 24 * 60 * 60 t2 = t1 + 23 * 60 * 60 + 59 * 60 + 59.999 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st1 = Stream() st1 = client.get_waveforms(net, sta, '', cha, t1, t2) # st is a stream, we can operate normally as in obspy st1.detrend(type='linear') st1.detrend(type='demean') break_test = st1 break_test = break_test[0].filter("bandpass", freqmin=1, freqmax=10) sorted_data = st1.copy() sorted_data = abs(sorted_data[0].data) sorted_data.sort() mid_dat = sorted_data[int(len(sorted_data) / 2)] if sum(abs(st1[0].data) ) < 10 or st1[0].stats.npts < 7920000 or mid_dat < 0.1: sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime( year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st1 = Stream() st1 = client.get_waveforms(net, sta, '', cha, t1, t2) st1.detrend(type='linear') st1.detrend(type='demean') st1[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 except: # give 2 seconds of data instead sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st1 = Stream() st1 = client.get_waveforms(net, sta, '', cha, t1, t2) st1.detrend(type='linear') st1.detrend(type='demean') st1[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 #%% LB02 try: sta = 'LB02' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.112.23', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 + day * 24 * 60 * 60 t2 = t1 + 23 * 60 * 60 + 59 * 60 + 59.999 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st2 = Stream() st2 = client.get_waveforms(net, sta, '', cha, t1, t2) # st is a stream, we can operate normally as in obspy st2.detrend(type='linear') st2.detrend(type='demean') break_test = st2 break_test = break_test[0].filter("bandpass", freqmin=1, freqmax=10) sorted_data = st2.copy() sorted_data = abs(sorted_data[0].data) sorted_data.sort() mid_dat = sorted_data[int(len(sorted_data) / 2)] if sum(abs(st2[0].data) ) < 10 or st2[0].stats.npts < 7920000 or mid_dat < 0.1: sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime( year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st2 = Stream() st2 = client.get_waveforms(net, sta, '', cha, t1, t2) st2.detrend(type='linear') st2.detrend(type='demean') st2[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 except: # give 2 seconds of data instead sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st2 = Stream() st2 = client.get_waveforms(net, sta, '', cha, t1, t2) st2.detrend(type='linear') st2.detrend(type='demean') st2[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 #%% LB03 try: sta = 'LB03' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.112.23', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 + day * 24 * 60 * 60 t2 = t1 + 23 * 60 * 60 + 59 * 60 + 59.999 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st3 = Stream() st3 = client.get_waveforms(net, sta, '', cha, t1, t2) # st is a stream, we can operate normally as in obspy st3.detrend(type='linear') st3.detrend(type='demean') break_test = st3 break_test = break_test[0].filter("bandpass", freqmin=1, freqmax=10) sorted_data = st3.copy() sorted_data = abs(sorted_data[0].data) sorted_data.sort() mid_dat = sorted_data[int(len(sorted_data) / 2)] if sum(abs(st3[0].data) ) < 10 or st3[0].stats.npts < 7920000 or mid_dat < 0.1: sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime( year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st3 = Stream() st3 = client.get_waveforms(net, sta, '', cha, t1, t2) st3.detrend(type='linear') st3.detrend(type='demean') st3[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 except: # give 2 seconds of data instead sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st3 = Stream() st3 = client.get_waveforms(net, sta, '', cha, t1, t2) st3.detrend(type='linear') st3.detrend(type='demean') st3[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 #%% LB04 try: sta = 'LB04' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.112.23', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 + day * 24 * 60 * 60 t2 = t1 + 23 * 60 * 60 + 59 * 60 + 59.999 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st4 = Stream() st4 = client.get_waveforms(net, sta, '', cha, t1, t2) # st is a stream, we can operate normally as in obspy st4.detrend(type='linear') st4.detrend(type='demean') break_test = st4 break_test = break_test[0].filter("bandpass", freqmin=1, freqmax=10) sorted_data = st4.copy() sorted_data = abs(sorted_data[0].data) sorted_data.sort() mid_dat = sorted_data[int(len(sorted_data) / 2)] if sum(abs(st4[0].data) ) < 10 or st4[0].stats.npts < 7920000 or mid_dat < 0.1: sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime( year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st4 = Stream() st4 = client.get_waveforms(net, sta, '', cha, t1, t2) st4.detrend(type='linear') st4.detrend(type='demean') st4[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 except: # give 2 seconds of data instead sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st4 = Stream() st4 = client.get_waveforms(net, sta, '', cha, t1, t2) st4.detrend(type='linear') st4.detrend(type='demean') st4[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 #%% LB05 try: sta = 'LB05' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.112.23', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 + day * 24 * 60 * 60 t2 = t1 + 23 * 60 * 60 + 59 * 60 + 59.999 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st5 = Stream() st5 = client.get_waveforms(net, sta, '', cha, t1, t2) # st is a stream, we can operate normally as in obspy st5.detrend(type='linear') st5.detrend(type='demean') break_test = st5 break_test = break_test[0].filter("bandpass", freqmin=1, freqmax=10) sorted_data = st5.copy() sorted_data = abs(sorted_data[0].data) sorted_data.sort() mid_dat = sorted_data[int(len(sorted_data) / 2)] if sum(abs(st5[0].data) ) < 10 or st5[0].stats.npts < 7920000 or mid_dat < 0.1: sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime( year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st5 = Stream() st5 = client.get_waveforms(net, sta, '', cha, t1, t2) st5.detrend(type='linear') st5.detrend(type='demean') st5[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 except: # give 2 seconds of data instead sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st5 = Stream() st5 = client.get_waveforms(net, sta, '', cha, t1, t2) st5.detrend(type='linear') st5.detrend(type='demean') st5[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 #%% LB06 try: sta = 'LB06' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.112.23', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 + day * 24 * 60 * 60 t2 = t1 + 23 * 60 * 60 + 59 * 60 + 59.999 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st6 = Stream() st6 = client.get_waveforms(net, sta, '', cha, t1, t2) # st is a stream, we can operate normally as in obspy st6.detrend(type='linear') st6.detrend(type='demean') break_test = st6 break_test = break_test[0].filter("bandpass", freqmin=1, freqmax=10) sorted_data = st6.copy() sorted_data = abs(sorted_data[0].data) sorted_data.sort() mid_dat = sorted_data[int(len(sorted_data) / 2)] if sum(abs(st6[0].data) ) < 10 or st6[0].stats.npts < 7920000 or mid_dat < 0.1: sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime( year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st6 = Stream() st6 = client.get_waveforms(net, sta, '', cha, t1, t2) st6.detrend(type='linear') st6.detrend(type='demean') st6[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 except: # give 2 seconds of blank data instead sta = 'LB01' # STATION LB01 cha = 'HHZ' # CHANNEL - Vertical net = 'Z4' # Santiaguito volcano loc = '' # location, it depends mostly of which network you are in. client = Client( '138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month t1 = t0 t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. st6 = Stream() st6 = client.get_waveforms(net, sta, '', cha, t1, t2) st6.detrend(type='linear') st6.detrend(type='demean') st6[0].filter("bandpass", freqmin=0.1, freqmax=0.1) num = num - 1 #%% LB07 # try: # # # STATION, CHANNEL (DDF --> 400 Hz), NETWWORK AND LOCATION CODES # sta = 'LB07' # STATION LB01 # cha = 'HHZ' # CHANNEL - Vertical # net = 'Z4' # Santiaguito volcano # loc = '' # location, it depends mostly of which network you are in. # # client = Client('138.253.112.23', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 # t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month # t1 = t0 + day*24*60*60 # t2 = t1 + 23*60*60 + 59*60 +59.999 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. # st7 = Stream() # st7 = client.get_waveforms(net, sta, '', cha, t1 , t2) # # # st is a stream, we can operate normally as in obspy # st7.detrend(type='linear') # st7.detrend(type='demean') # break_test=st7 # break_test = break_test[0].filter("bandpass", freqmin=1,freqmax=10) # # except: # give 2 seconds of blank data instead # # # STATION, CHANNEL (DDF --> 400 Hz), NETWWORK AND LOCATION CODES # sta = 'LB01' # STATION LB01 # cha = 'HHZ' # CHANNEL - Vertical # net = 'Z4' # Santiaguito volcano # loc = '' # location, it depends mostly of which network you are in. # # client = Client('138.253.113.19', 16022) # ip, port - ip's 138.253.113.19 or 138.253.112.23 # t0 = UTCDateTime(year1, month1, day1, hour1, minute1, second1) #the format is year:day_of_the_year:month # t1 = t0 # t2 = t1 + 2 #UTCDateTime(year2, month2, day2, hour2, minute2, second2) # notice we have here 10 minutes, but we can select our times. # st7 = Stream() # st7 = client.get_waveforms(net, sta, '', cha, t1 , t2) # # st7.detrend(type='linear') # st7.detrend(type='demean') # st7[0].filter("bandpass", freqmin=0.1,freqmax=0.1) # num = num -1 #%% return all stations return (st1, st2, st3, st4, st5, st6, num) #st7
def grab_data(scnl, T1, T2, fill_value=0): # scnl = list of station names (eg. ['PS4A.EHZ.AV.--','PVV.EHZ.AV.--','PS1A.EHZ.AV.--']) # T1 and T2 are start/end obspy UTCDateTimes # fill_value can be 0 (default), 'latest', or 'interpolate' # # returns stream of traces with gaps accounted for # # print('{} - {}'.format(T1.strftime('%Y.%m.%d %H:%M:%S'),T2.strftime('%Y.%m.%d %H:%M:%S'))) print('Grabbing data...') st = Stream() for sta in scnl: if sta.split('.')[2] == 'MI': client = Client(config.winston_address_cnmi, config.winston_port_cnmi) else: client = Client(config.winston_address, config.winston_port) try: tr = client.get_waveforms(sta.split('.')[2], sta.split('.')[0], sta.split('.')[3], sta.split('.')[1], T1, T2, cleanup=True) if len(tr) > 1: if fill_value == 0 or fill_value == None: tr.detrend('demean') tr.taper(max_percentage=0.01) for sub_trace in tr: # deal with error when sub-traces have different dtypes if sub_trace.data.dtype.name != 'int32': sub_trace.data = sub_trace.data.astype('int32') if sub_trace.data.dtype != np.dtype('int32'): sub_trace.data = sub_trace.data.astype('int32') # deal with rare error when sub-traces have different sample rates if sub_trace.stats.sampling_rate != np.round( sub_trace.stats.sampling_rate): sub_trace.stats.sampling_rate = np.round( sub_trace.stats.sampling_rate) print('Merging gappy data...') tr.merge(fill_value=fill_value) except: tr = Stream() # if no data, create a blank trace for that channel if not tr: from obspy import Trace from numpy import zeros tr = Trace() tr.stats['station'] = sta.split('.')[0] tr.stats['channel'] = sta.split('.')[1] tr.stats['network'] = sta.split('.')[2] tr.stats['location'] = sta.split('.')[3] tr.stats['sampling_rate'] = 100 tr.stats['starttime'] = T1 tr.data = zeros(int((T2 - T1) * tr.stats['sampling_rate']), dtype='int32') st += tr st.trim(T1, T2, pad=0) print('Detrending data...') st.detrend('demean') return st