From 7a4aa4ddc3140b5c9293f85e7f589e82f4428132 Mon Sep 17 00:00:00 2001 From: Lindsey Date: Fri, 15 Jan 2016 10:07:11 -0800 Subject: [PATCH 1/6] Update and rename EM_FDEM_1D_Inversion.py to EM_TDEM_1D_Inversion.py - this is a TDEM inversion (not FDEM) --- .../{EM_FDEM_1D_Inversion.py => EM_TDEM_1D_Inversion.py} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename SimPEG/Examples/{EM_FDEM_1D_Inversion.py => EM_TDEM_1D_Inversion.py} (97%) diff --git a/SimPEG/Examples/EM_FDEM_1D_Inversion.py b/SimPEG/Examples/EM_TDEM_1D_Inversion.py similarity index 97% rename from SimPEG/Examples/EM_FDEM_1D_Inversion.py rename to SimPEG/Examples/EM_TDEM_1D_Inversion.py index aba70f4b..d4d80e55 100644 --- a/SimPEG/Examples/EM_FDEM_1D_Inversion.py +++ b/SimPEG/Examples/EM_TDEM_1D_Inversion.py @@ -5,10 +5,10 @@ from scipy.constants import mu_0 def run(plotIt=True): """ - EM: FDEM: 1D: Inversion + EM: TDEM: 1D: Inversion ======================= - Here we will create and run a FDEM 1D inversion. + Here we will create and run a TDEM 1D inversion. """ From 0b971f4a50315d439c82672cbc6a885a9712e106 Mon Sep 17 00:00:00 2001 From: Lindsey Heagy Date: Fri, 15 Jan 2016 10:46:31 -0800 Subject: [PATCH 2/6] updated examples init to also update docs --- SimPEG/Examples/__init__.py | 4 ++-- ..._FDEM_1D_Inversion.rst => EM_TDEM_1D_Inversion.rst} | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) rename docs/examples/{EM_FDEM_1D_Inversion.rst => EM_TDEM_1D_Inversion.rst} (64%) diff --git a/SimPEG/Examples/__init__.py b/SimPEG/Examples/__init__.py index 8431e4ba..78b7c5a6 100644 --- a/SimPEG/Examples/__init__.py +++ b/SimPEG/Examples/__init__.py @@ -1,7 +1,7 @@ # Run this file to add imports. ##### AUTOIMPORTS ##### -import EM_FDEM_1D_Inversion +import EM_TDEM_1D_Inversion import FLOW_Richards_1D_Celia1990 import Forward_BasicDirectCurrent import Inversion_Linear @@ -13,7 +13,7 @@ import Mesh_QuadTree_FaceDiv import Mesh_QuadTree_HangingNodes import Mesh_Tensor_Creation -__examples__ = ["EM_FDEM_1D_Inversion", "FLOW_Richards_1D_Celia1990", "Forward_BasicDirectCurrent", "Inversion_Linear", "Mesh_Basic_PlotImage", "Mesh_Basic_Types", "Mesh_Operators_CahnHilliard", "Mesh_QuadTree_Creation", "Mesh_QuadTree_FaceDiv", "Mesh_QuadTree_HangingNodes", "Mesh_Tensor_Creation"] +__examples__ = ["EM_TDEM_1D_Inversion", "FLOW_Richards_1D_Celia1990", "Forward_BasicDirectCurrent", "Inversion_Linear", "Mesh_Basic_PlotImage", "Mesh_Basic_Types", "Mesh_Operators_CahnHilliard", "Mesh_QuadTree_Creation", "Mesh_QuadTree_FaceDiv", "Mesh_QuadTree_HangingNodes", "Mesh_Tensor_Creation"] ##### AUTOIMPORTS ##### diff --git a/docs/examples/EM_FDEM_1D_Inversion.rst b/docs/examples/EM_TDEM_1D_Inversion.rst similarity index 64% rename from docs/examples/EM_FDEM_1D_Inversion.rst rename to docs/examples/EM_TDEM_1D_Inversion.rst index acbc8cdc..53f6f9ef 100644 --- a/docs/examples/EM_FDEM_1D_Inversion.rst +++ b/docs/examples/EM_TDEM_1D_Inversion.rst @@ -1,4 +1,4 @@ -.. _examples_EM_FDEM_1D_Inversion: +.. _examples_EM_TDEM_1D_Inversion: .. --------------------------------- .. .. .. @@ -9,18 +9,18 @@ .. --------------------------------- .. -EM: FDEM: 1D: Inversion +EM: TDEM: 1D: Inversion ======================= -Here we will create and run a FDEM 1D inversion. +Here we will create and run a TDEM 1D inversion. .. plot:: from SimPEG import Examples - Examples.EM_FDEM_1D_Inversion.run() + Examples.EM_TDEM_1D_Inversion.run() -.. literalinclude:: ../../SimPEG/Examples/EM_FDEM_1D_Inversion.py +.. literalinclude:: ../../SimPEG/Examples/EM_TDEM_1D_Inversion.py :language: python :linenos: From 7107cd9d94c392d37b007ddea36a05d5fae3bca3 Mon Sep 17 00:00:00 2001 From: Lindsey Heagy Date: Tue, 19 Jan 2016 23:57:41 -0800 Subject: [PATCH 3/6] plot a harmonic mag dipole --- .../EM_Analytic_MagDipoleWholespace.py | 47 +++++++++++++++++++ SimPEG/Examples/__init__.py | 3 +- .../EM_Analytic_MagDipoleWholespace.rst | 26 ++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 SimPEG/Examples/EM_Analytic_MagDipoleWholespace.py create mode 100644 docs/examples/EM_Analytic_MagDipoleWholespace.rst diff --git a/SimPEG/Examples/EM_Analytic_MagDipoleWholespace.py b/SimPEG/Examples/EM_Analytic_MagDipoleWholespace.py new file mode 100644 index 00000000..31408bcc --- /dev/null +++ b/SimPEG/Examples/EM_Analytic_MagDipoleWholespace.py @@ -0,0 +1,47 @@ +from SimPEG import * +import SimPEG.EM as EM + +import matplotlib.pyplot as plt +from matplotlib.colors import LogNorm + +x = np.arange(-100.5,100.5,step = 1.) #(avoid putting measurement points where source is located) +y = np.r_[0] +z = x + +sig = 1. +freq = 1. + +XYZ = Utils.ndgrid(x,y,z) + + +def run(XYZ=XYZ,sig=sig,freq=freq,orientation='Z', plotIt=True): + """ + EM: Magnetic Dipole in a Whole-Space + ==================================== + + Here we plot the magnetic flux density from a harmonic dipole in a wholespace. + + """ + + Bx, By, Bz = EM.Analytics.FDEM.MagneticDipoleWholeSpace(XYZ, np.r_[0.,0.,0.], sig, freq,orientation=orientation) + absB = np.sqrt(Bx*Bx.conj()+By*By.conj()+Bz*Bz.conj()).real + + + if plotIt: + fig, ax = plt.subplots(1,1,figsize=(6,5)) + bxplt = Bx.reshape(x.size,z.size) + bzplt = Bz.reshape(x.size,z.size) + pc = ax.pcolor(x,z,absB.reshape(x.size,z.size),norm=LogNorm()) + ax.streamplot(x,z,bxplt.real,bzplt.real,color='k',density=1) + ax.set_xlim([x.min(),x.max()]) + ax.set_ylim([z.min(),z.max()]) + ax.set_xlabel('x') + ax.set_ylabel('z') + cb = plt.colorbar(pc,ax = ax) + cb.set_label('|B| (T)') + plt.show() + + return fig, ax + +if __name__ == '__main__': + run() \ No newline at end of file diff --git a/SimPEG/Examples/__init__.py b/SimPEG/Examples/__init__.py index 78b7c5a6..055feeac 100644 --- a/SimPEG/Examples/__init__.py +++ b/SimPEG/Examples/__init__.py @@ -1,6 +1,7 @@ # Run this file to add imports. ##### AUTOIMPORTS ##### +import EM_Analytic_MagDipoleWholespace import EM_TDEM_1D_Inversion import FLOW_Richards_1D_Celia1990 import Forward_BasicDirectCurrent @@ -13,7 +14,7 @@ import Mesh_QuadTree_FaceDiv import Mesh_QuadTree_HangingNodes import Mesh_Tensor_Creation -__examples__ = ["EM_TDEM_1D_Inversion", "FLOW_Richards_1D_Celia1990", "Forward_BasicDirectCurrent", "Inversion_Linear", "Mesh_Basic_PlotImage", "Mesh_Basic_Types", "Mesh_Operators_CahnHilliard", "Mesh_QuadTree_Creation", "Mesh_QuadTree_FaceDiv", "Mesh_QuadTree_HangingNodes", "Mesh_Tensor_Creation"] +__examples__ = ["EM_Analytic_MagDipoleWholespace", "EM_TDEM_1D_Inversion", "FLOW_Richards_1D_Celia1990", "Forward_BasicDirectCurrent", "Inversion_Linear", "Mesh_Basic_PlotImage", "Mesh_Basic_Types", "Mesh_Operators_CahnHilliard", "Mesh_QuadTree_Creation", "Mesh_QuadTree_FaceDiv", "Mesh_QuadTree_HangingNodes", "Mesh_Tensor_Creation"] ##### AUTOIMPORTS ##### diff --git a/docs/examples/EM_Analytic_MagDipoleWholespace.rst b/docs/examples/EM_Analytic_MagDipoleWholespace.rst new file mode 100644 index 00000000..bfe8d33b --- /dev/null +++ b/docs/examples/EM_Analytic_MagDipoleWholespace.rst @@ -0,0 +1,26 @@ +.. _examples_EM_Analytic_MagDipoleWholespace: + +.. --------------------------------- .. +.. .. +.. THIS FILE IS AUTO GENEREATED .. +.. .. +.. SimPEG/Examples/__init__.py .. +.. .. +.. --------------------------------- .. + + +EM: Magnetic Dipole in a Whole-Space +==================================== + +Here we plot the magnetic flux density from a harmonic dipole in a wholespace. + + + +.. plot:: + + from SimPEG import Examples + Examples.EM_Analytic_MagDipoleWholespace.run() + +.. literalinclude:: ../../SimPEG/Examples/EM_Analytic_MagDipoleWholespace.py + :language: python + :linenos: From 98f209d1f0a368912a42442aab7a5b9aa03d993f Mon Sep 17 00:00:00 2001 From: Lindsey Heagy Date: Wed, 20 Jan 2016 08:04:01 -0800 Subject: [PATCH 4/6] specify that example is FDEM --- ...holespace.py => EM_FDEM_Analytic_MagDipoleWholespace.py} | 0 SimPEG/Examples/__init__.py | 4 ++-- ...lespace.rst => EM_FDEM_Analytic_MagDipoleWholespace.rst} | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename SimPEG/Examples/{EM_Analytic_MagDipoleWholespace.py => EM_FDEM_Analytic_MagDipoleWholespace.py} (100%) rename docs/examples/{EM_Analytic_MagDipoleWholespace.rst => EM_FDEM_Analytic_MagDipoleWholespace.rst} (73%) diff --git a/SimPEG/Examples/EM_Analytic_MagDipoleWholespace.py b/SimPEG/Examples/EM_FDEM_Analytic_MagDipoleWholespace.py similarity index 100% rename from SimPEG/Examples/EM_Analytic_MagDipoleWholespace.py rename to SimPEG/Examples/EM_FDEM_Analytic_MagDipoleWholespace.py diff --git a/SimPEG/Examples/__init__.py b/SimPEG/Examples/__init__.py index 055feeac..894d6ea0 100644 --- a/SimPEG/Examples/__init__.py +++ b/SimPEG/Examples/__init__.py @@ -1,7 +1,7 @@ # Run this file to add imports. ##### AUTOIMPORTS ##### -import EM_Analytic_MagDipoleWholespace +import EM_FDEM_Analytic_MagDipoleWholespace import EM_TDEM_1D_Inversion import FLOW_Richards_1D_Celia1990 import Forward_BasicDirectCurrent @@ -14,7 +14,7 @@ import Mesh_QuadTree_FaceDiv import Mesh_QuadTree_HangingNodes import Mesh_Tensor_Creation -__examples__ = ["EM_Analytic_MagDipoleWholespace", "EM_TDEM_1D_Inversion", "FLOW_Richards_1D_Celia1990", "Forward_BasicDirectCurrent", "Inversion_Linear", "Mesh_Basic_PlotImage", "Mesh_Basic_Types", "Mesh_Operators_CahnHilliard", "Mesh_QuadTree_Creation", "Mesh_QuadTree_FaceDiv", "Mesh_QuadTree_HangingNodes", "Mesh_Tensor_Creation"] +__examples__ = ["EM_FDEM_Analytic_MagDipoleWholespace", "EM_TDEM_1D_Inversion", "FLOW_Richards_1D_Celia1990", "Forward_BasicDirectCurrent", "Inversion_Linear", "Mesh_Basic_PlotImage", "Mesh_Basic_Types", "Mesh_Operators_CahnHilliard", "Mesh_QuadTree_Creation", "Mesh_QuadTree_FaceDiv", "Mesh_QuadTree_HangingNodes", "Mesh_Tensor_Creation"] ##### AUTOIMPORTS ##### diff --git a/docs/examples/EM_Analytic_MagDipoleWholespace.rst b/docs/examples/EM_FDEM_Analytic_MagDipoleWholespace.rst similarity index 73% rename from docs/examples/EM_Analytic_MagDipoleWholespace.rst rename to docs/examples/EM_FDEM_Analytic_MagDipoleWholespace.rst index bfe8d33b..0e1b2d93 100644 --- a/docs/examples/EM_Analytic_MagDipoleWholespace.rst +++ b/docs/examples/EM_FDEM_Analytic_MagDipoleWholespace.rst @@ -1,4 +1,4 @@ -.. _examples_EM_Analytic_MagDipoleWholespace: +.. _examples_EM_FDEM_Analytic_MagDipoleWholespace: .. --------------------------------- .. .. .. @@ -19,8 +19,8 @@ Here we plot the magnetic flux density from a harmonic dipole in a wholespace. .. plot:: from SimPEG import Examples - Examples.EM_Analytic_MagDipoleWholespace.run() + Examples.EM_FDEM_Analytic_MagDipoleWholespace.run() -.. literalinclude:: ../../SimPEG/Examples/EM_Analytic_MagDipoleWholespace.py +.. literalinclude:: ../../SimPEG/Examples/EM_FDEM_Analytic_MagDipoleWholespace.py :language: python :linenos: From 91e37c5fa737f4215bfe2b73146f09e3d146b6fa Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Wed, 20 Jan 2016 12:52:51 -0700 Subject: [PATCH 5/6] Clean up init code, put inside run, remove mpl from TL import. --- .../EM_FDEM_Analytic_MagDipoleWholespace.py | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/SimPEG/Examples/EM_FDEM_Analytic_MagDipoleWholespace.py b/SimPEG/Examples/EM_FDEM_Analytic_MagDipoleWholespace.py index 31408bcc..791f8c63 100644 --- a/SimPEG/Examples/EM_FDEM_Analytic_MagDipoleWholespace.py +++ b/SimPEG/Examples/EM_FDEM_Analytic_MagDipoleWholespace.py @@ -1,33 +1,29 @@ from SimPEG import * import SimPEG.EM as EM -import matplotlib.pyplot as plt -from matplotlib.colors import LogNorm - -x = np.arange(-100.5,100.5,step = 1.) #(avoid putting measurement points where source is located) -y = np.r_[0] -z = x - -sig = 1. -freq = 1. - -XYZ = Utils.ndgrid(x,y,z) - - -def run(XYZ=XYZ,sig=sig,freq=freq,orientation='Z', plotIt=True): +def run(XYZ=None, sig=1.0, freq=1.0, orientation='Z', plotIt=True): """ EM: Magnetic Dipole in a Whole-Space ==================================== - Here we plot the magnetic flux density from a harmonic dipole in a wholespace. + Here we plot the magnetic flux density from a harmonic dipole in a wholespace. """ - Bx, By, Bz = EM.Analytics.FDEM.MagneticDipoleWholeSpace(XYZ, np.r_[0.,0.,0.], sig, freq,orientation=orientation) + if XYZ is None: + x = np.arange(-100.5,100.5,step = 1.) #(avoid putting measurement points where source is located) + y = np.r_[0] + z = x + XYZ = Utils.ndgrid(x,y,z) + + + Bx, By, Bz = EM.Analytics.FDEM.MagneticDipoleWholeSpace(XYZ, np.r_[0.,0.,0.], sig, freq, orientation=orientation) absB = np.sqrt(Bx*Bx.conj()+By*By.conj()+Bz*Bz.conj()).real - if plotIt: + if plotIt: + import matplotlib.pyplot as plt + from matplotlib.colors import LogNorm fig, ax = plt.subplots(1,1,figsize=(6,5)) bxplt = Bx.reshape(x.size,z.size) bzplt = Bz.reshape(x.size,z.size) @@ -44,4 +40,4 @@ def run(XYZ=XYZ,sig=sig,freq=freq,orientation='Z', plotIt=True): return fig, ax if __name__ == '__main__': - run() \ No newline at end of file + run() From 84400650fa35240c4f2bc3b8b0ab90a995c741cc Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Sat, 23 Jan 2016 16:37:11 -0700 Subject: [PATCH 6/6] Clean up init file in examples. --- SimPEG/Examples/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/SimPEG/Examples/__init__.py b/SimPEG/Examples/__init__.py index 894d6ea0..7ef15451 100644 --- a/SimPEG/Examples/__init__.py +++ b/SimPEG/Examples/__init__.py @@ -29,16 +29,17 @@ if __name__ == '__main__': from SimPEG import Examples # Create the examples dir in the docs folder. - docExamplesDir = os.path.sep.join(os.path.realpath(__file__).split(os.path.sep)[:-3] + ['docs', 'examples']) + fName = os.path.realpath(__file__) + docExamplesDir = os.path.sep.join(fName.split(os.path.sep)[:-3] + ['docs', 'examples']) shutil.rmtree(docExamplesDir) os.makedirs(docExamplesDir) # Get all the python examples in this folder - thispath = os.path.sep.join(__file__.split(os.path.sep)[:-1]) + thispath = os.path.sep.join(fName.split(os.path.sep)[:-1]) exfiles = [f[:-3] for f in os.listdir(thispath) if os.path.isfile(os.path.join(thispath, f)) and f.endswith('.py') and not f.startswith('_')] # Add the imports to the top in the AUTOIMPORTS section - f = file(__file__, 'r') + f = file(fName, 'r') inimports = False out = '' for line in f: @@ -53,7 +54,7 @@ if __name__ == '__main__': out += '\n##### AUTOIMPORTS #####\n' f.close() - f = file(__file__, 'w') + f = file(fName, 'w') f.write(out) f.close()