def test_load_nickel_ebsd_small(self): s = data.nickel_ebsd_small() assert isinstance(s, EBSD) assert s.data.shape == (3, 3, 60, 60) s_lazy = data.nickel_ebsd_small(lazy=True) assert isinstance(s_lazy, LazyEBSD) assert isinstance(s_lazy.data, Array)
def test_save_load_1d_nav(self, save_path_hdf5): """Save-load cycle of signals with one navigation dimension.""" desired_shape = (3, 60, 60) desired_nav_extent = (0, 3) s = nickel_ebsd_small() # One column of patterns s_y_only = s.inav[0] s_y_only.save(save_path_hdf5) s_y_only2 = load(save_path_hdf5) assert s_y_only2.data.shape == desired_shape assert s_y_only2.axes_manager.navigation_axes[0].name == "y" assert s_y_only2.axes_manager.navigation_extent == desired_nav_extent # One row of patterns s_x_only = s.inav[:, 0] s_x_only.save(save_path_hdf5, overwrite=True) s_x_only2 = load(save_path_hdf5) assert s_x_only2.data.shape == desired_shape assert s_x_only2.axes_manager.navigation_axes[0].name == "x" assert s_x_only2.axes_manager.navigation_extent == desired_nav_extent # Maintain axis name s_y_only2.axes_manager["y"].name = "x" s_y_only2.save(save_path_hdf5, overwrite=True) s_x_only3 = load(save_path_hdf5) assert s_x_only3.data.shape == desired_shape assert s_x_only3.axes_manager.navigation_axes[0].name == "x" assert s_x_only3.axes_manager.navigation_extent == desired_nav_extent
def test_passing_results_from_get_patterns(self): s = nickel_ebsd_small() print(s) s.remove_static_background() s.remove_dynamic_background() mp = nickel_ebsd_master_pattern_small(projection="lambert") r = Rotation([ [0.9522, -0.0151, -0.2883, 0.1001], # Left grain [0.9534, 0.0465, -0.2187, -0.2026], # Right grain [0.8876, -0.2312, 0.3364, -0.2131], # 50th best match ]) detector = EBSDDetector( shape=s.axes_manager.signal_shape[::-1], pc=[0.421, 0.7794, 0.5049], convention="tsl", sample_tilt=70, ) sim = mp.get_patterns(rotations=r, detector=detector, energy=20) xmap = s.match_patterns(sim, keep_n=1) scores = xmap.scores.reshape(xmap.size, ) sim_idx = xmap.simulation_indices.reshape(xmap.size, ) assert np.allclose( scores, [0.197, 0.188, 0.207, 0.198, 0.186, 0.225, 0.191, 0.191, 0.206], atol=1e-3, ) assert np.allclose(sim_idx, [0, 1, 1, 0, 1, 1, 0, 1, 1])
def test_save_load_0d_nav(self, save_path_hdf5): """Save-load cycle of a signal with no navigation dimension.""" s = nickel_ebsd_small() s0 = s.inav[0, 0] s0.save(save_path_hdf5) s1 = load(save_path_hdf5) assert s1.data.shape == (60, 60) assert s1.axes_manager.navigation_axes == ()
def test_init_static_pattern_matching(self): s = nickel_ebsd_small() sdi = StaticPatternMatching(s) assert isinstance(sdi.dictionaries, list) assert sdi.dictionaries[0] == s assert isinstance(sdi.dictionaries[0], EBSD) assert np.may_share_memory(sdi.dictionaries[0].data, s.data)
def test_keep_n(self, n_rot_in, n_rot_out, keep_n): s = nickel_ebsd_small() s_dict = EBSD(np.random.random((n_rot_in, 60, 60)).astype(np.float32)) s_dict._xmap = CrystalMap(Rotation(np.zeros((n_rot_in, 4)))) sd = StaticPatternMatching(s_dict) xmap = sd(s) assert xmap.rotations_per_point == n_rot_out xmap2 = sd(s, keep_n=keep_n) assert xmap2.rotations_per_point == keep_n
def test_pattern_match_phase_name(self): """Ensure that the `phase_name` accepts different types.""" exp = nickel_ebsd_small().data sim = exp.reshape((-1, ) + exp.shape[-2:]) sim_idx1, scores1 = _pattern_match(exp, sim, n_slices=2) sim_idx2, scores2 = _pattern_match(exp, sim, phase_name="a", n_slices=2) sim_idx3, scores3 = _pattern_match(exp, sim, phase_name="", n_slices=2) assert np.allclose(sim_idx1[0], [0, 3, 6, 4, 7, 1, 8, 5, 2]) assert np.allclose(sim_idx2[0], [0, 3, 6, 4, 7, 1, 8, 5, 2]) assert np.allclose(sim_idx3[0], [0, 3, 6, 4, 7, 1, 8, 5, 2])
def test_get_orientation_similarity_map(self): s = nickel_ebsd_small() s_dict1 = EBSD(s.data.reshape(-1, 60, 60)) s_dict2 = EBSD(s.data.reshape(-1, 60, 60)) n_patterns = s_dict1.axes_manager.navigation_size s_dict1._xmap = CrystalMap(Rotation(np.zeros((n_patterns, 4)))) s_dict2._xmap = CrystalMap(Rotation(np.zeros((n_patterns, 4)))) s_dict1.xmap.phases[0].name = "a" s_dict2.xmap.phases[0].name = "b" sd = StaticPatternMatching([s_dict1, s_dict2]) res = sd(s, keep_n=1, get_orientation_similarity_map=True) xmap1, _ = res assert np.allclose(xmap1.scores, 1) assert np.all(["osm" in xmap.prop for xmap in res])
def test_return_merged_crystal_map(self, return_merged_xmap, desired_n_xmaps_out): s = nickel_ebsd_small() s_dict1 = EBSD(s.data.reshape(-1, 60, 60)) s_dict2 = s_dict1.deepcopy() n_patterns = s_dict1.axes_manager.navigation_size s_dict1._xmap = CrystalMap(Rotation(np.zeros((n_patterns, 4)))) s_dict2._xmap = s_dict1.xmap.deepcopy() s_dict1.xmap.phases[0].name = "a" s_dict2.xmap.phases[0].name = "b" sd = StaticPatternMatching([s_dict1, s_dict2]) res1 = sd(s, return_merged_crystal_map=return_merged_xmap) assert len(res1) == desired_n_xmaps_out sd.dictionaries.pop(-1) res2 = sd(s, return_merged_crystal_map=True) assert isinstance(res2, CrystalMap) res3 = sd(s) assert isinstance(res3, CrystalMap)