def toRecArray(self,returnType='RealImag'): ''' Function that returns a numpy.recarray for a SimpegMT impedance data object. :param str returnType: Switches between returning a rec array where the impedance is split to real and imaginary ('RealImag') or is a complex ('Complex') ''' # Define the record fields dtRI = [('freq',float),('x',float),('y',float),('z',float),('zxxr',float),('zxxi',float),('zxyr',float),('zxyi',float), ('zyxr',float),('zyxi',float),('zyyr',float),('zyyi',float),('tzxr',float),('tzxi',float),('tzyr',float),('tzyi',float)] dtCP = [('freq',float),('x',float),('y',float),('z',float),('zxx',complex),('zxy',complex),('zyx',complex),('zyy',complex),('tzx',complex),('tzy',complex)] impList = ['zxxr','zxxi','zxyr','zxyi','zyxr','zyxi','zyyr','zyyi'] for src in self.survey.srcList: # Temp array for all the receivers of the source. # Note: needs to be written more generally, using diffterent rxTypes and not all the data at the locaitons # Assume the same locs for all RX locs = src.rxList[0].locs if locs.shape[1] == 1: locs = np.hstack((np.array([[0.0,0.0]]),locs)) elif locs.shape[1] == 2: locs = np.hstack((np.array([[0.0]]),locs)) tArrRec = np.concatenate((src.freq*np.ones((locs.shape[0],1)),locs,np.nan*np.ones((locs.shape[0],12))),axis=1).view(dtRI) # np.array([(src.freq,rx.locs[0,0],rx.locs[0,1],rx.locs[0,2],np.nan ,np.nan ,np.nan ,np.nan ,np.nan ,np.nan ,np.nan ,np.nan ) for rx in src.rxList],dtype=dtRI) # Get the type and the value for the DataMT object as a list typeList = [[rx.rxType.replace('z1d','zyx'),self[src,rx]] for rx in src.rxList] # Insert the values to the temp array for nr,(key,val) in enumerate(typeList): tArrRec[key] = mkvc(val,2) # Masked array mArrRec = np.ma.MaskedArray(rec2ndarr(tArrRec),mask=np.isnan(rec2ndarr(tArrRec))).view(dtype=tArrRec.dtype) # Unique freq and loc of the masked array uniFLmarr = np.unique(mArrRec[['freq','x','y','z']]).copy() try: outTemp = recFunc.stack_arrays((outTemp,mArrRec)) #outTemp = np.concatenate((outTemp,dataBlock),axis=0) except NameError as e: outTemp = mArrRec if 'RealImag' in returnType: outArr = outTemp elif 'Complex' in returnType: # Add the real and imaginary to a complex number outArr = np.empty(outTemp.shape,dtype=dtCP) for comp in ['freq','x','y','z']: outArr[comp] = outTemp[comp].copy() for comp in ['zxx','zxy','zyx','zyy','tzx','tzy']: outArr[comp] = outTemp[comp+'r'].copy() + 1j*outTemp[comp+'i'].copy() else: raise NotImplementedError('{:s} is not implemented, as to be RealImag or Complex.') # Return return outArr
def fromRecArray(cls, recArray, srcType='primary'): """ Class method that reads in a numpy record array to MTdata object. Only imports the impedance data. """ if srcType == 'primary': src = simpegMT.SurveyMT.srcMT_polxy_1Dprimary elif srcType == 'total': src = sdsimpegMT.SurveyMT.srcMT_polxy_1DhomotD else: raise NotImplementedError( '{:s} is not a valid source type for MTdata') # Find all the frequencies in recArray uniFreq = np.unique(recArray['freq']) srcList = [] dataList = [] for freq in uniFreq: # Initiate rxList rxList = [] # Find that data for freq dFreq = recArray[recArray['freq'] == freq].copy() # Find the impedance rxTypes in the recArray. rxTypes = [ comp for comp in recArray.dtype.names if (len(comp) == 4 or len(comp) == 3) and 'z' in comp ] for rxType in rxTypes: # Find index of not nan values in rxType notNaNind = ~np.isnan(dFreq[rxType]) if np.any( notNaNind): # Make sure that there is any data to add. locs = rec2ndarr(dFreq[['x', 'y', 'z']][notNaNind].copy()) if dFreq[rxType].dtype.name in 'complex128': rxList.append( simpegMT.SurveyMT.RxMT(locs, rxType + 'r')) dataList.append(dFreq[rxType][notNaNind].real.copy()) rxList.append( simpegMT.SurveyMT.RxMT(locs, rxType + 'i')) dataList.append(dFreq[rxType][notNaNind].imag.copy()) else: rxList.append(simpegMT.SurveyMT.RxMT(locs, rxType)) dataList.append(dFreq[rxType][notNaNind].copy()) srcList.append(src(rxList, freq)) # Make a survey survey = simpegMT.SurveyMT.SurveyMT(srcList) dataVec = np.hstack(dataList) return cls(survey, dataVec)
def fromRecArray(cls, recArray, srcType='primary'): """ Class method that reads in a numpy record array to MTdata object. Only imports the impedance data. """ if srcType=='primary': src = SrcMT.polxy_1Dprimary elif srcType=='total': src = SrcMT.polxy_1DhomotD else: raise NotImplementedError('{:s} is not a valid source type for MTdata') # Find all the frequencies in recArray uniFreq = np.unique(recArray['freq']) srcList = [] dataList = [] for freq in uniFreq: # Initiate rxList rxList = [] # Find that data for freq dFreq = recArray[recArray['freq'] == freq].copy() # Find the impedance rxTypes in the recArray. rxTypes = [ comp for comp in recArray.dtype.names if (len(comp)==4 or len(comp)==3) and 'z' in comp] for rxType in rxTypes: # Find index of not nan values in rxType notNaNind = ~np.isnan(dFreq[rxType]) if np.any(notNaNind): # Make sure that there is any data to add. locs = rec2ndarr(dFreq[['x','y','z']][notNaNind].copy()) if dFreq[rxType].dtype.name in 'complex128': rxList.append(Rx(locs,rxType+'r')) dataList.append(dFreq[rxType][notNaNind].real.copy()) rxList.append(Rx(locs,rxType+'i')) dataList.append(dFreq[rxType][notNaNind].imag.copy()) else: rxList.append(Rx(locs,rxType)) dataList.append(dFreq[rxType][notNaNind].copy()) srcList.append(src(rxList,freq)) # Make a survey survey = Survey(srcList) dataVec = np.hstack(dataList) return cls(survey,dataVec)
def getUniqueTimes(self): time_rx = [] for src in self.srcList: for rx in src.rxList: time_rx.append(rx.times) self.times = np.unique(np.hstack(time_rx))
# Assign Z-value from topo for ii in range(IPsurvey.nSrc): IPsurvey.srcList[ii].loc[0][2] = Ftopo(IPsurvey.srcList[ii].loc[0][0:2]) IPsurvey.srcList[ii].loc[1][2] = Ftopo(IPsurvey.srcList[ii].loc[1][0:2]) rx_x = IPsurvey.srcList[ii].rxList[0].locs[0][:, 0] rx_y = IPsurvey.srcList[ii].rxList[0].locs[0][:, 1] IPsurvey.srcList[ii].rxList[0].locs[0][:, 2] = Ftopo(rx_x, rx_y) rx_x = IPsurvey.srcList[ii].rxList[0].locs[1][:, 0] rx_y = IPsurvey.srcList[ii].rxList[0].locs[1][:, 1] IPsurvey.srcList[ii].rxList[0].locs[1][:, 2] = Ftopo(rx_x, rx_y) # Assign line ID to the survey lineID = DC.xy_2_lineID(DCsurvey) uniqueID = np.unique(lineID) IPlineID = DC.xy_2_lineID(IPsurvey) # Convert 3D locations to 2D survey DCdobs2D = DC.convertObs_DC3D_to_2D(DCsurvey, lineID, 'Xloc') IPdobs2D = DC.convertObs_DC3D_to_2D(IPsurvey, IPlineID, 'Xloc') srcMat = DC.getSrc_locs(IPsurvey) #DCdata[src0, src0.rxList[0]] # Find 2D data correspondance dataID = np.zeros(DCdobs2D.nD) count = 0 for ii in range(DCdobs2D.nSrc):
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 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
plt.scatter(X, Y, c=np.reshape(d, X.shape), s=20) ax.set_title('Forward data') #%% First test, just brake the intersecting cells ii = 1 ddata = 9999. while ddata > 2.: ii += 1 indx = np.unravel_index(bc, (mesh.nCx, mesh.nCy, mesh.nCz), order='F') xbreak = np.unique(indx[0]) ybreak = np.unique(indx[1]) zbreak = np.unique(indx[2]) # Compute the new distance dl = np.sum(hxind[xbreak]) dx = float(hxind[xbreak].min() / 2) nx = dl / dx hxind = np.r_[hxind[0:xbreak.min()], np.ones(nx) * dx, hxind[xbreak.max():]] dl = np.sum(hyind[ybreak]) dy = float(hyind[ybreak].min() / 2) ny = dl / dy