.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "content/tutorials/08-tdem/plot_fwd_1_em1dtm_waveforms.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_content_tutorials_08-tdem_plot_fwd_1_em1dtm_waveforms.py: 1D Forward Simulation with User-Defined Waveforms ================================================= For time-domain electromagnetic problems, the response depends strongly on the souce waveforms. In this tutorial, we construct a set of waveforms of different types and simulate the response for a halfspace. Many types of waveforms can be constructed within *SimPEG.electromagnetics.time_domain_1d*. These include: - the unit step off waveform - a set of basic waveforms: rectangular, triangular, quarter sine, etc... - a set of system-specific waveforms: SkyTEM, VTEM, GeoTEM, etc... - fully customized waveforms .. GENERATED FROM PYTHON SOURCE LINES 19-22 Import Modules -------------- .. GENERATED FROM PYTHON SOURCE LINES 22-33 .. code-block:: Python import numpy as np import matplotlib as mpl from matplotlib import pyplot as plt mpl.rcParams.update({"font.size": 16}) from SimPEG import maps import SimPEG.electromagnetics.time_domain as tdem .. GENERATED FROM PYTHON SOURCE LINES 34-40 Define Waveforms ---------------- Here, we define the set of waveforms that will be used to simulated the TEM response. .. GENERATED FROM PYTHON SOURCE LINES 40-83 .. code-block:: Python # Unit stepoff waveform can be defined directly stepoff_waveform = tdem.sources.StepOffWaveform() # Rectangular waveform. The user may customize the waveform by setting the start # time, end time and on time amplitude for the current waveform. eps = 1e-6 ramp_on = np.r_[-0.004, -0.004 + eps] ramp_off = np.r_[-eps, 0.0] rectangular_waveform = tdem.sources.TrapezoidWaveform( ramp_on=ramp_on, ramp_off=ramp_off ) # Triangular waveform. The user may customize the waveform by setting the start # time, peak time, end time and peak amplitude for the current waveform. eps = 1e-8 start_time = -0.02 peak_time = -0.01 off_time = 0.0 triangle_waveform = tdem.sources.TriangularWaveform( start_time=start_time, peak_time=peak_time, off_time=off_time ) # Quarter-sine ramp-off ramp_on = np.r_[-0.02, -0.01] ramp_off = np.r_[-0.01, 0.0] qs_waveform = tdem.sources.QuarterSineRampOnWaveform(ramp_on=ramp_on, ramp_off=ramp_off) # General waveform. This is a fully general way to define the waveform. # The use simply provides times and the current. def custom_waveform(t, tmax): out = np.cos(0.5 * np.pi * (t - tmax) / (tmax + 0.02)) out[t >= tmax] = 1 + (t[t >= tmax] - tmax) / tmax return out waveform_times = np.r_[np.linspace(-0.02, -0.011, 10), -np.logspace(-2, -6, 61), 0.0] waveform_current = custom_waveform(waveform_times, -0.0055) general_waveform = tdem.sources.PiecewiseLinearWaveform( times=waveform_times, currents=waveform_current ) .. GENERATED FROM PYTHON SOURCE LINES 84-89 Plot the Waveforms ------------------ Here, we plot the set of waveforms that are used in the simulation. .. GENERATED FROM PYTHON SOURCE LINES 89-113 .. code-block:: Python fig = plt.figure(figsize=(8, 6)) ax = fig.add_axes([0.1, 0.1, 0.85, 0.8]) ax.plot(np.r_[-2e-2, 0.0, 1e-10, 1e-3], np.r_[1.0, 1.0, 0.0, 0.0], "k", lw=3) plotting_current = [rectangular_waveform.eval(t) for t in waveform_times] ax.plot(waveform_times, plotting_current, "r", lw=2) plotting_current = [triangle_waveform.eval(t) for t in waveform_times] ax.plot(waveform_times, plotting_current, "b", lw=2) plotting_current = [qs_waveform.eval(t) for t in waveform_times] ax.plot(waveform_times, plotting_current, "g", lw=2) plotting_current = [general_waveform.eval(t) for t in waveform_times] ax.plot(waveform_times, plotting_current, "c", lw=2) ax.grid() ax.set_xlim([waveform_times.min(), 1e-3]) ax.set_xlabel("Time (s)") ax.set_ylabel("Current (A)") ax.set_title("Waveforms") ax.legend( ["Step-off", "Rectangular", "Triangle", "Quarter-Sine", "General"], loc="lower left" ) .. image-sg:: /content/tutorials/08-tdem/images/sphx_glr_plot_fwd_1_em1dtm_waveforms_001.png :alt: Waveforms :srcset: /content/tutorials/08-tdem/images/sphx_glr_plot_fwd_1_em1dtm_waveforms_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 114-121 Create Survey ------------- The waveform is a property of the source. So for each waveform, we will need to define a separate source object. For simplicity, all sources will be horizontal loops with a radius of 10 m. .. GENERATED FROM PYTHON SOURCE LINES 121-201 .. code-block:: Python # Define a receiver list. In this case, we measure the vertical component of # db/dt. Thus we only have a single receiver in the list. receiver_location = np.array([0.0, 0.0, 0.0]) receiver_orientation = "z" # "x", "y" or "z" times = np.logspace(-4, -1, 41) # time channels receiver_list = [ tdem.receivers.PointMagneticFluxTimeDerivative( receiver_location, times, orientation=receiver_orientation ) ] # Source properties. If you defined the true waveform (not normalized), the current amplitude # should be set to 1. Otherwise you will be accounting for the maximum current # amplitude twice!!! source_location = np.array([0.0, 0.0, 0.0]) source_radius = 10.0 current_amplitude = 1.0 source_list = [] # Stepoff Waveform source_list.append( tdem.sources.CircularLoop( receiver_list=receiver_list, location=source_location, waveform=stepoff_waveform, radius=source_radius, current=current_amplitude, ) ) # Rectangular Waveform source_list.append( tdem.sources.CircularLoop( receiver_list=receiver_list, location=source_location, waveform=rectangular_waveform, radius=source_radius, current=current_amplitude, ) ) # Triangle Waveform source_list.append( tdem.sources.CircularLoop( receiver_list=receiver_list, location=source_location, waveform=triangle_waveform, radius=source_radius, current=current_amplitude, ) ) # Quarter-sine ramp-off Waveform source_list.append( tdem.sources.CircularLoop( receiver_list=receiver_list, location=source_location, waveform=qs_waveform, radius=source_radius, current=current_amplitude, ) ) # General Waveform source_list.append( tdem.sources.CircularLoop( receiver_list=receiver_list, location=source_location, waveform=general_waveform, radius=source_radius, current=current_amplitude, ) ) # Survey survey = tdem.Survey(source_list) .. GENERATED FROM PYTHON SOURCE LINES 202-210 Defining a 1D Layered Earth Model --------------------------------- Here, we define the layer thicknesses and electrical conductivities for our 1D simulation. If we have N layers, we define N electrical conductivity values and N-1 layer thicknesses. The lowest layer is assumed to extend to infinity. .. GENERATED FROM PYTHON SOURCE LINES 210-233 .. code-block:: Python # Layer thicknesses thicknesses = np.array([40.0, 40.0]) n_layer = len(thicknesses) + 1 # half-space physical properties sigma = 1e-2 eta = 0.5 tau = 0.01 c = 0.5 chi = 0.0 # physical property models sigma_model = sigma * np.ones(n_layer) eta_model = eta * np.ones(n_layer) tau_model = tau * np.ones(n_layer) c_model = c * np.ones(n_layer) mu0 = 4 * np.pi * 1e-7 mu_model = mu0 * (1 + chi) * np.ones(n_layer) # Define a mapping for conductivities model_mapping = maps.IdentityMap(nP=n_layer) .. GENERATED FROM PYTHON SOURCE LINES 234-237 Define the Forward Simulation and Predict Data ---------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 237-246 .. code-block:: Python # Define the simulation simulation = tdem.Simulation1DLayered( survey=survey, thicknesses=thicknesses, sigmaMap=model_mapping, mu=mu_model ) # Predict data for a given model dpred = simulation.dpred(sigma_model) .. GENERATED FROM PYTHON SOURCE LINES 247-250 Plotting Results ------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 250-264 .. code-block:: Python fig = plt.figure(figsize=(8, 8)) d = np.reshape(dpred, (len(source_list), len(times))).T ax = fig.add_axes([0.15, 0.15, 0.8, 0.75]) colorlist = ["k", "b", "r", "g", "c"] for ii, k in enumerate(colorlist): ax.loglog(times, np.abs(d[:, ii]), k, lw=2) ax.set_xlim([times.min(), times.max()]) ax.grid() ax.legend(["Step-off", "Rectangular", "Triangle", "Quarter-Sine", "General"]) ax.set_xlabel("Times (s)") ax.set_ylabel("|dB/dt| (T/s)") ax.set_title("TEM Response") .. image-sg:: /content/tutorials/08-tdem/images/sphx_glr_plot_fwd_1_em1dtm_waveforms_002.png :alt: TEM Response :srcset: /content/tutorials/08-tdem/images/sphx_glr_plot_fwd_1_em1dtm_waveforms_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'TEM Response') .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.982 seconds) **Estimated memory usage:** 8 MB .. _sphx_glr_download_content_tutorials_08-tdem_plot_fwd_1_em1dtm_waveforms.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_fwd_1_em1dtm_waveforms.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_fwd_1_em1dtm_waveforms.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_