def get_waveforms(): events = get_events()[::-1] client = Client('GFZ') stream_raw = Stream() stream = RFStream() coords = inventory.get_coordinates(seedid[:-1] + 'Z') for i, event in enumerate(events): t = event.preferred_origin().time args = seedid.split('.') + [t + 4.9 * 60, t + 14.1 * 60] s = client.get_waveforms(*args) s.trim(t+5*60, t+14*60) s.decimate(int(round(s[0].stats.sampling_rate)) // 5, no_filter=True) stream_raw.extend(s) if i in (0, 2, 4): s = s.copy() stats = rfstats(station=coords, event=event, dist_range=(20, 95)) if stats is None: continue s.trim(stats.onset - 25, stats.onset + 75) stats = obj2stats(station=coords, event=event) s = RFStream(s) for tr in s: tr.stats.update(stats) stream.extend(s) stream_raw.write(wavname, 'MSEED') stream.write(wavname2, 'SAC')
#---+----------Main--------------------------------- if __name__=='__main__': # we use centre of Australia to calculate radius and gather events from 15 to 90 degrees lonlat = [133.88,-23.69] # Change parameters below data = os.path.join('DATA', '') invfile = data + '7X-inventory.xml' datafile = data + '7X-event_waveforms_for_rf.h5' start_time='2009-12-01 00:00:00' end_time ='2011-04-01 00:00:00' inventory = read_inventory(invfile) #----------------- End ---------------------- catalog =get_events(lonlat,UTC(start_time),UTC(end_time)) stream = RFStream() with tqdm() as pbar: for s in iter_event_data(catalog, inventory, custom_get_waveforms, pbar=pbar): for trace in s: stream.extend(s) stream.write(datafile, 'H5')
stream3c[1].stats['asdf'] = a2 stream3c[2].stats['asdf'] = a3 stream3c.trim2(-25, 75, 'onset') return stream3c print "Lets start the show..." data = read_rf('DATA/7X-event_waveforms_for_rf.h5', 'H5') print "Data in..." ''' # we can exclude bad stations inc_set = list(set([tr.stats.inclination for tr in data])) data_filtered = RFStream([tr for tr in data if tr.stats.inclination in inc_set and tr.stats.station not in ['MIJ2', 'MIL2']]) ''' stream = RFStream() rf_streams = Parallel(n_jobs=-1, verbose=1)(map(delayed(do_rf), IterMultipleComponents(data, 'onset', 3))) for i, rf in enumerate(rf_streams): event_id = {'event_id': 0} event_id['event_id'] = i for tr in rf: tr.stats.update(event_id) stream.extend(rf) stream.write('DATA/7X-rf_zrt', 'H5') print "No worries, mate..."
in_streamfile = 'data/7X-rf_profile_data-15deg.h5' out_streamfile = 'data/7X-rf_profile_data-15deg-out.h5' st = read_rf(in_streamfile, 'H5') stz = [tr for tr in st if tr.stats.channel.endswith('Z')] stn = [tr for tr in st if tr.stats.channel.endswith('N')] ste = [tr for tr in st if tr.stats.channel.endswith('E')] output_from_z = [] for trz, trn, tre in zip(stz, stn, ste): band, margin, upper = extract_filter_params(trz) if band and margin and upper: for tr in [trz, trn, tre]: clean_trace(tr, tr.stats.starttime, tr.stats.endtime, freqmin=band[0], freqmax=band[1]) print('Plot the cleaned trace here') else: print( 'None of filters produced an acceptable p-pick. discarding the 3 traces whose z-comp has stats: ' + str(trz.stats)) stz.remove(trz) stn.remove(trn) ste.remove(tre) st_out = stz + stn + ste st_out_rf = RFStream(st_out) st_out_rf.write(out_streamfile, 'H5')