.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/user_guide/plot_contribution_function.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_contribution_function.py: Calculating a contribution function =================================== This example shows how to calculate the contribution function of a particular transition of a particular ion, at given temperatures and densities. .. GENERATED FROM PYTHON SOURCE LINES 8-18 .. 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 Ion quantity_support() .. rst-class:: sphx-glr-script-out .. code-block:: none .MplQuantityConverter object at 0x7fc3a21f07d0> .. GENERATED FROM PYTHON SOURCE LINES 19-22 Specify the plasma properties; note that an `Ion` has to be created with a range of temperatures, but the density is only used later in the contribution function calculation. .. GENERATED FROM PYTHON SOURCE LINES 22-25 .. code-block:: Python Te = np.geomspace(0.1, 100, 51) * u.MK ne = 1e8 * u.cm**-3 .. GENERATED FROM PYTHON SOURCE LINES 26-27 Create the ion object .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python ion = Ion('O 5+', Te) print(ion) .. rst-class:: sphx-glr-script-out .. code-block:: none CHIANTI Database Ion --------------------- Name: O 6 Element: oxygen (8) Charge: +5 Number of Levels: 268 Number of Transitions: 3706 Temperature range: [0.100 MK, 100.000 MK] HDF5 Database: /home/docs/.fiasco/chianti_dbase.h5 Using Datasets: ioneq: chianti abundance: sun_coronal_1992_feldman_ext ip: chianti .. GENERATED FROM PYTHON SOURCE LINES 31-33 Calculate the contribution function, and get the index of the transition closest to the desired wavelength .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python contribution_func = ion.contribution_function(ne) wlen = 1031.93 * u.Angstrom .. rst-class:: sphx-glr-script-out .. code-block:: none WARNING: No proton data available for O 6. Not including proton excitation and de-excitation in level populations calculation. [fiasco.ions] .. GENERATED FROM PYTHON SOURCE LINES 37-40 Because the contribution function is calculated for all transitions at once, we need to get the index of the transition closest to the wavelength specified earlier. .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: Python transitions = ion.transitions.wavelength[~ion.transitions.is_twophoton] idx = np.argmin(np.abs(transitions - wlen)) .. GENERATED FROM PYTHON SOURCE LINES 44-45 Plot the result .. GENERATED FROM PYTHON SOURCE LINES 45-52 .. code-block:: Python plt.plot(Te, contribution_func[:, 0, idx], label=f'{ion.atomic_symbol} {ion.charge_state}+ {wlen}') plt.title('Contribution function') plt.xscale('log') plt.yscale('log') plt.legend() plt.show() .. image-sg:: /generated/gallery/user_guide/images/sphx_glr_plot_contribution_function_001.png :alt: Contribution function :srcset: /generated/gallery/user_guide/images/sphx_glr_plot_contribution_function_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.786 seconds) .. _sphx_glr_download_generated_gallery_user_guide_plot_contribution_function.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_contribution_function.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_contribution_function.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_