.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/user_guide/ion_collection.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_ion_collection.py: Creating an `IonCollection` =========================== This example shows how to create an `~fiasco.IonCollection` object. .. GENERATED FROM PYTHON SOURCE LINES 7-19 .. code-block:: Python import astropy.units as u import matplotlib.pyplot as plt import numpy as np from astropy.visualization import quantity_support import fiasco # sphinx_gallery_thumbnail_number = 2 quantity_support() .. rst-class:: sphx-glr-script-out .. code-block:: none .MplQuantityConverter object at 0x7fc3a277dcd0> .. GENERATED FROM PYTHON SOURCE LINES 20-28 The `~fiasco.IonCollection` object allows you to create arbitrary collections of `~fiasco.Ion` objects. This provides an easy way to compute quantities that combine emission from multiple ions, such as a spectra or a radiative loss curve. We will create `~fiasco.IonCollection` containing both O VI and Fe XVIII .. GENERATED FROM PYTHON SOURCE LINES 28-34 .. code-block:: Python temperature = np.geomspace(1e4,1e8,100) * u.K fe18 = fiasco.Ion('Fe XVIII', temperature) o6 = fiasco.Ion('O VI', temperature) col = fiasco.IonCollection(fe18, o6) print(col) .. rst-class:: sphx-glr-script-out .. code-block:: none Ion Collection -------------- Number of ions: 2 Temperature range: [0.010 MK, 100.000 MK] Available Ions -------------- Fe 18 O 6 .. GENERATED FROM PYTHON SOURCE LINES 35-39 The only requirement for ions in the same collection is that they use the same ``temperature`` array. We can also index our collection in the same manner as a `~fiasco.Element` object to access the individual ions. .. GENERATED FROM PYTHON SOURCE LINES 39-41 .. code-block:: Python print(col[0]) .. rst-class:: sphx-glr-script-out .. code-block:: none CHIANTI Database Ion --------------------- Name: Fe 18 Element: iron (26) Charge: +17 Number of Levels: 337 Number of Transitions: 7712 Temperature range: [0.010 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 42-43 Or iterate through them. .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python for ion in col: print(ion.ion_name_roman) .. rst-class:: sphx-glr-script-out .. code-block:: none Fe XVIII O VI .. GENERATED FROM PYTHON SOURCE LINES 47-50 You can also create a collection using the addition operator. This is equivalent to using the `~fiasco.IonCollection` constructor as we did above. .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python col = fe18 + o6 .. GENERATED FROM PYTHON SOURCE LINES 53-56 Furthermore, you can iteratively build a collection in this way as well. For example, to create a new collection that includes Fe XV from the collection we created above, .. GENERATED FROM PYTHON SOURCE LINES 56-59 .. code-block:: Python new_col = col + fiasco.Ion('Fe XV', temperature) print(new_col) .. rst-class:: sphx-glr-script-out .. code-block:: none Ion Collection -------------- Number of ions: 3 Temperature range: [0.010 MK, 100.000 MK] Available Ions -------------- Fe 18 O 6 Fe 15 .. GENERATED FROM PYTHON SOURCE LINES 60-63 You can even add `~fiasco.Element` objects as well, which results in every ion of that element being added to your collection. .. GENERATED FROM PYTHON SOURCE LINES 63-66 .. code-block:: Python new_col = col + fiasco.Element('carbon', temperature) print(new_col) .. rst-class:: sphx-glr-script-out .. code-block:: none Ion Collection -------------- Number of ions: 9 Temperature range: [0.010 MK, 100.000 MK] Available Ions -------------- Fe 18 O 6 C 1 C 2 C 3 C 4 C 5 C 6 C 7 .. GENERATED FROM PYTHON SOURCE LINES 67-74 There are several methods on `~fiasco.IonCollection` for easily computing quantities with contributions from multiple ions. As an example, let's compute the radiative loss for our collection containing Fe XVIII and O VI. First, let's create an `~fiasco.IonCollection` containing just Fe XVIII. .. GENERATED FROM PYTHON SOURCE LINES 74-76 .. code-block:: Python col = fiasco.IonCollection(fe18) .. GENERATED FROM PYTHON SOURCE LINES 77-79 Now, let's compute the radiative loss as a function of temperature for just Fe XVIII .. GENERATED FROM PYTHON SOURCE LINES 79-86 .. code-block:: Python density = 1e9*u.cm**(-3) rl = col.radiative_loss(density) plt.plot(col.temperature, rl) plt.yscale('log') plt.xscale('log') plt.ylim(1e-30, 1e-20) .. image-sg:: /generated/gallery/user_guide/images/sphx_glr_ion_collection_001.png :alt: ion collection :srcset: /generated/gallery/user_guide/images/sphx_glr_ion_collection_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none WARNING: No proton data available for Fe 18. Not including proton excitation and de-excitation in level populations calculation. [fiasco.ions] (1e-30, 1e-20) .. GENERATED FROM PYTHON SOURCE LINES 87-88 Next, let's add O VI and again compute the radiative loss. .. GENERATED FROM PYTHON SOURCE LINES 88-97 .. code-block:: Python new_col = fe18 + o6 rl_new = new_col.radiative_loss(density) plt.plot(col.temperature, rl, label=','.join([i.ion_name_roman for i in col])) plt.plot(new_col.temperature, rl_new, label=','.join([i.ion_name_roman for i in new_col])) plt.yscale('log') plt.xscale('log') plt.ylim(1e-30, 1e-20) plt.legend() .. image-sg:: /generated/gallery/user_guide/images/sphx_glr_ion_collection_002.png :alt: ion collection :srcset: /generated/gallery/user_guide/images/sphx_glr_ion_collection_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none WARNING: No proton data available for Fe 18. Not including proton excitation and de-excitation in level populations calculation. [fiasco.ions] 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 98-100 By comparing the radiative losses, we can clearly see at what temperatures the respective ions are dominating. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 25.449 seconds) .. _sphx_glr_download_generated_gallery_user_guide_ion_collection.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ion_collection.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ion_collection.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_