.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/electron_single_event.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_generated_gallery_electron_single_event.py: Heating only the Electrons with One Triangular Event ==================================================== In this example, only the electrons are heated by a single triangular pulse lasting 500 seconds and injecting 10 ergs per cubic centimeter into the loop plasma. .. GENERATED FROM PYTHON SOURCE LINES 7-20 .. code-block:: Python import astropy.units as u import matplotlib.pyplot as plt import numpy as np from astropy.visualization import quantity_support import ebtelplusplus from ebtelplusplus.models import DemModel, HeatingModel, TriangularHeatingEvent quantity_support() .. rst-class:: sphx-glr-script-out .. code-block:: none .MplQuantityConverter object at 0x7890e938a870> .. GENERATED FROM PYTHON SOURCE LINES 21-25 Set up a single heating event that is triangular in shape such that it rises linearly for 250 s and then falls linearly for 250 s starting at the beginning of the simulation (0 s). .. GENERATED FROM PYTHON SOURCE LINES 25-29 .. code-block:: Python event = TriangularHeatingEvent(0.0*u.s, 500*u.s, 0.04*u.Unit('erg cm-3 s-1')) .. GENERATED FROM PYTHON SOURCE LINES 30-32 Let's add this to a heating model in which we partition all of the energy into the electrons .. GENERATED FROM PYTHON SOURCE LINES 32-36 .. code-block:: Python heating = HeatingModel(background=3.5e-5*u.Unit('erg cm-3 s-1'), partition=1.0, events=[event]) .. GENERATED FROM PYTHON SOURCE LINES 37-40 Now run the simulation for a 40 Mm loop lasting a total of 5000 s. We'll also specify that we want to compute the DEM .. GENERATED FROM PYTHON SOURCE LINES 40-45 .. code-block:: Python result = ebtelplusplus.run(5e3*u.s, 40*u.Mm, heating=heating, dem=DemModel(calculate_dem=True)) .. GENERATED FROM PYTHON SOURCE LINES 46-48 Let's visualize the heating profile, temperature, and density as a function of time. .. GENERATED FROM PYTHON SOURCE LINES 48-55 .. code-block:: Python fig, axes = plt.subplots(3, 1, sharex=True) axes[0].plot(result.time, result.heat) axes[1].plot(result.time, result.electron_temperature, label='electron') axes[1].plot(result.time, result.ion_temperature, label='ion') axes[2].plot(result.time, result.density) axes[1].legend() .. image-sg:: /generated/gallery/images/sphx_glr_electron_single_event_001.png :alt: electron single event :srcset: /generated/gallery/images/sphx_glr_electron_single_event_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 56-59 Finally, let's visualize the DEM distribution. We'll first time-average each component over the duration of the simulation. .. GENERATED FROM PYTHON SOURCE LINES 59-70 .. code-block:: Python delta_t = np.gradient(result.time) dem_avg_total = np.average(result.dem_tr+result.dem_corona, axis=0, weights=delta_t) dem_avg_tr = np.average(result.dem_tr, axis=0, weights=delta_t) dem_avg_corona = np.average(result.dem_corona, axis=0, weights=delta_t) .. GENERATED FROM PYTHON SOURCE LINES 71-72 And now we can plot each component .. GENERATED FROM PYTHON SOURCE LINES 72-84 .. code-block:: Python fig = plt.figure() ax = fig.add_subplot() ax.plot(result.dem_temperature, dem_avg_total, label='Total') ax.plot(result.dem_temperature, dem_avg_tr, label='TR') ax.plot(result.dem_temperature, dem_avg_corona, label='Corona') ax.set_xlim([10**(4.5), 10**(7.5)]*u.K) ax.set_ylim([10**(20.0), 10**(23.5)]*u.Unit('cm-5 K-1')) ax.set_xscale('log') ax.set_yscale('log') ax.legend() plt.show() .. image-sg:: /generated/gallery/images/sphx_glr_electron_single_event_002.png :alt: electron single event :srcset: /generated/gallery/images/sphx_glr_electron_single_event_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.407 seconds) .. _sphx_glr_download_generated_gallery_electron_single_event.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: electron_single_event.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: electron_single_event.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: electron_single_event.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_