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

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

.. _sphx_glr_auto_examples_plot_gr_deflector_scan.py:


Graphene deflector scan
===============================

Simple workflow for analyzing a deflector scan data of graphene as simulated
from a third nearest neighbor tight binding model.
The same workflow can be applied to any tilt-, polar- or deflector-scan.

.. GENERATED FROM PYTHON SOURCE LINES 12-13

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

.. GENERATED FROM PYTHON SOURCE LINES 13-17

.. code-block:: Python


    import numpy as np
    import matplotlib.pyplot as plt








.. GENERATED FROM PYTHON SOURCE LINES 18-19

Instead of loading the file as for example:

.. GENERATED FROM PYTHON SOURCE LINES 19-24

.. code-block:: Python


    # from navarp.utils import navfile
    # file_name = r"nxarpes_simulated_cone.nxs"
    # entry = navfile.load(file_name)








.. GENERATED FROM PYTHON SOURCE LINES 25-27

Here we build the simulated graphene signal with a dedicated function defined
just for this purpose:

.. GENERATED FROM PYTHON SOURCE LINES 27-38

.. code-block:: Python

    from navarp.extras.simulation import get_tbgraphene_deflector

    entry = get_tbgraphene_deflector(
        scans=np.linspace(-5., 5., 51),
        angles=np.linspace(-7, 7, 300),
        ebins=np.linspace(-3.3, 0.4, 450),
        tht_an=-18,
        phi_an=0,
        hv=120
    )








.. GENERATED FROM PYTHON SOURCE LINES 39-43

Plot a single analyzer image at scan = 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
First I have to extract the isoscan from the entry, so I use the isoscan
method of entry:

.. GENERATED FROM PYTHON SOURCE LINES 43-45

.. code-block:: Python

    iso0 = entry.isoscan(scan=0, dscan=0)








.. GENERATED FROM PYTHON SOURCE LINES 46-47

Then to plot it using the 'show' method of the extracted iso0:

.. GENERATED FROM PYTHON SOURCE LINES 47-49

.. code-block:: Python

    iso0.show(yname='ekin')




.. image-sg:: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_001.png
   :alt: plot gr deflector scan
   :srcset: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_001.png
   :class: sphx-glr-single-img


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

 .. code-block:: none


    <matplotlib.collections.QuadMesh object at 0x7f088c5d47a0>



.. GENERATED FROM PYTHON SOURCE LINES 50-51

Or by string concatenation, directly as:

.. GENERATED FROM PYTHON SOURCE LINES 51-53

.. code-block:: Python

    entry.isoscan(scan=0, dscan=0).show(yname='ekin')




.. image-sg:: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_002.png
   :alt: plot gr deflector scan
   :srcset: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_002.png
   :class: sphx-glr-single-img


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

 .. code-block:: none


    <matplotlib.collections.QuadMesh object at 0x7f088c5c2600>



.. GENERATED FROM PYTHON SOURCE LINES 54-59

Fermi level determination
^^^^^^^^^^^^^^^^^^^^^^^^^
The initial guess for the binding energy is: ebins = ekins - (hv - work_fun).
However, the better way is to proper set the Fermi level first and then
derives everything form it. The Fermi level can be given directly as a value using:

.. GENERATED FROM PYTHON SOURCE LINES 59-62

.. code-block:: Python


    entry.set_efermi(114.8)








.. GENERATED FROM PYTHON SOURCE LINES 63-67

Or it can be detected from a fit using the method autoset_efermi.
In both cases the binding energy and the photon energy will be updated
consistently. Note that the work function depends on the beamline or
laboratory. If not specified is 4.5 eV.

.. GENERATED FROM PYTHON SOURCE LINES 67-74

.. code-block:: Python


    entry.autoset_efermi(scan_range=[-5, 5], energy_range=[115.2, 115.8])
    print("Energy of the Fermi level = {:.0f} eV".format(entry.efermi))
    print("Energy resolution = {:.0f} meV".format(entry.efermi_fwhm*1000))

    entry.plt_efermi_fit()




.. image-sg:: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_003.png
   :alt: plot gr deflector scan
   :srcset: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_003.png
   :class: sphx-glr-single-img


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

 .. code-block:: none

    Fermi level at 115.4017 eV
    Energy resolution = 56.4 meV (i.e. FWHM of the Gaussian shape which, convoluted with a step function, fits the Fermi edge)
    Photon energy is now set to 120.0017 eV (instead of 120.0000 eV)
    Energy of the Fermi level = 115 eV
    Energy resolution = 56 meV




.. GENERATED FROM PYTHON SOURCE LINES 75-77

Plot a single analyzer image at scan = 0 with the Fermi level aligned
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. GENERATED FROM PYTHON SOURCE LINES 77-80

.. code-block:: Python


    entry.isoscan(scan=0, dscan=0).show(yname='eef')




.. image-sg:: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_004.png
   :alt: plot gr deflector scan
   :srcset: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_004.png
   :class: sphx-glr-single-img


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

 .. code-block:: none


    <matplotlib.collections.QuadMesh object at 0x7f088c9763f0>



.. GENERATED FROM PYTHON SOURCE LINES 81-83

Plotting iso-energetic cut at ekin = efermi
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. GENERATED FROM PYTHON SOURCE LINES 83-86

.. code-block:: Python


    entry.isoenergy(0).show()




.. image-sg:: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_005.png
   :alt: plot gr deflector scan
   :srcset: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_005.png
   :class: sphx-glr-single-img


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

 .. code-block:: none


    <matplotlib.collections.QuadMesh object at 0x7f088c6b8a10>



.. GENERATED FROM PYTHON SOURCE LINES 87-94

Plotting in the reciprocal space (k-space)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I have to define first the reference point to be used for the transformation.
Meaning a point in the angular space which I know it correspond to a
particular point in the k-space. In this case the graphene Dirac-point which
is at ekin = 114.3 eV, in angle is at (tht_p, phi_p) = (0.1, 0) and in the
k-space has to correspond to (kx, ky) = (1.7, 0).

.. GENERATED FROM PYTHON SOURCE LINES 94-103

.. code-block:: Python


    entry.set_kspace(
        tht_p=0.1,
        k_along_slit_p=1.7,
        scan_p=0,
        ks_p=0,
        e_kin_p=114.3,
    )





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

 .. code-block:: none

    tht_an = -17.979
    scan_type =  deflector
    inn_pot = 14.000
    scans_0 = 0.000
    phi_an = 0.000
    kspace transformation ready




.. GENERATED FROM PYTHON SOURCE LINES 104-106

Once it is set, all the isoscan or isoenergy extracted from the entry will
now get their proper k-space scales:

.. GENERATED FROM PYTHON SOURCE LINES 106-109

.. code-block:: Python


    entry.isoscan(0).show()




.. image-sg:: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_006.png
   :alt: plot gr deflector scan
   :srcset: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_006.png
   :class: sphx-glr-single-img


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

 .. code-block:: none


    <matplotlib.collections.QuadMesh object at 0x7f088ca95d90>



.. GENERATED FROM PYTHON SOURCE LINES 110-115

.. code-block:: Python


    # sphinx_gallery_thumbnail_number = 7

    entry.isoenergy(0).show()




.. image-sg:: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_007.png
   :alt: plot gr deflector scan
   :srcset: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_007.png
   :class: sphx-glr-single-img


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

 .. code-block:: none


    <matplotlib.collections.QuadMesh object at 0x7f088c5f87d0>



.. GENERATED FROM PYTHON SOURCE LINES 116-117

I can also place together in a single figure different images:

.. GENERATED FROM PYTHON SOURCE LINES 117-126

.. code-block:: Python



    fig, axs = plt.subplots(1, 2)

    entry.isoscan(0).show(ax=axs[0])
    entry.isoenergy(0).show(ax=axs[1])

    plt.tight_layout()




.. image-sg:: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_008.png
   :alt: plot gr deflector scan
   :srcset: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_008.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 127-131

For the isoenergy case, I can also rotate the image around its origin.
Which can be useful sometime if the sample was not exactly aligned during
the data acquisition. Or if you are a fun on what I consider as a very
bad practice, you can repeat the same image at each symmetric point.

.. GENERATED FROM PYTHON SOURCE LINES 131-159

.. code-block:: Python


    fig, axs = plt.subplots(2, 2, constrained_layout=True)

    ax = axs[0][0]
    entry.isoenergy(0).show(ax=ax)
    ax.set_title('No rotation'.format())

    rot_ang = 30
    ax = axs[0][1]
    ax.set_title('Rotation of {} degrees'.format(rot_ang))
    entry.isoenergy(0).show(ax=ax, rotate=rot_ang)

    rot_ang = 90
    ax = axs[1][0]
    ax.set_title('Rotation of {} degrees'.format(rot_ang))
    entry.isoenergy(0).show(ax=ax, rotate=rot_ang)

    rot_angs = [0, 60, 120, 180, 240, 300]
    ax = axs[1][1]
    ax.set_title('Repetition at every 60 degrees')
    isoen_fs = entry.isoenergy(0)
    for rot_ang in rot_angs:
        isoen_fs.show(ax=ax, rotate=rot_ang)

    for ax in axs.ravel():
        ax.set_aspect('equal')





.. image-sg:: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_009.png
   :alt: No rotation, Rotation of 30 degrees, Rotation of 90 degrees, Repetition at every 60 degrees
   :srcset: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_009.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 160-162

Many other options:
^^^^^^^^^^^^^^^^^^^

.. GENERATED FROM PYTHON SOURCE LINES 162-212

.. code-block:: Python


    fig, axs = plt.subplots(2, 2)

    scan = 0.8
    dscan = 0.05
    ebin = -0.4
    debin = 0.05

    entry.isoscan(scan, dscan).show(ax=axs[0][0], xname='tht', yname='ekin')
    entry.isoscan(scan, dscan).show(ax=axs[0][1], cmap='binary')

    axs[0][0].axhline(ebin-debin+entry.efermi)
    axs[0][0].axhline(ebin+debin+entry.efermi)

    axs[0][1].axhline(ebin-debin)
    axs[0][1].axhline(ebin+debin)

    entry.isoenergy(ebin, debin).show(
        ax=axs[1][0], xname='tht', yname='phi', cmap='cividis')
    entry.isoenergy(ebin, debin).show(
        ax=axs[1][1], cmap='magma', cmapscale='log')

    axs[1][0].axhline(scan, color='w')

    x_note = 0.05
    y_note = 0.98

    for ax in axs[0][:]:
        ax.annotate(
            "$scan \: = \: {} \pm {} \; ^\circ$".format(scan, dscan),
            (x_note, y_note),
            xycoords='axes fraction',
            size=8, rotation=0, ha="left", va="top",
            bbox=dict(
                boxstyle="round", fc='w', alpha=0.65, edgecolor='None', pad=0.05
            )
        )

    for ax in axs[1][:]:
        ax.annotate(
            "$E-E_F \: = \: {} \pm {} \; eV$".format(ebin, debin),
            (x_note, y_note),
            xycoords='axes fraction',
            size=8, rotation=0, ha="left", va="top",
            bbox=dict(
                boxstyle="round", fc='w', alpha=0.65, edgecolor='None', pad=0.05
            )
        )

    plt.tight_layout()



.. image-sg:: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_010.png
   :alt: plot gr deflector scan
   :srcset: /auto_examples/images/sphx_glr_plot_gr_deflector_scan_010.png
   :class: sphx-glr-single-img


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

 .. code-block:: none

    /build/navarp-vbq5WR/navarp-1.6.0/examples/plot_gr_deflector_scan.py:30: SyntaxWarning: invalid escape sequence '\:'
      scans=np.linspace(-5., 5., 51),
    /build/navarp-vbq5WR/navarp-1.6.0/examples/plot_gr_deflector_scan.py:41: SyntaxWarning: invalid escape sequence '\:'
      # First I have to extract the isoscan from the entry, so I use the isoscan





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

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


.. _sphx_glr_download_auto_examples_plot_gr_deflector_scan.py:

.. only:: html

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

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

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

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

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


.. only:: html

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

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