.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/processing/centering_the_zero_beam.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_examples_processing_centering_the_zero_beam.py: Centering the Zero Beam ======================= .. GENERATED FROM PYTHON SOURCE LINES 7-8 Making a Dummy Dataset with a Zero Beam that systematically deviates from the center .. GENERATED FROM PYTHON SOURCE LINES 8-13 .. code-block:: Python import hyperspy.api as hs import pyxem as pxm s = pxm.data.tilt_boundary_data(correct_pivot_point=False) .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/49 [00:00, ] .. GENERATED FROM PYTHON SOURCE LINES 30-35 Centering the Zero Beam ----------------------- The zero beam can be centered using the :meth:`center_direct_beam` method. Then we sum all the diffraction patterns for the both the centered beam, and the non-centered one, to compare them. .. GENERATED FROM PYTHON SOURCE LINES 35-42 .. code-block:: Python s_centered = s.center_direct_beam(shifts=s_linear_plane, inplace=False) s_pacbed_centered = s_centered.sum() s_pacbed = s.sum() hs.plot.plot_images([s_pacbed, s_pacbed_centered], label=["Original", "Centered"]) .. image-sg:: /examples/processing/images/sphx_glr_centering_the_zero_beam_003.png :alt: Original, Centered :srcset: /examples/processing/images/sphx_glr_centering_the_zero_beam_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/49 [00:00, ] .. GENERATED FROM PYTHON SOURCE LINES 43-55 Centering the Zero Beam with constant deflection magnitude ---------------------------------------------------------- In the presence of electromagnetic fields in the entire sample area, the plane fitting can fail. In this case, two separate effects can be observed: 1. The zero beam position varies systematically with the scan position due to the effects of descan 2. The zero beam will be deflected from electromagnetic fields in the sample Assuming that the effects of 1 are systematic and that the electromagnetic fields have constant strengths, we can try to fit a plane to correct for effects of 1 by minimizing the magnitude variance. You may need use a mask and/or have several electromagnetic domains for good performance. .. GENERATED FROM PYTHON SOURCE LINES 55-60 .. code-block:: Python s_probes = pxm.data.simulated_constant_shift_magnitude() s_shifts = s_probes.get_direct_beam_position(method="center_of_mass") .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/49 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: centering_the_zero_beam.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: centering_the_zero_beam.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_