pyxem / diffsims

An open-source Python library providing utilities for simulating diffraction
https://diffsims.readthedocs.io
GNU General Public License v3.0
46 stars 26 forks source link

Stereographic Projection in Fast Template Matching Tutorial #225

Open SangPham1408 opened 1 month ago

SangPham1408 commented 1 month ago

Describe the bug Hello everyone, I am currently following the Fast Template Matching scripts (https://pyxem.readthedocs.io/en/v0.19.1/tutorials/pyxem-demos/11%20Accelerated%20orientation%20mapping%20with%20template%20matching.html) to map the crystal orientation in my samples. I followed the instruction in the tutorial and what I found a bit confusing is in the get_beam_directions_grid() for stereographic projection mesh grids. I am having a problem when setting crystal_systems = 'monoclinic' which produces the stereographic projection mesh grid that is not as stereographic triangle as expected (see attached file). I checked the source code and it seems to me like the source code for get_beam_directions_grid() should perform the crop to stereographic triangle for different crystal systems (?) (#crop to stereographic triangle which depends on crystal system). Further check with different crystal systems also shows the same for triclinic, trigonal, and orthorhombic (eee attached). I am new in crystal orientation mapping so I am not sure if these types of stenographic projection mesh presentation are common for these crystal systems.

Picture1

The reason why I am asking is because I am having error in the following step when trying to plot the results after doing template matching on the stereographic projection:

image

What I found was the script for stereographic projection (below) reshapes the size of x and y to not match with the number of simulated patterns when I selected the crystal_system = 'monoclinic'. For reference, the number of simulated patterns was 1497 after performing grid_mono = get_beam_directions_grid("monoclinic", resolution=4.3, mesh="spherified_cube_edge") while the shape of x and y after the stereographic projection (below) was 771. Is there any specific reasons for such a change in shape as it does occur for trigonal, triclinic, and orthorhombic as well. Many thanks!

def grid_to_xy(grid):
    from orix.quaternion.rotation import Rotation
    from orix.vector.vector3d import Vector3d
    from orix.projections import StereographicProjection
    s = StereographicProjection(pole=-1)
    rotations_regular =  Rotation.from_euler(np.deg2rad(grid))
    rot_reg_test = rotations_regular*Vector3d.zvector()
    x, y = s.vector2xy(rot_reg_test)
    return x, y