.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/user_guide/plot_ioneq.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_user_guide_plot_ioneq.py: Ionization fractions in equilibrium =============================================== This example shows how to compute the ionization fraction as a function of temperature, assuming equilibrium, for both a single ion as well as a whole element. .. GENERATED FROM PYTHON SOURCE LINES 9-19 .. code-block:: Python import astropy.units as u import matplotlib.pyplot as plt import numpy as np from astropy.visualization import quantity_support from fiasco import Element quantity_support() .. rst-class:: sphx-glr-script-out .. code-block:: none .MplQuantityConverter object at 0x7fc3a21ca190> .. GENERATED FROM PYTHON SOURCE LINES 20-21 First, create the `~fiasco.Element` object for carbon. .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python temperature = 10**np.arange(3.9, 6.5, 0.01) * u.K el = Element('C', temperature) .. GENERATED FROM PYTHON SOURCE LINES 25-32 The ionization fractions in equilibrium can be determined by calculating the ionization and recombination rates as a function of temperature for every ion of the element and then solving the associated system of equations. This can be done by creating a `~fiasco.Element` object and then accessing the `~fiasco.Element.equilibrium_ionization` property. We can use this to plot the population fraction of each ion as a function of temperature. .. GENERATED FROM PYTHON SOURCE LINES 32-42 .. code-block:: Python for ion in el: ioneq = el.equilibrium_ionization[:, ion.charge_state] imax = np.argmax(ioneq) plt.plot(el.temperature, ioneq) plt.text(el.temperature[imax], ioneq[imax], ion.ionization_stage_roman, horizontalalignment='center') plt.xscale('log') plt.title(f'{el.atomic_symbol} Equilibrium Ionization') plt.show() .. image-sg:: /generated/gallery/user_guide/images/sphx_glr_plot_ioneq_001.png :alt: C Equilibrium Ionization :srcset: /generated/gallery/user_guide/images/sphx_glr_plot_ioneq_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 43-50 The CHIANTI database also includes tabulated ionization equilibria for all ions in the database. The `ioneq` attribute on each `~fiasco.Ion` object returns the tabulated population fractions interpolated onto the `temperature` array. Note that these population fractions returned by `~fiasco.Ion.ioneq` are stored in the CHIANTI database and therefore are set to NaN for temperatures outside of the tabulated temperature data given in CHIANTI. .. GENERATED FROM PYTHON SOURCE LINES 50-55 .. code-block:: Python plt.plot(el.temperature, el[3].ioneq) plt.xscale('log') plt.title(f'{el[3].ion_name_roman} Equilibrium Ionization') plt.show() .. image-sg:: /generated/gallery/user_guide/images/sphx_glr_plot_ioneq_002.png :alt: C IV Equilibrium Ionization :srcset: /generated/gallery/user_guide/images/sphx_glr_plot_ioneq_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-60 We can then compare tabulated and calculated results for a single ion. Note that the two may not be equal due to differences in the rates when the tabulated results were calculated or due to artifacts from the interpolation. .. GENERATED FROM PYTHON SOURCE LINES 60-67 .. code-block:: Python plt.plot(el.temperature, el.equilibrium_ionization[:, el[3].charge_state], label='calculated') plt.plot(el.temperature, el[3].ioneq, label='interpolated') plt.xlim(4e4, 3e5) plt.xscale('log') plt.legend() plt.title(f'{el[3].ion_name_roman} Equilibrium Ionization') plt.show() .. image-sg:: /generated/gallery/user_guide/images/sphx_glr_plot_ioneq_003.png :alt: C IV Equilibrium Ionization :srcset: /generated/gallery/user_guide/images/sphx_glr_plot_ioneq_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.805 seconds) .. _sphx_glr_download_generated_gallery_user_guide_plot_ioneq.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_ioneq.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_ioneq.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_