예제 #1
0
파일: BaseDC.py 프로젝트: rowanc1/simpegdc
def writeUBC_DCobs(fileName,Tx,Rx,d,wd, dtype):
    
    from SimPEG import np, mkvc
    import re
    """
        Read UBC GIF DCIP 3D observation file and generate arrays for tx-rx location
    
        Input:
        :param fileName, path to the UBC GIF 3D obs file
    
        Output:
        :param rx, tx, d, wd
        :return
        
        Created on Mon December 7th, 2015
    
        @author: dominiquef
    
    """
    fid = open(fileName,'w')
    fid.write('! GENERAL FORMAT\n')  
    
    for ii in range(len(Tx)):
        
        tx = np.asarray(Tx[ii])
        rx = np.asarray(Rx[ii])
        nrx = rx.shape[0]
        
        fid.write('\n')
        
        if re.match(dtype,'2D'):
            
            for jj in range(nrx):
                
                fid.writelines("%e " % ii for ii in mkvc(tx))
                fid.writelines("%e " % ii for ii in mkvc(rx[jj]))
                fid.write('%e %e\n'% (d[ii][jj],wd[ii][jj]))
                #np.savetxt(fid, np.c_[ rx ,np.asarray(d[ii]), np.asarray(wd[ii]) ], fmt='%e',delimiter=' ',newline='\n') 
        
        elif re.match(dtype,'3D'):
                                
            fid.write('\n')
            fid.writelines("%e " % ii for ii in mkvc(tx))
            fid.write('%i\n'% nrx)
            np.savetxt(fid, np.c_[ rx ,np.asarray(d[ii]), np.asarray(wd[ii]) ], fmt='%e',delimiter=' ',newline='\n') 
        
        
    fid.close()  
예제 #2
0
mshfile2d = 'Mesh_2D.msh'
modfile2d = 'MtIsa_2D.con'
obsfile2d = 'FWR_3D_2_2D.dat'
ipfile2d = 'IP_2D.dat'
inp_file = 'dcinv2d.inp'

ini_mod = 1e-2
ref_mod = 1e-2

#%% Export 2D mesh
fid = open(inv_dir + dsep + mshfile2d, 'w')
fid.write('%i\n' % mesh2d.nCx)
fid.write('%f %f 1\n' % (mesh2d.vectorNx[0], mesh2d.vectorNx[1]))
np.savetxt(fid,
           np.c_[mesh2d.vectorNx[2:],
                 np.ones(mesh2d.nCx - 1)],
           fmt='\t %e %i',
           delimiter=' ',
           newline='\n')
fid.write('\n')
fid.write('%i\n' % mesh2d.nCy)
fid.write('%f %f 1\n' % (-mesh2d.vectorNy[-1], -mesh2d.vectorNy[-2]))
np.savetxt(fid,
           np.c_[-mesh2d.vectorNy[-3::-1],
                 np.ones(mesh2d.nCy - 1)],
           fmt='\t %f %i',
           delimiter=' ',
           newline='\n')
fid.close()

#==============================================================================
# # Export 2D model
예제 #3
0
def writeUBC_DCobs(fileName, DCsurvey, dim, surveyType, iptype = 0):
    """
        Write UBC GIF DCIP 2D or 3D observation file

        :param string fileName: including path where the file is written out
        :param Survey DCsurvey: DC survey class object
        :param string dim:  either '2D' | '3D'
        :param string surveyType:  either 'SURFACE' | 'GENERAL'
        :rtype: file
        :return: UBC2D-Data file
    """

    from SimPEG import mkvc

    assert (dim=='2D') | (dim=='3D'), "Data must be either '2D' | '3D'"
    assert (surveyType=='SURFACE') | (surveyType=='GENERAL') | (surveyType=='SIMPLE'), "Data must be either 'SURFACE' | 'GENERAL' | 'SIMPLE'"

    fid = open(fileName,'w')
    fid.write('! ' + surveyType + ' FORMAT\n')

    if iptype!=0:
        fid.write('IPTYPE=%i\n'%iptype)

    else:
        fid.write('! ' +  surveyType + ' FORMAT\n')

    count = 0

    for ii in range(DCsurvey.nSrc):

        tx = np.c_[DCsurvey.srcList[ii].loc]

        rx = DCsurvey.srcList[ii].rxList[0].locs

        nD = DCsurvey.srcList[ii].nD

        M = rx[0]
        N = rx[1]

        # Adapt source-receiver location for dim and surveyType
        if dim=='2D':

            if surveyType == 'SIMPLE':

                #fid.writelines("%e " % ii for ii in mkvc(tx[0,:]))
                A = np.repeat(tx[0,0],M.shape[0],axis=0)
                B = np.repeat(tx[0,1],M.shape[0],axis=0)
                M = M[:,0]
                N = N[:,0]

                np.savetxt(fid, np.c_[A, B, M, N , DCsurvey.dobs[count:count+nD], DCsurvey.std[count:count+nD] ], fmt='%e',delimiter=' ',newline='\n')


            else:

                if surveyType == 'SURFACE':

                    fid.writelines("%f " % ii for ii in mkvc(tx[0,:]))
                    M = M[:,0]
                    N = N[:,0]

                if surveyType == 'GENERAL':

                    # Flip sign for z-elevation to depth
                    tx[2::2,:] = -tx[2::2,:]

                    fid.writelines("%e " % ii for ii in mkvc(tx[::2,:]))
                    M = M[:,0::2]
                    N = N[:,0::2]

                    # Flip sign for z-elevation to depth
                    M[:,1::2] = -M[:,1::2]
                    N[:,1::2] = -N[:,1::2]

                fid.write('%i\n'% nD)
                np.savetxt(fid, np.c_[ M, N , DCsurvey.dobs[count:count+nD], DCsurvey.std[count:count+nD] ], fmt='%f',delimiter=' ',newline='\n')

        if dim=='3D':

            if surveyType == 'SURFACE':

                fid.writelines("%e " % ii for ii in mkvc(tx[0:2,:]))
                M = M[:,0:2]
                N = N[:,0:2]

            if surveyType == 'GENERAL':

                fid.writelines("%e " % ii for ii in mkvc(tx[0:3,:]))

            fid.write('%i\n'% nD)
            np.savetxt(fid, np.c_[ M, N , DCsurvey.dobs[count:count+nD], DCsurvey.std[count:count+nD] ], fmt='%e',delimiter=' ',newline='\n')
            fid.write('\n')

        count += nD

    fid.close()
예제 #4
0
def writeUBC_DCobs(fileName, DCsurvey, dtype, stype):
    """
        Write UBC GIF DCIP 2D or 3D observation file

        Input:
        :string fileName -> including path where the file is written out
        :DCsurvey -> DC survey class object
        :string dtype ->  either '2D' | '3D'
        :string  stype ->  either 'SURFACE' | 'GENERAL'

        Output:
        :param UBC2D-Data file
        :return

        Last edit: February 16th, 2016

        @author: dominiquef

    """
    from SimPEG import mkvc

    assert (dtype=='2D') | (dtype=='3D'), "Data must be either '2D' | '3D'"
    assert (stype=='SURFACE') | (stype=='GENERAL') | (stype=='SIMPLE'), "Data must be either 'SURFACE' | 'GENERAL' | 'SIMPLE'"

    fid = open(fileName,'w')
    fid.write('! ' + stype + ' FORMAT\n')

    count = 0

    for ii in range(DCsurvey.nSrc):

        tx = np.c_[DCsurvey.srcList[ii].loc]

        rx = DCsurvey.srcList[ii].rxList[0].locs

        nD = DCsurvey.srcList[ii].nD

        M = rx[0]
        N = rx[1]

        # Adapt source-receiver location for dtype and stype
        if dtype=='2D':

            if stype == 'SIMPLE':

                #fid.writelines("%e " % ii for ii in mkvc(tx[0,:]))
                A = np.repeat(tx[0,0],M.shape[0],axis=0)
                B = np.repeat(tx[0,1],M.shape[0],axis=0)
                M = M[:,0]
                N = N[:,0]

                np.savetxt(fid, np.c_[A, B, M, N , DCsurvey.dobs[count:count+nD], DCsurvey.std[count:count+nD] ], fmt='%e',delimiter=' ',newline='\n')


            else:

                if stype == 'SURFACE':

                    fid.writelines("%e " % ii for ii in mkvc(tx[0,:]))
                    M = M[:,0]
                    N = N[:,0]

                if stype == 'GENERAL':

                    fid.writelines("%e " % ii for ii in mkvc(tx[::2,:]))
                    M = M[:,0::2]
                    N = N[:,0::2]

                fid.write('%i\n'% nD)
                np.savetxt(fid, np.c_[ M, N , DCsurvey.dobs[count:count+nD], DCsurvey.std[count:count+nD] ], fmt='%e',delimiter=' ',newline='\n')

        if dtype=='3D':

            if stype == 'SURFACE':

                fid.writelines("%e " % ii for ii in mkvc(tx[0:2,:]))
                M = M[:,0:2]
                N = N[:,0:2]

            if stype == 'GENERAL':

                fid.writelines("%e " % ii for ii in mkvc(tx))

            fid.write('%i\n'% nD)
            np.savetxt(fid, np.c_[ M, N , DCsurvey.dobs[count:count+nD], DCsurvey.std[count:count+nD] ], fmt='%e',delimiter=' ',newline='\n')

        count += nD

    fid.close()
예제 #5
0
 #%% Create dcin2d inversion files and run
 inv_dir = home_dir + '\Inv2D' 
 if not os.path.exists(inv_dir):
     os.makedirs(inv_dir)
     
 mshfile2d = 'Mesh_2D.msh'
 modfile2d = 'MtIsa_2D.con'
 obsfile2d = 'FWR_3D_2_2D.dat'
 inp_file = 'dcinv2d.inp'
 
 
 # Export 2D mesh
 fid = open(inv_dir + dsep + mshfile2d,'w')
 fid.write('%i\n'% mesh2d.nCx)
 fid.write('%f %f 1\n'% (mesh2d.vectorNx[0],mesh2d.vectorNx[1]))  
 np.savetxt(fid, np.c_[mesh2d.vectorNx[2:],np.ones(mesh2d.nCx-1)], fmt='\t %e %i',delimiter=' ',newline='\n')
 fid.write('\n')
 fid.write('%i\n'% mesh2d.nCy)
 fid.write('%f %f 1\n'%( 0,mesh2d.hy[-1]))   
 np.savetxt(fid, np.c_[np.cumsum(mesh2d.hy[-2::-1])+mesh2d.hy[-1],np.ones(mesh2d.nCy-1)], fmt='\t %e %i',delimiter=' ',newline='\n')
 fid.close()
 
 # Export 2D model
 fid = open(inv_dir + dsep + modfile2d,'w')
 fid.write('%i %i\n'% (mesh2d.nCx,mesh2d.nCy))
 np.savetxt(fid, mkvc(m2D[::-1,:].T), fmt='%e',delimiter=' ',newline='\n')
 fid.close()
 
 # Export data file
 DC.writeUBC_DCobs(inv_dir + dsep + obsfile2d,Tx2d,Rx2d,data,unct,'2D')