.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/reference_frames/estimate_tilts_about_detector_xaxis_zaxis.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_reference_frames_estimate_tilts_about_detector_xaxis_zaxis.py: Estimate tilts about the detector x and z axis ============================================== This example shows how to (robustly) estimate the tilts about the detector :math:`X_d` and :math:`Z_d` axes, which bring the sample plane normal into coincidence with the detector plane normal (but in the opposite direction) :cite:`winkelmann2020refined`. Estimates are found using :meth:`~kikuchipy.detectors.EBSDDetector.estimate_xtilt_ztilt`, which fits a hyperplane to :attr:`~kikuchipy.detectors.EBSDDetector.pc` using singular value decomposition. To test the estimations, we add some noise to realistic projection center (PC) values (PCx, PCy, PCz). The realistic PCs are extrapolated from a PC in the upper left corner of a map, assuming a nominal sample tilt of 70 degrees, a detector tilt of 0 degrees, a detector pixel size of 70 microns and a sample step size of 50 microns. .. GENERATED FROM PYTHON SOURCE LINES 18-73 .. image-sg:: /examples/reference_frames/images/sphx_glr_estimate_tilts_about_detector_xaxis_zaxis_001.png :alt: estimate tilts about detector xaxis zaxis :srcset: /examples/reference_frames/images/sphx_glr_estimate_tilts_about_detector_xaxis_zaxis_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none True/estimated tilt about detector x [deg]: 20.00/19.21 True/estimated tilt about detector z [deg]: 0/-1.98 | .. code-block:: default import kikuchipy as kp import matplotlib.pyplot as plt import numpy as np plt.rcParams["font.size"] = 18 # Create an initial detector with one PC assumed to be for the upper # left corner of a map det0 = kp.detectors.EBSDDetector( shape=(480, 480), pc=(0.5, 0.3, 0.5), sample_tilt=70, tilt=0, px_size=70, ) # Extrapolate a map of PCs nav_shape = (15, 20) nav_size = np.prod(nav_shape) det = det0.extrapolate_pc( pc_indices=[0, 0], navigation_shape=nav_shape, step_sizes=(50, 50), ) # Add +/- 0.0025 as random noise dev_noise = 0.001 rng = np.random.default_rng() det.pcx += rng.uniform(-dev_noise, dev_noise, nav_size).reshape(nav_shape) det.pcy += rng.uniform(-dev_noise, dev_noise, nav_size).reshape(nav_shape) det.pcz += rng.uniform(-dev_noise, dev_noise, nav_size).reshape(nav_shape) # Add outliers by adding more noise dev_outlier = 0.01 n_outliers = 20 outlier_idx1d = rng.choice(nav_size, n_outliers, replace=False) is_outlier = np.zeros(nav_size, dtype=bool) is_outlier[outlier_idx1d] = True outlier_idx2d = np.unravel_index(outlier_idx1d, shape=det.navigation_shape) det.pcx[outlier_idx2d] += rng.uniform(-dev_outlier, dev_outlier, n_outliers) det.pcy[outlier_idx2d] += rng.uniform(-dev_outlier, dev_outlier, n_outliers) det.pcz[outlier_idx2d] += rng.uniform(-dev_outlier, dev_outlier, n_outliers) # Plot PC values det.plot_pc("scatter") # Robust estimation by detecting outliers xtilt, ztilt = det.estimate_xtilt_ztilt(degrees=True) # Print true tilt and estimated tilt true_xtilt = 90 - det.sample_tilt + det.tilt print(f"True/estimated tilt about detector x [deg]: {true_xtilt:.2f}/{xtilt:.2f}") print(f"True/estimated tilt about detector z [deg]: {0}/{ztilt:.2f}") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.589 seconds) **Estimated memory usage:** 9 MB .. _sphx_glr_download_examples_reference_frames_estimate_tilts_about_detector_xaxis_zaxis.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: estimate_tilts_about_detector_xaxis_zaxis.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: estimate_tilts_about_detector_xaxis_zaxis.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_