def stack(in_, out): print 'loading files for stacking...' st_sum = Stream() st1 = read(in_) print 'stack traces...' for station in ProgressBar()('PB01 PB02 PB03 PB04 PB05 PB06 PB07 PB08 PB09 PB10 PB11 PB12 PB13 PB14 PB15 HMBCX MNMCX PATCX PSGCX'.split()): #st2 = st1.select(station=station, expr='st.event.rms_ratio > 1.5 and st.sampling_rate>40 and -25<st.event.lat<-18 and -67.8<st.event.lon<-66.0') st2 = st1.select(station=station, expr='st.event.rms_ratio > 1.5 and st.sampling_rate>40') if len(st2) == 0: print 'No traces for station %s' % station continue tr = st2.simpleStack() tr.stats.label = station st_sum += tr st_sum.write(out, 'Q')
def profile(stations, expr=None): """ plots summation trace for all stations """ log.info('***** Create profile plots') util.setRootLogger(logdebugfile=data.rf_results_dir + 'a_log_profile.txt') filename = 'sum_%s_%s' % (stations, expr) file_ = data.rf_results_dir + filename try: sum_stream = read(file_ + '.QHD') except: stream = read_rf() sum_stream = Stream() for station in stations.split(): temp = stream.select(station=station, component='Q', expr=expr) sum_stream += temp.simpleStack() sum_stream.write(file_, 'Q') plot = sum_stream.plotProfile(-2, 21, scale=5) plot.fig.savefig(plotdir + filename + '.eps') plot.fig.savefig(plotdir + filename + '.png') plt.close(plot.fig)
def stack(in_, out): print 'loading files for stacking...' st_sum = Stream() st1 = read(in_) print 'stack traces...' for station in ProgressBar( )('PB01 PB02 PB03 PB04 PB05 PB06 PB07 PB08 PB09 PB10 PB11 PB12 PB13 PB14 PB15 HMBCX MNMCX PATCX PSGCX' .split()): #st2 = st1.select(station=station, expr='st.event.rms_ratio > 1.5 and st.sampling_rate>40 and -25<st.event.lat<-18 and -67.8<st.event.lon<-66.0') st2 = st1.select( station=station, expr='st.event.rms_ratio > 1.5 and st.sampling_rate>40') if len(st2) == 0: print 'No traces for station %s' % station continue tr = st2.simpleStack() tr.stats.label = station st_sum += tr st_sum.write(out, 'Q')
def cut_events(in_, out): print 'read events...' catalog = readEvents(in_, 'QUAKEML') print 'cut events...' for event in ProgressBar()(catalog): oid = get_event_id(event.origins[0].resource_id.getQuakeMLURI()) ori = event.origins[0] etime = ori.time #print 'Select', event st = Stream() for arrival in ori.arrivals: arrival.pick_id.convertIDToQuakeMLURI() pick = arrival.pick_id.getReferredObject() if not pick: print 'FAIL to get pick from arrival' continue ptime = pick.time seed_id = pick.waveform_id.getSEEDString() try: st1 = Stream(data.client.getWaveform(*(seed_id.split('.') + [ptime - 50, ptime + 250]))) except Exception as ex: print '%s for %s' % (ex, seed_id) continue st1.merge() #print 'load %s %s %.1f' % (seed_id, pick.phase_hint, ptime - etime) st1[0].stats['event'] = AttribDict( id=event.resource_id.resource_id, origin_id=oid, etime=etime, ptime=ptime, lat=ori.latitude, lon=ori.longitude, depth=ori.depth, rms=ori.quality.standard_error, mag=event.magnitudes[0].mag) st += st1 st.write(out % oid, 'Q')
def onpress(event): if not event.inaxes or event.key != "shift": return lon, lat = map(event.xdata, event.ydata, inverse=True) dlon = 0.05 dlat = 0.05 filter = "%f < latitude < %f and %f < longitude < %f" % (lat - dlat, lat + dlat, lon - dlon, lon + dlon) ev = catalog.filter2(filter) if len(ev) == 0: print "No event picked" return from sito import Stream st = Stream() print "Selcet", ev for arrival in ev[0].origins[0].arrivals: arrival.pick_id.convertIDToQuakeMLURI() pick = arrival.pick_id.getReferredObject() if not pick: print "FAIL" return time = pick.time seed_id = pick.waveform_id.getSEEDString() try: st1 = Stream(client.getWaveform(*(seed_id.split(".") + [time - 50, time + 250]))) except Exception as ex: print "%s for %s" % (ex, seed_id) continue st1.merge() print "load %s %s %.1f" % (seed_id, pick.phase_hint, time - ev[0].origins[0].time) st1[0].stats["label"] = "%s %s %.1f" % (seed_id, pick.phase_hint, time - ev[0].origins[0].time) st += st1 st.setHI("filter", "") st.filter2(2, None) # st.plot(automerge=False, method='fast', type='relative') im = st.plot_() plt.show()
def cut_events(in_, out): print 'read events...' catalog = readEvents(in_, 'QUAKEML') print 'cut events...' for event in ProgressBar()(catalog): oid = get_event_id(event.origins[0].resource_id.getQuakeMLURI()) ori = event.origins[0] etime = ori.time #print 'Select', event st = Stream() for arrival in ori.arrivals: arrival.pick_id.convertIDToQuakeMLURI() pick = arrival.pick_id.getReferredObject() if not pick: print 'FAIL to get pick from arrival' continue ptime = pick.time seed_id = pick.waveform_id.getSEEDString() try: st1 = Stream( data.client.getWaveform(*(seed_id.split('.') + [ptime - 50, ptime + 250]))) except Exception as ex: print '%s for %s' % (ex, seed_id) continue st1.merge() #print 'load %s %s %.1f' % (seed_id, pick.phase_hint, ptime - etime) st1[0].stats['event'] = AttribDict( id=event.resource_id.resource_id, origin_id=oid, etime=etime, ptime=ptime, lat=ori.latitude, lon=ori.longitude, depth=ori.depth, rms=ori.quality.standard_error, mag=event.magnitudes[0].mag) st += st1 st.write(out % oid, 'Q')
def onpress(event): if not event.inaxes or event.key != 'shift': return lon, lat = map(event.xdata, event.ydata, inverse=True) dlon = 0.05 dlat = 0.05 filter = ('%f < latitude < %f and %f < longitude < %f' % (lat - dlat, lat + dlat, lon - dlon, lon + dlon)) ev = catalog.filter2(filter) if len(ev) == 0: print 'No event picked' return from sito import Stream st = Stream() print 'Selcet', ev for arrival in ev[0].origins[0].arrivals: arrival.pick_id.convertIDToQuakeMLURI() pick = arrival.pick_id.getReferredObject() if not pick: print 'FAIL' return time = pick.time seed_id = pick.waveform_id.getSEEDString() try: st1 = Stream( client.getWaveform(*(seed_id.split('.') + [time - 50, time + 250]))) except Exception as ex: print '%s for %s' % (ex, seed_id) continue st1.merge() print 'load %s %s %.1f' % (seed_id, pick.phase_hint, time - ev[0].origins[0].time) st1[0].stats['label'] = '%s %s %.1f' % ( seed_id, pick.phase_hint, time - ev[0].origins[0].time) st += st1 st.setHI('filter', '') st.filter2(2, None) #st.plot(automerge=False, method='fast', type='relative') im = st.plot_() plt.show()