From aede5cd784d2bb37d61c8c50a6c6c544e8a3badf Mon Sep 17 00:00:00 2001 From: Viljar Femoen Date: Fri, 10 May 2024 18:25:42 +0200 Subject: [PATCH] Update test to use `si_phase_simple` --- pyxem/data/__init__.py | 3 +- pyxem/data/simulated_si.py | 28 ++++++++++++------ .../tests/signals/test_indexation_results.py | 29 +++++++++++++++---- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/pyxem/data/__init__.py b/pyxem/data/__init__.py index 5da863656..6ee3014be 100644 --- a/pyxem/data/__init__.py +++ b/pyxem/data/__init__.py @@ -30,7 +30,7 @@ """ from pyxem.data.simulated_tilt import tilt_boundary_data -from pyxem.data.simulated_si import si_phase, si_tilt, si_grains +from pyxem.data.simulated_si import si_phase, si_tilt, si_grains, si_grains_simple from pyxem.data.simulation_fe import fe_bcc_phase, fe_fcc_phase, fe_multi_phase_grains from pyxem.data._data import ( au_grating, @@ -52,6 +52,7 @@ "si_phase", "si_tilt", "si_grains", + "si_grains_simple", "fe_multi_phase_grains", "fe_fcc_phase", "fe_bcc_phase", diff --git a/pyxem/data/simulated_si.py b/pyxem/data/simulated_si.py index 8f4be1e57..b4f09e1e9 100644 --- a/pyxem/data/simulated_si.py +++ b/pyxem/data/simulated_si.py @@ -60,7 +60,10 @@ def si_tilt(): tilt.axes_manager.signal_axes[1].scale = 0.01 return tilt -def si_grains_from_orientations(oris: Orientation, seed: int = 2, size: int = 20, recip_pixels: int = 128): + +def si_grains_from_orientations( + oris: Orientation, seed: int = 2, size: int = 20, recip_pixels: int = 128 +): p = si_phase() gen = SimulationGenerator() num_grains = oris.size @@ -95,37 +98,44 @@ def si_grains_from_orientations(oris: Orientation, seed: int = 2, size: int = 20 grains.axes_manager.signal_axes[1].scale = 0.01 return grains -def si_grains_random(num_grains=4, seed=2, size=20, recip_pixels=128, return_rotations=False): + +def si_grains(num_grains=4, seed=2, size=20, recip_pixels=128, return_rotations=False): """Generate a simulated dataset with grains in random orientations""" p = si_phase() rotations = Orientation.random(num_grains, symmetry=p.point_group) - grains = si_grains_from_orientations(rotations, seed=seed, size=size, recip_pixels=recip_pixels) - + grains = si_grains_from_orientations( + rotations, seed=seed, size=size, recip_pixels=recip_pixels + ) + if return_rotations: return grains, rotations else: return grains + def si_grains_simple(seed=2, size=20, recip_pixels=128, return_rotations=False): """Generate a simulated dataset with low-index zone axes""" p = si_phase() rotations = Orientation.from_euler( [ - [0, 0, 0], # [0 0 1] - [0, 45, 0], # [0 1 1] + [0, 0, 0], # [0 0 1] + [0, 45, 0], # [0 1 1] [0, 54.7, 45], # [1 1 1] - [0, 35, 45], # [1 1 2] + [0, 35, 45], # [1 1 2] ], degrees=True, - symmetry=p.point_group + symmetry=p.point_group, + ) + grains = si_grains_from_orientations( + rotations, seed=seed, size=size, recip_pixels=recip_pixels ) - grains = si_grains_from_orientations(rotations, seed=seed, size=size, recip_pixels=recip_pixels) if return_rotations: return grains, rotations else: return grains + def simulated1dsi( num_points=200, accelerating_voltage=200, diff --git a/pyxem/tests/signals/test_indexation_results.py b/pyxem/tests/signals/test_indexation_results.py index de7621d46..3fa7a1079 100644 --- a/pyxem/tests/signals/test_indexation_results.py +++ b/pyxem/tests/signals/test_indexation_results.py @@ -32,7 +32,7 @@ from pyxem.generators import TemplateIndexationGenerator from pyxem.signals import VectorMatchingResults, DiffractionVectors, OrientationMap from pyxem.utils.indexation_utils import OrientationResult -from pyxem.data import si_grains, si_phase, si_tilt +from pyxem.data import si_grains, si_phase, si_tilt, si_grains_simple @pytest.fixture @@ -191,6 +191,24 @@ def multi_rot_orientation_result(self): orientations = polar.get_orientation(sims) return orientations, r + @pytest.fixture + def simple_multi_rot_orientation_result(self): + s, r = si_grains_simple(return_rotations=True) + s.calibration.center = None + polar = s.get_azimuthal_integral2d( + npt=100, npt_azim=180, inplace=False, mean=True + ) + phase = si_phase() + generator = SimulationGenerator(200, minimum_intensity=0.05) + rotations = get_sample_reduced_fundamental( + resolution=1, point_group=phase.point_group + ) + sims = generator.calculate_diffraction2d( + phase, rotation=rotations, max_excitation_error=0.1, reciprocal_radius=2 + ) + orientations = polar.get_orientation(sims) + return orientations, r + def test_tilt_orientation_result(self, single_rot_orientation_result): assert isinstance(single_rot_orientation_result, OrientationMap) orients = single_rot_orientation_result.to_single_phase_orientations() @@ -206,15 +224,16 @@ def test_tilt_orientation_result(self, single_rot_orientation_result): ) assert np.all(degrees_between[:, 5:] <= 1) - def test_grain_orientation_result(self, multi_rot_orientation_result): - orientations, rotations = multi_rot_orientation_result + def test_grain_orientation_result(self, simple_multi_rot_orientation_result): + orientations, rotations = simple_multi_rot_orientation_result assert isinstance(rotations, Orientation) assert isinstance(orientations, OrientationMap) orients = orientations.to_single_phase_orientations() - # Check that the orientations are within 1 degree of the expected value + # Check that the orientations are within 2 degrees of the expected value. + # Use 2 degrees since that is the angular resolution of the polar dataset degrees_between = orients.angle_with(rotations, degrees=True) - assert np.all(np.min(degrees_between, axis=2) <= 1) + assert np.all(np.min(degrees_between, axis=2) <= 2) def test_orientation_result(self, orientation_result): assert isinstance(orientation_result[0], OrientationMap)