def __init__(self): # Template cut self.win_len = 45 # cut window length self.t_blank = 15 # time before P in the cut window self.min_sta = 4 # min sta num for a template events self.chn_dict = {'ZSY':['HHE','HHN','HHZ'], 'YN': ['HHE','HHN','HHZ'], 'XLS':['HHE','HHN','HHZ']} self.get_data_dict = dps.Data(None).get_data_dict # MFT params self.temp_win_trig = [1., 9.] # win fr trig temp cut, rel p self.temp_win_p = [0.5,1.5] # win for p temp cut, rel p self.temp_win_s = [0, 2.] # win for s temp cut, rel s self.trig_thres = 0.25 # cc thres for det & mask self.mask_len = 1. # win len for cc mask self.det_gap = 5. # gap sec for detection self.ppk_win_p = [1., 1.] # win for p pick self.ppk_win_s = [2., 2.] # win for s pick # data process self.resp_dict = {'ZSY': 3.02e8, 'YN': 1.67785e9, 'XLS': 1/1.6e-9} # instrumental gain (cnt/m/s) self.samp_rate = 50 self.freq_band = ['bandpass', [1., 40.]] self.picker = pickers.Trad_PS(self.samp_rate) self.num_workers = 5
def __init__(self): # 1. picker params pick_win = [10., 1.] # pick win for STA/LTA trig_thres = 15. # threshold to trig picker (by energy) pick_thres = 0.96 # threshold for picking p_win = [1., 1.] # win len for P picking s_win = [0, 15.] # win len for S picking pca_win = 1. # win len for PCA filter pca_rng = [0, 2.5] # time range to apply PCA filter fd_thres = 2.5 # min value of dominant frequency amp_win = 5. # time win to get S amplitude det_gap = 5. # time gap between detections freq_band = ['highpass', 1] # frequency band for ppk # 2. assoc params ot_dev = 3. # time deviation for ot assoc ttp_dev = 2. # time deviation for ttp assoc assoc_num = 4 # num of stations to assoc # 3. loc params side_width = 0.2 # ratio of sides relative to sta range xy_grid = 0.02 # lateral grid width, in degree # sta info sta_file = '/data2/ZSY_SAC/header/station_ZSY.dat' resp_dict = { 'ZSY': 3.02e8, 'YN': 1.67785e9, 'XLS': 1 / 1.6e-9, } # instrumental gain (cnt/m/s) # 4. define func dp = dps.Data(resp_dict) self.get_data_dict = dp.get_data_dict self.get_picks = dp.get_picks self.read_data = dp.read_data sta_dict = dp.get_sta_dict(sta_file) self.picker = pickers.Trad_PS(\ trig_thres = trig_thres, s_win = s_win) self.associator = associators.TS_Assoc(\ sta_dict, assoc_num = assoc_num, ot_dev = ot_dev, ttp_dev = ttp_dev)
def __init__(self): # 1. picker params self.pick_win = [10., 1.] # pick win for STA/LTA self.trig_thres = 15. # threshold to trig picker (by energy) self.pick_thres = 0.96 # threshold for picking self.p_win = [1., 1.] # win len for P picking self.s_win = [0, 15.] # win len for S picking self.pca_win = 1. # # win len for PCA filter self.pca_rng = [0, 2.5] # time range to apply PCA filter self.fd_thres = 2.5 # min value of dominant frequency self.amp_win = 5. # time win to get S amplitude self.det_gap = 5. # time gap between detections self.freq_band = ['highpass', 1] # frequency band for ppk # 2. assoc params self.ot_dev = 3. # time deviation for ot assoc self.ttp_dev = 2. # time deviation for ttp assoc self.assoc_num = 4 # num of stations to assoc # 3. loc params self.side_width = 0.2 # ratio of sides relative to sta range self.xy_grid = 0.02 # lateral grid width, in degree self.resp_dict = { 'ZSY': 3.02e8, 'YN': 1.67785e9, 'XLS': 1 / 1.6e-9, 'G70': 1 / 1.6e-9, 'G4Z': 1 / 1.6e-9, 'G4V': 1 / 1.6e-9, 'REF': 1 / 1.6e-9 } # instrumental response (cnt/m/s) # 4. define func self.get_data = dp.get_data sta_dict = dp.get_sta('/data3/XLS_SAC/header/station_XLS.dat') self.picker = pickers.Trad_PS(\ trig_thres = self.trig_thres, s_win = self.s_win) self.associator = associators.TS_Assoc(\ sta_dict, self.resp_dict, assoc_num = self.assoc_num, ot_dev = self.ot_dev, ttp_dev = self.ttp_dev)
parser.add_argument('--out_pha', type=str, default='./output/zsy/aug_zsy.pha') args = parser.parse_args() # MFT params cfg = config.Config() decim_rate = cfg.decim_rate freq_band = cfg.freq_band samp_rate = 100. / decim_rate win_trig = cfg.win_trig win_p = cfg.win_p win_s = cfg.win_s trig_thres = cfg.trig_thres mask_len = int(samp_rate * cfg.mask_len) picker = pickers.Trad_PS() # i/o file out_ctlg = open(args.out_ctlg, 'w') out_pha = open(args.out_pha, 'w') temp_dict = get_temp_dict(args.temp_pha, args.temp_root) # get time range start_date = UTCDateTime(args.time_range.split(',')[0]) end_date = UTCDateTime(args.time_range.split(',')[1]) print('Run MFT (gpu version)') print('time range: {} to {}'.format(start_date, end_date)) # for all days num_day = (end_date.date - start_date.date).days for day_idx in range(num_day):
def main(args): # i/o file if os.path.exists(args.out_ctlg): os.unlink(args.out_ctlg) os.unlink(args.out_pha) out_ctlg = open(args.out_ctlg, 'a') out_pha = open(args.out_pha, 'a') sta_dict = data_pipeline.get_sta_dict(args.sta_file) cfg = config.Config() # define algorithm picker = pickers.Trad_PS(trig_thres=cfg.trig_thres) associator = associators.Simple_Assoc(assoc_num=cfg.assoc_num, ot_dev=cfg.ot_dev) locator = locators.Simple_Loc(sta_dict, cfg.resp_dict) # get time range start_date = UTCDateTime(args.time_range.split(',')[0]) end_date = UTCDateTime(args.time_range.split(',')[1]) print('Making catalog') print('time range: {} to {}'.format(start_date, end_date)) # for all days num_day = (end_date.date - start_date.date).days for day_idx in range(num_day): # get data paths datetime = start_date + day_idx * 86400 data_dict = data_pipeline.get_xj(args.data_dir, datetime) if data_dict == {}: continue # 1. waveform --> phase picks # pick all sta for i, sta in enumerate(data_dict): # read data if len(data_dict[sta]) < 3: continue stream = read(data_dict[sta][0]) stream += read(data_dict[sta][1]) stream += read(data_dict[sta][2]) # phase picking picksi = picker.pick(stream) if i == 0: picks = picksi else: picks = np.append(picks, picksi) # 2. associate: picks --> events event_picks = associator.pick2event(picks) # write pahse file associator.write(event_picks, out_pha) # 3. locate evnets for event_pick in event_picks: event_loc = locator.locate(event_pick) # 4. estimate magnitude event_loc_mag = locator.calc_mag(event_pick, event_loc) # write catalog locator.write(event_loc_mag, out_ctlg) # finish making catalog out_pha.close() out_ctlg.close()
def main(args): # i/o files data_dir = args.data_dir org_ctlg = args.org_ctlg f = open(org_ctlg) events = f.readlines() f.close() out_root = args.out_root temp_root = os.path.join(out_root, args.temp_root) if not os.path.exists(temp_root): os.makedirs(temp_root) ctlg_path = os.path.join(out_root, args.out_ctlg) pha_path = os.path.join(out_root, args.out_pha) out_ctlg = open(ctlg_path, 'w') out_pha = open(pha_path, 'w') # make sta dir sta_file = args.sta_file sta_dict = dp.get_sta_dict(sta_file) # params cfg = config.Config() max_dist = cfg.max_dist # km win_len = cfg.win_len # sec min_sta = cfg.min_sta # min number of sta t_blank = cfg.t_blank # sec before tp (cut win) dt_p = cfg.dt_s dt_s = cfg.dt_s p_thres = cfg.p_thres s_thres = cfg.s_thres fd_thres = cfg.fd_thres picker = pickers.Trad_PS(trig_thres=p_thres, fd_thres=fd_thres) # for all events event_picks = [] for i, event in enumerate(events): # event info ot, lat, lon, dep, mag = event.split(',') event_dir = os.path.join(temp_root, ot) if not os.path.exists(event_dir): os.mkdir(event_dir) ot = UTCDateTime(ot) lat = float(lat) lon = float(lon) dep = float(dep) data_dict = dp.get_xj(data_dir, ot) event_picks.append([event, event_dir, []]) print('-' * 40) print('checking {}th event'.format(i)) for sta in data_dict: # select all stations sta_line = sta_dict[sta_dict['station'] == sta] sta_lat = float(sta_line['latitude']) sta_lon = float(sta_line['longitude']) sta_ele = float(sta_line['elevation']) dist0 = 111 * np.sqrt((sta_lat - lat)**2 + (sta_lon - lon)**2) if dist0 > max_dist: continue # theoretical arrival time dist1 = np.sqrt(dist0**2 + (dep + 2.5)**2) ttp, tts = calc_tt(dist1) # travel time tp0 = ot + ttp # arrival time ts0 = ot + tts b = tp0 - UTCDateTime(ot.date) - t_blank # cut event out_paths = [] for data in data_dict[sta]: data = os.path.split(data)[-1] net, chn = data.split('.')[0], data.split('.')[-2] out_paths.append( os.path.join(event_dir, '%s.%s.%s' % (net, sta, chn))) if len(data_dict[sta]) != 3: continue sac.cut(data_dict[sta][0], b, b + win_len, out_paths[0]) sac.cut(data_dict[sta][1], b, b + win_len, out_paths[1]) sac.cut(data_dict[sta][2], b, b + win_len, out_paths[2]) # read event data st = read(out_paths[0]) st += read(out_paths[1]) st += read(out_paths[2]) # run picker picks = picker.pick(st) if len(picks) == 0: for fname in out_paths: os.unlink(fname) continue tp = picks['p_arr'][0] ts = picks['s_arr'][-1] p_snr = picks['p_snr'][0] s_snr = picks['s_snr'][-1] # write head t0 = tp - tp0 + t_blank t1 = ts - tp0 + t_blank sac.ch_event(out_paths[0], lon, lat, dep, 1, [t0, t1]) sac.ch_event(out_paths[1], lon, lat, dep, 1, [t0, t1]) sac.ch_event(out_paths[2], lon, lat, dep, 1, [t0, t1]) # select if s_snr>s_thres\ and abs(tp-tp0)<dt_p\ and abs(ts-ts0)<dt_s: event_picks[-1][-1].append('{},{},{},{:.1f},{:.1f}\n'\ .format(sta, tp, ts, p_snr, s_snr)) else: for fname in out_paths: os.unlink(fname) # select all event picks for event_pick in event_picks: print('select {}'.format(event_pick[0][:-1])) event = event_pick[0] event_dir = event_pick[1] picks = event_pick[2] if len(picks) < min_sta: if os.path.exists(event_dir): shutil.rmtree(event_dir) continue out_ctlg.write(event) out_pha.write(event) for pick in picks: out_pha.write(pick) out_ctlg.close() out_pha.close()