Exemplo n.º 1
0
    def __init__(self,parfile,method='auto',sublayercriteria = 5.,numiter = 10,conv_level = 0.01,verbose=False):
        # parameter file initialization
        self.parfile = parfile
        # read file parameter
        self.parameters = IOfile.parsing_input_file(parfile)
        # method is automatically defined
#        if method=='auto':
#            if self.parameters['type']=='PSV':
#                self.method = 'knopoff_psv_adv'
#            else:
#                if self.parameters['nlayer']<=5:
#                    if self.parameters['iang']==0.:
#                        self.method='knopoff_sh'
#                    else:
#                        self.method='knopoff_sh_adv'
#                else:
#                    self.method = 'kennet_sh'
        # checking input file
        if self.parameters['inputmotion'][1]=='ascii':
            self.inp_time,self.inp_signal = IOfile.read_ascii_seismogram(self.parameters['inputmotion'][0])
        else:
            raise KeyError('Input motion other than ascii format is not yet supported! Please convert it to displacement on another software first!')
        self.inp_signal = [i/100. for i in self.inp_signal]
        self.fs = 1/(self.inp_time[1]-self.inp_time[0])
        self.dt = self.inp_time[1]-self.inp_time[0]
        self.df = 1./((len(self.inp_signal)-1)*self.dt)
        
        # baseline correction for input signal
        self.inp_signal = self.inp_signal-np.mean(self.inp_signal)        
        
#        if self.parameters['inputmotion'][2]=='vel':
#            self.inp_signal = GT.vel2disp(self.inp_signal,self.dt)
#            self.inp_signal = self.cosine_tapering(self.inp_signal)
#            self.inp_signal = self.butter_highpass_filter(self.inp_signal,2.*self.df,self.fs)
#        elif self.parameters['inputmotion'][2]=='acc':
#            self.inp_signal = GT.acc2disp(self.inp_signal,self.dt)
#            self.inp_signal = self.cosine_tapering(self.inp_signal)
#            self.inp_signal = self.butter_highpass_filter(self.inp_signal,2.*self.df,self.fs)
            
        if self.parameters['modeID']==11 or self.parameters['modeID']==12:
            # method is automatically defined
            if method=='auto':
                if self.parameters['type']=='PSV':
                    self.method = 'knopoff_psv_adv'
                else:
                    if self.parameters['iang']==0.:
                        self.method = 'kramer286_sh'
                    else:
                        self.method = 'knopoff_sh_adv'
            else:
                self.method = method
            self.linear_equivalent_TF2TS(sublayercriteria,numiter,conv_level,verbose)
        else:
            # method is automatically defined
            if method=='auto':
                if self.parameters['type']=='PSV':
                    self.method = 'knopoff_psv_adv'
                else:
                    if self.parameters['iang']==0.:
                        self.method = 'knopoff_sh'
                    else:
                        self.method = 'knopoff_sh_adv'
            else:
                self.method = method
            self.linear_TF2TS()
            self.lastiter = 1
        
        if self.parameters['inputmotion'][2]=='acc':
            for i in range(len(self.time_series)):
                self.time_series[i] = GT.disp2acc(self.time_series[i],self.dt)
        elif self.parameters['inputmotion'][2]=='vel':
            for i in range(len(self.time_series)):
                self.time_series[i] = GT.disp2vel(self.time_series[i],self.dt)
Exemplo n.º 2
0
 def circ_convolution(self,data,tf,disp=False):
     # perform circular convolution on time domain
     # if domain is time, then :
     # data --> input data in time domain
     # IR --> impulse response
     # if domain is frequency, then : 
     # data --> DFT of data
     # IR --> DFT of IR
     df = 1./((1./self.fs)*len(tf))
     datafreq = [(i+1)*df for i in range(len(tf))]
     if self.parameters['inputmotion'][2]=='acc':
         tf = GT.acc2dispfreq(tf,datafreq)
     elif self.parameters['inputmotion'][2]=='vel':
         tf = GT.vel2dispfreq(tf,datafreq)
     
     newlength=len(data)*2
     dat1 = self.zeropadding(data,newlength)
     dat2 = np.real(np.fft.ifft(tf))*4.
     
     dat2[len(dat2)/2:]=0.
     
     # highpass filter
     dt = 1./self.fs
     df = 1./((len(dat1)-1)*dt)
     dat1 = self.butter_highpass_filter(dat1,2.*df,self.fs)
     dat2 = self.butter_highpass_filter(dat2,2.*df,self.fs)
     
     out = np.real(np.fft.ifft(np.fft.fft(dat1)*np.fft.fft(dat2)))
     
     # correction of freq vector
     fmax = 1./(2.*dt)
     self.freq = np.linspace(0.,fmax,len(dat1)/2.)
     
     if disp:
         # plot the result(s)
         fig = plt.figure(figsize=(12.,4.))
         a1 = fig.add_subplot(121)
         a1.set_title('Time Series')
         a1.plot(self.inp_time,self.inp_signal,label='input')
         a1.plot(self.inp_time,np.real(out[:len(self.inp_time)]),lw=2.,label='output',alpha=0.5)
         a1.legend(loc='best',fancybox=True,framealpha=0.5)
         a1.grid(True)
         #a1.set_xlim(0,2)
         
         
         # plot the tf abs
         a2 = fig.add_subplot(122)
         a2.set_title('Frequency domain')
         tmp = np.abs(np.fft.fft(dat1))
         a2.plot(self.freq,tmp[:len(self.tfclass.freq)],label='input signal')
         a2.plot(self.tfclass.freq,np.abs(self.tfclass.tf[0]),label='transfer function')
         dftts = np.abs(np.fft.fft(out))
         a2.plot(self.freq,dftts[:len(self.freq)],lw=2.,label='output',alpha=0.5)
         a2.legend(loc='best',fancybox=True,framealpha=0.5)
         a2.set_xscale('log')
         a2.grid(True)  
         
         
         
         # plot the result(s)
         fig = plt.figure(figsize=(12.,4.))
         a1 = fig.add_subplot(121)
         a1.set_title('Time Series')
         a1.plot(self.inp_time,self.inp_signal,label='input')
         a1.plot(self.inp_time,np.real(out[:len(self.inp_time)]),lw=2.,label='output',alpha=0.5)
         a1.legend(loc='best',fancybox=True,framealpha=0.5)
         a1.grid(True)
         #a1.set_xlim(0,2)
         
         
         # plot the tf angle
         a2 = fig.add_subplot(122)
         a2.set_title('Frequency domain')
         tmp = np.angle(np.fft.fft(dat1))
         a2.plot(self.freq,tmp[:len(self.tfclass.freq)],label='input signal')
         a2.plot(self.tfclass.freq,np.angle(self.tfclass.tf[0]),label='transfer function')
         dftts = np.angle(np.fft.fft(out))
         a2.plot(self.freq,dftts[:len(self.freq)],lw=2.,label='output',alpha=0.5)
         a2.legend(loc='best',fancybox=True,framealpha=0.5)
         a2.set_xscale('log')
         a2.grid(True)  
     
     return out