diff --git a/SimPEG/Survey.py b/SimPEG/Survey.py index f2637e95..0d56145f 100644 --- a/SimPEG/Survey.py +++ b/SimPEG/Survey.py @@ -353,7 +353,10 @@ class Fields(object): else: # Aliased fields alias, loc, func = self.aliasFields[name] - out = func(self, self._fields[alias][:,ind], ind) + 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], ind) if out.shape[1] == 1: out = Utils.mkvc(out) @@ -431,16 +434,19 @@ class TimeFields(Fields): 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] pointerShape = self._correctShape(alias, ind, deflate=True) pointerFields = pointerFields.reshape(pointerShape, order='F') if len(pointerShape) < 3: - out = func(self, pointerFields, txInd) + out = func(pointerFields, txInd) else: #loop over the time steps nT = pointerShape[2] out = range(nT) for i in range(nT): - out[i] = func(self, pointerFields[:,:,i], txInd) + out[i] = func(pointerFields[:,:,i], txInd) out[i] = out[i][:,:,np.newaxis] out = np.concatenate(out, axis=2) diff --git a/SimPEG/Tests/test_Survey.py b/SimPEG/Tests/test_Survey.py index 53a252be..df476ebb 100644 --- a/SimPEG/Tests/test_Survey.py +++ b/SimPEG/Tests/test_Survey.py @@ -133,7 +133,7 @@ class FieldsTest_Alias(unittest.TestCase): txList = [Tx0,Tx1,Tx2,Tx3,Tx4] survey = Survey.BaseSurvey(txList=txList) self.D = Survey.Data(survey) - self.F = Survey.Fields(mesh, survey, knownFields={'e':'E'}, aliasFields={'b':['e','F',(lambda F, e, ind: F.mesh.edgeCurl * e)]}) + self.F = Survey.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.mesh = mesh @@ -287,8 +287,8 @@ class FieldsTest_Time_Aliased(unittest.TestCase): survey = Survey.BaseSurvey(txList=txList) prob = Problem.BaseTimeProblem(mesh, timeSteps=[(10.,3), (20.,2)]) survey.pair(prob) - def alias(F, b, ind): - return F.mesh.edgeCurl.T * b + def alias(b, ind): + return self.F.mesh.edgeCurl.T * b self.F = Survey.TimeFields(mesh, survey, knownFields={'b':'F'}, aliasFields={'e':['b','E',alias]}) self.Tx0 = Tx0 self.Tx1 = Tx1