def traveltimes(self): Logfile.red('Enter AUTOMATIC CROSSCORRELATION ') Logfile.red( '\n\n+++++++++++++++++++++++++++++++++++++++++++++++++++\n ') T = [] Wdict = {} SNR = {} for i in self.StationMeta: Logfile.red('read in %s ' % (i)) de = loc2degrees(self.Origin, i) tt = obs_TravelTimes(de, self.Origin.depth) ptime = 0 phasename = ('%sphase') % (os.path.basename(self.AF)) for j in tt: if j['phase_name'] == self.Config[phasename] or j[ 'phase_name'] == ('%sdiff') % (self.Config[phasename]): ptime = j['time'] T.append(ptime) Logfile.add('%sdiff' % (self.Config[phasename])) Logfile.add('j = ' + str(j)) if ptime == 0: Logfile.red( 'Available phases for station %s in range %f deegree' % (i, de)) # print '\033[31m'+'|'.join([str(item['phase_name']) for item in tt])+'' ??? Logfile.red('you tried phase %s' % (self.Config[phasename])) raise Exception("ILLEGAL: phase definition") tw = self.calculateTimeWindows(ptime) try: w, snr = self.readWaveformsCross(i, tw, ptime) Wdict[i.getName()] = w SNR[i.getName()] = snr except: continue Logfile.red( '\n\n+++++++++++++++++++++++++++++++++++++++++++++++++++ ') Logfile.red('Exit AUTOMATIC FILTER ') return Wdict, SNR
def calctakeoff(Station, Event, Config): de = loc2degrees(Event, Station) tt = obs_TravelTimes(de, Event.depth) cfgPhase = Config['phasename'] for k in tt: phase_name = k['phase_name'] if phase_name == cfgPhase or phase_name == ('%sdiff') % (cfgPhase): ttime = k['time'] if tt[0]['phase_name'] == Config['ttphase']: takeoff = tt[0]['take-off angle'] #for r in tt: # if r['phase_name'] is Config [phasename]: # takeoff = r['take-off angle'] return takeoff
def traveltimes(self): Logfile.red('Enter AUTOMATIC FILTER') T = [] Wdict = {} for i in self.StationMeta: de = loc2degrees(self.Origin, i) tt = obs_TravelTimes(de, self.Origin.depth) if tt[0]['phase_name'] == 'P': time = tt[0]['time'] T.append(time) tw = self.calculateTimeWindows(time) w = self.readWaveformsCross(i, tw) Wdict[i.getName()] = w Logfile.red('Exit AUTOMATIC FILTER') return Wdict
def traveltimes(MetaDict, Config, Event, Folder, evpath): Logfile.red('Enter AUTOMATIC FILTER') T = [] for i in MetaDict: delta = loc2degrees(Event, i) tt = obs_TravelTimes(delta, Event.depth) if tt[0]['phase_name'] == Config['ttphase']: time = tt[0]['time'] T.append(time) mint = min(T) maxt = max(T) tw = times.calculateTimeWindows(mint, maxt, Config, Event, switch) readWaveformsCross(i, tw, evpath, Event) #endfor Logfile.red('Exit AUTOMATIC FILTER')
def refTrigger(self, RefWaveform): name = ('%s.%s.%s.%s') % ( RefWaveform[0].stats.network, RefWaveform[0].stats.station, RefWaveform[0].stats.location, RefWaveform[0].stats.channel) i = self.searchMeta(name, self.StationMeta) de = loc2degrees(self.Origin, i) tt = obs_TravelTimes(de, self.Origin.depth) ptime = 0 phasename = ('%sphase') % (os.path.basename(self.AF)) #print phasename,self.Config[phasename] for j in tt: if j['phase_name'] == self.Config[phasename] or j[ 'phase_name'] == ('%sdiff') % (self.Config[phasename]): ptime = j['time'] if ptime == 0: print '\033[31mAvailable phases for reference station %s in range %f deegree\033[0m' % ( i, de) print '\033[31m' + '|'.join( [str(item['phase_name']) for item in tt]) + '\033[0m' print '\033[31myou tried phase %s\033[0m' % ( self.Config[phasename]) raise Exception("\033[31mILLEGAL: phase definition\033[0m") tw = self.calculateTimeWindows(ptime) stP = self.readWaveformsPicker(i, tw, self.Origin, ptime) refuntouchname = os.path.basename(self.AF) + '-refstation-raw.mseed' stP.write(os.path.join(self.EventPath, refuntouchname), format='MSEED', byteorder='>') stP.filter("bandpass", freqmin=float(self.Config['refstationfreqmin']), freqmax=float(self.Config['refstationfreqmax']), corners=int(self.Config['refstationcorners']), zerophase=bool(self.Config['refstationzph'])) stP.trim(tw['xcorrstart'], tw['xcorrend']) trP = stP[0] trP.stats.starttime = UTCDateTime(3600) refname = os.path.basename(self.AF) + '-refstation-filtered.mseed' trP.write(os.path.join(self.EventPath, refname), format='MSEED', byteorder='>') sta = float(self.Config['refsta']) lta = float(self.Config['reflta']) cft = recSTALTA(trP.data, int(sta * trP.stats.sampling_rate), int(lta * trP.stats.sampling_rate)) t = triggerOnset(cft, lta, sta) try: onset = t[0][0] / trP.stats.sampling_rate print 'ONSET ', onset except: onset = self.mintforerun trigger = trP.stats.starttime + onset print 'TRIGGER ', trigger print 'THEORETICAL: ', UTCDateTime(3600) + self.mintforerun tdiff = (trP.stats.starttime + onset) - (UTCDateTime(3600) + self.mintforerun) print 'TDIFF: ', tdiff refp = UTCDateTime(self.Origin.time) + ptime reftriggeronset = refp + onset - self.mintforerun if int(self.Config['autoxcorrcorrectur']) == 1: try: refmarkername = os.path.join(self.EventPath, ('%s-marker') % (os.path.basename(self.AF))) fobjrefmarkername = open(refmarkername, 'w') fobjrefmarkername.write( '# Snuffler Markers File Version 0.2\n') fobjrefmarkername.write(( 'phase: %s 0 %s None None None XWStart None False\n' ) % (tw['xcorrstart'].strftime('%Y-%m-%d %H:%M:%S.%f'), name)) fobjrefmarkername.write(( 'phase: %s 0 %s None None None XWEnd None False\n' ) % (tw['xcorrend'].strftime('%Y-%m-%d %H:%M:%S.%f'), name)) fobjrefmarkername.write(( 'phase: %s 1 %s None None None TheoP None False\n' ) % (refp.strftime('%Y-%m-%d %H:%M:%S.%f'), name)) fobjrefmarkername.write(( 'phase: %s 3 %s None None None XTrig None False' ) % (reftriggeronset.strftime('%Y-%m-%d %H:%M:%S.%f'), name)) fobjrefmarkername.close() cmd = 'snuffler %s --markers=%s&' % (os.path.join( self.EventPath, refuntouchname), refmarkername) os.system(cmd) thrOn = float(self.Config['reflta']) # 4 thrOff = float(self.Config['refsta']) # 0.7 plotTrigger(trP, cft, thrOn, thrOff) selection = float( raw_input('Enter self picked phase in seconds: ')) tdiff = selection - self.mintforerun print selection - self.mintforerun refname = os.path.basename(self.AF) + '-shift.mseed' trP.stats.starttime = trP.stats.starttime - selection trP.write(os.path.join(self.EventPath, refname), format='MSEED') except: selection = 0. refname = os.path.basename(self.AF) + '-shift.mseed' trP.stats.starttime = trP.stats.starttime - selection - self.mintforerun trP.write(os.path.join(self.EventPath, refname), format='MSEED') ''' tdiff = 0 trigger = trP.stats.starttime ''' To = Trigger(name, trigger, os.path.basename(self.AF), tdiff) return tdiff, To
def calcTTTAdv(Config, station, Origin, flag, arrayname, Xcorrshift=None, Refshift=None): phasename = ('%sphase') % (os.path.basename(arrayname)) cfg = ConfigObj(dict=Config) dimX = cfg.Int('dimx') dimY = cfg.Int('dimy') gridspacing = cfg.Float('gridspacing') o_lat = float(Origin['lat']) o_lon = float(Origin['lon']) o_depth = float(Origin['depth']) oLator = o_lat + dimX / 2 oLonor = o_lon + dimY / 2 oLatul = 0 oLonul = 0 #mint= 100000 #maxt=-100000 TTTGridMap = {} LMINMAX = [] GridArray = {} locStation = Location(station.lat, station.lon) sdelta = loc2degrees(Location(o_lat, o_lon), locStation) tt = obs_TravelTimes(sdelta, o_depth) for r in tt: if r['phase_name'] is Config[phasename] or r['phase_name'] == ( '%sdiff') % (Config[phasename]): station.takeoff = r['take-off angle'] ph = r['phase_name'] #endfor #15.12.2015 : rauskommentiert #Logfile.add ('STATIONINFO ' + str(station) + ' ' + str(station.takeoff) + ' ' + str(ph), # 'PROCESS %d STATION: %s --> DELTA: %f' % (flag,station,sdelta), ' ') z = 0 for i in xrange(dimX): oLatul = o_lat - ((dimX - 1) / 2) * gridspacing + i * gridspacing if z == 0 and i == 0: Latul = oLatul o = 0 for j in xrange(dimY): ttime = 0 oLonul = o_lon - ((dimY - 1) / 2) * gridspacing + j * gridspacing if o == 0 and j == 0: Lonul = oLonul de = loc2degrees(Location(oLatul, oLonul), locStation) tt = obs_TravelTimes(de, o_depth) for k in tt: if k['phase_name'] == Config[phasename] or k['phase_name'] == ( '%sdiff') % (Config[phasename]): ttime = k['time'] if int(Config['xcorr']) == 1: ttime = ttime - float( Xcorrshift[station.getName()].shift) - Refshift GridArray[(i, j)] = GridElem(oLatul, oLonul, o_depth, ttime, de) LMINMAX.append(ttime) #endfor if ttime == 0: print '\033[31mAvailable phases for station %s in range %f deegree\033[0m' % ( station, de) print '\033[31m' + '|'.join( [str(item['phase_name']) for item in tt]) + '\033[0m' print '\033[31myou tried phase %s\033[0m' % (Config[phasename]) raise Exception("\033[31mILLEGAL: phase definition\033[0m") #endif #endfor #endfor mint = min(LMINMAX) maxt = max(LMINMAX) # maxt = time TTTGridMap[station.getName()] = TTTGrid(o_depth, mint, maxt, Latul, Lonul, oLator, oLonor, GridArray) k = MinTMaxT(mint, maxt) Basic.dumpToFile(str(flag) + '-ttt.pkl', TTTGridMap) Basic.dumpToFile('minmax-' + str(flag) + '.pkl', k) Basic.dumpToFile('station-' + str(flag) + '.pkl', station)
def calcTTTAdv(Config, station, Origin, flag, arrayname, Xcorrshift, Refshift, phase): cfg = ConfigObj(dict=Config) if cfg.Bool('correct_shifts_empirical') is True: dimX = cfg.Int('dimx_emp') dimY = cfg.Int('dimy_emp') else: dimX = cfg.Int('dimx') dimY = cfg.Int('dimy') gridspacing = cfg.Float('gridspacing') traveltime_model = cfg.Str('traveltime_model') o_lat = float(Origin['lat']) o_lon = float(Origin['lon']) o_depth = float(Origin['depth']) oLator = o_lat + dimX / 2 oLonor = o_lon + dimY / 2 oLatul = 0 oLonul = 0 o_dip = 80. plane = False TTTGridMap = {} LMINMAX = [] GridArray = {} locStation = Location(station.lat, station.lon) sdelta = loc2degrees(Location(o_lat, o_lon), locStation) Phase = cake.PhaseDef(phase) model = cake.load_model('../data/' + traveltime_model) z = 0 if plane is True: depth = np.linspace(0., 40., num=dimY) for i in xrange(70): oLatul = o_lat - ((dimX - 1) / 2) * gridspacing + i * gridspacing if z == 0 and i == 0: Latul = oLatul o = 0 start_time = time.clock() for j in xrange(40): oLonul = o_lon - ( (dimY - 1) / 2) * gridspacing + j * gridspacing / np.cos(o_dip) if o == 0 and j == 0: Lonul = oLonul de = loc2degrees(Location(oLatul, oLonul), locStation) arrivals = model.arrivals([de, de], phases=Phase, zstart=depth[j] * km, zstop=0.) try: ttime = arrivals[0].t except Exception: try: arrivals = model.arrivals([de, de], phases=Phase, zstart=depth[j] * km - 2.5, zstop=depth[j] * km + 2.5, refine=True) ttime = arrivals[0].t except Exception: tt = obs_TravelTimes(de, o_depth) for k in tt: if k['phase_name'] == 'P' or k['phase_name'] == ( '%sdiff') % (Config[phasename]): ttime = k['time'] print("Something wrong with phase arrival, too large\ distances choosen?") GridArray[(i, j)] = GridElem(oLatul, oLonul, depth[j], ttime, de) LMINMAX.append(ttime) GridArray[(i, j)] = GridElem(oLatul, oLonul, o_depth, ttime, de) LMINMAX.append(ttime) if ttime == 0: raise Exception("\033[31mILLEGAL: phase definition\033[0m") else: for i in xrange(dimX): oLatul = o_lat - ((dimX - 1) / 2) * gridspacing + i * gridspacing if z == 0 and i == 0: Latul = oLatul o = 0 for j in xrange(dimY): oLonul = o_lon - ( (dimY - 1) / 2) * gridspacing + j * gridspacing if o == 0 and j == 0: Lonul = oLonul de = loc2degrees(Location(oLatul, oLonul), locStation) arrivals = model.arrivals([de, de], phases=Phase, zstart=o_depth * km) try: ttime = arrivals[0].t except: try: arrivals = model.arrivals([de, de], phases=Phase, zstart=o_depth * km, zstop=o_depth * km, refine=True) ttime = arrivals[0].t except: arrivals = model.arrivals([de, de], phases=Phase, zstart=o_depth * km - 2.5, zstop=o_depth * km + 2.5, refine=True) ttime = arrivals[0].t GridArray[(i, j)] = GridElem(oLatul, oLonul, o_depth, ttime, de) LMINMAX.append(ttime) GridArray[(i, j)] = GridElem(oLatul, oLonul, o_depth, ttime, de) LMINMAX.append(ttime) if ttime == 0: raise Exception("\033[31mILLEGAL: phase definition\033[0m") mint = min(LMINMAX) maxt = max(LMINMAX) TTTGridMap[station.getName()] = TTTGrid(o_depth, mint, maxt, Latul, Lonul, oLator, oLonor, GridArray) k = MinTMaxT(mint, maxt) Basic.dumpToFile(str(flag) + '-ttt.pkl', TTTGridMap) Basic.dumpToFile('minmax-' + str(flag) + '.pkl', k) Basic.dumpToFile('station-' + str(flag) + '.pkl', station)
def calcTTTAdv(Config, station, Origin, flag, arrayname, Xcorrshift=None, Refshift=None): phasename = ('%sphase') % (os.path.basename(arrayname)) cfg = ConfigObj(dict=Config) dimX = cfg.Int('dimx') dimY = cfg.Int('dimy') gridspacing = cfg.Float('gridspacing') o_lat = float(Origin['lat']) o_lon = float(Origin['lon']) o_depth = float(Origin['depth']) oLator = o_lat + dimX / 2 oLonor = o_lon + dimY / 2 oLatul = 0 oLonul = 0 o_dip = 80. plane = False TTTGridMap = {} LMINMAX = [] GridArray = {} locStation = Location(station.lat, station.lon) sdelta = loc2degrees(Location(o_lat, o_lon), locStation) Phase = cake.PhaseDef(Config[phasename]) model = cake.load_model() z = 0 if plane is True: depth = np.linspace(0., 40., num=dimY) for i in xrange(70): oLatul = o_lat - ((dimX - 1) / 2) * gridspacing + i * gridspacing if z == 0 and i == 0: Latul = oLatul o = 0 start_time = time.clock() for j in xrange(40): oLonul = o_lon - ( (dimY - 1) / 2) * gridspacing + j * gridspacing / np.cos(o_dip) if o == 0 and j == 0: Lonul = oLonul de = loc2degrees(Location(oLatul, oLonul), locStation) arrivals = model.arrivals([de, de], phases=Phase, zstart=depth[j] * km, zstop=0.) try: ttime = arrivals[0].t except: try: arrivals = model.arrivals([de, de], phases=Phase, zstart=depth[j] * km - 2.5, zstop=depth[j] * km + 2.5, refine=True) ttime = arrivals[0].t except: tt = obs_TravelTimes(de, o_depth) for k in tt: if k['phase_name'] == 'P' or k['phase_name'] == ( '%sdiff') % (Config[phasename]): ttime = k['time'] print "Something wrong with phase arrival too large\ distances choosen?" GridArray[(i, j)] = GridElem(oLatul, oLonul, depth[j], ttime, de) LMINMAX.append(ttime) if int(Config['xcorr']) == 1: ttime = ttime-float(Xcorrshift[station.getName()].shift)\ - Refshift GridArray[(i, j)] = GridElem(oLatul, oLonul, o_depth, ttime, de) LMINMAX.append(ttime) if ttime == 0: print '\033[31mAvailable phases for station %s in range %f deegree\033[0m' % ( station, de) print '\033[31m' + '|'.join( [str(item['phase_name']) for item in tt]) + '\033[0m' print '\033[31myou tried phase %s\033[0m' % ( Config[phasename]) raise Exception("\033[31mILLEGAL: phase definition\033[0m") else: for i in xrange(dimX): oLatul = o_lat - ((dimX - 1) / 2) * gridspacing + i * gridspacing if z == 0 and i == 0: Latul = oLatul o = 0 for j in xrange(dimY): oLonul = o_lon - ( (dimY - 1) / 2) * gridspacing + j * gridspacing if o == 0 and j == 0: Lonul = oLonul de = loc2degrees(Location(oLatul, oLonul), locStation) arrivals = model.arrivals([de, de], phases=Phase, zstart=o_depth * km) try: ttime = arrivals[0].t except: try: arrivals = model.arrivals([de, de], phases=Phase, zstart=o_depth * km - 2.5, zstop=o_depth * km - 2.5, refine=True) ttime = arrivals[0].t except: arrivals = model.arrivals([de, de], phases=Phase, zstart=o_depth * km - 2.5, zstop=0., refine=True) ttime = arrivals[0].t GridArray[(i, j)] = GridElem(oLatul, oLonul, o_depth, ttime, de) LMINMAX.append(ttime) if int(Config['xcorr']) == 1: ttime = ttime-float(Xcorrshift[station.getName()].shift)\ - Refshift GridArray[(i, j)] = GridElem(oLatul, oLonul, o_depth, ttime, de) LMINMAX.append(ttime) if ttime == 0: print '\033[31mAvailable phases for station %s in range %f deegree\033[0m' % ( station, de) print '\033[31m' + '|'.join( [str(item['phase_name']) for item in tt]) + '\033[0m' print '\033[31myou tried phase %s\033[0m' % ( Config[phasename]) raise Exception("\033[31mILLEGAL: phase definition\033[0m") mint = min(LMINMAX) maxt = max(LMINMAX) TTTGridMap[station.getName()] = TTTGrid(o_depth, mint, maxt, Latul, Lonul, oLator, oLonor, GridArray) k = MinTMaxT(mint, maxt) Basic.dumpToFile(str(flag) + '-ttt.pkl', TTTGridMap) Basic.dumpToFile('minmax-' + str(flag) + '.pkl', k) Basic.dumpToFile('station-' + str(flag) + '.pkl', station)