From f7c13d917ee34f2a82831f106fd62f766f9e3bdc Mon Sep 17 00:00:00 2001 From: Lindsey Date: Fri, 17 Apr 2015 15:38:27 -0700 Subject: [PATCH] Tx -> Src --- SimPEG/Problem.py | 92 ++++++------- SimPEG/Survey.py | 96 +++++++------- SimPEG/Tests/test_Survey.py | 256 ++++++++++++++++++------------------ 3 files changed, 223 insertions(+), 221 deletions(-) diff --git a/SimPEG/Problem.py b/SimPEG/Problem.py index a4251a8f..29fcde34 100644 --- a/SimPEG/Problem.py +++ b/SimPEG/Problem.py @@ -1,13 +1,14 @@ import Utils, Survey, Models, numpy as np, scipy.sparse as sp Solver = Utils.SolverUtils.Solver import Maps, Mesh +import copy class Fields(object): """Fancy Field Storage u[:,'phi'] = phi - print u[tx0,'phi'] + print u[src0,'phi'] """ @@ -43,14 +44,14 @@ class Fields(object): return "%e MB"%sz def _storageShape(self, loc): - nTx = self.survey.nTx + nSrc = self.survey.nSrc nP = {'CC': self.mesh.nC, 'N': self.mesh.nN, 'F': self.mesh.nF, 'E': self.mesh.nE}[loc] - return (nP, nTx) + return (nP, nSrc) def _initStore(self, name): if name in self._fields: @@ -70,17 +71,17 @@ class Fields(object): return field - def _txIndex(self, txTestList): - if type(txTestList) is slice: - ind = txTestList + def _srcIndex(self, srcTestList): + if type(srcTestList) is slice: + ind = srcTestList else: - if type(txTestList) is not list: - txTestList = [txTestList] - for txTest in txTestList: - if txTest not in self.survey.txList: + if type(srcTestList) is not list: + srcTestList = [srcTestList] + for srcTest in srcTestList: + if srcTest not in self.survey.srcList: raise KeyError('Invalid Transmitter, not in survey list.') - ind = np.in1d(self.survey.txList, txTestList) + ind = np.in1d(self.survey.srcList, srcTestList) return ind def _nameIndex(self, name, accessType): @@ -107,11 +108,11 @@ class Fields(object): if len(key) == 1: key += (None,) - assert len(key) == 2, 'must be [Tx, fieldName]' + assert len(key) == 2, 'must be [Src, fieldName]' - txTestList, name = key + srcTestList, name = key name = self._nameIndex(name, accessType) - ind = self._txIndex(txTestList) + ind = self._srcIndex(srcTestList) return ind, name def __setitem__(self, key, value): @@ -150,16 +151,16 @@ class Fields(object): # Aliased fields alias, loc, func = self.aliasFields[name] - txII = np.array(self.survey.txList)[ind] - if isinstance(txII, np.ndarray): - txII = txII.tolist() - if len(txII) == 1: - txII = txII[0] + srcII = np.array(self.survey.srcList)[ind] + if isinstance(srcII, np.ndarray): + srcII = srcII.tolist() + if len(srcII) == 1: + srcII = srcII[0] if type(func) is str: assert hasattr(self, func), 'The alias field function is a string, but it does not exist in the Fields class.' func = getattr(self, func) - out = func(self._fields[alias][:,ind], txII) + out = func(self._fields[alias][:,ind], srcII) if out.shape[1] == 1: out = Utils.mkvc(out) @@ -175,7 +176,7 @@ class TimeFields(Fields): """Fancy Field Storage for time domain problems u[:,'phi', timeInd] = phi - print u[tx0,'phi'] + print u[src0,'phi'] """ @@ -184,9 +185,9 @@ class TimeFields(Fields): 'N': self.mesh.nN, 'F': self.mesh.nF, 'E': self.mesh.nE}[loc] - nTx = self.survey.nTx + nSrc = self.survey.nSrc nT = self.survey.prob.nT + 1 - return (nP, nTx, nT) + return (nP, nSrc, nT) def _indexAndNameFromKey(self, key, accessType): if type(key) is not tuple: @@ -196,66 +197,66 @@ class TimeFields(Fields): if len(key) == 2: key += (slice(None,None,None),) - assert len(key) == 3, 'must be [Tx, fieldName, times]' + assert len(key) == 3, 'must be [Src, fieldName, times]' - txTestList, name, timeInd = key + srcTestList, name, timeInd = key name = self._nameIndex(name, accessType) - txInd = self._txIndex(txTestList) + srcInd = self._srcIndex(srcTestList) - return (txInd, timeInd), name + return (srcInd, timeInd), name def _correctShape(self, name, ind, deflate=False): - txInd, timeInd = ind + srcInd, timeInd = ind if name in self.knownFields: loc = self.knownFields[name] else: loc = self.aliasFields[name][1] - nP, total_nTx, total_nT = self._storageShape(loc) - nTx = np.ones(total_nTx, dtype=bool)[txInd].sum() + nP, total_nSrc, total_nT = self._storageShape(loc) + nSrc = np.ones(total_nSrc, dtype=bool)[srcInd].sum() nT = np.ones(total_nT, dtype=bool)[timeInd].sum() - shape = nP, nTx, nT + shape = nP, nSrc, nT if deflate: shape = tuple([s for s in shape if s > 1]) return shape def _setField(self, field, val, name, ind): - txInd, timeInd = ind + srcInd, timeInd = ind shape = self._correctShape(name, ind) if Utils.isScalar(val): - field[:,txInd,timeInd] = val + field[:,srcInd,timeInd] = val return if val.size != np.array(shape).prod(): raise ValueError('Incorrect size for data.') - correctShape = field[:,txInd,timeInd].shape - field[:,txInd,timeInd] = val.reshape(correctShape, order='F') + correctShape = field[:,srcInd,timeInd].shape + field[:,srcInd,timeInd] = val.reshape(correctShape, order='F') def _getField(self, name, ind): - txInd, timeInd = ind + srcInd, timeInd = ind if name in self._fields: - out = self._fields[name][:,txInd,timeInd] + out = self._fields[name][:,srcInd,timeInd] else: # Aliased fields alias, loc, func = self.aliasFields[name] if type(func) is str: assert hasattr(self, func), 'The alias field function is a string, but it does not exist in the Fields class.' func = getattr(self, func) - pointerFields = self._fields[alias][:,txInd,timeInd] + pointerFields = self._fields[alias][:,srcInd,timeInd] pointerShape = self._correctShape(alias, ind) pointerFields = pointerFields.reshape(pointerShape, order='F') timeII = np.arange(self.survey.prob.nT + 1)[timeInd] - txII = np.array(self.survey.txList)[txInd] - if isinstance(txII, np.ndarray): - txII = txII.tolist() - if len(txII) == 1: - txII = txII[0] + srcII = np.array(self.survey.srcList)[srcInd] + if isinstance(srcII, np.ndarray): + srcII = srcII.tolist() + if len(srcII) == 1: + srcII = srcII[0] if timeII.size == 1: pointerShapeDeflated = self._correctShape(alias, ind, deflate=True) pointerFields = pointerFields.reshape(pointerShapeDeflated, order='F') - out = func(pointerFields, txII, timeII) + out = func(pointerFields, srcII, timeII) else: #loop over the time steps nT = pointerShape[2] out = range(nT) @@ -263,7 +264,7 @@ class TimeFields(Fields): fieldI = pointerFields[:,:,i] if fieldI.ndim == 2 and fieldI.shape[1] == 1: fieldI = Utils.mkvc(fieldI) - out[i] = func(fieldI, txII, TIND_i) + out[i] = func(fieldI, srcII, TIND_i) if out[i].ndim == 1: out[i] = out[i][:,np.newaxis,np.newaxis] elif out[i].ndim == 2: @@ -321,6 +322,7 @@ class BaseProblem(object): self.survey._prob = None self._survey = None + deleteTheseOnModelUpdate = [] # List of strings, e.g. ['_MeSigma', '_MeSigmaI'] @property diff --git a/SimPEG/Survey.py b/SimPEG/Survey.py index e72b7d22..e2b30faa 100644 --- a/SimPEG/Survey.py +++ b/SimPEG/Survey.py @@ -6,7 +6,7 @@ class BaseRx(object): locs = None #: Locations (nRx x nDim) - knownRxTypes = None #: Set this to a list of strings to ensure that txType is known + knownRxTypes = None #: Set this to a list of strings to ensure that srcType is known projGLoc = 'CC' #: Projection grid location, default is CC @@ -111,37 +111,37 @@ class BaseTimeRx(BaseRx): return P -class BaseTx(object): - """SimPEG Transmitter Object""" +class BaseSrc(object): + """SimPEG Source Object""" loc = None #: Location [x,y,z] rxList = None #: SimPEG Receiver List rxPair = BaseRx - knownTxTypes = None #: Set this to a list of strings to ensure that txType is known + knownSrcTypes = None #: Set this to a list of strings to ensure that srcType is known - def __init__(self, loc, txType, rxList, **kwargs): + def __init__(self, loc, srcType, rxList, **kwargs): assert type(rxList) is list, 'rxList must be a list' for rx in rxList: assert isinstance(rx, self.rxPair), 'rxList must be a %s'%self.rxPair.__name__ assert len(set(rxList)) == len(rxList), 'The rxList must be unique' self.loc = loc - self.txType = txType + self.srcType = srcType self.rxList = rxList Utils.setKwargs(self, **kwargs) @property - def txType(self): - """Transmitter Type""" - return getattr(self, '_txType', None) - @txType.setter - def txType(self, value): - known = self.knownTxTypes + def srcType(self): + """Source Type""" + return getattr(self, '_srcType', None) + @srcType.setter + def srcType(self, value): + known = self.knownSrcTypes if known is not None: - assert value in known, "txType must be in ['%s']" % ("', '".join(known)) - self._txType = value + assert value in known, "srcType must be in ['%s']" % ("', '".join(known)) + self._srcType = value @property def nD(self): @@ -155,59 +155,59 @@ class BaseTx(object): class Data(object): - """Fancy data storage by Tx and Rx""" + """Fancy data storage by Src and Rx""" def __init__(self, survey, v=None): self.survey = survey self._dataDict = {} - for tx in self.survey.txList: - self._dataDict[tx] = {} + for src in self.survey.srcList: + self._dataDict[src] = {} if v is not None: self.fromvec(v) def _ensureCorrectKey(self, key): if type(key) is tuple: if len(key) is not 2: - raise KeyError('Key must be [Tx, Rx]') - if key[0] not in self.survey.txList: - raise KeyError('Tx Key must be a transmitter in the survey.') + raise KeyError('Key must be [Src, Rx]') + if key[0] not in self.survey.srcList: + raise KeyError('Src Key must be a transmitter in the survey.') if key[1] not in key[0].rxList: raise KeyError('Rx Key must be a receiver for the transmitter.') return key - elif isinstance(key, self.survey.txPair): - if key not in self.survey.txList: + elif isinstance(key, self.survey.srcPair): + if key not in self.survey.srcList: raise KeyError('Key must be a transmitter in the survey.') return key, None else: - raise KeyError('Key must be [Tx] or [Tx,Rx]') + raise KeyError('Key must be [Src] or [Src,Rx]') def __setitem__(self, key, value): - tx, rx = self._ensureCorrectKey(key) - assert rx is not None, 'set data using [Tx, Rx]' + src, rx = self._ensureCorrectKey(key) + assert rx is not None, 'set data using [Src, Rx]' assert isinstance(value, np.ndarray), 'value must by ndarray' assert value.size == rx.nD, "value must have the same number of data as the transmitter." - self._dataDict[tx][rx] = Utils.mkvc(value) + self._dataDict[src][rx] = Utils.mkvc(value) def __getitem__(self, key): - tx, rx = self._ensureCorrectKey(key) + src, rx = self._ensureCorrectKey(key) if rx is not None: - if rx not in self._dataDict[tx]: + if rx not in self._dataDict[src]: raise Exception('Data for receiver has not yet been set.') - return self._dataDict[tx][rx] + return self._dataDict[src][rx] - return np.concatenate([self[tx,rx] for rx in tx.rxList]) + return np.concatenate([self[src,rx] for rx in src.rxList]) def tovec(self): - return np.concatenate([self[tx] for tx in self.survey.txList]) + return np.concatenate([self[src] for src in self.survey.srcList]) def fromvec(self, v): v = Utils.mkvc(v) assert v.size == self.survey.nD, 'v must have the correct number of data.' indBot, indTop = 0, 0 - for tx in self.survey.txList: - for rx in tx.rxList: + for src in self.survey.srcList: + for rx in src.rxList: indTop += rx.nD - self[tx, rx] = v[indBot:indTop] + self[src, rx] = v[indBot:indTop] indBot += rx.nD @@ -226,19 +226,19 @@ class BaseSurvey(object): def __init__(self, **kwargs): Utils.setKwargs(self, **kwargs) - txPair = BaseTx #: Transmitter Pair + srcPair = BaseSrc #: Source Pair @property - def txList(self): - """Transmitter List""" - return getattr(self, '_txList', None) + def srcList(self): + """Source List""" + return getattr(self, '_srcList', None) - @txList.setter - def txList(self, value): - assert type(value) is list, 'txList must be a list' - assert np.all([isinstance(tx, self.txPair) for tx in value]), 'All transmitters must be instances of %s' % self.txPair.__name__ - assert len(set(value)) == len(value), 'The txList must be unique' - self._txList = value + @srcList.setter + def srcList(self, value): + assert type(value) is list, 'srcList must be a list' + assert np.all([isinstance(src, self.srcPair) for src in value]), 'All transmitters must be instances of %s' % self.srcPair.__name__ + assert len(set(value)) == len(value), 'The srcList must be unique' + self._srcList = value @property def prob(self): @@ -282,12 +282,12 @@ class BaseSurvey(object): @property def vnD(self): """Vector number of data""" - return np.array([tx.nD for tx in self.txList]) + return np.array([src.nD for src in self.srcList]) @property - def nTx(self): - """Number of Transmitters""" - return len(self.txList) + def nSrc(self): + """Number of Sources""" + return len(self.srcList) @Utils.count @Utils.requires('prob') diff --git a/SimPEG/Tests/test_Survey.py b/SimPEG/Tests/test_Survey.py index 5a5b8fc2..f93395ce 100644 --- a/SimPEG/Tests/test_Survey.py +++ b/SimPEG/Tests/test_Survey.py @@ -7,22 +7,22 @@ class DataAndFieldsTest(unittest.TestCase): mesh = Mesh.TensorMesh([np.ones(n)*5 for n in [10,11,12]],[0,0,-30]) x = np.linspace(5,10,3) XYZ = Utils.ndgrid(x,x,np.r_[0.]) - txLoc = np.r_[0,0,0.] + srcLoc = np.r_[0,0,0.] rxList0 = Survey.BaseRx(XYZ, 'exi') - Tx0 = Survey.BaseTx(txLoc, 'VMD', [rxList0]) + Src0 = Survey.BaseSrc(srcLoc, 'VMD', [rxList0]) rxList1 = Survey.BaseRx(XYZ, 'bxi') - Tx1 = Survey.BaseTx(txLoc, 'VMD', [rxList1]) + Src1 = Survey.BaseSrc(srcLoc, 'VMD', [rxList1]) rxList2 = Survey.BaseRx(XYZ, 'bxi') - Tx2 = Survey.BaseTx(txLoc, 'VMD', [rxList2]) + Src2 = Survey.BaseSrc(srcLoc, 'VMD', [rxList2]) rxList3 = Survey.BaseRx(XYZ, 'bxi') - Tx3 = Survey.BaseTx(txLoc, 'VMD', [rxList3]) - Tx4 = Survey.BaseTx(txLoc, 'VMD', [rxList0, rxList1, rxList2, rxList3]) - txList = [Tx0,Tx1,Tx2,Tx3,Tx4] - survey = Survey.BaseSurvey(txList=txList) + Src3 = Survey.BaseSrc(srcLoc, 'VMD', [rxList3]) + Src4 = Survey.BaseSrc(srcLoc, 'VMD', [rxList0, rxList1, rxList2, rxList3]) + srcList = [Src0,Src1,Src2,Src3,Src4] + survey = Survey.BaseSurvey(srcList=srcList) self.D = Survey.Data(survey) self.F = Problem.Fields(mesh, survey, knownFields={'phi':'CC','e':'E','b':'F'}, dtype={"phi":float,"e":complex,"b":complex}) - self.Tx0 = Tx0 - self.Tx1 = Tx1 + self.Src0 = Src0 + self.Src1 = Src1 self.mesh = mesh self.XYZ = XYZ @@ -33,12 +33,12 @@ class DataAndFieldsTest(unittest.TestCase): def test_data(self): V = [] - for tx in self.D.survey.txList: - for rx in tx.rxList: + for src in self.D.survey.srcList: + for rx in src.rxList: v = np.random.rand(rx.nD) V += [v] - self.D[tx, rx] = v - self.assertTrue(np.all(v == self.D[tx, rx])) + self.D[src, rx] = v + self.assertTrue(np.all(v == self.D[src, rx])) V = np.concatenate(V) self.assertTrue(np.all(V == Utils.mkvc(self.D))) @@ -47,25 +47,25 @@ class DataAndFieldsTest(unittest.TestCase): def test_contains(self): F = self.F - nTx = F.survey.nTx + nSrc = F.survey.nSrc self.assertTrue('b' not in F) self.assertTrue('e' not in F) - e = np.random.rand(F.mesh.nE, nTx) + e = np.random.rand(F.mesh.nE, nSrc) F[:, 'e'] = e self.assertTrue('b' not in F) self.assertTrue('e' in F) - def test_uniqueTxs(self): - txs = self.D.survey.txList - txs += [txs[0]] - self.assertRaises(AssertionError, Survey.BaseSurvey, txList=txs) + def test_uniqueSrcs(self): + srcs = self.D.survey.srcList + srcs += [srcs[0]] + self.assertRaises(AssertionError, Survey.BaseSurvey, srcList=srcs) def test_SetGet(self): F = self.F - nTx = F.survey.nTx - e = np.random.rand(F.mesh.nE, nTx) + np.random.rand(F.mesh.nE, nTx)*1j + nSrc = F.survey.nSrc + e = np.random.rand(F.mesh.nE, nSrc) + np.random.rand(F.mesh.nE, nSrc)*1j F[:, 'e'] = e - b = np.random.rand(F.mesh.nF, nTx) + np.random.rand(F.mesh.nF, nTx)*1j + b = np.random.rand(F.mesh.nF, nSrc) + np.random.rand(F.mesh.nF, nSrc)*1j F[:, 'b'] = b self.assertTrue(np.all(F[:, 'e'] == e)) @@ -79,31 +79,31 @@ class DataAndFieldsTest(unittest.TestCase): self.assertTrue(np.all(F[:, 'b'] == b*0)) b = np.random.rand(F.mesh.nF,1) - F[self.Tx0, 'b'] = b - self.assertTrue(np.all(F[self.Tx0, 'b'] == Utils.mkvc(b))) + F[self.Src0, 'b'] = b + self.assertTrue(np.all(F[self.Src0, 'b'] == Utils.mkvc(b))) b = np.random.rand(F.mesh.nF) - F[self.Tx0, 'b'] = b - self.assertTrue(np.all(F[self.Tx0, 'b'] == b)) + F[self.Src0, 'b'] = b + self.assertTrue(np.all(F[self.Src0, 'b'] == b)) phi = np.random.rand(F.mesh.nC,2) - F[[self.Tx0,self.Tx1], 'phi'] = phi - self.assertTrue(np.all(F[[self.Tx0,self.Tx1], 'phi'] == phi)) + F[[self.Src0,self.Src1], 'phi'] = phi + self.assertTrue(np.all(F[[self.Src0,self.Src1], 'phi'] == phi)) fdict = F[:,:] self.assertTrue(type(fdict) is dict) self.assertTrue(sorted([k for k in fdict]) == ['b','e','phi']) b = np.random.rand(F.mesh.nF, 2) - F[[self.Tx0, self.Tx1],'b'] = b - self.assertTrue(F[self.Tx0]['b'].shape == (F.mesh.nF,)) - self.assertTrue(F[self.Tx0,'b'].shape == (F.mesh.nF,)) - self.assertTrue(np.all(F[self.Tx0,'b'] == b[:,0])) - self.assertTrue(np.all(F[self.Tx1,'b'] == b[:,1])) + F[[self.Src0, self.Src1],'b'] = b + self.assertTrue(F[self.Src0]['b'].shape == (F.mesh.nF,)) + self.assertTrue(F[self.Src0,'b'].shape == (F.mesh.nF,)) + self.assertTrue(np.all(F[self.Src0,'b'] == b[:,0])) + self.assertTrue(np.all(F[self.Src1,'b'] == b[:,1])) def test_assertions(self): - freq = [self.Tx0, self.Tx1] - bWrongSize = np.random.rand(self.F.mesh.nE, self.F.survey.nTx) + freq = [self.Src0, self.Src1] + bWrongSize = np.random.rand(self.F.mesh.nE, self.F.survey.nSrc) def fun(): self.F[freq, 'b'] = bWrongSize self.assertRaises(ValueError, fun) def fun(): self.F[-999.] @@ -120,69 +120,69 @@ class FieldsTest_Alias(unittest.TestCase): mesh = Mesh.TensorMesh([np.ones(n)*5 for n in [10,11,12]],[0,0,-30]) x = np.linspace(5,10,3) XYZ = Utils.ndgrid(x,x,np.r_[0.]) - txLoc = np.r_[0,0,0.] + srcLoc = np.r_[0,0,0.] rxList0 = Survey.BaseRx(XYZ, 'exi') - Tx0 = Survey.BaseTx(txLoc, 'VMD', [rxList0]) + Src0 = Survey.BaseSrc(srcLoc, 'VMD', [rxList0]) rxList1 = Survey.BaseRx(XYZ, 'bxi') - Tx1 = Survey.BaseTx(txLoc, 'VMD', [rxList1]) + Src1 = Survey.BaseSrc(srcLoc, 'VMD', [rxList1]) rxList2 = Survey.BaseRx(XYZ, 'bxi') - Tx2 = Survey.BaseTx(txLoc, 'VMD', [rxList2]) + Src2 = Survey.BaseSrc(srcLoc, 'VMD', [rxList2]) rxList3 = Survey.BaseRx(XYZ, 'bxi') - Tx3 = Survey.BaseTx(txLoc, 'VMD', [rxList3]) - Tx4 = Survey.BaseTx(txLoc, 'VMD', [rxList0, rxList1, rxList2, rxList3]) - txList = [Tx0,Tx1,Tx2,Tx3,Tx4] - survey = Survey.BaseSurvey(txList=txList) + Src3 = Survey.BaseSrc(srcLoc, 'VMD', [rxList3]) + Src4 = Survey.BaseSrc(srcLoc, 'VMD', [rxList0, rxList1, rxList2, rxList3]) + srcList = [Src0,Src1,Src2,Src3,Src4] + survey = Survey.BaseSurvey(srcList=srcList) self.D = Survey.Data(survey) self.F = Problem.Fields(mesh, survey, knownFields={'e':'E'}, aliasFields={'b':['e','F',(lambda e, ind: self.F.mesh.edgeCurl * e)]}) - self.Tx0 = Tx0 - self.Tx1 = Tx1 + self.Src0 = Src0 + self.Src1 = Src1 self.mesh = mesh self.XYZ = XYZ def test_contains(self): F = self.F - nTx = F.survey.nTx + nSrc = F.survey.nSrc self.assertTrue('b' not in F) self.assertTrue('e' not in F) - e = np.random.rand(F.mesh.nE, nTx) + e = np.random.rand(F.mesh.nE, nSrc) F[:, 'e'] = e self.assertTrue('b' in F) self.assertTrue('e' in F) def test_simpleAlias(self): F = self.F - nTx = F.survey.nTx - e = np.random.rand(F.mesh.nE, nTx) + nSrc = F.survey.nSrc + e = np.random.rand(F.mesh.nE, nSrc) F[:, 'e'] = e self.assertTrue(np.all(F[:, 'b'] == F.mesh.edgeCurl * e )) e = np.random.rand(F.mesh.nE,1) - F[self.Tx0, 'e'] = e - self.assertTrue(np.all(F[self.Tx0, 'b'] == F.mesh.edgeCurl * Utils.mkvc(e))) + F[self.Src0, 'e'] = e + self.assertTrue(np.all(F[self.Src0, 'b'] == F.mesh.edgeCurl * Utils.mkvc(e))) def f(): - F[self.Tx0, 'b'] = F[self.Tx0, 'b'] + F[self.Src0, 'b'] = F[self.Src0, 'b'] self.assertRaises(KeyError, f) # can't set a alias attr. def test_aliasFunction(self): def alias(e, ind): - self.assertTrue(ind is self.Tx0) + self.assertTrue(ind is self.Src0) return self.F.mesh.edgeCurl * e F = Problem.Fields(self.F.mesh, self.F.survey, knownFields={'e':'E'}, aliasFields={'b':['e','F',alias]}) e = np.random.rand(F.mesh.nE,1) - F[self.Tx0, 'e'] = e - F[self.Tx0, 'b'] + F[self.Src0, 'e'] = e + F[self.Src0, 'b'] def alias(e, ind): self.assertTrue(type(ind) is list) - self.assertTrue(ind[0] is self.Tx0) - self.assertTrue(ind[1] is self.Tx1) + self.assertTrue(ind[0] is self.Src0) + self.assertTrue(ind[1] is self.Src1) return self.F.mesh.edgeCurl * e F = Problem.Fields(self.F.mesh, self.F.survey, knownFields={'e':'E'}, aliasFields={'b':['e','F',alias]}) e = np.random.rand(F.mesh.nE,2) - F[[self.Tx0, self.Tx1], 'e'] = e - F[[self.Tx0, self.Tx1], 'b'] + F[[self.Src0, self.Src1], 'e'] = e + F[[self.Src0, self.Src1], 'b'] class FieldsTest_Time(unittest.TestCase): @@ -191,34 +191,34 @@ class FieldsTest_Time(unittest.TestCase): mesh = Mesh.TensorMesh([np.ones(n)*5 for n in [10,11,12]],[0,0,-30]) x = np.linspace(5,10,3) XYZ = Utils.ndgrid(x,x,np.r_[0.]) - txLoc = np.r_[0,0,0.] + srcLoc = np.r_[0,0,0.] rxList0 = Survey.BaseRx(XYZ, 'exi') - Tx0 = Survey.BaseTx(txLoc, 'VMD', [rxList0]) + Src0 = Survey.BaseSrc(srcLoc, 'VMD', [rxList0]) rxList1 = Survey.BaseRx(XYZ, 'bxi') - Tx1 = Survey.BaseTx(txLoc, 'VMD', [rxList1]) + Src1 = Survey.BaseSrc(srcLoc, 'VMD', [rxList1]) rxList2 = Survey.BaseRx(XYZ, 'bxi') - Tx2 = Survey.BaseTx(txLoc, 'VMD', [rxList2]) + Src2 = Survey.BaseSrc(srcLoc, 'VMD', [rxList2]) rxList3 = Survey.BaseRx(XYZ, 'bxi') - Tx3 = Survey.BaseTx(txLoc, 'VMD', [rxList3]) - Tx4 = Survey.BaseTx(txLoc, 'VMD', [rxList0, rxList1, rxList2, rxList3]) - txList = [Tx0,Tx1,Tx2,Tx3,Tx4] - survey = Survey.BaseSurvey(txList=txList) + Src3 = Survey.BaseSrc(srcLoc, 'VMD', [rxList3]) + Src4 = Survey.BaseSrc(srcLoc, 'VMD', [rxList0, rxList1, rxList2, rxList3]) + srcList = [Src0,Src1,Src2,Src3,Src4] + survey = Survey.BaseSurvey(srcList=srcList) prob = Problem.BaseTimeProblem(mesh, timeSteps=[(10.,3), (20.,2)]) survey.pair(prob) self.F = Problem.TimeFields(mesh, survey, knownFields={'phi':'CC','e':'E','b':'F'}) - self.Tx0 = Tx0 - self.Tx1 = Tx1 + self.Src0 = Src0 + self.Src1 = Src1 self.mesh = mesh self.XYZ = XYZ def test_contains(self): F = self.F - nTx = F.survey.nTx + nSrc = F.survey.nSrc nT = F.survey.prob.nT + 1 self.assertTrue('b' not in F) self.assertTrue('e' not in F) self.assertTrue('phi' not in F) - e = np.random.rand(F.mesh.nE, nTx, nT) + e = np.random.rand(F.mesh.nE, nSrc, nT) F[:, 'e', :] = e self.assertTrue('e' in F) self.assertTrue('b' not in F) @@ -226,11 +226,11 @@ class FieldsTest_Time(unittest.TestCase): def test_SetGet(self): F = self.F - nTx = F.survey.nTx + nSrc = F.survey.nSrc nT = F.survey.prob.nT + 1 - e = np.random.rand(F.mesh.nE, nTx, nT) + e = np.random.rand(F.mesh.nE, nSrc, nT) F[:, 'e'] = e - b = np.random.rand(F.mesh.nF, nTx, nT) + b = np.random.rand(F.mesh.nF, nSrc, nT) F[:, 'b'] = b self.assertTrue(np.all(F[:, 'e'] == e)) @@ -244,39 +244,39 @@ class FieldsTest_Time(unittest.TestCase): self.assertTrue(np.all(F[:, 'b'] == b*0)) b = np.random.rand(F.mesh.nF,1,nT) - F[self.Tx0, 'b'] = b - self.assertTrue(np.all(F[self.Tx0, 'b'] == b[:,0,:])) + F[self.Src0, 'b'] = b + self.assertTrue(np.all(F[self.Src0, 'b'] == b[:,0,:])) b = np.random.rand(F.mesh.nF,1,nT) - F[self.Tx0, 'b', 0] = b[:,:,0] - self.assertTrue(np.all(F[self.Tx0, 'b', 0] == b[:,0,0])) + F[self.Src0, 'b', 0] = b[:,:,0] + self.assertTrue(np.all(F[self.Src0, 'b', 0] == b[:,0,0])) phi = np.random.rand(F.mesh.nC,2,nT) - F[[self.Tx0,self.Tx1], 'phi'] = phi - self.assertTrue(np.all(F[[self.Tx0,self.Tx1], 'phi'] == phi)) + F[[self.Src0,self.Src1], 'phi'] = phi + self.assertTrue(np.all(F[[self.Src0,self.Src1], 'phi'] == phi)) fdict = F[:] self.assertTrue(type(fdict) is dict) self.assertTrue(sorted([k for k in fdict]) == ['b','e','phi']) b = np.random.rand(F.mesh.nF, 2, nT) - F[[self.Tx0, self.Tx1],'b'] = b - self.assertTrue(F[self.Tx0]['b'].shape == (F.mesh.nF,nT)) - self.assertTrue(F[self.Tx0,'b'].shape == (F.mesh.nF,nT)) - self.assertTrue(np.all(F[self.Tx0,'b'] == b[:,0,:])) - self.assertTrue(np.all(F[self.Tx1,'b'] == b[:,1,:])) - self.assertTrue(np.all(F[self.Tx0,'b',1] == b[:,0,1])) - self.assertTrue(np.all(F[self.Tx1,'b',1] == b[:,1,1])) - self.assertTrue(np.all(F[self.Tx0,'b',4] == b[:,0,4])) - self.assertTrue(np.all(F[self.Tx1,'b',4] == b[:,1,4])) + F[[self.Src0, self.Src1],'b'] = b + self.assertTrue(F[self.Src0]['b'].shape == (F.mesh.nF,nT)) + self.assertTrue(F[self.Src0,'b'].shape == (F.mesh.nF,nT)) + self.assertTrue(np.all(F[self.Src0,'b'] == b[:,0,:])) + self.assertTrue(np.all(F[self.Src1,'b'] == b[:,1,:])) + self.assertTrue(np.all(F[self.Src0,'b',1] == b[:,0,1])) + self.assertTrue(np.all(F[self.Src1,'b',1] == b[:,1,1])) + self.assertTrue(np.all(F[self.Src0,'b',4] == b[:,0,4])) + self.assertTrue(np.all(F[self.Src1,'b',4] == b[:,1,4])) b = np.random.rand(F.mesh.nF, 2, nT) - F[[self.Tx0, self.Tx1],'b', 0] = b[:,:,0] + F[[self.Src0, self.Src1],'b', 0] = b[:,:,0] def test_assertions(self): - freq = [self.Tx0, self.Tx1] - bWrongSize = np.random.rand(self.F.mesh.nE, self.F.survey.nTx) + freq = [self.Src0, self.Src1] + bWrongSize = np.random.rand(self.F.mesh.nE, self.F.survey.nSrc) def fun(): self.F[freq, 'b'] = bWrongSize self.assertRaises(ValueError, fun) def fun(): self.F[-999.] @@ -293,35 +293,35 @@ class FieldsTest_Time_Aliased(unittest.TestCase): mesh = Mesh.TensorMesh([np.ones(n)*5 for n in [10,11,12]],[0,0,-30]) x = np.linspace(5,10,3) XYZ = Utils.ndgrid(x,x,np.r_[0.]) - txLoc = np.r_[0,0,0.] + srcLoc = np.r_[0,0,0.] rxList0 = Survey.BaseRx(XYZ, 'exi') - Tx0 = Survey.BaseTx(txLoc, 'VMD', [rxList0]) + Src0 = Survey.BaseSrc(srcLoc, 'VMD', [rxList0]) rxList1 = Survey.BaseRx(XYZ, 'bxi') - Tx1 = Survey.BaseTx(txLoc, 'VMD', [rxList1]) + Src1 = Survey.BaseSrc(srcLoc, 'VMD', [rxList1]) rxList2 = Survey.BaseRx(XYZ, 'bxi') - Tx2 = Survey.BaseTx(txLoc, 'VMD', [rxList2]) + Src2 = Survey.BaseSrc(srcLoc, 'VMD', [rxList2]) rxList3 = Survey.BaseRx(XYZ, 'bxi') - Tx3 = Survey.BaseTx(txLoc, 'VMD', [rxList3]) - Tx4 = Survey.BaseTx(txLoc, 'VMD', [rxList0, rxList1, rxList2, rxList3]) - txList = [Tx0,Tx1,Tx2,Tx3,Tx4] - survey = Survey.BaseSurvey(txList=txList) + Src3 = Survey.BaseSrc(srcLoc, 'VMD', [rxList3]) + Src4 = Survey.BaseSrc(srcLoc, 'VMD', [rxList0, rxList1, rxList2, rxList3]) + srcList = [Src0,Src1,Src2,Src3,Src4] + survey = Survey.BaseSurvey(srcList=srcList) prob = Problem.BaseTimeProblem(mesh, timeSteps=[(10.,3), (20.,2)]) survey.pair(prob) - def alias(b, txInd, timeInd): + def alias(b, srcInd, timeInd): return self.F.mesh.edgeCurl.T * b + timeInd self.F = Problem.TimeFields(mesh, survey, knownFields={'b':'F'}, aliasFields={'e':['b','E',alias]}) - self.Tx0 = Tx0 - self.Tx1 = Tx1 + self.Src0 = Src0 + self.Src1 = Src1 self.mesh = mesh self.XYZ = XYZ def test_contains(self): F = self.F - nTx = F.survey.nTx + nSrc = F.survey.nSrc nT = F.survey.prob.nT + 1 self.assertTrue('b' not in F) self.assertTrue('e' not in F) - b = np.random.rand(F.mesh.nF, nTx, nT) + b = np.random.rand(F.mesh.nF, nSrc, nT) F[:, 'b', :] = b self.assertTrue('e' in F) self.assertTrue('b' in F) @@ -329,9 +329,9 @@ class FieldsTest_Time_Aliased(unittest.TestCase): def test_simpleAlias(self): F = self.F - nTx = F.survey.nTx + nSrc = F.survey.nSrc nT = F.survey.prob.nT + 1 - b = np.random.rand(F.mesh.nF, nTx, nT) + b = np.random.rand(F.mesh.nF, nSrc, nT) F[:, 'b', :] = b self.assertTrue(np.all(F[:, 'e', 0] == F.mesh.edgeCurl.T * b[:,:,0] )) @@ -341,57 +341,57 @@ class FieldsTest_Time_Aliased(unittest.TestCase): e[i] = e[i][:,:,np.newaxis] e = np.concatenate(e, axis=2) self.assertTrue(np.all(F[:, 'e', :] == e )) - self.assertTrue(np.all(F[self.Tx0, 'e', :] == e[:,0,:] )) - self.assertTrue(np.all(F[self.Tx1, 'e', :] == e[:,1,:] )) + self.assertTrue(np.all(F[self.Src0, 'e', :] == e[:,0,:] )) + self.assertTrue(np.all(F[self.Src1, 'e', :] == e[:,1,:] )) for t in range(nT): - self.assertTrue(np.all(F[self.Tx1, 'e', t] == e[:,1,t] )) + self.assertTrue(np.all(F[self.Src1, 'e', t] == e[:,1,t] )) b = np.random.rand(F.mesh.nF,nT) - F[self.Tx0, 'b',:] = b + F[self.Src0, 'b',:] = b Cb = F.mesh.edgeCurl.T * b for i in range(Cb.shape[1]): Cb[:,i] += i - self.assertTrue(np.all(F[self.Tx0, 'e',:] == Cb)) + self.assertTrue(np.all(F[self.Src0, 'e',:] == Cb)) def f(): - F[self.Tx0, 'e'] = F[self.Tx0, 'e'] + F[self.Src0, 'e'] = F[self.Src0, 'e'] self.assertRaises(KeyError, f) # can't set a alias attr. def test_aliasFunction(self): nT = self.F.survey.prob.nT + 1 count = [0] - def alias(e, txInd, timeInd): + def alias(e, srcInd, timeInd): count[0] += 1 - self.assertTrue(txInd is self.Tx0) + self.assertTrue(srcInd is self.Src0) return self.F.mesh.edgeCurl * e F = Problem.TimeFields(self.F.mesh, self.F.survey, knownFields={'e':'E'}, aliasFields={'b':['e','F',alias]}) e = np.random.rand(F.mesh.nE,1,nT) - F[self.Tx0, 'e', :] = e - F[self.Tx0, 'b', :] + F[self.Src0, 'e', :] = e + F[self.Src0, 'b', :] self.assertTrue(count[0] == nT) # ensure that this is called for every time separately. e = np.random.rand(F.mesh.nE,1,1) - F[self.Tx0, 'e', 1] = e + F[self.Src0, 'e', 1] = e count[0] = 0 - F[self.Tx0, 'b', 1] + F[self.Src0, 'b', 1] self.assertTrue(count[0] == 1) # ensure that this is called only once. - def alias(e, txInd, timeInd): + def alias(e, srcInd, timeInd): count[0] += 1 - self.assertTrue(type(txInd) is list) - self.assertTrue(txInd[0] is self.Tx0) - self.assertTrue(txInd[1] is self.Tx1) + self.assertTrue(type(srcInd) is list) + self.assertTrue(srcInd[0] is self.Src0) + self.assertTrue(srcInd[1] is self.Src1) return self.F.mesh.edgeCurl * e F = Problem.TimeFields(self.F.mesh, self.F.survey, knownFields={'e':'E'}, aliasFields={'b':['e','F',alias]}) e = np.random.rand(F.mesh.nE,2, nT) - F[[self.Tx0, self.Tx1], 'e', :] = e + F[[self.Src0, self.Src1], 'e', :] = e count[0] = 0 - F[[self.Tx0, self.Tx1], 'b', :] + F[[self.Src0, self.Src1], 'b', :] self.assertTrue(count[0] == nT) # ensure that this is called for every time separately. e = np.random.rand(F.mesh.nE,2, 1) - F[[self.Tx0, self.Tx1], 'e', 1] = e + F[[self.Src0, self.Src1], 'e', 1] = e count[0] = 0 - F[[self.Tx0, self.Tx1], 'b', 1] + F[[self.Src0, self.Src1], 'b', 1] self.assertTrue(count[0] == 1) # ensure that this is called only once.