
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/plot_cone_old_way.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_plot_cone_old_way.py>`
        to download the full example code.

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

.. _sphx_glr_auto_examples_plot_cone_old_way.py:


The old way analysis
====================

Old workflow for analyzing a deflector scan data. This workflow use the
all the function in the most explicit way without using any entry method.
This is not a recommended workflow but it can help on understanding what it is
behind the entry methods.

.. GENERATED FROM PYTHON SOURCE LINES 13-14

Import the "fundamental" python libraries for a generic data analysis:

.. GENERATED FROM PYTHON SOURCE LINES 14-18

.. code-block:: Python


    import numpy as np
    import matplotlib.pyplot as plt








.. GENERATED FROM PYTHON SOURCE LINES 19-20

Import the navarp libraries:

.. GENERATED FROM PYTHON SOURCE LINES 20-23

.. code-block:: Python


    from navarp.utils import navfile, fermilevel, navplt, ktransf, isocut








.. GENERATED FROM PYTHON SOURCE LINES 24-25

Load the data from a file:

.. GENERATED FROM PYTHON SOURCE LINES 25-29

.. code-block:: Python


    file_name = r"nxarpes_simulated_cone.nxs"
    entry = navfile.load(file_name)





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

 .. code-block:: none

    instrument_name = simulated




.. GENERATED FROM PYTHON SOURCE LINES 30-32

Plot a single slice
Ex: scan = 0.5

.. GENERATED FROM PYTHON SOURCE LINES 32-40

.. code-block:: Python


    scan = 0.5
    scan_ind = np.argmin(abs(entry.scans-scan))
    isoscan = isocut.maps_sum(scan, 0, entry.scans, entry.data)

    qmisoscan = navplt.pimage(
        entry.angles, entry.energies, isoscan, cmap='binary', style='tht_ekin')




.. image-sg:: /auto_examples/images/sphx_glr_plot_cone_old_way_001.png
   :alt: plot cone old way
   :srcset: /auto_examples/images/sphx_glr_plot_cone_old_way_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 41-42

Fermi level determination

.. GENERATED FROM PYTHON SOURCE LINES 42-75

.. code-block:: Python


    energy_range = [93.8, 94.3]
    data_sum = np.sum(entry.data, axis=tuple([0, 1]))
    popt = fermilevel.fit_efermi(entry.energies, data_sum, energy_range)
    efermi, res = popt[0], popt[1]*4

    fig, axfit = plt.subplots(1)
    axfit.axvline(popt[0])
    axfit.plot(entry.energies, data_sum, '+')
    axfit.plot(entry.energies, fermilevel.fermi_fun(entry.energies, *popt), 'r-')
    axfit.set_xlabel(r'Kinetic Energy (eV)')
    axfit.set_xlim(energy_range)
    dvis = data_sum[
        (entry.energies >= energy_range[0]) &
        (entry.energies <= energy_range[1])
    ]
    dvis_min = dvis.min()
    dvis_max = dvis.max()
    dvis_delta = dvis_max - dvis_min
    axfit.set_ylim(
        dvis_min - dvis_delta*0.05,
        dvis_max + dvis_delta*0.05
    )

    # Overwrite hv from the derived fermi level and the known work function
    hv_from_file = np.copy(entry.hv)
    entry.hv = np.array([efermi + entry.analyzer.work_fun])
    print(
        "hv = {:g} eV (from the file was {:g})".format(
            np.squeeze(entry.hv), np.squeeze(hv_from_file))
    )
    print("Energy resolution = {:.0f} meV".format(res*1000))




.. image-sg:: /auto_examples/images/sphx_glr_plot_cone_old_way_002.png
   :alt: plot cone old way
   :srcset: /auto_examples/images/sphx_glr_plot_cone_old_way_002.png
   :class: sphx-glr-single-img


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

 .. code-block:: none

    /build/navarp-1RRLiy/navarp-1.6.0/navarp/utils/fermilevel.py:67: RuntimeWarning: divide by zero encountered in divide
      ddata_s_denergies = ddata_s_denergies/np.abs(data_sum)
    /build/navarp-1RRLiy/navarp-1.6.0/navarp/utils/fermilevel.py:67: RuntimeWarning: invalid value encountered in divide
      ddata_s_denergies = ddata_s_denergies/np.abs(data_sum)
    hv = 98.4881 eV (from the file was 100)
    Energy resolution = 67 meV




.. GENERATED FROM PYTHON SOURCE LINES 76-78

Plot a single slice with fermi level alignment
Ex: scan = 0.5

.. GENERATED FROM PYTHON SOURCE LINES 78-87

.. code-block:: Python


    scan = 0.5
    scan_ind = np.argmin(abs(entry.scans-scan))
    isoscan = isocut.maps_sum(scan, 0, entry.scans, entry.data)

    qmisoscan = navplt.pimage(
        entry.angles, entry.energies-efermi, isoscan,
        cmap='magma_r', style='tht_eef')




.. image-sg:: /auto_examples/images/sphx_glr_plot_cone_old_way_003.png
   :alt: plot cone old way
   :srcset: /auto_examples/images/sphx_glr_plot_cone_old_way_003.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 88-90

Plotting iso-energetic cut
Ex: isoenergy cut at ekin = efermi

.. GENERATED FROM PYTHON SOURCE LINES 90-97

.. code-block:: Python


    ekin = efermi
    dekin = 0.005
    isoev = isocut.maps_sum(ekin, dekin, entry.energies, entry.data)
    qmisoev = navplt.pimage(
        entry.angles, entry.scans, isoev,
        cmap='magma_r', style='tht_phi', cmapscale='linear')



.. image-sg:: /auto_examples/images/sphx_glr_plot_cone_old_way_004.png
   :alt: plot cone old way
   :srcset: /auto_examples/images/sphx_glr_plot_cone_old_way_004.png
   :class: sphx-glr-single-img






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

   **Total running time of the script:** (0 minutes 1.371 seconds)


.. _sphx_glr_download_auto_examples_plot_cone_old_way.py:

.. only:: html

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

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

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

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_cone_old_way.zip <plot_cone_old_way.zip>`


.. only:: html

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

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