.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/ion_multi_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_ion_multi_event.py: Heating only the Ions with Multiple Square Events ================================================= In this example, only the ions are heated by multiple square pulses each lasting 200 seconds with heating rates chosen from a uniform distribution. .. 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, SquareHeatingEvent quantity_support() .. rst-class:: sphx-glr-script-out .. code-block:: none .MplQuantityConverter object at 0x714089832a20> .. GENERATED FROM PYTHON SOURCE LINES 21-26 Set up a series of 5 square heating events each lasting 200 s with the first starting at 1500 s. The rates are chosen from a uniform distribution between 0.001 and 0.1 erg per cubic centimeter per second. .. GENERATED FROM PYTHON SOURCE LINES 26-35 .. code-block:: Python events = [] time_start = 1500 * u.s for i in range(5): events.append(SquareHeatingEvent( (i+1)*time_start, 200*u.s, np.random.uniform(0.001, 0.1)*u.Unit('erg cm-3 s-1') )) .. GENERATED FROM PYTHON SOURCE LINES 36-38 Let's add this to a heating model in which we partition all of the energy into the ions .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: Python heating = HeatingModel(background=3.5e-5*u.Unit('erg cm-3 s-1'), partition=0, events=events) .. GENERATED FROM PYTHON SOURCE LINES 43-46 Now run the simulation for a 40 Mm loop lasting a total of 3 h. We'll also specify that we want to compute the DEM .. GENERATED FROM PYTHON SOURCE LINES 46-51 .. code-block:: Python result = ebtelplusplus.run(3*u.h, 40*u.Mm, heating=heating, dem=DemModel(calculate_dem=True)) .. GENERATED FROM PYTHON SOURCE LINES 52-54 Let's visualize the heating profile, temperature, and density as a function of time. .. GENERATED FROM PYTHON SOURCE LINES 54-61 .. 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_ion_multi_event_001.png :alt: ion multi event :srcset: /generated/gallery/images/sphx_glr_ion_multi_event_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 62-65 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 65-76 .. 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 77-78 And now we can plot each component .. GENERATED FROM PYTHON SOURCE LINES 78-90 .. 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_ion_multi_event_002.png :alt: ion multi event :srcset: /generated/gallery/images/sphx_glr_ion_multi_event_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.298 seconds) .. _sphx_glr_download_generated_gallery_ion_multi_event.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ion_multi_event.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ion_multi_event.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ion_multi_event.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_