From 0ceb15794b969944f99378e51cb2e3aa4367ca38 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 15:21:54 +0000 Subject: [PATCH 01/62] Scopes out get_rotation_list_streographic --- .../generators/rotation_list_generators.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index ea950be5..42c350d8 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -58,6 +58,27 @@ def get_fundemental_zone_grid(space_group_number, resolution): fz_grid_axangle = reduce_to_fundemental_zone(raw_grid_axangle, zone_string) return _returnable_eulers_from_axangle(fz_grid_axangle,'rzxz',round_to=2) +def get_grid_streographic(crystal_system,resolution): + """ + Creates a rotation list by combining the minimum region of the streogram's beam directions + with in plane rotations + + Parameters + ---------- + crytal_system : string + 'cubic','hexagonal','tetragonal','orthorhombic','monoclinic','trigonal' add 'triclinc' which acts as 'none' + + resolution : float + Rotations about beam directions and beam directions are seperated by rotations of the size 'resolution' + """ + beam_directions = Euler(get_beam_directions(crystal_system,resolution,equal='angle'),axis_convention='rzxz') + # convert to szxz + # drop in all the inplane rotations to form z + raw_grid = Euler(z, axis_convention='szxz') + grid_rzxz = raw_grid.to_AxAngle().to_Euler(axis_convention='rzxz') #convert back Bunge convention to return + rotation_list = grid_rzxz.to_rotation_list(round_to=2) + return rotation_list + def get_local_grid(center, max_rotation, resolution): """ From 7849b884329bf65394fecfdd301bcb58dee0361e Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 15:23:21 +0000 Subject: [PATCH 02/62] Callsign for get_beam_directions --- diffsims/generators/rotation_list_generators.py | 4 ++-- diffsims/utils/gridding_utils.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index 42c350d8..1bd04db9 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -27,7 +27,7 @@ from diffsims.utils.fundemental_zone_utils import get_proper_point_group_string, reduce_to_fundemental_zone from diffsims.utils.gridding_utils import create_linearly_spaced_array_in_rzxz,rotate_axangle, \ _create_advanced_linearly_spaced_array_in_rzxz, \ - _get_rotation_to_beam_direction + _get_rotation_to_beam_direction, get_beam_directions def _returnable_eulers_from_axangle(grid,axis_convention,round_to): @@ -72,7 +72,7 @@ def get_grid_streographic(crystal_system,resolution): Rotations about beam directions and beam directions are seperated by rotations of the size 'resolution' """ beam_directions = Euler(get_beam_directions(crystal_system,resolution,equal='angle'),axis_convention='rzxz') - # convert to szxz + # convert to szxz # drop in all the inplane rotations to form z raw_grid = Euler(z, axis_convention='szxz') grid_rzxz = raw_grid.to_AxAngle().to_Euler(axis_convention='rzxz') #convert back Bunge convention to return diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 47b71904..e15ac8ae 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -99,7 +99,7 @@ def rotate_axangle(Axangles, new_center): new_center : (alpha,beta,gamma) The location of the (0,0,0) rotation as an rzxz euler angle - Returns + Returns ------- AxAngles : @@ -169,3 +169,6 @@ def _create_advanced_linearly_spaced_array_in_rzxz(resolution, max_alpha, max_be gamma = np.linspace(0, max_gamma, num=steps_gamma, endpoint=False) z = np.asarray(list(product(alpha, beta, gamma))) return Euler(z, axis_convention='rzxz') + +def get_beam_directions(resolution,crystal_system,equal='angle'): + pass From 996c1d9bd55538689a1fba72437953e2455ba4c7 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 15:24:22 +0000 Subject: [PATCH 03/62] Adds crystal system dictionary --- diffsims/utils/gridding_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index e15ac8ae..ecc6a91c 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -26,6 +26,15 @@ from transforms3d.quaternions import quat2axangle, axangle2quat, mat2quat, qmult from diffsims.utils.rotation_conversion_utils import * +crystal_system_dictionary = +{'cubic':[45,54.7,0], + 'hexagonal':[45,90,26.565], + 'tetragonal':[45,90,0], + 'orthorhombic':[90.90,0], + 'trigonal': [45,90,-116.5], + 'monoclinic':[90,0,-90], + 'none':[360,180,0]} + def vectorised_qmult(q1, qdata): """ A vectorised implementation that multiplies qdata (array) by q1 (single quaternion) """ From 2cbaa228e6016c231a3c0e4df48da8e7ec3bcb6e Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 15:24:51 +0000 Subject: [PATCH 04/62] Call to crystal system dictionary --- diffsims/utils/gridding_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index ecc6a91c..944e7f43 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -180,4 +180,6 @@ def _create_advanced_linearly_spaced_array_in_rzxz(resolution, max_alpha, max_be return Euler(z, axis_convention='rzxz') def get_beam_directions(resolution,crystal_system,equal='angle'): - pass + """ + """ + theta_max,psi_max,psi_min = crystal_system_dictionary[crystal_system] From befec0597a7b30b7bcdfe43e63f61ca16182b47c Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 15:26:31 +0000 Subject: [PATCH 05/62] Including (no implementation) equal area --- diffsims/utils/gridding_utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 944e7f43..2fc30b4c 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -183,3 +183,10 @@ def get_beam_directions(resolution,crystal_system,equal='angle'): """ """ theta_max,psi_max,psi_min = crystal_system_dictionary[crystal_system] + + if equal == 'area': + # http://mathworld.wolfram.com/SpherePointPicking.html + # Need to do sensible point counting for this + raise NotImplementedError("Use equal='angle' instead") + else: + From 54ae5def05a5c0b04e9d17add11108f598e8d84d Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 15:31:46 +0000 Subject: [PATCH 06/62] Adds equal='angle' functionality --- diffsims/utils/gridding_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 2fc30b4c..9271a1a0 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -189,4 +189,7 @@ def get_beam_directions(resolution,crystal_system,equal='angle'): # Need to do sensible point counting for this raise NotImplementedError("Use equal='angle' instead") else: - + steps_theta = int(np.ceil((theta_max - 0)/resolution)) #see docstrings for np.arange, np.linspace has better endpoint handling + steps_psi = int(np.ceil((psi_max - psi_max)/resolution)) + theta = np.linspace(0,theta_max,num=steps_theta) + psi = np.linspace(psi_min,psi_max,num=steps_theta) From 9c3ec2d78ae19521434b2188b26c26632cf89eca Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 15:32:50 +0000 Subject: [PATCH 07/62] Scoping the later stages of get_beam_direction --- diffsims/utils/gridding_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 9271a1a0..5d79ca1a 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -193,3 +193,11 @@ def get_beam_directions(resolution,crystal_system,equal='angle'): steps_psi = int(np.ceil((psi_max - psi_max)/resolution)) theta = np.linspace(0,theta_max,num=steps_theta) psi = np.linspace(psi_min,psi_max,num=steps_theta) + + points_in_spherical_polars = 'x' + if crystal_system = 'cubic': + # reject points below the geodesic + # add points on the geodesic + pass + points_in_cartesians = 'x' + points_as_eulers_from_North_Pole = 'x' From 15d99c8e7f3f0dcc8763a080bfd8154c9109e975 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 16:03:56 +0000 Subject: [PATCH 08/62] vectorised_to_spherical_polars --- diffsims/utils/vector_utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/diffsims/utils/vector_utils.py b/diffsims/utils/vector_utils.py index 60f1ceba..4068f3b7 100644 --- a/diffsims/utils/vector_utils.py +++ b/diffsims/utils/vector_utils.py @@ -65,3 +65,26 @@ def get_angle_cartesian(a, b): if denom == 0: return 0.0 return math.acos(max(-1.0, min(1.0, np.dot(a, b) / denom))) + +def vectorised_spherical_polars_to_cartesians(z): + """ + Converts an array of spherical polars into an array of + (x,y,z) = r(cos(psi)sin(theta),sin(psi)sin(theta),cos(theta)) + + Parameters + ---------- + z : np.array + With rows of + r : the radius value, r = sqrt(x**2+y**2+z**2) + psi : The azimuthal angle generally (0,2pi]) + theta : The elevation angle generally (0,pi) + + Returns + ------- + + """ + r, psi, theta = z[:,0],z[:,1],z[:,2] + x = r * np.cos(psi) * np.sin(theta) + y = r * np.sin(psi) * np.sin(theta) + z = r * np.cos(theta) + return np.asarray([x,y,z]) From 99dfc25a03442798e2b057a6141f4f1ab52754b9 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 16:10:28 +0000 Subject: [PATCH 09/62] Finishing up get_beam_directions --- diffsims/utils/gridding_utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 5d79ca1a..cd1491ed 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -25,6 +25,7 @@ from transforms3d.euler import axangle2euler, euler2axangle, euler2mat from transforms3d.quaternions import quat2axangle, axangle2quat, mat2quat, qmult from diffsims.utils.rotation_conversion_utils import * +from diffsims.utils.vector_utils import vectorised_spherical_polars_to_cartesians crystal_system_dictionary = {'cubic':[45,54.7,0], @@ -194,10 +195,17 @@ def get_beam_directions(resolution,crystal_system,equal='angle'): theta = np.linspace(0,theta_max,num=steps_theta) psi = np.linspace(psi_min,psi_max,num=steps_theta) - points_in_spherical_polars = 'x' + psi_theta = np.asarray(list(product(psi,theta))) + r = np.ones((psi_theta.shape[0],1)) + points_in_spherical_polars = np.hstack((r,psi_theta)) + if crystal_system = 'cubic': # reject points below the geodesic # add points on the geodesic pass - points_in_cartesians = 'x' - points_as_eulers_from_North_Pole = 'x' + + points_in_cartesians = vectorised_spherical_polars_to_cartesians(z) + axis = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] + angle = np.arcsin(np.linalg.norm(axis)) + eulers = AxAngle(np.hstack(axis,angle)).to_Euler(axis_convention='rzxz') + return eulers From 0308cd8065f0a966cdc98a97051b2aeb70588ef2 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 16:24:16 +0000 Subject: [PATCH 10/62] Building the beam direction spins for get_grid_streographic --- diffsims/generators/rotation_list_generators.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index 1bd04db9..3294977b 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -71,9 +71,19 @@ def get_grid_streographic(crystal_system,resolution): resolution : float Rotations about beam directions and beam directions are seperated by rotations of the size 'resolution' """ + from itertools import product beam_directions = Euler(get_beam_directions(crystal_system,resolution,equal='angle'),axis_convention='rzxz') - # convert to szxz + beam_directions_szxz = beam_directions.toAxAngle().toEuler(axis_convention='szxz') # convert to high speed convention + # drop in all the inplane rotations to form z + alpha = beam_directions.data[:,:0] + beta = beam_directions.data[:,:1] + in_plane = np.arange(0,360,resolution) + + ipalpha = np.asarray(list(product(alpha,np.asarray(in_plane)))) + ipbeta = np.asarray(list(product(beta,np.asarray(in_plane)))) + z = np.rad2deg(np.hstack(ipalpha[:,0],ipbeta)) + raw_grid = Euler(z, axis_convention='szxz') grid_rzxz = raw_grid.to_AxAngle().to_Euler(axis_convention='rzxz') #convert back Bunge convention to return rotation_list = grid_rzxz.to_rotation_list(round_to=2) From 20c2ca7c6530abe4d40642122a7952a26e63e738 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 16:43:21 +0000 Subject: [PATCH 11/62] Including the reshape discovered when making #53 --- diffsims/generators/rotation_list_generators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index 3294977b..941eabe0 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -82,7 +82,7 @@ def get_grid_streographic(crystal_system,resolution): ipalpha = np.asarray(list(product(alpha,np.asarray(in_plane)))) ipbeta = np.asarray(list(product(beta,np.asarray(in_plane)))) - z = np.rad2deg(np.hstack(ipalpha[:,0],ipbeta)) + z = np.rad2deg(np.hstack(ipalpha[:,0].reshape((-1,1)),ipbeta)) raw_grid = Euler(z, axis_convention='szxz') grid_rzxz = raw_grid.to_AxAngle().to_Euler(axis_convention='rzxz') #convert back Bunge convention to return From 57ffeeca18e0b85ad712d675af9078c9a936ad4a Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 16:45:18 +0000 Subject: [PATCH 12/62] Adds an assertionless test to check nothing is very broken --- .../tests/test_generators/test_rotation_list_generator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/diffsims/tests/test_generators/test_rotation_list_generator.py b/diffsims/tests/test_generators/test_rotation_list_generator.py index e14b57a7..95754dfc 100644 --- a/diffsims/tests/test_generators/test_rotation_list_generator.py +++ b/diffsims/tests/test_generators/test_rotation_list_generator.py @@ -18,7 +18,7 @@ import pytest import numpy as np -from diffsims.generators.rotation_list_generators import get_local_grid, get_grid_around_beam_direction,get_fundemental_zone_grid +from diffsims.generators.rotation_list_generators import get_local_grid, get_grid_around_beam_direction, get_fundemental_zone_grid, get_grid_streographic from diffsims.utils.rotation_conversion_utils import Euler @@ -41,6 +41,9 @@ def test_get_grid_around_beam_direction(): def test_get_fundemental_zone_grid(space_group_number): grid = get_fundemental_zone_grid(space_group_number,resolution=3) +def test_get_grid_streographic(): + grid = get_grid_streographic('cubic',1) + @pytest.mark.skip(reason="This tests a theoretical underpinning of the code") def test_small_angle_shortcut(): #pragma: no cover From 94315d44e5543c301054a6fa9b4d1fe4d6b34e76 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 16:48:49 +0000 Subject: [PATCH 13/62] Fixes for the obvious/easy broke stuff --- .../tests/test_generators/test_rotation_list_generator.py | 2 +- diffsims/utils/gridding_utils.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/diffsims/tests/test_generators/test_rotation_list_generator.py b/diffsims/tests/test_generators/test_rotation_list_generator.py index 95754dfc..ae6659eb 100644 --- a/diffsims/tests/test_generators/test_rotation_list_generator.py +++ b/diffsims/tests/test_generators/test_rotation_list_generator.py @@ -42,7 +42,7 @@ def test_get_fundemental_zone_grid(space_group_number): grid = get_fundemental_zone_grid(space_group_number,resolution=3) def test_get_grid_streographic(): - grid = get_grid_streographic('cubic',1) + grid = get_grid_streographic(1,'cubic') @pytest.mark.skip(reason="This tests a theoretical underpinning of the code") diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index cd1491ed..25040009 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -27,8 +27,7 @@ from diffsims.utils.rotation_conversion_utils import * from diffsims.utils.vector_utils import vectorised_spherical_polars_to_cartesians -crystal_system_dictionary = -{'cubic':[45,54.7,0], +crystal_system_dictionary = {'cubic':[45,54.7,0], 'hexagonal':[45,90,26.565], 'tetragonal':[45,90,0], 'orthorhombic':[90.90,0], @@ -199,12 +198,12 @@ def get_beam_directions(resolution,crystal_system,equal='angle'): r = np.ones((psi_theta.shape[0],1)) points_in_spherical_polars = np.hstack((r,psi_theta)) - if crystal_system = 'cubic': + if crystal_system == 'cubic': # reject points below the geodesic # add points on the geodesic pass - points_in_cartesians = vectorised_spherical_polars_to_cartesians(z) + points_in_cartesians = vectorised_spherical_polars_to_cartesians(points_in_spherical_polars) axis = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] angle = np.arcsin(np.linalg.norm(axis)) eulers = AxAngle(np.hstack(axis,angle)).to_Euler(axis_convention='rzxz') From cb482a75d2ecf57598af4cde6ecb433f4b1bcec4 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 16:53:39 +0000 Subject: [PATCH 14/62] Adding a missed transpose --- diffsims/utils/vector_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/utils/vector_utils.py b/diffsims/utils/vector_utils.py index 4068f3b7..81acecfb 100644 --- a/diffsims/utils/vector_utils.py +++ b/diffsims/utils/vector_utils.py @@ -87,4 +87,4 @@ def vectorised_spherical_polars_to_cartesians(z): x = r * np.cos(psi) * np.sin(theta) y = r * np.sin(psi) * np.sin(theta) z = r * np.cos(theta) - return np.asarray([x,y,z]) + return np.asarray([x,y,z]).T From c6dda28e63bfa039357de0ec63ce6b4783472fa9 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 16:59:09 +0000 Subject: [PATCH 15/62] Tidying up some numpy array bits --- diffsims/utils/gridding_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 25040009..4d3cfa2d 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -205,6 +205,6 @@ def get_beam_directions(resolution,crystal_system,equal='angle'): points_in_cartesians = vectorised_spherical_polars_to_cartesians(points_in_spherical_polars) axis = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] - angle = np.arcsin(np.linalg.norm(axis)) - eulers = AxAngle(np.hstack(axis,angle)).to_Euler(axis_convention='rzxz') + angle = np.arcsin(np.linalg.norm(axis,axis=1)) + eulers = AxAngle(np.hstack((axis,angle.reshape((-1,1))))).to_Euler(axis_convention='rzxz') return eulers From 0464ca7049d3418c69ff272f12a9b1e13195de28 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 17:06:10 +0000 Subject: [PATCH 16/62] Normalising axes --- diffsims/utils/gridding_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 4d3cfa2d..909f5f96 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -205,6 +205,8 @@ def get_beam_directions(resolution,crystal_system,equal='angle'): points_in_cartesians = vectorised_spherical_polars_to_cartesians(points_in_spherical_polars) axis = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] + angle = np.arcsin(np.linalg.norm(axis,axis=1)) - eulers = AxAngle(np.hstack((axis,angle.reshape((-1,1))))).to_Euler(axis_convention='rzxz') + normalised_axis = np.divide(axis,np.linalg.norm(axis,axis=1).reshape(-1,1)) + eulers = AxAngle(np.hstack((normalised_axis,angle.reshape((-1,1))))).to_Euler(axis_convention='rzxz') return eulers From 8d8f2c362afc4164500e2f9e97783c9f6a4a5e69 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 17:07:01 +0000 Subject: [PATCH 17/62] axis --> axes --- diffsims/utils/gridding_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 909f5f96..9cddbd0e 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -204,9 +204,9 @@ def get_beam_directions(resolution,crystal_system,equal='angle'): pass points_in_cartesians = vectorised_spherical_polars_to_cartesians(points_in_spherical_polars) - axis = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] + axes = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] - angle = np.arcsin(np.linalg.norm(axis,axis=1)) - normalised_axis = np.divide(axis,np.linalg.norm(axis,axis=1).reshape(-1,1)) - eulers = AxAngle(np.hstack((normalised_axis,angle.reshape((-1,1))))).to_Euler(axis_convention='rzxz') + angle = np.arcsin(np.linalg.norm(axes,axis=1)) + normalised_axes = np.divide(axes,np.linalg.norm(axes,axis=1).reshape(-1,1)) + eulers = AxAngle(np.hstack((normalised_axes,angle.reshape((-1,1))))).to_Euler(axis_convention='rzxz') return eulers From 72e0d65b56af08958165cbf2654446d4d1242f5a Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 17:08:35 +0000 Subject: [PATCH 18/62] Line refactor for readability --- diffsims/utils/gridding_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 9cddbd0e..05b57344 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -208,5 +208,6 @@ def get_beam_directions(resolution,crystal_system,equal='angle'): angle = np.arcsin(np.linalg.norm(axes,axis=1)) normalised_axes = np.divide(axes,np.linalg.norm(axes,axis=1).reshape(-1,1)) - eulers = AxAngle(np.hstack((normalised_axes,angle.reshape((-1,1))))).to_Euler(axis_convention='rzxz') + np_axangles = np.hstack((normalised_axes,angle.reshape((-1,1)))) + eulers = AxAngle(np_axangles).to_Euler(axis_convention='rzxz') return eulers From 50517e2b88edab5f629c666c126d0662f7b573f8 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 17:09:17 +0000 Subject: [PATCH 19/62] Downstream function returns Euler so no need to convert --- diffsims/generators/rotation_list_generators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index 941eabe0..341318d2 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -72,7 +72,7 @@ def get_grid_streographic(crystal_system,resolution): Rotations about beam directions and beam directions are seperated by rotations of the size 'resolution' """ from itertools import product - beam_directions = Euler(get_beam_directions(crystal_system,resolution,equal='angle'),axis_convention='rzxz') + beam_directions = get_beam_directions(crystal_system,resolution,equal='angle') beam_directions_szxz = beam_directions.toAxAngle().toEuler(axis_convention='szxz') # convert to high speed convention # drop in all the inplane rotations to form z From edcd19390547ccc44c2bc987bc38298747415c3f Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 17:10:13 +0000 Subject: [PATCH 20/62] syntax error --- diffsims/generators/rotation_list_generators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index 341318d2..bdbe3bea 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -73,7 +73,7 @@ def get_grid_streographic(crystal_system,resolution): """ from itertools import product beam_directions = get_beam_directions(crystal_system,resolution,equal='angle') - beam_directions_szxz = beam_directions.toAxAngle().toEuler(axis_convention='szxz') # convert to high speed convention + beam_directions_szxz = beam_directions.to_AxAngle().to_Euler(axis_convention='szxz') # convert to high speed convention # drop in all the inplane rotations to form z alpha = beam_directions.data[:,:0] From 593ed5a7a469a034ba180c76d972f36b085758ae Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 17:11:40 +0000 Subject: [PATCH 21/62] fix order a crystal_system,resolution --- diffsims/tests/test_generators/test_rotation_list_generator.py | 2 +- diffsims/utils/gridding_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/diffsims/tests/test_generators/test_rotation_list_generator.py b/diffsims/tests/test_generators/test_rotation_list_generator.py index ae6659eb..95754dfc 100644 --- a/diffsims/tests/test_generators/test_rotation_list_generator.py +++ b/diffsims/tests/test_generators/test_rotation_list_generator.py @@ -42,7 +42,7 @@ def test_get_fundemental_zone_grid(space_group_number): grid = get_fundemental_zone_grid(space_group_number,resolution=3) def test_get_grid_streographic(): - grid = get_grid_streographic(1,'cubic') + grid = get_grid_streographic('cubic',1) @pytest.mark.skip(reason="This tests a theoretical underpinning of the code") diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 05b57344..70f02b21 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -179,7 +179,7 @@ def _create_advanced_linearly_spaced_array_in_rzxz(resolution, max_alpha, max_be z = np.asarray(list(product(alpha, beta, gamma))) return Euler(z, axis_convention='rzxz') -def get_beam_directions(resolution,crystal_system,equal='angle'): +def get_beam_directions(crystal_system,resolution,equal='angle'): """ """ theta_max,psi_max,psi_min = crystal_system_dictionary[crystal_system] From a906c7bf1eb4c85e6f185863003461d9cdd4dfc6 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 17:12:35 +0000 Subject: [PATCH 22/62] Syntax fix for hstack brackets --- diffsims/generators/rotation_list_generators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index bdbe3bea..f3c1338e 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -82,7 +82,7 @@ def get_grid_streographic(crystal_system,resolution): ipalpha = np.asarray(list(product(alpha,np.asarray(in_plane)))) ipbeta = np.asarray(list(product(beta,np.asarray(in_plane)))) - z = np.rad2deg(np.hstack(ipalpha[:,0].reshape((-1,1)),ipbeta)) + z = np.rad2deg(np.hstack((ipalpha[:,0].reshape((-1,1)),ipbeta))) raw_grid = Euler(z, axis_convention='szxz') grid_rzxz = raw_grid.to_AxAngle().to_Euler(axis_convention='rzxz') #convert back Bunge convention to return From c749646459311d961db89f0c031f25edb74d6dfa Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 23 Jan 2020 17:20:24 +0000 Subject: [PATCH 23/62] Drop a poor bit of array selection and an erronous rad2deg --- diffsims/generators/rotation_list_generators.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index f3c1338e..e6504983 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -76,14 +76,14 @@ def get_grid_streographic(crystal_system,resolution): beam_directions_szxz = beam_directions.to_AxAngle().to_Euler(axis_convention='szxz') # convert to high speed convention # drop in all the inplane rotations to form z - alpha = beam_directions.data[:,:0] - beta = beam_directions.data[:,:1] + alpha = beam_directions.data[:,0] + beta = beam_directions.data[:,1] in_plane = np.arange(0,360,resolution) ipalpha = np.asarray(list(product(alpha,np.asarray(in_plane)))) ipbeta = np.asarray(list(product(beta,np.asarray(in_plane)))) - z = np.rad2deg(np.hstack((ipalpha[:,0].reshape((-1,1)),ipbeta))) - + z = np.hstack((ipalpha[:,0].reshape((-1,1)),ipbeta)) + raw_grid = Euler(z, axis_convention='szxz') grid_rzxz = raw_grid.to_AxAngle().to_Euler(axis_convention='rzxz') #convert back Bunge convention to return rotation_list = grid_rzxz.to_rotation_list(round_to=2) From b7985822beaaf83c32b8478e3c5081077892b990 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 16:11:50 +0000 Subject: [PATCH 24/62] test non-cubic and cubic sep --- .../tests/test_generators/test_rotation_list_generator.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/diffsims/tests/test_generators/test_rotation_list_generator.py b/diffsims/tests/test_generators/test_rotation_list_generator.py index 95754dfc..0cd941df 100644 --- a/diffsims/tests/test_generators/test_rotation_list_generator.py +++ b/diffsims/tests/test_generators/test_rotation_list_generator.py @@ -41,8 +41,9 @@ def test_get_grid_around_beam_direction(): def test_get_fundemental_zone_grid(space_group_number): grid = get_fundemental_zone_grid(space_group_number,resolution=3) -def test_get_grid_streographic(): - grid = get_grid_streographic('cubic',1) +@pytest.mark.parametrize("crystal_system",['hexagonal','cubic']) +def test_get_grid_streographic(crytal_system): + grid = get_grid_streographic(crystal_system,1) @pytest.mark.skip(reason="This tests a theoretical underpinning of the code") From 23714c8540d5393f9ad820afaecb0d35afc4bab5 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 16:12:11 +0000 Subject: [PATCH 25/62] scoping out the cubic functionality --- diffsims/utils/gridding_utils.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 70f02b21..16e50996 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -198,14 +198,26 @@ def get_beam_directions(crystal_system,resolution,equal='angle'): r = np.ones((psi_theta.shape[0],1)) points_in_spherical_polars = np.hstack((r,psi_theta)) - if crystal_system == 'cubic': - # reject points below the geodesic - # add points on the geodesic - pass - points_in_cartesians = vectorised_spherical_polars_to_cartesians(points_in_spherical_polars) - axes = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] + if crystal_system = 'cubic': + # add in the geodesic that runs [1,1,1] to [1,0,1] + v1 = np.divide([1,1,1],np.sqrt(3)) + v2 = np.divide([1,0,1],np.sqrt(2)) + def cubic_corner_geodesic(t): + # https://math.stackexchange.com/questions/1883904/a-time-parameterization-of-geodesics-on-the-sphere + w = v2 - np.multiply(np.dot(v1,v2),v1) + w = np.divide(w,np.linalg.norm(w)) + return np.cos(t)*v1 + np.sin(t)*w #in cartesians, t_end = np.arccos(np.dot(v1,v2)) + + t_list = np.linspace(0,np.arcos(np.dot(v1,v2)),num=steps_theta) + geodesic = cubic_corner_geodesic(t_list) + points_in_cartesians = np.vstack((points_in_cartesians,geodesic)) + # the great circle (from [1,1,1] to [1,0,1]) forms a plane (with the origin), points on the same side as (0,0,1) are safe, the others are not + plane_normal = np.cross(v2,v1) # dotting this with (0,0,1) gives a positive number + points_in_cartesians[np.dot(plane_normal,points_in_cartesians)>=0] #0 is the points on the geodesic + + axes = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] angle = np.arcsin(np.linalg.norm(axes,axis=1)) normalised_axes = np.divide(axes,np.linalg.norm(axes,axis=1).reshape(-1,1)) np_axangles = np.hstack((normalised_axes,angle.reshape((-1,1)))) From 00f37de9eecc246bb9ee98646a3eef0de5904b59 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 16:14:24 +0000 Subject: [PATCH 26/62] Fixing typos --- .../tests/test_generators/test_rotation_list_generator.py | 2 +- diffsims/utils/gridding_utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/diffsims/tests/test_generators/test_rotation_list_generator.py b/diffsims/tests/test_generators/test_rotation_list_generator.py index 0cd941df..ee5fe5d9 100644 --- a/diffsims/tests/test_generators/test_rotation_list_generator.py +++ b/diffsims/tests/test_generators/test_rotation_list_generator.py @@ -42,7 +42,7 @@ def test_get_fundemental_zone_grid(space_group_number): grid = get_fundemental_zone_grid(space_group_number,resolution=3) @pytest.mark.parametrize("crystal_system",['hexagonal','cubic']) -def test_get_grid_streographic(crytal_system): +def test_get_grid_streographic(crystal_system): grid = get_grid_streographic(crystal_system,1) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 16e50996..e3e0c22d 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -200,7 +200,7 @@ def get_beam_directions(crystal_system,resolution,equal='angle'): points_in_cartesians = vectorised_spherical_polars_to_cartesians(points_in_spherical_polars) - if crystal_system = 'cubic': + if crystal_system == 'cubic': # add in the geodesic that runs [1,1,1] to [1,0,1] v1 = np.divide([1,1,1],np.sqrt(3)) v2 = np.divide([1,0,1],np.sqrt(2)) @@ -210,7 +210,7 @@ def cubic_corner_geodesic(t): w = np.divide(w,np.linalg.norm(w)) return np.cos(t)*v1 + np.sin(t)*w #in cartesians, t_end = np.arccos(np.dot(v1,v2)) - t_list = np.linspace(0,np.arcos(np.dot(v1,v2)),num=steps_theta) + t_list = np.linspace(0,np.arccos(np.dot(v1,v2)),num=steps_theta) geodesic = cubic_corner_geodesic(t_list) points_in_cartesians = np.vstack((points_in_cartesians,geodesic)) # the great circle (from [1,1,1] to [1,0,1]) forms a plane (with the origin), points on the same side as (0,0,1) are safe, the others are not From 67ab6a632bf5fa4f527b52f00eec04e9094f5e3c Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 16:23:18 +0000 Subject: [PATCH 27/62] vectorising internal geodesic functionality --- diffsims/utils/gridding_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index e3e0c22d..a662a6f2 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -208,7 +208,8 @@ def cubic_corner_geodesic(t): # https://math.stackexchange.com/questions/1883904/a-time-parameterization-of-geodesics-on-the-sphere w = v2 - np.multiply(np.dot(v1,v2),v1) w = np.divide(w,np.linalg.norm(w)) - return np.cos(t)*v1 + np.sin(t)*w #in cartesians, t_end = np.arccos(np.dot(v1,v2)) + #return in cartesians with t_end = np.arccos(np.dot(v1,v2)) + return np.add(np.multiply(np.cos(t.reshape(-1,1)),v1),np.multiply(np.sin(t.reshape(-1,1)),w)) t_list = np.linspace(0,np.arccos(np.dot(v1,v2)),num=steps_theta) geodesic = cubic_corner_geodesic(t_list) From 14c48e753c1b14b4b9356d83cf3d5d8258bb5069 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 16:25:25 +0000 Subject: [PATCH 28/62] Adding a missing transpose --- diffsims/utils/gridding_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index a662a6f2..d67d4019 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -216,7 +216,7 @@ def cubic_corner_geodesic(t): points_in_cartesians = np.vstack((points_in_cartesians,geodesic)) # the great circle (from [1,1,1] to [1,0,1]) forms a plane (with the origin), points on the same side as (0,0,1) are safe, the others are not plane_normal = np.cross(v2,v1) # dotting this with (0,0,1) gives a positive number - points_in_cartesians[np.dot(plane_normal,points_in_cartesians)>=0] #0 is the points on the geodesic + points_in_cartesians[np.dot(plane_normal,points_in_cartesians.T)>=0] #0 is the points on the geodesic axes = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] angle = np.arcsin(np.linalg.norm(axes,axis=1)) From 0bd56bdd8f7da6a5bb65a09a466ac4c20ac524e9 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 16:30:12 +0000 Subject: [PATCH 29/62] Avoids normalising by the [0,0,0] axis --- diffsims/utils/gridding_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index d67d4019..f926a07e 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -220,7 +220,7 @@ def cubic_corner_geodesic(t): axes = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] angle = np.arcsin(np.linalg.norm(axes,axis=1)) - normalised_axes = np.divide(axes,np.linalg.norm(axes,axis=1).reshape(-1,1)) + normalised_axes = np.where(angle.reshape(-1,1) > 0, np.divide(axes,np.linalg.norm(axes,axis=1).reshape(-1,1)), axes) np_axangles = np.hstack((normalised_axes,angle.reshape((-1,1)))) eulers = AxAngle(np_axangles).to_Euler(axis_convention='rzxz') return eulers From 55a584d286a528ceca080014df9d52b8572e31fb Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 16:58:59 +0000 Subject: [PATCH 30/62] Fix a typo --- diffsims/utils/gridding_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index f926a07e..649df889 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -30,7 +30,7 @@ crystal_system_dictionary = {'cubic':[45,54.7,0], 'hexagonal':[45,90,26.565], 'tetragonal':[45,90,0], - 'orthorhombic':[90.90,0], + 'orthorhombic':[90,90,0], 'trigonal': [45,90,-116.5], 'monoclinic':[90,0,-90], 'none':[360,180,0]} From 171b4aa61d13fce802284838d769010c90bacf39 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 16:59:26 +0000 Subject: [PATCH 31/62] Assertioned testing for get_grid_streographic --- .../test_rotation_list_generator.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/diffsims/tests/test_generators/test_rotation_list_generator.py b/diffsims/tests/test_generators/test_rotation_list_generator.py index ee5fe5d9..0252e08c 100644 --- a/diffsims/tests/test_generators/test_rotation_list_generator.py +++ b/diffsims/tests/test_generators/test_rotation_list_generator.py @@ -37,14 +37,25 @@ def test_get_grid_around_beam_direction(): assert isinstance(grid_simple[0],tuple) assert len(grid_simple) == 360 +@pytest.mark.skip(reason="local dev") @pytest.mark.parametrize("space_group_number",[1,3,30,190,215,229]) def test_get_fundemental_zone_grid(space_group_number): grid = get_fundemental_zone_grid(space_group_number,resolution=3) -@pytest.mark.parametrize("crystal_system",['hexagonal','cubic']) +@pytest.mark.parametrize("crystal_system",['tetragonal','cubic']) def test_get_grid_streographic(crystal_system): grid = get_grid_streographic(crystal_system,1) - + assert (0,0,0) in grid + if crystal_system == 'tetragonal': + grid_twice_as_many = get_grid_streographic('orthorhombic',1) + assert len(grid_twice_as_many)/len(grid) == 4 + if crystal_system == 'cubic': + # Following "Orientation precision of TEM-based orientation mapping techniques" - Morawiec et al, Ultramicroscopy 136,2014 + grid = get_grid_streographic(crystal_system,1.6) + theory = 234240 #page 113 of the above, as (976*240) + grid_length = len(grid) + assert grid_length > theory - (0.1) * theory + assert grid_length < theory + (0.1) * theory @pytest.mark.skip(reason="This tests a theoretical underpinning of the code") def test_small_angle_shortcut(): #pragma: no cover From 47c95fd9d9404a3b6e1e2b7c8d446ecbf2ac96cf Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 17:02:35 +0000 Subject: [PATCH 32/62] Fix a syntax error --- diffsims/utils/gridding_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 649df889..d4287601 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -216,7 +216,7 @@ def cubic_corner_geodesic(t): points_in_cartesians = np.vstack((points_in_cartesians,geodesic)) # the great circle (from [1,1,1] to [1,0,1]) forms a plane (with the origin), points on the same side as (0,0,1) are safe, the others are not plane_normal = np.cross(v2,v1) # dotting this with (0,0,1) gives a positive number - points_in_cartesians[np.dot(plane_normal,points_in_cartesians.T)>=0] #0 is the points on the geodesic + points_in_cartesians = points_in_cartesians[np.dot(plane_normal,points_in_cartesians.T)>=0] #0 is the points on the geodesic axes = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] angle = np.arcsin(np.linalg.norm(axes,axis=1)) From a60376a44a8ed2de881b64e83a749bc44787e3ba Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 17:15:29 +0000 Subject: [PATCH 33/62] Modularising get_beam_directions for testing purposes --- diffsims/generators/rotation_list_generators.py | 6 +++--- diffsims/utils/gridding_utils.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index e6504983..fa3967fd 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -27,7 +27,7 @@ from diffsims.utils.fundemental_zone_utils import get_proper_point_group_string, reduce_to_fundemental_zone from diffsims.utils.gridding_utils import create_linearly_spaced_array_in_rzxz,rotate_axangle, \ _create_advanced_linearly_spaced_array_in_rzxz, \ - _get_rotation_to_beam_direction, get_beam_directions + _get_rotation_to_beam_direction, get_beam_directions, beam_directions_to_euler_angles def _returnable_eulers_from_axangle(grid,axis_convention,round_to): @@ -72,7 +72,7 @@ def get_grid_streographic(crystal_system,resolution): Rotations about beam directions and beam directions are seperated by rotations of the size 'resolution' """ from itertools import product - beam_directions = get_beam_directions(crystal_system,resolution,equal='angle') + beam_directions = beam_directions_to_euler_angles(get_beam_directions(crystal_system,resolution,equal='angle')) beam_directions_szxz = beam_directions.to_AxAngle().to_Euler(axis_convention='szxz') # convert to high speed convention # drop in all the inplane rotations to form z @@ -83,7 +83,7 @@ def get_grid_streographic(crystal_system,resolution): ipalpha = np.asarray(list(product(alpha,np.asarray(in_plane)))) ipbeta = np.asarray(list(product(beta,np.asarray(in_plane)))) z = np.hstack((ipalpha[:,0].reshape((-1,1)),ipbeta)) - + raw_grid = Euler(z, axis_convention='szxz') grid_rzxz = raw_grid.to_AxAngle().to_Euler(axis_convention='rzxz') #convert back Bunge convention to return rotation_list = grid_rzxz.to_rotation_list(round_to=2) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index d4287601..bd3239ea 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -218,6 +218,17 @@ def cubic_corner_geodesic(t): plane_normal = np.cross(v2,v1) # dotting this with (0,0,1) gives a positive number points_in_cartesians = points_in_cartesians[np.dot(plane_normal,points_in_cartesians.T)>=0] #0 is the points on the geodesic + return points_in_cartesians + +def beam_directions_to_euler_angles(points_in_cartesians): + """ + + + Parameters + ---------- + points_in_cartesians : + + """ axes = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] angle = np.arcsin(np.linalg.norm(axes,axis=1)) normalised_axes = np.where(angle.reshape(-1,1) > 0, np.divide(axes,np.linalg.norm(axes,axis=1).reshape(-1,1)), axes) From ef13e28bdf4019cf80aa67adfb766da27012ed35 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 17:38:52 +0000 Subject: [PATCH 34/62] test_get_beam_direction implemented --- .../tests/test_utils/test_gridding_utils.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/diffsims/tests/test_utils/test_gridding_utils.py b/diffsims/tests/test_utils/test_gridding_utils.py index 450485ee..d58c96e3 100644 --- a/diffsims/tests/test_utils/test_gridding_utils.py +++ b/diffsims/tests/test_utils/test_gridding_utils.py @@ -22,7 +22,7 @@ from diffsims.utils.rotation_conversion_utils import AxAngle, Euler from diffsims.utils.fundemental_zone_utils import get_proper_point_group_string, reduce_to_fundemental_zone, numpy_bounding_plane from diffsims.utils.gridding_utils import create_linearly_spaced_array_in_rzxz, vectorised_qmult, \ - _create_advanced_linearly_spaced_array_in_rzxz + _create_advanced_linearly_spaced_array_in_rzxz, get_beam_directions from transforms3d.quaternions import qmult @@ -64,3 +64,20 @@ def test_select_fundemental_zone(): def test_edge_case_numpy_bounding_plane(): z = np.asarray([1,1,1,np.inf]) numpy_bounding_plane(data=z,vector=[1,1,1],distance=1) + +""" This tests get_beam_directions """ +@pytest.mark.parametrize("crystal_system,expected_corners", + [ + ['monoclinic',[(0,0,1),(0,1,0),(0,-1,0)]], + ['orthorhombic',[(0,0,1),(1,0,0),(0,1,0)]], + ['tetragonal',[(0,0,1),(1,0,0),(1,1,0)]], + ['cubic',[(0,0,1),(1,0,1),(1,1,1)]], + ['hexagonal',[(0,0,1),(2,1,0),(1,1,0)]], + ['trigonal',[(0,0,1),(-2,-1,0),(1,1,0)]] + ]) +def test_get_beam_directions(crystal_system,expected_corners): + z = get_beam_directions(crystal_system,1) + assert np.allclose(np.linalg.norm(z,axis=1),1) + for corner in expected_corners: + norm_corner = np.divide(corner,np.linalg.norm(corner)) + assert np.any(np.isin(z,norm_corner)) From 71bb311aacdb21649fbebaee76975e61bd93eabd Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 17:42:28 +0000 Subject: [PATCH 35/62] Shortening the top level testing --- .../test_rotation_list_generator.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/diffsims/tests/test_generators/test_rotation_list_generator.py b/diffsims/tests/test_generators/test_rotation_list_generator.py index 0252e08c..3900c7ff 100644 --- a/diffsims/tests/test_generators/test_rotation_list_generator.py +++ b/diffsims/tests/test_generators/test_rotation_list_generator.py @@ -42,20 +42,11 @@ def test_get_grid_around_beam_direction(): def test_get_fundemental_zone_grid(space_group_number): grid = get_fundemental_zone_grid(space_group_number,resolution=3) -@pytest.mark.parametrize("crystal_system",['tetragonal','cubic']) -def test_get_grid_streographic(crystal_system): - grid = get_grid_streographic(crystal_system,1) +def test_get_grid_streographic(): + grid = get_grid_streographic('tetragonal',1) assert (0,0,0) in grid - if crystal_system == 'tetragonal': - grid_twice_as_many = get_grid_streographic('orthorhombic',1) - assert len(grid_twice_as_many)/len(grid) == 4 - if crystal_system == 'cubic': - # Following "Orientation precision of TEM-based orientation mapping techniques" - Morawiec et al, Ultramicroscopy 136,2014 - grid = get_grid_streographic(crystal_system,1.6) - theory = 234240 #page 113 of the above, as (976*240) - grid_length = len(grid) - assert grid_length > theory - (0.1) * theory - assert grid_length < theory + (0.1) * theory + grid_four_times_as_many = get_grid_streographic('orthorhombic',1) + assert len(grid_twice_as_many)/len(grid) == 4 @pytest.mark.skip(reason="This tests a theoretical underpinning of the code") def test_small_angle_shortcut(): #pragma: no cover From a9f31ee1210557a6344e130ab977f41cae15b782 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 17:56:02 +0000 Subject: [PATCH 36/62] Fix a typo, and switch a dot product --- diffsims/utils/gridding_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index bd3239ea..1c3d7e1a 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -190,7 +190,7 @@ def get_beam_directions(crystal_system,resolution,equal='angle'): raise NotImplementedError("Use equal='angle' instead") else: steps_theta = int(np.ceil((theta_max - 0)/resolution)) #see docstrings for np.arange, np.linspace has better endpoint handling - steps_psi = int(np.ceil((psi_max - psi_max)/resolution)) + steps_psi = int(np.ceil((psi_max - psi_min)/resolution)) theta = np.linspace(0,theta_max,num=steps_theta) psi = np.linspace(psi_min,psi_max,num=steps_theta) @@ -216,14 +216,14 @@ def cubic_corner_geodesic(t): points_in_cartesians = np.vstack((points_in_cartesians,geodesic)) # the great circle (from [1,1,1] to [1,0,1]) forms a plane (with the origin), points on the same side as (0,0,1) are safe, the others are not plane_normal = np.cross(v2,v1) # dotting this with (0,0,1) gives a positive number - points_in_cartesians = points_in_cartesians[np.dot(plane_normal,points_in_cartesians.T)>=0] #0 is the points on the geodesic + points_in_cartesians = points_in_cartesians[np.dot(points_in_cartesians,plane_normal)>=0] #0 is the points on the geodesic return points_in_cartesians def beam_directions_to_euler_angles(points_in_cartesians): """ - + Parameters ---------- points_in_cartesians : From e0bb36e6914bc7aa56f6bd80307ab3ba5595cf6f Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 17:57:22 +0000 Subject: [PATCH 37/62] Another typo fixed --- diffsims/utils/gridding_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 1c3d7e1a..ddee1e06 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -192,7 +192,7 @@ def get_beam_directions(crystal_system,resolution,equal='angle'): steps_theta = int(np.ceil((theta_max - 0)/resolution)) #see docstrings for np.arange, np.linspace has better endpoint handling steps_psi = int(np.ceil((psi_max - psi_min)/resolution)) theta = np.linspace(0,theta_max,num=steps_theta) - psi = np.linspace(psi_min,psi_max,num=steps_theta) + psi = np.linspace(psi_min,psi_max,num=steps_psi) psi_theta = np.asarray(list(product(psi,theta))) r = np.ones((psi_theta.shape[0],1)) From a2e531e358799cc78a8123fff6b5fa2dd74f71c2 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 18:04:51 +0000 Subject: [PATCH 38/62] cubic case tests --- diffsims/tests/test_utils/test_gridding_utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/diffsims/tests/test_utils/test_gridding_utils.py b/diffsims/tests/test_utils/test_gridding_utils.py index d58c96e3..14f8ebc9 100644 --- a/diffsims/tests/test_utils/test_gridding_utils.py +++ b/diffsims/tests/test_utils/test_gridding_utils.py @@ -81,3 +81,9 @@ def test_get_beam_directions(crystal_system,expected_corners): for corner in expected_corners: norm_corner = np.divide(corner,np.linalg.norm(corner)) assert np.any(np.isin(z,norm_corner)) + +def test_beam_directions_cubic(): + # Following "Orientation precision of TEM-based orientation mapping techniques" - Morawiec et al, Ultramicroscopy 136,2014 + z = get_beam_directions('cubic',1.6) + assert z.shape[0] > 950 + assert z.shape[0] < 1000 From a6d2dbba501a014e7b1bd65440b770ab3c69085b Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 18:05:02 +0000 Subject: [PATCH 39/62] Clarification if/else clause --- diffsims/utils/gridding_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index ddee1e06..318adb4c 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -188,7 +188,7 @@ def get_beam_directions(crystal_system,resolution,equal='angle'): # http://mathworld.wolfram.com/SpherePointPicking.html # Need to do sensible point counting for this raise NotImplementedError("Use equal='angle' instead") - else: + elif equal == 'angle': steps_theta = int(np.ceil((theta_max - 0)/resolution)) #see docstrings for np.arange, np.linspace has better endpoint handling steps_psi = int(np.ceil((psi_max - psi_min)/resolution)) theta = np.linspace(0,theta_max,num=steps_theta) From a72e96230664e8a6b131e5c7fc7b21459737c360 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 18:06:27 +0000 Subject: [PATCH 40/62] degree --> radians --- diffsims/utils/gridding_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 318adb4c..e014573c 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -191,8 +191,8 @@ def get_beam_directions(crystal_system,resolution,equal='angle'): elif equal == 'angle': steps_theta = int(np.ceil((theta_max - 0)/resolution)) #see docstrings for np.arange, np.linspace has better endpoint handling steps_psi = int(np.ceil((psi_max - psi_min)/resolution)) - theta = np.linspace(0,theta_max,num=steps_theta) - psi = np.linspace(psi_min,psi_max,num=steps_psi) + theta = np.linspace(0,np.deg2rad(theta_max),num=steps_theta) + psi = np.linspace(np.deg2rad(psi_min),np.deg2rad(psi_max),num=steps_psi) psi_theta = np.asarray(list(product(psi,theta))) r = np.ones((psi_theta.shape[0],1)) From e4d63ab747242f74dbbdd01ddac24747d3510da6 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 18:19:38 +0000 Subject: [PATCH 41/62] Isolates the cause of the hexagonal/trigonal failure --- diffsims/utils/gridding_utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index e014573c..f54241cd 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -191,6 +191,7 @@ def get_beam_directions(crystal_system,resolution,equal='angle'): elif equal == 'angle': steps_theta = int(np.ceil((theta_max - 0)/resolution)) #see docstrings for np.arange, np.linspace has better endpoint handling steps_psi = int(np.ceil((psi_max - psi_min)/resolution)) + # now in radians as we're about to make spherical polar cordinates theta = np.linspace(0,np.deg2rad(theta_max),num=steps_theta) psi = np.linspace(np.deg2rad(psi_min),np.deg2rad(psi_max),num=steps_psi) @@ -198,6 +199,8 @@ def get_beam_directions(crystal_system,resolution,equal='angle'): r = np.ones((psi_theta.shape[0],1)) points_in_spherical_polars = np.hstack((r,psi_theta)) + # keep only theta ==0 psi ==0, do this with np.abs(theta) > 0 or psi == 0 + #points_in_spherical_polars = points_in_spherical_polars[np.logical_or(np.abs(psi_theta[:,1])>0,psi_theta[:,0]==0)] points_in_cartesians = vectorised_spherical_polars_to_cartesians(points_in_spherical_polars) if crystal_system == 'cubic': From 4926863b24bf791363601fcd39889e91577c2b60 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 18:22:53 +0000 Subject: [PATCH 42/62] Fixing the theta=0 degenracy for case when psi is never 0 --- diffsims/utils/gridding_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index f54241cd..a4163bf7 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -199,8 +199,8 @@ def get_beam_directions(crystal_system,resolution,equal='angle'): r = np.ones((psi_theta.shape[0],1)) points_in_spherical_polars = np.hstack((r,psi_theta)) - # keep only theta ==0 psi ==0, do this with np.abs(theta) > 0 or psi == 0 - #points_in_spherical_polars = points_in_spherical_polars[np.logical_or(np.abs(psi_theta[:,1])>0,psi_theta[:,0]==0)] + # keep only theta ==0 psi ==0, do this with np.abs(theta) > 0 or psi == 0 - more generally use the smallest psi value + points_in_spherical_polars = points_in_spherical_polars[np.logical_or(np.abs(psi_theta[:,1])>0,psi_theta[:,0]==np.min(psi_theta[:,0]))] points_in_cartesians = vectorised_spherical_polars_to_cartesians(points_in_spherical_polars) if crystal_system == 'cubic': From e00fb12d2f40c9321528fcdcaee860381fe74fbd Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 18:23:21 +0000 Subject: [PATCH 43/62] being a bit more generous, as our edge sampling system is a bit odd --- diffsims/tests/test_utils/test_gridding_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/tests/test_utils/test_gridding_utils.py b/diffsims/tests/test_utils/test_gridding_utils.py index 14f8ebc9..bd16d59f 100644 --- a/diffsims/tests/test_utils/test_gridding_utils.py +++ b/diffsims/tests/test_utils/test_gridding_utils.py @@ -86,4 +86,4 @@ def test_beam_directions_cubic(): # Following "Orientation precision of TEM-based orientation mapping techniques" - Morawiec et al, Ultramicroscopy 136,2014 z = get_beam_directions('cubic',1.6) assert z.shape[0] > 950 - assert z.shape[0] < 1000 + assert z.shape[0] < 1050 From 0a863201c2f811c9ac589783b2149ffc9cbf027a Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 18:46:56 +0000 Subject: [PATCH 44/62] adding equal area option --- diffsims/utils/gridding_utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index a4163bf7..f43e86f3 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -184,15 +184,17 @@ def get_beam_directions(crystal_system,resolution,equal='angle'): """ theta_max,psi_max,psi_min = crystal_system_dictionary[crystal_system] + steps_theta = int(np.ceil((theta_max - 0)/resolution)) #see docstrings for np.arange, np.linspace has better endpoint handling + steps_psi = int(np.ceil((psi_max - psi_min)/resolution)) + theta = np.linspace(0,np.deg2rad(theta_max),num=steps_theta) # radians as we're about to make spherical polar cordinates if equal == 'area': # http://mathworld.wolfram.com/SpherePointPicking.html - # Need to do sensible point counting for this - raise NotImplementedError("Use equal='angle' instead") + v_1 = (1 + np.cos(np.deg2rad(psi_max))) / 2 + v_2 = (1 + np.cos(np.deg2rad(psi_min))) / 2 + v_array = np.linspace(min(v_1,v_2),max(v_1,v_2),num=steps_psi) + psi = np.arccos(2*v_array-1) #in radians elif equal == 'angle': - steps_theta = int(np.ceil((theta_max - 0)/resolution)) #see docstrings for np.arange, np.linspace has better endpoint handling - steps_psi = int(np.ceil((psi_max - psi_min)/resolution)) # now in radians as we're about to make spherical polar cordinates - theta = np.linspace(0,np.deg2rad(theta_max),num=steps_theta) psi = np.linspace(np.deg2rad(psi_min),np.deg2rad(psi_max),num=steps_psi) psi_theta = np.asarray(list(product(psi,theta))) From 8c729497b2754f77895bb47c3993a4d11efe2b80 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 18:48:20 +0000 Subject: [PATCH 45/62] Adds an equal area test --- .../tests/test_utils/test_gridding_utils.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/diffsims/tests/test_utils/test_gridding_utils.py b/diffsims/tests/test_utils/test_gridding_utils.py index bd16d59f..3873b801 100644 --- a/diffsims/tests/test_utils/test_gridding_utils.py +++ b/diffsims/tests/test_utils/test_gridding_utils.py @@ -75,8 +75,24 @@ def test_edge_case_numpy_bounding_plane(): ['hexagonal',[(0,0,1),(2,1,0),(1,1,0)]], ['trigonal',[(0,0,1),(-2,-1,0),(1,1,0)]] ]) -def test_get_beam_directions(crystal_system,expected_corners): - z = get_beam_directions(crystal_system,1) +def test_get_beam_directions_equal_angle(crystal_system,expected_corners): + z = get_beam_directions(crystal_system,1,'angle') + assert np.allclose(np.linalg.norm(z,axis=1),1) + for corner in expected_corners: + norm_corner = np.divide(corner,np.linalg.norm(corner)) + assert np.any(np.isin(z,norm_corner)) + +@pytest.mark.parametrize("crystal_system,expected_corners", + [ + ['monoclinic',[(0,0,1),(0,1,0),(0,-1,0)]], + ['orthorhombic',[(0,0,1),(1,0,0),(0,1,0)]], + ['tetragonal',[(0,0,1),(1,0,0),(1,1,0)]], + ['cubic',[(0,0,1),(1,0,1),(1,1,1)]], + ['hexagonal',[(0,0,1),(2,1,0),(1,1,0)]], + ['trigonal',[(0,0,1),(-2,-1,0),(1,1,0)]] + ]) +def test_get_beam_directions_equal_area(crystal_system,expected_corners): + z = get_beam_directions(crystal_system,1,equal='area') assert np.allclose(np.linalg.norm(z,axis=1),1) for corner in expected_corners: norm_corner = np.divide(corner,np.linalg.norm(corner)) From 396605f3147293aa4450c850df1da21cf5b664c1 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 18:50:04 +0000 Subject: [PATCH 46/62] Feeding equal through to top level function --- diffsims/generators/rotation_list_generators.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index fa3967fd..2cdbfca9 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -58,7 +58,7 @@ def get_fundemental_zone_grid(space_group_number, resolution): fz_grid_axangle = reduce_to_fundemental_zone(raw_grid_axangle, zone_string) return _returnable_eulers_from_axangle(fz_grid_axangle,'rzxz',round_to=2) -def get_grid_streographic(crystal_system,resolution): +def get_grid_streographic(crystal_system,resolution,equal='angle'): """ Creates a rotation list by combining the minimum region of the streogram's beam directions with in plane rotations @@ -70,9 +70,11 @@ def get_grid_streographic(crystal_system,resolution): resolution : float Rotations about beam directions and beam directions are seperated by rotations of the size 'resolution' + + equal : 'angle' or 'area' """ from itertools import product - beam_directions = beam_directions_to_euler_angles(get_beam_directions(crystal_system,resolution,equal='angle')) + beam_directions = beam_directions_to_euler_angles(get_beam_directions(crystal_system,resolution,equal=equal)) beam_directions_szxz = beam_directions.to_AxAngle().to_Euler(axis_convention='szxz') # convert to high speed convention # drop in all the inplane rotations to form z From 9feda3290964140f4e01071ca215ed3d5ef21775 Mon Sep 17 00:00:00 2001 From: pc494 Date: Fri, 24 Jan 2020 18:51:56 +0000 Subject: [PATCH 47/62] testing equal arguments --- .../test_generators/test_rotation_list_generator.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/diffsims/tests/test_generators/test_rotation_list_generator.py b/diffsims/tests/test_generators/test_rotation_list_generator.py index 3900c7ff..47ff027f 100644 --- a/diffsims/tests/test_generators/test_rotation_list_generator.py +++ b/diffsims/tests/test_generators/test_rotation_list_generator.py @@ -37,16 +37,18 @@ def test_get_grid_around_beam_direction(): assert isinstance(grid_simple[0],tuple) assert len(grid_simple) == 360 -@pytest.mark.skip(reason="local dev") @pytest.mark.parametrize("space_group_number",[1,3,30,190,215,229]) def test_get_fundemental_zone_grid(space_group_number): grid = get_fundemental_zone_grid(space_group_number,resolution=3) def test_get_grid_streographic(): - grid = get_grid_streographic('tetragonal',1) + grid = get_grid_streographic('tetragonal',1,equal='angle') assert (0,0,0) in grid - grid_four_times_as_many = get_grid_streographic('orthorhombic',1) - assert len(grid_twice_as_many)/len(grid) == 4 + grid_four_times_as_many = get_grid_streographic('orthorhombic',1,equal='angle') + + # for equal angle you wouldn't expect perfect ratios + assert len(grid_four_times_as_many)/len(grid) > 1.9 + assert len(grid_four_times_as_many)/len(grid) < 2.1 @pytest.mark.skip(reason="This tests a theoretical underpinning of the code") def test_small_angle_shortcut(): #pragma: no cover From 7448b178ae3aa84b9c8429482bf9e355e3d0d513 Mon Sep 17 00:00:00 2001 From: Phillip Crout <32455330+pc494@users.noreply.github.com> Date: Sat, 25 Jan 2020 15:45:56 +0000 Subject: [PATCH 48/62] [ci skip] Detailed docstrings for get_beam_directions --- diffsims/utils/gridding_utils.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index f43e86f3..586f68c8 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -181,6 +181,35 @@ def _create_advanced_linearly_spaced_array_in_rzxz(resolution, max_alpha, max_be def get_beam_directions(crystal_system,resolution,equal='angle'): """ + Produces an array of beam directions, evenly (see equal argument) spaced that lie within the streographic + triangle of the relevant crystal system. + + Parameters + ---------- + crystal_system : str + Allowed are: 'cubic','hexagonal','tetragonal','orthorhombic','monoclinic','trigonal' and 'none' + + resolution : angle in degrees + If the 'equal' option is set to 'angle' this is the misorientation between a beam direction and its + nearest neighbour(s). For 'equal'=='area' the density of points is as in the equal angle case but each + point covers an equal area + + equal : 'angle' (default) or 'area' + See the resolution argument + + Returns + ------- + points_in_cartesians : np.array (N,3) + Rows are x,y,z where z is the 001 pole direction. + Notes + ----- + For all cases: The input 'resolution' may differ slightly from the expected value. This is so that each of the corners + of the streographic triangle are included. Actual 'resolution' will always be equal to or higher than the input resolution. As + an example, if resolution is set to 4 to cover a range [0,90] we can't include both endpoints. The code makes 23 steps + of 3.91 degrees instead. + + For the cubic case: Each edge of the streographic triangle will behave as expected. The region above the (1,0,1), (1,1,1) edge + will (for implementation reasons) be slightly more densly packed than the wider region. """ theta_max,psi_max,psi_min = crystal_system_dictionary[crystal_system] From 69137ced788b72beafb2ee769791dcb3a8040567 Mon Sep 17 00:00:00 2001 From: Phillip Crout <32455330+pc494@users.noreply.github.com> Date: Sat, 25 Jan 2020 16:20:32 +0000 Subject: [PATCH 49/62] minor clarity adjustments --- diffsims/generators/rotation_list_generators.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index 2cdbfca9..58c2b810 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -68,14 +68,19 @@ def get_grid_streographic(crystal_system,resolution,equal='angle'): crytal_system : string 'cubic','hexagonal','tetragonal','orthorhombic','monoclinic','trigonal' add 'triclinc' which acts as 'none' - resolution : float - Rotations about beam directions and beam directions are seperated by rotations of the size 'resolution' + resolution : float (angle in degrees) + Nearest neighbour rotations are seperated by a distance of 'resolution' equal : 'angle' or 'area' + See docstrings for diffsims.utils.gridding_utils.get_beam_directions + + Returns + ------- + rotation_list : """ from itertools import product - beam_directions = beam_directions_to_euler_angles(get_beam_directions(crystal_system,resolution,equal=equal)) - beam_directions_szxz = beam_directions.to_AxAngle().to_Euler(axis_convention='szxz') # convert to high speed convention + beam_directions_rzxz = beam_directions_to_euler_angles(get_beam_directions(crystal_system,resolution,equal=equal)) + beam_directions_szxz = beam_directions_rzxz.to_AxAngle().to_Euler(axis_convention='szxz') # convert to high speed convention # drop in all the inplane rotations to form z alpha = beam_directions.data[:,0] From 804eb02d1199eda7ce6f30259a44a531bd032435 Mon Sep 17 00:00:00 2001 From: Phillip Crout <32455330+pc494@users.noreply.github.com> Date: Sat, 25 Jan 2020 16:27:10 +0000 Subject: [PATCH 50/62] [ci skip] docstrings for vectorised_spc2cart --- diffsims/utils/vector_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/diffsims/utils/vector_utils.py b/diffsims/utils/vector_utils.py index 81acecfb..2264e8dd 100644 --- a/diffsims/utils/vector_utils.py +++ b/diffsims/utils/vector_utils.py @@ -81,7 +81,9 @@ def vectorised_spherical_polars_to_cartesians(z): Returns ------- - + xyz : np.array + With rows of + x,y,z """ r, psi, theta = z[:,0],z[:,1],z[:,2] x = r * np.cos(psi) * np.sin(theta) From 6f6793dcf95d2dec6cbb20ef948247c9e17de069 Mon Sep 17 00:00:00 2001 From: Phillip Crout <32455330+pc494@users.noreply.github.com> Date: Sat, 25 Jan 2020 16:30:23 +0000 Subject: [PATCH 51/62] [ci skip] docstring 4 beam_direction2euler_angles --- diffsims/utils/gridding_utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 586f68c8..0b2a7ca0 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -256,12 +256,16 @@ def cubic_corner_geodesic(t): def beam_directions_to_euler_angles(points_in_cartesians): """ - + Converts an array of cartesians (x,y,z unit basis vectors) to the euler angles that would take [0,0,1] to [x,y,z] Parameters ---------- - points_in_cartesians : - + points_in_cartesians : + Generally output from get_beam_directions() + Returns + ------- + diffsims.Euler : + The appropriate euler angles """ axes = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] angle = np.arcsin(np.linalg.norm(axes,axis=1)) From e87b384b8b8830a000791b8bd07c943ea1dacc5e Mon Sep 17 00:00:00 2001 From: Phillip Crout <32455330+pc494@users.noreply.github.com> Date: Sat, 25 Jan 2020 16:34:53 +0000 Subject: [PATCH 52/62] Tests area&angle generate same number of points As that's what the docstrings now claim. --- diffsims/tests/test_utils/test_gridding_utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/diffsims/tests/test_utils/test_gridding_utils.py b/diffsims/tests/test_utils/test_gridding_utils.py index 3873b801..a4aba896 100644 --- a/diffsims/tests/test_utils/test_gridding_utils.py +++ b/diffsims/tests/test_utils/test_gridding_utils.py @@ -98,6 +98,12 @@ def test_get_beam_directions_equal_area(crystal_system,expected_corners): norm_corner = np.divide(corner,np.linalg.norm(corner)) assert np.any(np.isin(z,norm_corner)) +@pytest.mark.parametrize("crystal_system",[['cubic','hexagonal']]) +def test_equal_area_same_as_equal_angle(crystal_system): + z_angle = get_beam_directions(crystal_system,1,equal='angle') + z_area = get_beam_directions(crystal_system,1,equal='area') + assert np.all(z_angle.shape()==z_area.shape()) + def test_beam_directions_cubic(): # Following "Orientation precision of TEM-based orientation mapping techniques" - Morawiec et al, Ultramicroscopy 136,2014 z = get_beam_directions('cubic',1.6) From e5eea804a0267926bf743bd23e0383acc487f51a Mon Sep 17 00:00:00 2001 From: pc494 Date: Sun, 26 Jan 2020 15:52:15 +0000 Subject: [PATCH 53/62] bugfix + docstrings --- diffsims/generators/rotation_list_generators.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index 58c2b810..8cc56ee8 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -66,25 +66,25 @@ def get_grid_streographic(crystal_system,resolution,equal='angle'): Parameters ---------- crytal_system : string - 'cubic','hexagonal','tetragonal','orthorhombic','monoclinic','trigonal' add 'triclinc' which acts as 'none' + 'cubic','hexagonal','tetragonal','orthorhombic','monoclinic','trigonal' and 'triclinc' resolution : float (angle in degrees) Nearest neighbour rotations are seperated by a distance of 'resolution' - equal : 'angle' or 'area' - See docstrings for diffsims.utils.gridding_utils.get_beam_directions - + equal : str + 'angle' or 'area' + Returns ------- - rotation_list : + rotation_list : list of tuples """ from itertools import product beam_directions_rzxz = beam_directions_to_euler_angles(get_beam_directions(crystal_system,resolution,equal=equal)) beam_directions_szxz = beam_directions_rzxz.to_AxAngle().to_Euler(axis_convention='szxz') # convert to high speed convention # drop in all the inplane rotations to form z - alpha = beam_directions.data[:,0] - beta = beam_directions.data[:,1] + alpha = beam_directions_szxz.data[:,0] + beta = beam_directions_szxz.data[:,1] in_plane = np.arange(0,360,resolution) ipalpha = np.asarray(list(product(alpha,np.asarray(in_plane)))) From b2fe30d5d4632f8d35a5e7e75162d9641ecdcf9e Mon Sep 17 00:00:00 2001 From: pc494 Date: Sun, 26 Jan 2020 15:54:57 +0000 Subject: [PATCH 54/62] Fixes a testing syntax typo --- diffsims/tests/test_utils/test_gridding_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diffsims/tests/test_utils/test_gridding_utils.py b/diffsims/tests/test_utils/test_gridding_utils.py index a4aba896..020d337a 100644 --- a/diffsims/tests/test_utils/test_gridding_utils.py +++ b/diffsims/tests/test_utils/test_gridding_utils.py @@ -98,12 +98,12 @@ def test_get_beam_directions_equal_area(crystal_system,expected_corners): norm_corner = np.divide(corner,np.linalg.norm(corner)) assert np.any(np.isin(z,norm_corner)) -@pytest.mark.parametrize("crystal_system",[['cubic','hexagonal']]) +@pytest.mark.parametrize("crystal_system",['cubic','hexagonal']) def test_equal_area_same_as_equal_angle(crystal_system): z_angle = get_beam_directions(crystal_system,1,equal='angle') z_area = get_beam_directions(crystal_system,1,equal='area') assert np.all(z_angle.shape()==z_area.shape()) - + def test_beam_directions_cubic(): # Following "Orientation precision of TEM-based orientation mapping techniques" - Morawiec et al, Ultramicroscopy 136,2014 z = get_beam_directions('cubic',1.6) From e4459ef03af90116d2fa36f08d8b44e605cbe6f2 Mon Sep 17 00:00:00 2001 From: pc494 Date: Sun, 26 Jan 2020 16:08:23 +0000 Subject: [PATCH 55/62] Fix syntax error in tests --- diffsims/tests/test_utils/test_gridding_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diffsims/tests/test_utils/test_gridding_utils.py b/diffsims/tests/test_utils/test_gridding_utils.py index 020d337a..46d6c7fd 100644 --- a/diffsims/tests/test_utils/test_gridding_utils.py +++ b/diffsims/tests/test_utils/test_gridding_utils.py @@ -102,7 +102,7 @@ def test_get_beam_directions_equal_area(crystal_system,expected_corners): def test_equal_area_same_as_equal_angle(crystal_system): z_angle = get_beam_directions(crystal_system,1,equal='angle') z_area = get_beam_directions(crystal_system,1,equal='area') - assert np.all(z_angle.shape()==z_area.shape()) + assert np.all(z_angle.shape==z_area.shape) def test_beam_directions_cubic(): # Following "Orientation precision of TEM-based orientation mapping techniques" - Morawiec et al, Ultramicroscopy 136,2014 From 6239caa606daaed0106b9a330cb6cface1a62bb6 Mon Sep 17 00:00:00 2001 From: pc494 Date: Sun, 26 Jan 2020 16:14:27 +0000 Subject: [PATCH 56/62] docstring corrections --- diffsims/generators/rotation_list_generators.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index 8cc56ee8..5cd47ec4 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -65,11 +65,11 @@ def get_grid_streographic(crystal_system,resolution,equal='angle'): Parameters ---------- - crytal_system : string - 'cubic','hexagonal','tetragonal','orthorhombic','monoclinic','trigonal' and 'triclinc' + crytal_system : str + 'cubic','hexagonal','triclinc','tetragonal','orthorhombic','monoclinic' and 'trigonal' - resolution : float (angle in degrees) - Nearest neighbour rotations are seperated by a distance of 'resolution' + resolution : float + Nearest neighbour rotations are seperated by a distance of 'resolution' in degrees equal : str 'angle' or 'area' From edde0f06841822046c74c1286c984083760c6cbd Mon Sep 17 00:00:00 2001 From: pc494 Date: Sun, 26 Jan 2020 16:21:48 +0000 Subject: [PATCH 57/62] 'none' to 'triclinic' --- diffsims/utils/gridding_utils.py | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 0b2a7ca0..1e4b7973 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -33,7 +33,7 @@ 'orthorhombic':[90,90,0], 'trigonal': [45,90,-116.5], 'monoclinic':[90,0,-90], - 'none':[360,180,0]} + 'triclinic':[360,180,0]} def vectorised_qmult(q1, qdata): @@ -181,33 +181,33 @@ def _create_advanced_linearly_spaced_array_in_rzxz(resolution, max_alpha, max_be def get_beam_directions(crystal_system,resolution,equal='angle'): """ - Produces an array of beam directions, evenly (see equal argument) spaced that lie within the streographic + Produces an array of beam directions, evenly (see equal argument) spaced that lie within the streographic triangle of the relevant crystal system. - + Parameters ---------- crystal_system : str - Allowed are: 'cubic','hexagonal','tetragonal','orthorhombic','monoclinic','trigonal' and 'none' - - resolution : angle in degrees - If the 'equal' option is set to 'angle' this is the misorientation between a beam direction and its - nearest neighbour(s). For 'equal'=='area' the density of points is as in the equal angle case but each - point covers an equal area - - equal : 'angle' (default) or 'area' - See the resolution argument - - Returns + Allowed are: 'cubic','hexagonal','trigonal','tetragonal','orthorhombic','monoclinic','triclinic' + + resolution : float + An angle in degrees. If the 'equal' option is set to 'angle' this is the misorientation between a + beam direction and its nearest neighbour(s). For 'equal'=='area' the density of points is as in + the equal angle case but each point covers an equal area + + equal : str + 'angle' (default) or 'area' + + Returns ------- points_in_cartesians : np.array (N,3) Rows are x,y,z where z is the 001 pole direction. Notes ----- For all cases: The input 'resolution' may differ slightly from the expected value. This is so that each of the corners - of the streographic triangle are included. Actual 'resolution' will always be equal to or higher than the input resolution. As + of the streographic triangle are included. Actual 'resolution' will always be equal to or higher than the input resolution. As an example, if resolution is set to 4 to cover a range [0,90] we can't include both endpoints. The code makes 23 steps of 3.91 degrees instead. - + For the cubic case: Each edge of the streographic triangle will behave as expected. The region above the (1,0,1), (1,1,1) edge will (for implementation reasons) be slightly more densly packed than the wider region. """ @@ -260,11 +260,11 @@ def beam_directions_to_euler_angles(points_in_cartesians): Parameters ---------- - points_in_cartesians : + points_in_cartesians : Generally output from get_beam_directions() Returns ------- - diffsims.Euler : + diffsims.Euler : The appropriate euler angles """ axes = np.cross([0,0,1],points_in_cartesians) #in unit cartesians so this is fine, [0,0,1] returns [0,0,0] From 41fee7a60bba4548ee84c1c8355b455fbb8a14ef Mon Sep 17 00:00:00 2001 From: pc494 Date: Sun, 26 Jan 2020 16:25:43 +0000 Subject: [PATCH 58/62] global import rather than local for 'product' --- diffsims/generators/rotation_list_generators.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index 5cd47ec4..a7b65c04 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -22,6 +22,7 @@ import numpy as np import warnings +from itertools import product from diffsims.utils.rotation_conversion_utils import Euler from diffsims.utils.fundemental_zone_utils import get_proper_point_group_string, reduce_to_fundemental_zone @@ -78,7 +79,6 @@ def get_grid_streographic(crystal_system,resolution,equal='angle'): ------- rotation_list : list of tuples """ - from itertools import product beam_directions_rzxz = beam_directions_to_euler_angles(get_beam_directions(crystal_system,resolution,equal=equal)) beam_directions_szxz = beam_directions_rzxz.to_AxAngle().to_Euler(axis_convention='szxz') # convert to high speed convention @@ -149,7 +149,6 @@ def get_grid_around_beam_direction(beam_direction,resolution, angular_range=(0, ------- rotation_list : list of tuples """ - from itertools import product if not cubic: warnings.warn("This code only works for cubic systems at present") From c08eab3311d97a6b16b616a682d7ca8a7c3361bf Mon Sep 17 00:00:00 2001 From: pc494 Date: Sun, 26 Jan 2020 16:31:40 +0000 Subject: [PATCH 59/62] Docstrings for rotate_axangles --- diffsims/utils/gridding_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 1e4b7973..fa5cecec 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -103,15 +103,15 @@ def rotate_axangle(Axangles, new_center): Parameters ---------- - Axangles : - Axangles in the correct class + Axangles : diffsims.Axangles + Pre-rotation new_center : (alpha,beta,gamma) The location of the (0,0,0) rotation as an rzxz euler angle Returns ------- - AxAngles : - + AxAngles : diffsims.Axangles + Rotated See Also -------- generators.get_local_grid From 53ca196666dc65a22c2957bc8fa065e155b77822 Mon Sep 17 00:00:00 2001 From: "Duncan N. Johnstone" Date: Mon, 27 Jan 2020 08:51:17 +0000 Subject: [PATCH 60/62] Update rotation_list_generators.py --- .../generators/rotation_list_generators.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/diffsims/generators/rotation_list_generators.py b/diffsims/generators/rotation_list_generators.py index a7b65c04..46d575c9 100644 --- a/diffsims/generators/rotation_list_generators.py +++ b/diffsims/generators/rotation_list_generators.py @@ -32,7 +32,8 @@ def _returnable_eulers_from_axangle(grid,axis_convention,round_to): - """ Converts a grid of orientations in axis-angle space to Euler angles following a user specified convention and rounding.""" + """ Converts a grid of orientations in axis-angle space to Euler + angles following a user specified convention and rounding.""" eulers = grid.to_Euler(axis_convention=axis_convention) rotation_list = eulers.to_rotation_list(round_to=round_to) return rotation_list @@ -61,23 +62,27 @@ def get_fundemental_zone_grid(space_group_number, resolution): def get_grid_streographic(crystal_system,resolution,equal='angle'): """ - Creates a rotation list by combining the minimum region of the streogram's beam directions - with in plane rotations + Creates a rotation list by determining the beam directions within the symmetry reduced + region of the inverse pole figure, corresponding to the specified crystal system, and + combining this with rotations about the beam direction at a given resolution. Parameters ---------- crytal_system : str - 'cubic','hexagonal','triclinc','tetragonal','orthorhombic','monoclinic' and 'trigonal' + 'cubic','hexagonal','trigonal','tetragonal','orthorhombic','monoclinic' and 'triclinic' resolution : float - Nearest neighbour rotations are seperated by a distance of 'resolution' in degrees - + The maximum misorientation between rotations in the list, as defined according to + the parameter 'equal'. Specified as an angle in degrees. equal : str - 'angle' or 'area' + 'angle' or 'area'. If 'angle', the misorientation is calculated between each beam direction + and its nearest neighbour(s). If 'area', the density of points is as in the equal angle case + but each point covers an equal area. Returns ------- rotation_list : list of tuples + List of rotations """ beam_directions_rzxz = beam_directions_to_euler_angles(get_beam_directions(crystal_system,resolution,equal=equal)) beam_directions_szxz = beam_directions_rzxz.to_AxAngle().to_Euler(axis_convention='szxz') # convert to high speed convention @@ -103,7 +108,7 @@ def get_local_grid(center, max_rotation, resolution): Parameters ---------- - center : 3 angle tuple + center : tuple The orientation that acts as the center of the grid, as euler angles specified in the 'rzxz' convention (degrees) @@ -141,9 +146,9 @@ def get_grid_around_beam_direction(beam_direction,resolution, angular_range=(0, angular_range : tuple The minimum (included) and maximum (excluded) rotation around the beam direction to be included - cubic : bool (Default=False) + cubic : bool This only works for cubic systems at the present, when False this raises a warning, set to - True to supress said warning + True to supress said warning. The default is False Returns ------- From 9a7bc4e3a3a96af8b0be241719d79c2d0db99636 Mon Sep 17 00:00:00 2001 From: "Duncan N. Johnstone" Date: Mon, 27 Jan 2020 08:55:34 +0000 Subject: [PATCH 61/62] Update gridding_utils.py --- diffsims/utils/gridding_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index fa5cecec..9b3df913 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -169,7 +169,9 @@ def _create_advanced_linearly_spaced_array_in_rzxz(resolution, max_alpha, max_be diffsims.Euler """ - steps_alpha = int(np.ceil((max_alpha - 0)/resolution)) #see docstrings for np.arange, np.linspace has better endpoint handling + # We use np.linspace rather than np.arange to get list of evenly spaced Euler + # angles due to better end point handling. Therefore convert "step_size" to a "num" + steps_alpha = int(np.ceil((max_alpha - 0)/resolution)) steps_beta = int(np.ceil((max_beta - 0)/resolution)) steps_gamma = int(np.ceil((max_gamma - 0)/resolution)) From eba0b4ba38695c0227024d4327572dacaec003cb Mon Sep 17 00:00:00 2001 From: "Duncan N. Johnstone" Date: Mon, 27 Jan 2020 08:58:59 +0000 Subject: [PATCH 62/62] Update gridding_utils.py --- diffsims/utils/gridding_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/diffsims/utils/gridding_utils.py b/diffsims/utils/gridding_utils.py index 9b3df913..263e1882 100644 --- a/diffsims/utils/gridding_utils.py +++ b/diffsims/utils/gridding_utils.py @@ -27,11 +27,13 @@ from diffsims.utils.rotation_conversion_utils import * from diffsims.utils.vector_utils import vectorised_spherical_polars_to_cartesians +# Defines the maximum rotation angles [theta_max,psi_max,psi_min] associated with the +# corners of the symmetry reduced region of the inverse pole figure for each crystal system. crystal_system_dictionary = {'cubic':[45,54.7,0], 'hexagonal':[45,90,26.565], + 'trigonal': [45,90,-116.5], 'tetragonal':[45,90,0], 'orthorhombic':[90,90,0], - 'trigonal': [45,90,-116.5], 'monoclinic':[90,0,-90], 'triclinic':[360,180,0]}