Example #1
0
def _compute_res_phase(z,zerr,freq):
    """
    calculates *resistivity*, *phase*, *resistivity_err*, *phase_err*
    
    values for resistivity are in in Ohm m and phase in degrees.

    """ 

    resistivity_err = np.zeros_like(zerr)
    phase_err = np.zeros_like(zerr)

    resistivity = np.zeros_like(z, dtype='float')
    phase = np.zeros_like(z, dtype='float')

    #calculate resistivity and phase
    for idx_f in range(len(z)): 
        for i in range(2):                        
            for j in range(2):
                resistivity[idx_f,i,j] = np.abs(z[idx_f,i,j])**2/\
                                              freq[idx_f]*0.2
                phase[idx_f,i,j] = math.degrees(cmath.phase(
                                                z[idx_f,i,j]))
            
                if zerr is not None:
                    
                    r_err, phi_err = MTcc.zerror2r_phi_error(
                                             np.real(z[idx_f,i,j]), 
                                             zerr[idx_f,i,j], 
                                             np.imag(z[idx_f,i,j]), 
                                             zerr[idx_f,i,j])

                    

                    resistivity_err[idx_f,i,j] = \
                                           0.4*np.abs(z[idx_f,i,j])/\
                                           freq[idx_f]*r_err
                    phase_err[idx_f,i,j] = phi_err        
    return resistivity, resistivity_err, phase, phase_err
        
Example #2
0
    def read_datafile(self):
        """
        read data file into the data object.
        calculate resistivity and phase
        
        """
        if self.datafile is None:

            default_files = ['ai1dat.dat','ai1mod.dat','ai1fit.dat',
                             'inmodel.dat','inregulm.dat']
            dlst = [i for i in os.listdir(self.working_directory) if \
            (i[-4:] == '.dat') and (i not in default_files)]
            if len(dlst) == 1:
                self.datafile = dlst[0]
            else:
                print "please define datafile"
                return

        # define path to file
        datafpath = os.path.join(self.working_directory,self.datafile)
        self.mode = open(datafpath).readline().strip().split()[0]
        data = np.loadtxt(datafpath,skiprows = 2)
        self.freq = 1./data[:,0]
   
        if self.mode == 'I':   
            zr = np.vstack([data[:,i] for i in range(len(data[0])) if (i-1)%4 == 0])
            ze = np.vstack([data[:,i] for i in range(len(data[0])) if (i-2)%4 == 0])
            zi = -np.vstack([data[:,i] for i in range(len(data[0])) if (i-3)%4 == 0])
            z = zr + 1j*zi
            self.z = z.T.reshape(len(z[0]),2,2)
            self.zerr = ze.T.reshape(len(z[0]),2,2)

            
            # make a frequency array that has the same shape as z
            freq2 = np.zeros(np.shape(self.z))
            for i in range(len(freq2)):
                freq2[i,:,:] = 1./data[:,0][i]             
            
#           calculate resistivity
            self.resistivity = 0.2*np.abs(self.z)**2/freq2
            
            q = np.zeros(np.shape(self.resistivity))
#            q[(zr<0)&(zi<0)] = np.pi
#            q[(zr<0)&(zi>0)] = -np.pi
            phase = np.zeros([len(self.z),2,2])
            res = np.zeros([len(self.z),2,2])
            self.resistivity_err = np.zeros([len(self.z),2,2])
            self.phase_err = np.zeros([len(self.z),2,2])        
            
            
            self.q = q
            for iz in range(len(self.z)):
                for i in range(2):
                    for j in range(2):
                        phase[iz,i,j] = np.rad2deg(cmath.phase(self.z[iz,i,j]))
                        res[iz,i,j]= 0.2*np.abs(self.z[iz,i,j])**2/self.freq[iz]
                        r_err, phi_err = MTcc.zerror2r_phi_error(
                                                 np.real(self.z[iz,i,j]), 
                                                 self.zerr[iz,i,j], 
                                                 np.imag(self.z[iz,i,j]), 
                                                 self.zerr[iz,i,j])

                        

                        self.resistivity_err[iz,i,j] = \
                                               0.4*np.abs(self.z[iz,i,j])/\
                                               self.freq[iz]*r_err
                        self.phase_err[iz,i,j] = phi_err

            phase[phase<-180] += 360
            self.phase = phase
            self.resistivity = res
            
        elif self.mode == 'R':
            res = np.vstack([data[:,i] for i in range(len(data[0])) if (i-1)%4 == 0])
            self.resistivity = res.T.reshape(len(res[0]),2,2)
            res_err = np.vstack([data[:,i] for i in range(len(data[0])) if (i-2)%4 == 0])
            self.resistivity_err = res_err.T.reshape(len(res_err[0]),2,2)
            
            phs = np.vstack([data[:,i] for i in range(len(data[0])) if (i-3)%4 == 0])
            self.phase = phs.T.reshape(len(phs[0]),2,2)
            phs_err = np.vstack([data[:,i] for i in range(len(data[0])) if (i-4)%4 == 0])
            self.phase_err = phs_err.T.reshape(len(phs_err[0]),2,2)