def autocorrelate2(filelst): """ Autocorrelation in frequency domain. The implementation of AC is from SCIPY. The autocorrelograms is normalized. :param filelst: :return: """ for file in filelst: print "AC: ", file tr = read(file)[0] x = tr.data stel = tr.stats.sac.stel stla = tr.stats.sac.stla stlo = tr.stats.sac.stlo try: # auto-correlation from SCIPY implemented in F domain, which is much faster than those in time domain ac = signal.fftconvolve(x, x[::-1], mode="full") ac = ac / max(abs(ac)) except: continue tr1 = Trace(data=ac) tr1.stats.network = tr.stats.network tr1.stats.station = tr.stats.station tr1.stats.location = tr.stats.location tr1.stats.delta = tr.stats.delta tr1.stats.sampling_rate = tr.stats.sampling_rate tr1.stats.channel = tr.stats.channel tr1.stats._format = "SAC" tr1.stats.sac = {u'stla': stla, u'stlo': stlo, u'stel': stel} tr1.stats.sac.user1 = tr.stats.sac.user1 tr1.stats.sac.user2 = tr.stats.sac.user2 tr1.stats.sac.kuser1 = tr.stats.sac.kuser1 tr1.stats.sac.kuser2 = tr.stats.sac.kuser2 # tr1.stats.sac.stla = tr.stats.sac.stla # tr1.stats.sac.stlo = tr.stats.sac.stlo # tr1.stats.sac.stel = tr.stats.sac.stel path, fn = filen2(file) fullfn = "SDI/ac/" + path + "/" + fn # print fullfn try: os.makedirs("SDI/ac/" + path) except: pass tr1.write(fullfn, format="SAC") pass
def on_data(self, trace): global i global traces global fn global day if i == 1: print('Received traces. Checking for existing data...') if (os.path.isfile(fn)): print('Found %s, reading...' % fn) traces = read(fn) print('Done.') else: print('No data found. Creating new blank trace to write to...') traces = Trace() traces = trace print('Trace %s: %s' % (i, trace)) else: print('Trace %s: %s' % (i, trace)) traces += trace traces.__add__(trace) if (float(i) / 10. == int(float(i) / 10.)): print('Saving %s traces to %s...' % (i, fn)) traces.write(fn, format='MSEED') print('Done.') i += 1 if (day != UTCDateTime.now().strftime('%Y.%j')): day = UTCDateTime.now().strftime('%Y.%j') fn = fn = '%s.%s.%s.%s.D.%s' % (net, sta, loc, cha, day) i = 1
def autocorrelate(filelst): for file in filelst: print "AC: ", file tr = read(file)[0] x = tr.data stel = tr.stats.sac.stel stla = tr.stats.sac.stla stlo = tr.stats.sac.stlo try: # auto-correlation from SCIPY implemented in F domain, which is much faster than those in time domain ac = signal.fftconvolve(x, x[::-1], mode="full") ac = ac/max(abs(ac)) except: continue tr1 = Trace(data=ac) tr1.stats.network = tr.stats.network tr1.stats.station =tr.stats.station tr1.stats.location = tr.stats.location tr1.stats.delta = tr.stats.delta tr1.stats.sampling_rate = tr.stats.sampling_rate tr1.stats.channel = tr.stats.channel tr1.stats._format = "SAC" tr1.stats.sac = {u'stla': stla, u'stlo': stlo, u'stel': stel} tr1.stats.sac.user1 = tr.stats.sac.user1 tr1.stats.sac.user2 = tr.stats.sac.user2 tr1.stats.sac.kuser1 = tr.stats.sac.kuser1 tr1.stats.sac.kuser2 = tr.stats.sac.kuser2 # tr1.stats.sac.stla = tr.stats.sac.stla # tr1.stats.sac.stlo = tr.stats.sac.stlo # tr1.stats.sac.stel = tr.stats.sac.stel path, fn = filen(file) fullfn = "SDI/ac/"+path+"/"+fn # print fullfn try: os.makedirs("SDI/ac/"+path) except: pass tr1.write(fullfn, format="SAC") pass
def write(self, trace: Trace): trace.write(self._get_unique_filepath(trace))
#!/usr/bin/env python3 from numpy import ones from obspy.core.trace import Trace t100 = Trace(ones(100)) t100.write('t100.sac', format='sac') t101 = Trace(ones(101)) t101.write('t101.sac', format='sac')