.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/processing/background_subtraction.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_background_subtraction.py: Background subtraction ====================== If your diffraction data is noisy, you might want to subtract the background from the dataset. Pyxem offers some built-in functionality for this, with the `subtract_diffraction_background` class method. Custom filtering is also possible, an example is shown in the 'Filtering Data'-example. .. GENERATED FROM PYTHON SOURCE LINES 10-35 .. code-block:: Python import pyxem as pxm import hyperspy.api as hs s = pxm.data.tilt_boundary_data() s_filtered = s.subtract_diffraction_background( "difference of gaussians", inplace=False, min_sigma=3, max_sigma=20, ) s_filtered_h = s.subtract_diffraction_background("h-dome", inplace=False, h=0.7) hs.plot.plot_images( [s.inav[2, 2], s_filtered.inav[2, 2], s_filtered_h.inav[2, 2]], label=["Original", "Difference of Gaussians", "H-Dome"], tight_layout=True, norm="symlog", cmap="viridis", colorbar=None, ) .. image-sg:: /examples/processing/images/sphx_glr_background_subtraction_001.png :alt: Original, Difference of Gaussians, H-Dome :srcset: /examples/processing/images/sphx_glr_background_subtraction_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/33 [00:00, , ] .. GENERATED FROM PYTHON SOURCE LINES 36-44 ====================== Filtering Polar Images ====================== The available methods differ for `Diffraction2D` datasets and `PolarDiffraction2D` datasets. Set the center of the diffraction pattern to its default, i.e. the middle of the image .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: Python s.calibration.center = None .. GENERATED FROM PYTHON SOURCE LINES 48-49 Transform to polar coordinates .. GENERATED FROM PYTHON SOURCE LINES 49-72 .. code-block:: Python s_polar = s.get_azimuthal_integral2d(npt=100, mean=True) s_polar_filtered = s_polar.subtract_diffraction_background( "radial median", inplace=False, ) s_polar_filtered2 = s_polar.subtract_diffraction_background( "radial percentile", percentile=70, inplace=False, ) hs.plot.plot_images( [s_polar.inav[2, 2], s_polar_filtered.inav[2, 2], s_polar_filtered2.inav[2, 2]], label=["Original (polar)", "Radial Median", "Radial Percentile"], tight_layout=True, norm="symlog", cmap="viridis", colorbar=None, ) .. image-sg:: /examples/processing/images/sphx_glr_background_subtraction_002.png :alt: Original (polar), Radial Median, Radial Percentile :srcset: /examples/processing/images/sphx_glr_background_subtraction_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/17 [00:00, , ] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 11.650 seconds) .. _sphx_glr_download_examples_processing_background_subtraction.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: background_subtraction.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: background_subtraction.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: background_subtraction.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_