.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/idl_comparisons/ioneq_comparison.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_idl_comparisons_ioneq_comparison.py: CHIANTI IDL Comparison: Ionization Fraction =============================================== Compare the ionization fraction calculation to that in the CHIANTI IDL routines for a few select ions. .. GENERATED FROM PYTHON SOURCE LINES 7-19 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from astropy.visualization import quantity_support from jinja2 import Template import fiasco from fiasco.tests.idl.helpers import read_idl_test_output quantity_support() .. rst-class:: sphx-glr-script-out .. code-block:: none .MplQuantityConverter object at 0x7fc37d206750> .. GENERATED FROM PYTHON SOURCE LINES 20-23 Define a function for comparing and plotting the outputs from fiasco and IDL. Note that we have precomputed the IDL outputs. .. GENERATED FROM PYTHON SOURCE LINES 23-62 .. code-block:: Python def plot_idl_comparison(x, y_idl, y_python, fig, n_rows, i_row, quantity_name, thresh=1e-6): # Highlight region where value of goft is within some value of the peak idx = np.where(y_idl>=y_idl.max()*thresh) x_thresh_min, x_thresh_max = x[idx[0][[0,-1]]] # Direct comparison ax1 = fig.add_subplot(n_rows, 3, i_row+1) ax1.plot(x, y_python, label='fiasco') ax1.plot(x, y_idl, color='k', marker='o', ls='--', markevery=2, label='IDL') ax1.axvspan(x[0], x_thresh_min, color='r', alpha=0.25) ax1.axvspan(x_thresh_max, x[-1], color='r', alpha=0.25) ax1.set_xscale('log') ax1.set_yscale('log') if i_row == 0: ax1.set_title('Ionization Fraction') ax1.set_xlim(x[[0,-1]]) ax1.set_ylim(y_python.max()*np.array([thresh,2])) ax1.set_ylabel(quantity_name) # Ratio ax2 = fig.add_subplot(n_rows, 3, i_row+2, sharex=ax1) ax2.plot(x, (y_python/y_idl).decompose()) ax2.axvspan(x[0], x_thresh_min, color='r', alpha=0.25) ax2.axvspan(x_thresh_max, x[-1], color='r', alpha=0.25) ax2.axhline(y=1, color='k', ls=':') if i_row == 0: ax2.set_title('fiasco / IDL') diff_limit = .001 ax2.set_ylim(1-diff_limit, 1+diff_limit) # Normalized difference ax3 = fig.add_subplot(n_rows, 3, i_row+3, sharex=ax1) ax3.plot(x, ((y_python - y_idl)/y_idl).decompose()) ax3.axvspan(x[0], x_thresh_min, color='r', alpha=0.25) ax3.axvspan(x_thresh_max, x[-1], color='r', alpha=0.25) ax3.axhline(y=0, color='k', ls=':') if i_row == 0: ax3.set_title('(fiasco - IDL)/IDL') ax3.set_ylim(-diff_limit, diff_limit) return ax1, ax2, ax3 .. GENERATED FROM PYTHON SOURCE LINES 63-72 Next, plot the comparison between the ionization fraction results for a selected number of ions. In the case of fiasco, we will also compute the ionization fraction in addition to reading the tabulated values. The regions highlighted in red denote places where the ionization fraction is less than :math:`10^{-6}` times the peak of the ionization fraction. In these regions, the comparison is between the two results is not as critical as differences due to the interpolation schemes may show large deviations between the two approaches. However, the ionization fraction in these regions does not meaningfully contribute to any other derived quantities. .. GENERATED FROM PYTHON SOURCE LINES 72-100 .. code-block:: Python ioneq_files = [ 'ioneq_1_1', 'ioneq_6_1', 'ioneq_6_2', 'ioneq_6_3', 'ioneq_20_2', 'ioneq_26_5', 'ioneq_26_16', 'ioneq_26_18', 'ioneq_26_20', 'ioneq_26_27', ] fig = plt.figure(figsize=(9,3*len(ioneq_files)), layout='constrained') for i, name in enumerate(ioneq_files): idl_result = read_idl_test_output(name, '8.0.7') ion = fiasco.Ion((idl_result['Z'], idl_result['iz']), idl_result['temperature'], ioneq_filename=idl_result['ioneq_filename']) element = fiasco.Element(ion.atomic_symbol, ion.temperature) ioneq = element.equilibrium_ionization print(f'IDL code to produce ioneq result for {ion.ion_name_roman}:') print(Template(idl_result['idl_script']).render(**idl_result)) axes = plot_idl_comparison(ion.temperature, idl_result['ioneq'], ion.ioneq, fig, len(ioneq_files), 3*i, f'{ion.ion_name_roman}') axes[0].plot(element.temperature, ioneq[:, ion.charge_state], label='fiasco (rates)', color='C1', ls='-') axes[0].legend() plt.show() .. image-sg:: /generated/gallery/idl_comparisons/images/sphx_glr_ioneq_comparison_001.png :alt: Ionization Fraction, fiasco / IDL, (fiasco - IDL)/IDL :srcset: /generated/gallery/idl_comparisons/images/sphx_glr_ioneq_comparison_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/asdf/_asdf.py:359: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/fiasco/tests/idl/data/ioneq_1_1_v8.0.7.asdf' was created with extension URI 'asdf://astropy.org/core/extensions/core-1.5.0' (from package asdf-astropy==0.5.0), which is not currently installed warnings.warn(msg, AsdfWarning) IDL code to produce ioneq result for H I: ioneq_file = FILEPATH('chianti.ioneq', ROOT_DIR=!xuvtop, SUBDIR='ioneq') read_ioneq, ioneq_file, temperature, ioneq, ioneq_ref ioneq = ioneq[*,0,0] /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/asdf/_asdf.py:359: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/fiasco/tests/idl/data/ioneq_6_1_v8.0.7.asdf' was created with extension URI 'asdf://astropy.org/core/extensions/core-1.5.0' (from package asdf-astropy==0.5.0), which is not currently installed warnings.warn(msg, AsdfWarning) IDL code to produce ioneq result for C I: ioneq_file = FILEPATH('chianti.ioneq', ROOT_DIR=!xuvtop, SUBDIR='ioneq') read_ioneq, ioneq_file, temperature, ioneq, ioneq_ref ioneq = ioneq[*,5,0] /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/astropy/units/quantity.py:671: RuntimeWarning: invalid value encountered in divide result = super().__array_ufunc__(function, method, *arrays, **kwargs) /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/asdf/_asdf.py:359: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/fiasco/tests/idl/data/ioneq_6_2_v8.0.7.asdf' was created with extension URI 'asdf://astropy.org/core/extensions/core-1.5.0' (from package asdf-astropy==0.5.0), which is not currently installed warnings.warn(msg, AsdfWarning) IDL code to produce ioneq result for C II: ioneq_file = FILEPATH('chianti.ioneq', ROOT_DIR=!xuvtop, SUBDIR='ioneq') read_ioneq, ioneq_file, temperature, ioneq, ioneq_ref ioneq = ioneq[*,5,1] /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/asdf/_asdf.py:359: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/fiasco/tests/idl/data/ioneq_6_3_v8.0.7.asdf' was created with extension URI 'asdf://astropy.org/core/extensions/core-1.5.0' (from package asdf-astropy==0.5.0), which is not currently installed warnings.warn(msg, AsdfWarning) IDL code to produce ioneq result for C III: ioneq_file = FILEPATH('chianti.ioneq', ROOT_DIR=!xuvtop, SUBDIR='ioneq') read_ioneq, ioneq_file, temperature, ioneq, ioneq_ref ioneq = ioneq[*,5,2] /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/asdf/_asdf.py:359: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/fiasco/tests/idl/data/ioneq_20_2_v8.0.7.asdf' was created with extension URI 'asdf://astropy.org/core/extensions/core-1.5.0' (from package asdf-astropy==0.5.0), which is not currently installed warnings.warn(msg, AsdfWarning) IDL code to produce ioneq result for Ca II: ioneq_file = FILEPATH('chianti.ioneq', ROOT_DIR=!xuvtop, SUBDIR='ioneq') read_ioneq, ioneq_file, temperature, ioneq, ioneq_ref ioneq = ioneq[*,19,1] /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/asdf/_asdf.py:359: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/fiasco/tests/idl/data/ioneq_26_5_v8.0.7.asdf' was created with extension URI 'asdf://astropy.org/core/extensions/core-1.5.0' (from package asdf-astropy==0.5.0), which is not currently installed warnings.warn(msg, AsdfWarning) IDL code to produce ioneq result for Fe V: ioneq_file = FILEPATH('chianti.ioneq', ROOT_DIR=!xuvtop, SUBDIR='ioneq') read_ioneq, ioneq_file, temperature, ioneq, ioneq_ref ioneq = ioneq[*,25,4] /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/asdf/_asdf.py:359: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/fiasco/tests/idl/data/ioneq_26_16_v8.0.7.asdf' was created with extension URI 'asdf://astropy.org/core/extensions/core-1.5.0' (from package asdf-astropy==0.5.0), which is not currently installed warnings.warn(msg, AsdfWarning) IDL code to produce ioneq result for Fe XVI: ioneq_file = FILEPATH('chianti.ioneq', ROOT_DIR=!xuvtop, SUBDIR='ioneq') read_ioneq, ioneq_file, temperature, ioneq, ioneq_ref ioneq = ioneq[*,25,15] /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/asdf/_asdf.py:359: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/fiasco/tests/idl/data/ioneq_26_18_v8.0.7.asdf' was created with extension URI 'asdf://astropy.org/core/extensions/core-1.5.0' (from package asdf-astropy==0.5.0), which is not currently installed warnings.warn(msg, AsdfWarning) IDL code to produce ioneq result for Fe XVIII: ioneq_file = FILEPATH('chianti.ioneq', ROOT_DIR=!xuvtop, SUBDIR='ioneq') read_ioneq, ioneq_file, temperature, ioneq, ioneq_ref ioneq = ioneq[*,25,17] /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/asdf/_asdf.py:359: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/fiasco/tests/idl/data/ioneq_26_20_v8.0.7.asdf' was created with extension URI 'asdf://astropy.org/core/extensions/core-1.5.0' (from package asdf-astropy==0.5.0), which is not currently installed warnings.warn(msg, AsdfWarning) IDL code to produce ioneq result for Fe XX: ioneq_file = FILEPATH('chianti.ioneq', ROOT_DIR=!xuvtop, SUBDIR='ioneq') read_ioneq, ioneq_file, temperature, ioneq, ioneq_ref ioneq = ioneq[*,25,19] /home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/asdf/_asdf.py:359: AsdfWarning: File 'file:///home/docs/checkouts/readthedocs.org/user_builds/fiasco/conda/latest/lib/python3.11/site-packages/fiasco/tests/idl/data/ioneq_26_27_v8.0.7.asdf' was created with extension URI 'asdf://astropy.org/core/extensions/core-1.5.0' (from package asdf-astropy==0.5.0), which is not currently installed warnings.warn(msg, AsdfWarning) IDL code to produce ioneq result for Fe XXVII: ioneq_file = FILEPATH('chianti.ioneq', ROOT_DIR=!xuvtop, SUBDIR='ioneq') read_ioneq, ioneq_file, temperature, ioneq, ioneq_ref ioneq = ioneq[*,25,26] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 14.738 seconds) .. _sphx_glr_download_generated_gallery_idl_comparisons_ioneq_comparison.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ioneq_comparison.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ioneq_comparison.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_