.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/comparisons/compare_matrix_contributions.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_auto_examples_comparisons_compare_matrix_contributions.py: Matrix Contribution Correlation Comparison ========================================== This example demonstrates how to generate a matrix comparison plot for the contribution correlation method (described in :ref:`sphx_glr_auto_examples_matrix_plot_matrix_of_contribution_plots.py` and :ref:`sphx_glr_auto_examples_correlation_plot_perturbation_correlation_plot.py`). This example compares the calculated correlation correlation coefficient to the TSUNAMI-IP calculated :math:`c_k` value for a set of SDFs computed from the HMF series of critical experiments [Bess2019]_. .. GENERATED FROM PYTHON SOURCE LINES 12-17 Getting TSUNAMI-IP :math:`c_k` Values ------------------------------------- First, we need to get the TSUNAMI-IP :math:`c_k` values for the experiment and application SDFs we want to compare. We can do this by using the :func:`tsunami_ip_utils.integral_indices.get_integral_indices` function, as shown in :ref:`sphx_glr_auto_examples_integral_index_reader.py`. .. GENERATED FROM PYTHON SOURCE LINES 17-29 .. code-block:: Python from tsunami_ip_utils.integral_indices import get_integral_indices from paths import EXAMPLES application_sdfs = [ EXAMPLES / 'data' / 'example_sdfs' / 'HMF' / f'HEU-MET-FAST-003-00{i}.sdf' for i in range(1, 8) ] experiment_sdfs = application_sdfs # Get the TSUNAMI-IP integral indices coverx_library = '56groupcov7.1' integral_indices = get_integral_indices(application_sdfs, experiment_sdfs, coverx_library=coverx_library) c_k = integral_indices['c_k'] .. GENERATED FROM PYTHON SOURCE LINES 30-38 Nuclide-Wise Comparison ----------------------- Variance Contributions ^^^^^^^^^^^^^^^^^^^^^^ First we show a comparison of the calculated correlation coefficient using the contribution correlation method with nuclide-wise variance contributions to the TSUNAMI-IP :math:`c_k` values. To generate this comparison, we just have to specify the correct method, which in this case is ``'variance_contributions_nuclide'``. .. GENERATED FROM PYTHON SOURCE LINES 38-55 .. code-block:: Python from tsunami_ip_utils.comparisons import correlation_comparison labels = { 'applications': [ application_file.name for application_file in application_sdfs ], 'experiments': [ experiment_file.name for experiment_file in experiment_sdfs ], } comparisons, fig = correlation_comparison( integral_index_matrix=c_k, integral_index_name='c_k', application_files=application_sdfs, experiment_files=experiment_sdfs, method='variance_contributions_nuclide', matrix_plot_kwargs={'labels': labels}, ) fig.show() .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 56-59 Uncertainty Contributions ^^^^^^^^^^^^^^^^^^^^^^^^^ We can also generate a comparison using the contribution correlation method with the uncertainty contributions .. GENERATED FROM PYTHON SOURCE LINES 59-69 .. code-block:: Python comparisons, fig = correlation_comparison( integral_index_matrix=c_k, integral_index_name='c_k', application_files=application_sdfs, experiment_files=experiment_sdfs, method='uncertainty_contributions_nuclide', ) fig.show() .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 70-71 We can also generate an image of the comparison .. GENERATED FROM PYTHON SOURCE LINES 71-83 .. code-block:: Python comparisons, fig = correlation_comparison( integral_index_matrix=c_k, integral_index_name='c_k', application_files=application_sdfs, experiment_files=experiment_sdfs, method='uncertainty_contributions_nuclide', ) fig.to_image( EXAMPLES / '_static' / 'contribution_matrix_comparison.png' ) # sphinx_gallery_thumbnail_path = '../../examples/_static/contribution_matrix_comparison.png' .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 84-88 Generating a Comparison Heatmap ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ We can also generate a heatmap of the comparison between the calculated correlation coefficient and the TSUNAMI-IP :math:`c_k` values by using the :func:`tsunami_ip_utils.viz.generate_heatmap_from_comparison` function. .. GENERATED FROM PYTHON SOURCE LINES 88-95 .. code-block:: Python from tsunami_ip_utils.viz import generate_heatmap_from_comparison plot_dict = generate_heatmap_from_comparison(comparisons) print(plot_dict.keys()) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/comparisons/images/sphx_glr_compare_matrix_contributions_001.png :alt: compare matrix contributions :srcset: /auto_examples/comparisons/images/sphx_glr_compare_matrix_contributions_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/comparisons/images/sphx_glr_compare_matrix_contributions_002.png :alt: compare matrix contributions :srcset: /auto_examples/comparisons/images/sphx_glr_compare_matrix_contributions_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/comparisons/images/sphx_glr_compare_matrix_contributions_003.png :alt: compare matrix contributions :srcset: /auto_examples/comparisons/images/sphx_glr_compare_matrix_contributions_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/comparisons/images/sphx_glr_compare_matrix_contributions_004.png :alt: compare matrix contributions :srcset: /auto_examples/comparisons/images/sphx_glr_compare_matrix_contributions_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none dict_keys(['Calculated', 'TSUNAMI-IP', 'Percent Difference']) .. GENERATED FROM PYTHON SOURCE LINES 96-100 The :func:`tsunami_ip_utils.viz.generate_heatmap_from_comparison` takes in the comparison dataframe generated by the :func:`tsunami_ip_utils.comparisons_correlation_comparison` function and returns a dictionary of matplotlib heatmaps. From the output above you can see that the function contains heatmaps of the calculated value, the TSUNAMI-IP value, and the percent difference between the two. Note that this function was used to generate the plots shown in the :ref:`technical manual `. .. GENERATED FROM PYTHON SOURCE LINES 100-108 .. code-block:: Python fig, axs = plot_dict['Calculated'] fig.show() fig, axs = plot_dict['TSUNAMI-IP'] fig.show() fig, axs = plot_dict['Percent Difference'] fig.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (2 minutes 4.479 seconds) .. _sphx_glr_download_auto_examples_comparisons_compare_matrix_contributions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: compare_matrix_contributions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: compare_matrix_contributions.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: compare_matrix_contributions.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_