From 11e6b452c96cf419e0f36224975c7c8fdbba8a8b Mon Sep 17 00:00:00 2001 From: Lindsey Heagy Date: Tue, 10 May 2016 17:26:16 -0700 Subject: [PATCH 1/4] renamed FDEM.py to ProblemFDEM.py, changed real_or_imag to component --- SimPEG/EM/FDEM/{FDEM.py => ProblemFDEM.py} | 4 +-- SimPEG/EM/FDEM/RxFDEM.py | 40 +++++++++++----------- SimPEG/EM/FDEM/__init__.py | 2 +- SimPEG/Examples/EM_FDEM_1D_Inversion.py | 2 +- 4 files changed, 24 insertions(+), 24 deletions(-) rename SimPEG/EM/FDEM/{FDEM.py => ProblemFDEM.py} (99%) diff --git a/SimPEG/EM/FDEM/FDEM.py b/SimPEG/EM/FDEM/ProblemFDEM.py similarity index 99% rename from SimPEG/EM/FDEM/FDEM.py rename to SimPEG/EM/FDEM/ProblemFDEM.py index 026230c6..75b05bf9 100644 --- a/SimPEG/EM/FDEM/FDEM.py +++ b/SimPEG/EM/FDEM/ProblemFDEM.py @@ -137,9 +137,9 @@ class BaseFDEMProblem(BaseEMProblem): df_dmT = df_dmT + du_dmT # TODO: this should be taken care of by the reciever? - if rx.real_or_imag is 'real': + if rx.component is 'real': Jtv += np.array(df_dmT, dtype=complex).real - elif rx.real_or_imag is 'imag': + elif rx.component is 'imag': Jtv += - np.array(df_dmT, dtype=complex).real else: raise Exception('Must be real or imag') diff --git a/SimPEG/EM/FDEM/RxFDEM.py b/SimPEG/EM/FDEM/RxFDEM.py index ef58d807..f15040fb 100644 --- a/SimPEG/EM/FDEM/RxFDEM.py +++ b/SimPEG/EM/FDEM/RxFDEM.py @@ -7,15 +7,15 @@ class BaseRx(SimPEG.Survey.BaseRx): :param numpy.ndarray locs: receiver locations (ie. :code:`np.r_[x,y,z]`) :param string orientation: receiver orientation 'x', 'y' or 'z' - :param string real_or_imag: real or imaginary component 'real' or 'imag' + :param string component: real or imaginary component 'real' or 'imag' """ - def __init__(self, locs, orientation=None, real_or_imag=None): + def __init__(self, locs, orientation=None, component=None): assert(orientation in ['x','y','z']), "Orientation %s not known. Orientation must be in 'x', 'y', 'z'. Arbitrary orientations have not yet been implemented."%orientation - assert(real_or_imag in ['real', 'imag']), "'real_or_imag' must be 'real' or 'imag', not %s"%real_or_imag + assert(component in ['real', 'imag']), "'component' must be 'real' or 'imag', not %s"%component self.projComp = orientation - self.real_or_imag = real_or_imag + self.component = component SimPEG.Survey.BaseRx.__init__(self, locs, rxType=None) #TODO: remove rxType from baseRx @@ -36,7 +36,7 @@ class BaseRx(SimPEG.Survey.BaseRx): P = self.getP(mesh, self.projGLoc(f)) f_part_complex = f[src, self.projField] - f_part = getattr(f_part_complex, self.real_or_imag) # get the real or imag component + f_part = getattr(f_part_complex, self.component) # get the real or imag component return P*f_part @@ -56,13 +56,13 @@ class BaseRx(SimPEG.Survey.BaseRx): if not adjoint: Pv_complex = P * v - Pv = getattr(Pv_complex, self.real_or_imag) + Pv = getattr(Pv_complex, self.component) elif adjoint: Pv_real = P.T * v - if self.real_or_imag == 'imag': + if self.component == 'imag': Pv = 1j*Pv_real - elif self.real_or_imag == 'real': + elif self.component == 'real': Pv = Pv_real.astype(complex) else: raise NotImplementedError('must be real or imag') @@ -76,12 +76,12 @@ class eField(BaseRx): :param numpy.ndarray locs: receiver locations (ie. :code:`np.r_[x,y,z]`) :param string orientation: receiver orientation 'x', 'y' or 'z' - :param string real_or_imag: real or imaginary component 'real' or 'imag' + :param string component: real or imaginary component 'real' or 'imag' """ - def __init__(self, locs, orientation=None, real_or_imag=None): + def __init__(self, locs, orientation=None, component=None): self.projField = 'e' - BaseRx.__init__(self, locs, orientation, real_or_imag) + BaseRx.__init__(self, locs, orientation, component) class bField(BaseRx): @@ -90,12 +90,12 @@ class bField(BaseRx): :param numpy.ndarray locs: receiver locations (ie. :code:`np.r_[x,y,z]`) :param string orientation: receiver orientation 'x', 'y' or 'z' - :param string real_or_imag: real or imaginary component 'real' or 'imag' + :param string component: real or imaginary component 'real' or 'imag' """ - def __init__(self, locs, orientation=None, real_or_imag=None): + def __init__(self, locs, orientation=None, component=None): self.projField = 'b' - BaseRx.__init__(self, locs, orientation, real_or_imag) + BaseRx.__init__(self, locs, orientation, component) class hField(BaseRx): @@ -104,12 +104,12 @@ class hField(BaseRx): :param numpy.ndarray locs: receiver locations (ie. :code:`np.r_[x,y,z]`) :param string orientation: receiver orientation 'x', 'y' or 'z' - :param string real_or_imag: real or imaginary component 'real' or 'imag' + :param string component: real or imaginary component 'real' or 'imag' """ - def __init__(self, locs, orientation=None, real_or_imag=None): + def __init__(self, locs, orientation=None, component=None): self.projField = 'h' - BaseRx.__init__(self, locs, orientation, real_or_imag) + BaseRx.__init__(self, locs, orientation, component) class jField(BaseRx): @@ -118,9 +118,9 @@ class jField(BaseRx): :param numpy.ndarray locs: receiver locations (ie. :code:`np.r_[x,y,z]`) :param string orientation: receiver orientation 'x', 'y' or 'z' - :param string real_or_imag: real or imaginary component 'real' or 'imag' + :param string component: real or imaginary component 'real' or 'imag' """ - def __init__(self, locs, orientation=None, real_or_imag=None): + def __init__(self, locs, orientation=None, component=None): self.projField = 'j' - BaseRx.__init__(self, locs, orientation, real_or_imag) + BaseRx.__init__(self, locs, orientation, component) diff --git a/SimPEG/EM/FDEM/__init__.py b/SimPEG/EM/FDEM/__init__.py index 1701fe3e..c4ff6451 100644 --- a/SimPEG/EM/FDEM/__init__.py +++ b/SimPEG/EM/FDEM/__init__.py @@ -1,5 +1,5 @@ from SurveyFDEM import Survey import SrcFDEM as Src import RxFDEM as Rx -from FDEM import Problem3D_e, Problem3D_b, Problem3D_j, Problem3D_h +from ProblemFDEM import Problem3D_e, Problem3D_b, Problem3D_j, Problem3D_h from FieldsFDEM import Fields3D_e, Fields3D_b, Fields3D_j, Fields3D_h diff --git a/SimPEG/Examples/EM_FDEM_1D_Inversion.py b/SimPEG/Examples/EM_FDEM_1D_Inversion.py index 0a5c59a0..95e3f09f 100644 --- a/SimPEG/Examples/EM_FDEM_1D_Inversion.py +++ b/SimPEG/Examples/EM_FDEM_1D_Inversion.py @@ -43,7 +43,7 @@ def run(plotIt=True): rxOffset=10. - bzi = EM.FDEM.Rx.bField(np.array([[rxOffset, 0., 1e-3]]), orientation='z', real_or_imag='imag') + bzi = EM.FDEM.Rx.bField(np.array([[rxOffset, 0., 1e-3]]), orientation='z', component='imag') freqs = np.logspace(1,3,10) srcLoc = np.array([0., 0., 10.]) From c1b1c2467f737aa6462070826b4ee5277f343dc4 Mon Sep 17 00:00:00 2001 From: Lindsey Heagy Date: Tue, 10 May 2016 19:57:16 -0700 Subject: [PATCH 2/4] import from ProblemFDEM in baseMT, fixed a missed real_or_imag --> component --- SimPEG/MT/BaseMT.py | 2 +- tests/em/fdem/forward/test_FDEM_analytics.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SimPEG/MT/BaseMT.py b/SimPEG/MT/BaseMT.py index c201dfb0..579f590f 100644 --- a/SimPEG/MT/BaseMT.py +++ b/SimPEG/MT/BaseMT.py @@ -1,5 +1,5 @@ from SimPEG import SolverLU as SimpegSolver, PropMaps, Utils, mkvc, sp, np -from SimPEG.EM.FDEM.FDEM import BaseFDEMProblem +from SimPEG.EM.FDEM.ProblemFDEM import BaseFDEMProblem from SurveyMT import Survey, Data from FieldsMT import BaseMTFields diff --git a/tests/em/fdem/forward/test_FDEM_analytics.py b/tests/em/fdem/forward/test_FDEM_analytics.py index 0ea43ca7..b9de4a26 100644 --- a/tests/em/fdem/forward/test_FDEM_analytics.py +++ b/tests/em/fdem/forward/test_FDEM_analytics.py @@ -28,7 +28,7 @@ class FDEM_analyticTests(unittest.TestCase): x = np.linspace(-10,10,5) XYZ = Utils.ndgrid(x,np.r_[0],np.r_[0]) - rxList = EM.FDEM.Rx.eField(XYZ, orientation='x', real_or_imag='imag') + rxList = EM.FDEM.Rx.eField(XYZ, orientation='x', component='imag') Src0 = EM.FDEM.Src.MagDipole([rxList],loc=np.r_[0.,0.,0.], freq=freq) survey = EM.FDEM.Survey([Src0]) From a690cab13132681f7b9972f3c72547883af5c422 Mon Sep 17 00:00:00 2001 From: Lindsey Heagy Date: Wed, 11 May 2016 09:05:13 -0700 Subject: [PATCH 3/4] simple field receivers are `Point` receivers --- SimPEG/EM/FDEM/RxFDEM.py | 16 ++++++++-------- SimPEG/EM/Utils/testingUtils.py | 2 +- SimPEG/Examples/EM_FDEM_1D_Inversion.py | 2 +- tests/em/fdem/forward/test_FDEM_analytics.py | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/SimPEG/EM/FDEM/RxFDEM.py b/SimPEG/EM/FDEM/RxFDEM.py index f15040fb..53d6c722 100644 --- a/SimPEG/EM/FDEM/RxFDEM.py +++ b/SimPEG/EM/FDEM/RxFDEM.py @@ -70,7 +70,7 @@ class BaseRx(SimPEG.Survey.BaseRx): return Pv -class eField(BaseRx): +class Point_e(BaseRx): """ Electric field FDEM receiver @@ -81,10 +81,10 @@ class eField(BaseRx): def __init__(self, locs, orientation=None, component=None): self.projField = 'e' - BaseRx.__init__(self, locs, orientation, component) + super(Point_e, self).__init__(locs, orientation, component) -class bField(BaseRx): +class Point_b(BaseRx): """ Magnetic flux FDEM receiver @@ -95,10 +95,10 @@ class bField(BaseRx): def __init__(self, locs, orientation=None, component=None): self.projField = 'b' - BaseRx.__init__(self, locs, orientation, component) + super(Point_b, self).__init__(locs, orientation, component) -class hField(BaseRx): +class Point_h(BaseRx): """ Magnetic field FDEM receiver @@ -109,10 +109,10 @@ class hField(BaseRx): def __init__(self, locs, orientation=None, component=None): self.projField = 'h' - BaseRx.__init__(self, locs, orientation, component) + super(Point_h, self).__init__(locs, orientation, component) -class jField(BaseRx): +class Point_j(BaseRx): """ Current density FDEM receiver @@ -123,4 +123,4 @@ class jField(BaseRx): def __init__(self, locs, orientation=None, component=None): self.projField = 'j' - BaseRx.__init__(self, locs, orientation, component) + super(Point_j, self).__init__(locs, orientation, component) diff --git a/SimPEG/EM/Utils/testingUtils.py b/SimPEG/EM/Utils/testingUtils.py index c3fc50d2..22c925b6 100644 --- a/SimPEG/EM/Utils/testingUtils.py +++ b/SimPEG/EM/Utils/testingUtils.py @@ -26,7 +26,7 @@ def getFDEMProblem(fdemType, comp, SrcList, freq, useMu=False, verbose=False): x = np.array([np.linspace(-5.*cs,-2.*cs,3),np.linspace(5.*cs,2.*cs,3)]) + cs/4. #don't sample right by the source, slightly off alignment from either staggered grid XYZ = Utils.ndgrid(x,x,np.linspace(-2.*cs,2.*cs,5)) - Rx0 = getattr(EM.FDEM.Rx, comp[0] + 'Field') + Rx0 = getattr(EM.FDEM.Rx, 'Point_' + comp[0]) if comp[2] == 'r': real_or_imag = 'real' elif comp[2] == 'i': diff --git a/SimPEG/Examples/EM_FDEM_1D_Inversion.py b/SimPEG/Examples/EM_FDEM_1D_Inversion.py index 95e3f09f..4275903d 100644 --- a/SimPEG/Examples/EM_FDEM_1D_Inversion.py +++ b/SimPEG/Examples/EM_FDEM_1D_Inversion.py @@ -43,7 +43,7 @@ def run(plotIt=True): rxOffset=10. - bzi = EM.FDEM.Rx.bField(np.array([[rxOffset, 0., 1e-3]]), orientation='z', component='imag') + bzi = EM.FDEM.Rx.Point_b(np.array([[rxOffset, 0., 1e-3]]), orientation='z', component='imag') freqs = np.logspace(1,3,10) srcLoc = np.array([0., 0., 10.]) diff --git a/tests/em/fdem/forward/test_FDEM_analytics.py b/tests/em/fdem/forward/test_FDEM_analytics.py index b9de4a26..6f283666 100644 --- a/tests/em/fdem/forward/test_FDEM_analytics.py +++ b/tests/em/fdem/forward/test_FDEM_analytics.py @@ -28,7 +28,7 @@ class FDEM_analyticTests(unittest.TestCase): x = np.linspace(-10,10,5) XYZ = Utils.ndgrid(x,np.r_[0],np.r_[0]) - rxList = EM.FDEM.Rx.eField(XYZ, orientation='x', component='imag') + rxList = EM.FDEM.Rx.Point_e(XYZ, orientation='x', component='imag') Src0 = EM.FDEM.Src.MagDipole([rxList],loc=np.r_[0.,0.,0.], freq=freq) survey = EM.FDEM.Survey([Src0]) From 029171fb1d7652207f7ba10423d0f3a8ceef89d1 Mon Sep 17 00:00:00 2001 From: Lindsey Heagy Date: Wed, 11 May 2016 09:09:26 -0700 Subject: [PATCH 4/4] use .format for strings --- SimPEG/EM/FDEM/ProblemFDEM.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SimPEG/EM/FDEM/ProblemFDEM.py b/SimPEG/EM/FDEM/ProblemFDEM.py index 75b05bf9..2aed1d91 100644 --- a/SimPEG/EM/FDEM/ProblemFDEM.py +++ b/SimPEG/EM/FDEM/ProblemFDEM.py @@ -87,7 +87,7 @@ class BaseFDEMProblem(BaseEMProblem): du_dm_v = Ainv * ( - dA_dm_v + dRHS_dm_v ) for rx in src.rxList: - df_dmFun = getattr(f, '_%sDeriv'%rx.projField, None) + df_dmFun = getattr(f, '_{0}Deriv'.format(rx.projField), None) df_dm_v = df_dmFun(src, du_dm_v, v, adjoint=False) Jv[src, rx] = rx.evalDeriv(src, self.mesh, f, df_dm_v) Ainv.clean() @@ -125,7 +125,7 @@ class BaseFDEMProblem(BaseEMProblem): for rx in src.rxList: PTv = rx.evalDeriv(src, self.mesh, f, v[src, rx], adjoint=True) # wrt f, need possibility wrt m - df_duTFun = getattr(f, '_%sDeriv'%rx.projField, None) + df_duTFun = getattr(f, '_{0}Deriv'.format(rx.projField), None) df_duT, df_dmT = df_duTFun(src, None, PTv, adjoint=True) ATinvdf_duT = ATinv * df_duT