Skip to content

Commit

Permalink
Update test to use si_phase_simple
Browse files Browse the repository at this point in the history
  • Loading branch information
viljarjf committed May 10, 2024
1 parent 2ab8143 commit aede5cd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
3 changes: 2 additions & 1 deletion pyxem/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,6 +52,7 @@
"si_phase",
"si_tilt",
"si_grains",
"si_grains_simple",
"fe_multi_phase_grains",
"fe_fcc_phase",
"fe_bcc_phase",
Expand Down
28 changes: 19 additions & 9 deletions pyxem/data/simulated_si.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 24 additions & 5 deletions pyxem/tests/signals/test_indexation_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit aede5cd

Please sign in to comment.