.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/strain_mapping/strain_mapping.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_strain_mapping_strain_mapping.py: Strain Mapping ============== Strain mapping in pyxem is done by fitting a :class:`~.signals.tensor_field.DisplacementGradientMap` to the data. This can be thought of as image distortion around some central point. .. GENERATED FROM PYTHON SOURCE LINES 8-13 .. code-block:: Python from pyxem.data import simulated_strain import hyperspy.api as hs .. GENERATED FROM PYTHON SOURCE LINES 14-18 In this example we will create a simulated strain map using the :meth:`~.data.simulated_strain` function. This just creates a simulated diffraction pattern and applies a simple "strain" to it. In this case using simulated data is slightly easier for demonstration purposes. If you want to use real data the :meth:`~.data.zrnb_precipitate` dataset is a good example of strain from a precipitate. .. GENERATED FROM PYTHON SOURCE LINES 18-28 .. code-block:: Python strained_signal = simulated_strain( navigation_shape=(32, 32), signal_shape=(512, 512), disk_radius=20, num_electrons=1e5, strain_matrix=None, lazy=True, ) .. GENERATED FROM PYTHON SOURCE LINES 29-31 The first thing we want to do is to find peaks within the diffraction pattern. I'd recommend using the :meth:`~.signals.diffraction2d.get_diffraction_vectors` method .. GENERATED FROM PYTHON SOURCE LINES 31-37 .. code-block:: Python strained_signal.calibration.center = ( None # First set the center to be (256, 256) or the center of the signal ) template_matched = strained_signal.template_match_disk(disk_r=20, subtract_min=False) template_matched.plot(vmin=0.4) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/strain_mapping/images/sphx_glr_strain_mapping_001.png :alt: strain mapping :srcset: /examples/strain_mapping/images/sphx_glr_strain_mapping_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/strain_mapping/images/sphx_glr_strain_mapping_002.png :alt: Signal :srcset: /examples/strain_mapping/images/sphx_glr_strain_mapping_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/65 [00:00` example to see how to select which vectors you want to use more generally. You can also just manually input the un-strained vectors or use simulated/ rotated vectors as well. .. GENERATED FROM PYTHON SOURCE LINES 57-70 .. code-block:: Python first_ring_vectors = diffraction_vectors.filter_magnitude( min_magnitude=0.1, max_magnitude=1, ) unstrained_vectors = first_ring_vectors.inav[0, 0] strain_maps = first_ring_vectors.get_strain_maps( unstrained_vectors=unstrained_vectors, return_residuals=False ) strain_maps.plot() .. image-sg:: /examples/strain_mapping/images/sphx_glr_strain_mapping_005.png :alt: e11, e22, e12, theta :srcset: /examples/strain_mapping/images/sphx_glr_strain_mapping_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/2 [00:00, , , ] .. GENERATED FROM PYTHON SOURCE LINES 71-75 Some final notes about strain mapping. In general, you want to use as many pixels as possible. 512 x 512 is a good place to start. You can do strain mapping with fewer pixels, but the results will be less accurate. Precession also helps improve the results as does having a thinner sample both of which reduce the effects of dynamical diffraction. .. GENERATED FROM PYTHON SOURCE LINES 77-78 sphinx_gallery_thumbnail_number = 5 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 31.719 seconds) .. _sphx_glr_download_examples_strain_mapping_strain_mapping.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: strain_mapping.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: strain_mapping.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: strain_mapping.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_