.. 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 O VI as a function of temperature at a given density. .. 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 0x7ce9ee315fd0> .. GENERATED FROM PYTHON SOURCE LINES 19-22 Specify the plasma properties; note that an `~fiasco.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, 10, 26) * 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 Isoelectronic Sequence: Li Number of Levels: 923 Number of Transitions: 25876 Temperature range: [0.100 MK, 10.000 MK] HDF5 Database: /home/docs/.fiasco/chianti_dbase.h5 Using Datasets: ionization_fraction: chianti abundance: sun_coronal_1992_feldman_ext ip: chianti .. GENERATED FROM PYTHON SOURCE LINES 31-32 Calculate the contribution function .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python contribution_func = ion.contribution_function(ne) .. 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] WARNING: No proton data available for O 7. Not including proton excitation and de-excitation in level populations calculation. [fiasco.ions] .. GENERATED FROM PYTHON SOURCE LINES 35-38 Because the contribution function is calculated for all transitions at once, we need to get the index of the transition closest to the specified wavelength. .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: Python wavelength = 1031.92 * u.Angstrom transitions = ion.transitions.wavelength[ion.transitions.is_bound_bound] idx = np.argmin(np.abs(transitions - wavelength)) .. GENERATED FROM PYTHON SOURCE LINES 43-44 Plot the result .. GENERATED FROM PYTHON SOURCE LINES 44-51 .. code-block:: Python plt.plot(Te, contribution_func[:, 0, idx], label=f'{ion.atomic_symbol} {ion.charge_state}+ {wavelength:latex}') 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 37.905 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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_contribution_function.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_