def readUBC_DC3Dobs(fileName): """ 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 """ # Load file obsfile = np.genfromtxt(fileName,delimiter=' \n',dtype=np.str,comments='!') # Pre-allocate srcLists = [] Rx = [] d = [] wd = [] zflag = True # Flag for z value provided # Countdown for number of obs/tx count = 0 for ii in range(obsfile.shape[0]): if not obsfile[ii]: continue # First line is transmitter with number of receivers if count==0: temp = (np.fromstring(obsfile[ii], dtype=float,sep=' ').T) count = int(temp[-1]) # Check if z value is provided, if False -> nan if len(temp)==5: tx = np.r_[temp[0:2],np.nan,temp[0:2],np.nan] zflag = False else: tx = temp[:-1] rx = [] continue temp = np.fromstring(obsfile[ii], dtype=float,sep=' ') if zflag: rx.append(temp[:-2]) # Check if there is data with the location if len(temp)==8: d.append(temp[-2]) wd.append(temp[-1]) else: rx.append(np.r_[temp[0:2],np.nan,temp[0:2],np.nan] ) # Check if there is data with the location if len(temp)==6: d.append(temp[-2]) wd.append(temp[-1]) count = count -1 # Reach the end of transmitter block if count == 0: rx = np.asarray(rx) Rx = DC.RxDipole(rx[:,:3],rx[:,3:]) srcLists.append( DC.SrcDipole( [Rx], tx[:3],tx[3:]) ) # Create survey class survey = DC.SurveyDC(srcLists) survey.dobs = np.asarray(d) survey.std = np.asarray(wd) return {'DCsurvey':survey}
def convertObs_DC3D_to_2D(DCsurvey,lineID): """ Read DC survey and data and change coordinate system to distance along line assuming all data is acquired along line. First transmitter pole is assumed to be at the origin Assumes flat topo for now... Input: :param Tx, Rx Output: :figure Tx2d, Rx2d Edited Feb 17th, 2016 @author: dominiquef """ from SimPEG import np def stn_id(v0,v1,r): """ Compute station ID along line """ dl = int(v0.dot(v1)) * r return dl srcLists = [] srcMat = getSrc_locs(DCsurvey) # Find all unique line id uniqueID = np.unique(lineID) for jj in range(len(uniqueID)): indx = np.where(lineID==uniqueID[jj])[0] # Find origin of survey r = 1e+8 # Initialize to some large number Tx = srcMat[indx] x0 = Tx[0][0,0:2] # Define station zero along line vecTx, r1 = r_unit(x0,Tx[-1][1,0:2]) for ii in range(len(indx)): # Get all receivers Rx = DCsurvey.srcList[indx[ii]].rxList[0].locs nrx = Rx[0].shape[0] # Find A electrode along line vec, r = r_unit(x0,Tx[ii][0,0:2]) A = stn_id(vecTx,vec,r) # Find B electrode along line vec, r = r_unit(x0,Tx[ii][1,0:2]) B = stn_id(vecTx,vec,r) M = np.zeros(nrx) N = np.zeros(nrx) for kk in range(nrx): # Find all M electrodes along line vec, r = r_unit(x0,Rx[0][kk,0:2]) M[kk] = stn_id(vecTx,vec,r) # Find all N electrodes along line vec, r = r_unit(x0,Rx[1][kk,0:2]) N[kk] = stn_id(vecTx,vec,r) Rx = DC.RxDipole(np.c_[M,np.zeros(nrx),Rx[0][:,2]],np.c_[N,np.zeros(nrx),Rx[1][:,2]]) srcLists.append( DC.SrcDipole( [Rx], np.asarray([A,0,Tx[ii][0,2]]),np.asarray([B,0,Tx[ii][1,2]]) ) ) DCsurvey2D = DC.SurveyDC(srcLists) DCsurvey2D.dobs = np.asarray(DCsurvey.dobs) DCsurvey2D.std = np.asarray(DCsurvey.std) return DCsurvey2D
def gen_DCIPsurvey(endl, mesh, stype, a, b, n): """ Load in endpoints and survey specifications to generate Tx, Rx location stations. Assumes flat topo for now... Input: :param endl -> input endpoints [x1, y1, z1, x2, y2, z2] :object mesh -> SimPEG mesh object :switch stype -> "dpdp" (dipole-dipole) | "pdp" (pole-dipole) | 'gradient' : param a, n -> pole seperation, number of rx dipoles per tx Output: :param Tx, Rx -> List objects for each tx location Lines: P1x, P1y, P1z, P2x, P2y, P2z Created on Wed December 9th, 2015 @author: dominiquef !! Require clean up to deal with DCsurvey """ from SimPEG import np def xy_2_r(x1,x2,y1,y2): r = np.sqrt( np.sum((x2 - x1)**2 + (y2 - y1)**2) ) return r ## Evenly distribute electrodes and put on surface # Mesure survey length and direction dl_len = xy_2_r(endl[0,0],endl[1,0],endl[0,1],endl[1,1]) dl_x = ( endl[1,0] - endl[0,0] ) / dl_len dl_y = ( endl[1,1] - endl[0,1] ) / dl_len nstn = np.floor( dl_len / a ) # Compute discrete pole location along line stn_x = endl[0,0] + np.array(range(int(nstn)))*dl_x*a stn_y = endl[0,1] + np.array(range(int(nstn)))*dl_y*a # Create line of P1 locations M = np.c_[stn_x, stn_y, np.ones(nstn).T*mesh.vectorNz[-1]] # Create line of P2 locations N = np.c_[stn_x+a*dl_x, stn_y+a*dl_y, np.ones(nstn).T*mesh.vectorNz[-1]] ## Build list of Tx-Rx locations depending on survey type # Dipole-dipole: Moving tx with [a] spacing -> [AB a MN1 a MN2 ... a MNn] # Pole-dipole: Moving pole on one end -> [A a MN1 a MN2 ... MNn a B] Tx = [] Rx = [] SrcList = [] if stype != 'gradient': for ii in range(0, int(nstn)-1): if stype == 'dpdp': tx = np.c_[M[ii,:],N[ii,:]] elif stype == 'pdp': tx = np.c_[M[ii,:],M[ii,:]] # Rx.append(np.c_[M[ii+1:indx,:],N[ii+1:indx,:]]) # Current elctrode seperation AB = xy_2_r(tx[0,1],endl[1,0],tx[1,1],endl[1,1]) # Number of receivers to fit nstn = np.min([np.floor( (AB - b) / a ) , n]) # Check if there is enough space, else break the loop if nstn <= 0: continue # Compute discrete pole location along line stn_x = N[ii,0] + dl_x*b + np.array(range(int(nstn)))*dl_x*a stn_y = N[ii,1] + dl_y*b + np.array(range(int(nstn)))*dl_y*a # Create receiver poles # Create line of P1 locations P1 = np.c_[stn_x, stn_y, np.ones(nstn).T*mesh.vectorNz[-1]] # Create line of P2 locations P2 = np.c_[stn_x+a*dl_x, stn_y+a*dl_y, np.ones(nstn).T*mesh.vectorNz[-1]] Rx.append(np.c_[P1,P2]) rxClass = DC.RxDipole(P1, P2) Tx.append(tx) if stype == 'dpdp': srcClass = DC.SrcDipole([rxClass], M[ii,:],N[ii,:]) elif stype == 'pdp': srcClass = DC.SrcDipole([rxClass], M[ii,:],M[ii,:]) SrcList.append(srcClass) #============================================================================== # elif re.match(stype,'dpdp'): # # for ii in range(0, int(nstn)-2): # # indx = np.min([ii+n+1,nstn]) # Tx.append(np.c_[M[ii,:],N[ii,:]]) # Rx.append(np.c_[M[ii+2:indx,:],N[ii+2:indx,:]]) #============================================================================== elif stype == 'gradient': # Gradient survey only requires Tx at end of line and creates a square # grid of receivers at in the middle at a pre-set minimum distance Tx.append(np.c_[M[0,:],N[-1,:]]) # Get the edge limit of survey area min_x = endl[0,0] + dl_x * b min_y = endl[0,1] + dl_y * b max_x = endl[1,0] - dl_x * b max_y = endl[1,1] - dl_y * b box_l = np.sqrt( (min_x - max_x)**2 + (min_y - max_y)**2 ) box_w = box_l/2. nstn = np.floor( box_l / a ) # Compute discrete pole location along line stn_x = min_x + np.array(range(int(nstn)))*dl_x*a stn_y = min_y + np.array(range(int(nstn)))*dl_y*a # Define number of cross lines nlin = int(np.floor( box_w / a )) lind = range(-nlin,nlin+1) ngrad = nstn * len(lind) rx = np.zeros([ngrad,6]) for ii in range( len(lind) ): # Move line in perpendicular direction by dipole spacing lxx = stn_x - lind[ii]*a*dl_y lyy = stn_y + lind[ii]*a*dl_x M = np.c_[ lxx, lyy , np.ones(nstn).T*mesh.vectorNz[-1]] N = np.c_[ lxx+a*dl_x, lyy+a*dl_y, np.ones(nstn).T*mesh.vectorNz[-1]] rx[(ii*nstn):((ii+1)*nstn),:] = np.c_[M,N] Rx.append(rx) rxClass = DC.RxDipole(rx[:,:3], rx[:,3:]) srcClass = DC.SrcDipole([rxClass], M[0,:], N[-1,:]) SrcList.append(srcClass) else: print """stype must be either 'pdp', 'dpdp' or 'gradient'. """ survey = DC.SurveyDC(SrcList) return survey, Tx, Rx
def readUBC_DC2Dpre(fileName): """ Read UBC GIF DCIP 2D observation file and generate arrays for tx-rx location Input: :param fileName, path to the UBC GIF 3D obs file Output: DCsurvey :return Created on Mon March 9th, 2016 << Doug's 70th Birthday !! >> @author: dominiquef """ # Load file obsfile = np.genfromtxt(fileName,delimiter=' \n',dtype=np.str,comments='!') # Pre-allocate srcLists = [] Rx = [] d = [] zflag = True # Flag for z value provided for ii in range(obsfile.shape[0]): if not obsfile[ii]: continue # First line is transmitter with number of receivers temp = (np.fromstring(obsfile[ii], dtype=float,sep=' ').T) # Check if z value is provided, if False -> nan if len(temp)==5: tx = np.r_[temp[0],np.nan,np.nan,temp[1],np.nan,np.nan] zflag = False else: tx = np.r_[temp[0],np.nan,temp[1],temp[2],np.nan,temp[3]] if zflag: rx = np.c_[temp[4],np.nan,temp[5],temp[6],np.nan,temp[7]] else: rx = np.c_[temp[2],np.nan,np.nan,temp[3],np.nan,np.nan] # Check if there is data with the location d.append(temp[-1]) Rx = DC.RxDipole(rx[:,:3],rx[:,3:]) srcLists.append( DC.SrcDipole( [Rx], tx[:3],tx[3:]) ) # Create survey class survey = DC.SurveyDC(srcLists) survey.dobs = np.asarray(d) return {'DCsurvey':survey}
def readUBC_DC3Dobs(fileName, rtype = 'DC'): """ Read UBC GIF IP 3D observation file and generate survey :param string fileName:, path to the UBC GIF 3D obs file :rtype: Survey :return: DCIPsurvey """ zflag = True # Flag for z value provided # Load file if rtype == 'IP': obsfile = np.genfromtxt(fileName,delimiter=' \n',dtype=np.str,comments='IPTYPE') elif rtype == 'DC': obsfile = np.genfromtxt(fileName,delimiter=' \n',dtype=np.str,comments='!') else: print "rtype must be 'DC'(default) | 'IP'" # Pre-allocate srcLists = [] Rx = [] d = [] wd = [] # Countdown for number of obs/tx count = 0 for ii in range(obsfile.shape[0]): # Skip if blank line if not obsfile[ii]: continue # First line or end of a transmitter block, read transmitter info if count==0: # Read the line temp = (np.fromstring(obsfile[ii], dtype=float, sep=' ').T) count = int(temp[-1]) # Check if z value is provided, if False -> nan if len(temp)==5: tx = np.r_[temp[0:2],np.nan,temp[2:4],np.nan] zflag = False # Pass on the flag to the receiver loc else: tx = temp[:-1] rx = [] continue temp = np.fromstring(obsfile[ii], dtype=float,sep=' ') # Get the string # Filter out negative IP # if temp[-2] < 0: # count = count -1 # print "Negative!" # # else: # If the Z-location is provided, otherwise put nan if zflag: rx.append(temp[:-2]) # Check if there is data with the location if len(temp)==8: d.append(temp[-2]) wd.append(temp[-1]) else: rx.append(np.r_[temp[0:2],np.nan,temp[2:4],np.nan] ) # Check if there is data with the location if len(temp)==6: d.append(temp[-2]) wd.append(temp[-1]) count = count -1 # Reach the end of transmitter block, append the src, rx and continue if count == 0: rx = np.asarray(rx) Rx = DC.RxDipole(rx[:,:3],rx[:,3:]) srcLists.append( DC.SrcDipole( [Rx], tx[:3],tx[3:]) ) # Create survey class survey = DC.SurveyDC(srcLists) survey.dobs = np.asarray(d) survey.std = np.asarray(wd) return {'DCsurvey':survey}
def convertObs_DC3D_to_2D(DCsurvey,lineID, flag = 'local'): """ Read DC survey and projects the coordinate system according to the flag = 'Xloc' | 'Yloc' | 'local' (default) In the 'local' system, station coordinates are referenced to distance from the first srcLoc[0].loc[0] The Z value is preserved, but Y coordinates zeroed. Input: :param survey3D Output: :figure survey2D Edited April 6th, 2016 @author: dominiquef """ from SimPEG import np def stn_id(v0,v1,r): """ Compute station ID along line """ dl = int(v0.dot(v1)) * r return dl srcLists = [] srcMat = getSrc_locs(DCsurvey) # Find all unique line id uniqueID = np.unique(lineID) for jj in range(len(uniqueID)): indx = np.where(lineID==uniqueID[jj])[0] # Find origin of survey r = 1e+8 # Initialize to some large number Tx = srcMat[indx] x0 = Tx[0][0,0:2] # Define station zero along line vecTx, r1 = r_unit(x0,Tx[-1][1,0:2]) for ii in range(len(indx)): # Get all receivers Rx = DCsurvey.srcList[indx[ii]].rxList[0].locs nrx = Rx[0].shape[0] if flag == 'local': # Find A electrode along line vec, r = r_unit(x0,Tx[ii][0,0:2]) A = stn_id(vecTx,vec,r) # Find B electrode along line vec, r = r_unit(x0,Tx[ii][1,0:2]) B = stn_id(vecTx,vec,r) M = np.zeros(nrx) N = np.zeros(nrx) for kk in range(nrx): # Find all M electrodes along line vec, r = r_unit(x0,Rx[0][kk,0:2]) M[kk] = stn_id(vecTx,vec,r) # Find all N electrodes along line vec, r = r_unit(x0,Rx[1][kk,0:2]) N[kk] = stn_id(vecTx,vec,r) elif flag == 'Yloc': """ Flip the XY axis locs""" A = Tx[ii][0,1] B = Tx[ii][1,1] M = Rx[0][:,1] N = Rx[1][:,1] elif flag == 'Xloc': """ Copy the rx-tx locs""" A = Tx[ii][0,0] B = Tx[ii][1,0] M = Rx[0][:,0] N = Rx[1][:,0] Rx = DC.RxDipole(np.c_[M,np.zeros(nrx),Rx[0][:,2]],np.c_[N,np.zeros(nrx),Rx[1][:,2]]) srcLists.append( DC.SrcDipole( [Rx], np.asarray([A,0,Tx[ii][0,2]]),np.asarray([B,0,Tx[ii][1,2]]) ) ) DCsurvey2D = DC.SurveyDC(srcLists) DCsurvey2D.dobs = np.asarray(DCsurvey.dobs) DCsurvey2D.std = np.asarray(DCsurvey.std) return DCsurvey2D