
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/ESR/calculate_covariance.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_ESR_calculate_covariance.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_ESR_calculate_covariance.py:


Calculation of the Covariance Matrix
====================================
After rescaling plots, the covariance matrix is calculated
and then plotted for a 2D Field experiment (spectra as a function
of field with multiple collections or "Times")

.. GENERATED FROM PYTHON SOURCE LINES 9-34



.. rst-class:: sphx-glr-horizontal


    *

      .. image-sg:: /auto_examples/ESR/images/sphx_glr_calculate_covariance_001.png
         :alt: covariance in B domain
         :srcset: /auto_examples/ESR/images/sphx_glr_calculate_covariance_001.png, /auto_examples/ESR/images/sphx_glr_calculate_covariance_001_2_00x.png 2.00x
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /auto_examples/ESR/images/sphx_glr_calculate_covariance_002.png
         :alt: Covariance in U domain
         :srcset: /auto_examples/ESR/images/sphx_glr_calculate_covariance_002.png, /auto_examples/ESR/images/sphx_glr_calculate_covariance_002_2_00x.png 2.00x
         :class: sphx-glr-multi-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    1: covariance in B domain |||('mT', 'mT')
    2: Covariance in U domain |||('kcyc/T', 'kcyc/T')







|

.. code-block:: Python


    import pyspecdata as psd

    fieldaxis = "$B_0$"
    with psd.figlist_var() as fl:
        for filenum, (thisfile, exp_type) in enumerate(
            [("230504_3p8mM_TEMPOL_stb_wt_4x.DSC", "francklab_esr/alex")]
        ):
            # TODO: Zenodo ID does not work. .YGF file is missing from the
            # deposition. Need to fix this.
            d = psd.find_file(thisfile, exp_type=exp_type, zenodo="21287247")[
                "harmonic", 0
            ]
            d.set_units(fieldaxis, "T").set_axis(fieldaxis, lambda x: x * 1e-4)
            d.rename("Time", "observations")
            d.reorder(["observations", fieldaxis])
            fl.next("covariance in B domain")
            # we do this first, because if we were to ift to go to u domain and
            # then ft back, we would introduce a complex component to our data
            fl.image(d.C.cov_mat("observations"))
            d.ift(fieldaxis, shift=True)
            fl.next("Covariance in U domain")
            fl.image(
                d.cov_mat("observations")
            )  # this time, do not spin up an extra copy of the data


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (1 minutes 16.063 seconds)


.. _sphx_glr_download_auto_examples_ESR_calculate_covariance.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: calculate_covariance.ipynb <calculate_covariance.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: calculate_covariance.py <calculate_covariance.py>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
