def GetSacInfo(fileName): stream = pread(fileName) time = [ stream[0].stats.sac.nzyear, stream[0].stats.sac.nzjday, stream[0].stats.sac.nzhour * 3600 + stream[0].stats.sac.nzmin * 60 + stream[0].stats.sac.nzsec + stream[0].stats.sac.nzmsec / 1000 ] return stream[0].data, time
def __init__(self, file_name): from pysac import SacStreamIO import stft import numpy as np self.wlWinN = 60 self.wlLagN = 6 self.fqWinN = 60 self.fqLagN = 10 self.fqRspN = 32 self.wlRspN = 32 self.max900 = 0 self.wl_x_level = 3 #sac file read stream = Stream() for fileName in file_name: stream += pread(fileName) self.stream_count = 0 self.hash = [] self.stro = 0 for temp_data in stream: self.sac_data = temp_data.data[:100000] self.sac_data = signal.detrend(self.sac_data) print(temp_data.stats.sac.nzyear) fqData = stft.stft(self.sac_data, self.fqWinN, self.fqLagN, self.fqRspN) fqData = np.abs(fqData) print(" STFT FINISHED!") wlDataX = self.WaveLetX(fqData, level=3) self.wlData = self.WaveLetAndRegular(wlDataX, level=3) print(" WALE FINISHED!") self.wlData = self.RegularS(self.wlData) print(" REGU FINISHED!") self.wlData = self.TrimData(self.wlData) print(" TRIM FINISHED!") self.GetFingerPoint(2) print(" FIGU FINISHED!") self.hash.append(self.itr_hash) self.stream_count += 1 self.stro += 1
def GetData(self, file): st = pread(file) return st[0].data
def trunk(): HSF = GetHashFile(os.getcwd() + '/').GetList() TPF = GetTempFile(os.getcwd() + '/').GetList() mysel = Select(TPF, HSF) mysel.GetHashFile() mysel.GetTempFile() #tm=mysel.GetTime() #print(tm) #return files = [ DIR + "s28/2015337/2015337_00_00_00_s28_BHE.SAC", DIR + "s28/2015337/2015337_00_00_00_s28_BHN.SAC", DIR + "s28/2015337/2015337_00_00_00_s28_BHZ.SAC" ] st = Stream() dt = [] for file in files: st = pread(file) dt.append(st[0].data) #tm=mysel.Find(np.array([22813171,127266168,12470431,17266034,132721297,6361937,30551886,56546867,27689246,235320713,86101458,93624353,13858394,49972221,103683464,31376115,104910045,64306427,143938973,121058633])) tm = mysel.Find( np.array([ 22813171, 24130584, 12470431, 17266034, 132721297, 173306923, 100774281, 39951099, 27689246, 289724735, 86101458, 75492665, 29604049, 183910497, 45187728, 27032361, 97663355, 7276142, 143938973, 70629991 ])) print(tm) #return fig = plt.figure() timelen = 300 jsfile = open("D:/xampp/htdocs/data/data_plot.json", "w") jsfile.write("{\"timeseries\":[") for itr in tm: jsfile.write("%d," % int(itr)) jsfile.seek(jsfile.tell() - 1) jsfile.write("],\n") jsfile.write("\"datas\":[") for itr in tm: itr = int(itr * 100) jsfile.write("[[") for itry in range(timelen): jsfile.write("[%f,%f]," % ((itry) / 100, dt[0][itr + itry])) jsfile.seek(jsfile.tell() - 1) jsfile.write("],\n[") for itry in range(timelen): jsfile.write("[%f,%f]," % ((itry) / 100, dt[1][itr + itry])) jsfile.seek(jsfile.tell() - 1) jsfile.write("],\n[") for itry in range(timelen): jsfile.write("[%f,%f]," % ((itry) / 100, dt[2][itr + itry])) jsfile.seek(jsfile.tell() - 1) jsfile.write("]],\n") #name="selfig/"+("%.2f"%(itr/100))+".jpg" #fig.clf() #ax=fig.add_subplot(311) #ax.plot(dt[0][itr:itr+timelen]) #ax=fig.add_subplot(312) #ax.plot(dt[1][itr:itr+timelen]) #ax=fig.add_subplot(313) #ax.plot(dt[2][itr:itr+timelen]) #plt.savefig(name) jsfile.seek(jsfile.tell() - 3) jsfile.write("]}") jsfile.close()
DIR + "s28/2015336/2015336_00_00_00_s28_BHZ.SAC", DIR + "s28/2015336/2015336_00_00_00_s28_BHN.SAC", DIR + "s28/2015336/2015336_00_00_00_s28_BHE.SAC" ], [ DIR + "s28/2015337/2015337_00_00_00_s28_BHZ.SAC", DIR + "s28/2015337/2015337_00_00_00_s28_BHN.SAC", DIR + "s28/2015337/2015337_00_00_00_s28_BHE.SAC" ], [ DIR + "s28/2015338/2015338_00_00_00_s28_BHZ.SAC", DIR + "s28/2015338/2015338_00_00_00_s28_BHN.SAC", DIR + "s28/2015338/2015338_00_00_00_s28_BHE.SAC" ]][1:2] st = pread(scFile[0][0]) st += pread(scFile[0][1]) st += pread(scFile[0][2]) fig = plt.figure(1) xxx = np.linspace(0, 20, 2000) a1 = st[0].data a2 = st[1].data a3 = st[2].data for itr in time: if (itr[1] > 1): plt.clf() file.write(str(itr[0]) + "\n") continue stt = int(itr[0] * 100) edd = stt + 2000 ax = fig.add_subplot(311)
from mpl_toolkits.mplot3d import Axes3D import numpy as np import scipy.signal as signal def FileToList(fileName): f=open(fileName,"r",encoding=None) fdata=f.readlines() data=[] for itr in fdata: #print(itr) if(itr[:2]=='20'): data.append([ii.strip() for ii in itr.split() if(len(ii)>0)]) return data stream = Stream() stream = pread("after/SC.XJI.2008133160000.D.00.BHN.sac") stream += pread("after/SC.XJI.2008133160000.D.00.BHZ.sac") stream += pread("after/SC.XJI.2008133160001.D.00.BHE.sac") stream.detrend() nzy1,nzd1,nzs1=(stream[0].stats.sac.nzyear, stream[0].stats.sac.nzjday, stream[2].stats.sac.nzhour*3600+ stream[2].stats.sac.nzmin*60+ stream[2].stats.sac.nzsec+ stream[2].stats.sac.nzmsec/1000) nzy2,nzd2,nzs2=(stream[1].stats.sac.nzyear, stream[1].stats.sac.nzjday, stream[2].stats.sac.nzhour*3600+ stream[2].stats.sac.nzmin*60+ stream[2].stats.sac.nzsec+ stream[2].stats.sac.nzmsec/1000)
from obspy import read as pread from obspy import Stream import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np import os from DIRS import * from getfiles.getdir import * cGetLogDir = GetLogDir(DIR + CATLOG) logDirs = cGetLogDir.GetDirList() ccct = 0 for itr in logDirs: logFileTime = GetLogFile(itr[0]) for sacFile in os.listdir(DIR + itr[1] + itr[2]): print(DIR + itr[1] + itr[2] + sacFile) stream = pread(DIR + itr[1] + itr[2] + sacFile) for time_t in logFileTime: time_i = int(time_t * 100) plt.plot(stream[0].data[time_i:time_i + 2000], c='k') ccct = 1 if (ccct == 1): break if (ccct == 1): break plt.show()