def test_masking(structure, rot_list, edc): dp = create_sample(edc, structure, rot_list[0], rot_list[1]) library = get_template_library(structure, rot_list, edc) indexer = IndexationGenerator(dp, library) mask = hs.signals.Signal1D(([[[1], [1]], [[0], [1]]])) match_results = indexer.correlate(mask=mask) assert match_results.inav[0, 1].isig[4] == 0 #correlation of zero
def get_match_results(structure, rot_list, edc, rots): #get params dp = create_sample(edc, structure, rots[0], rots[1]) library = get_template_library(structure, rot_list, edc) indexer = IndexationGenerator(dp, library) match_results = indexer.correlate() return match_results
def get_template_match_results_fullframe_bad_size(structure, edc, rot_list, mask=None): dp = generate_difficult_diffraction_patterns(structure, edc) library = get_template_library(structure, rot_list, edc) indexer = IndexationGenerator(dp, library) return indexer.correlate(mask=mask, method="full_frame_correlation")
def get_template_match_results(structure, pattern_list, edc, rot_list, mask=None): dp_library = get_template_library(structure, pattern_list, edc) for key in dp_library['A']: pattern = (dp_library['A'][key]['Sim'].as_signal(2 * half_side_length, 0.025, 1).data) dp = pxm.ElectronDiffraction([[pattern, pattern], [pattern, pattern]]) library = get_template_library(structure, rot_list, edc) indexer = IndexationGenerator(dp, library) return indexer.correlate(mask=mask)
def test_masked_OM(default_structure, rot_list, pattern_list, edc): dp_library = get_template_library(default_structure, pattern_list, edc) for key in dp_library['A']: pattern = (dp_library['A'][key]['Sim'].as_signal(2 * half_side_length, 0.025, 1).data) dp = pxm.ElectronDiffraction([[pattern, pattern], [pattern, pattern]]) library = get_template_library(default_structure, rot_list, edc) indexer = IndexationGenerator(dp, library) mask = hs.signals.Signal1D(([[[1], [1]], [[0], [1]]])) M = indexer.correlate(mask=mask) assert np.all(np.isnan(M.inav[0, 1].data))
def test_orientation_mapping_physical(structure, rot_list, pattern_list, edc): dp_library = get_template_library(structure, pattern_list, edc) for key in dp_library['A']: pattern = (dp_library['A'][key]['Sim'].as_signal(2 * half_side_length, 0.025, 1).data) dp = pxm.ElectronDiffraction([[pattern, pattern], [pattern, pattern]]) library = get_template_library(structure, rot_list, edc) indexer = IndexationGenerator(dp, library) M = indexer.correlate() assert np.all(M.inav[0, 0] == M.inav[1, 0]) assert np.allclose(M.inav[0, 0].isig[:4, 0].data, [0, 2, 0, 0], atol=1e-3)
def get_template_match_results(structure, pattern_list, edc, rot_list, mask=None, inplane_rotations=[0]): dp_library = get_template_library(structure, pattern_list, edc) for sim in dp_library['A']['simulations']: pattern = (sim_as_signal(sim, 2 * half_side_length, 0.025, 1).data) dp = pxm.ElectronDiffraction2D([[pattern, pattern], [pattern, pattern]]) library = get_template_library(structure, rot_list, edc) indexer = IndexationGenerator(dp, library) return indexer.correlate(mask=mask, inplane_rotations=inplane_rotations)
def update_correlation_list(_=None): reciprocal_angstrom_per_pixel = slider_scale.val beam_energy = slider_energy.val specimen_thickness = slider_thick.val structure_info = structures[current_structure] rotation_list_resolution = np.deg2rad(1) phase_descriptions = [(structure_info['name'], structure_info['structure'], structure_info['system'])] inplane_rotations = [[np.deg2rad(103)]] diffraction_library, structure_library = create_diffraction_library( specimen_thickness, beam_energy, reciprocal_angstrom_per_pixel, rotation_list_resolution, phase_descriptions, inplane_rotations, target_pattern_dimension_pixels) # Set up the indexer and get the indexation results data_dir = r'D:\Dokumenter/MTNANO/Prosjektoppgave/Data/' experimental_pattern_filename = data_dir + 'SPED_data_GaAs_NW/gen/Julie_180510_SCN45_FIB_a_three_phase_single_area.hdf5' dp = pxm.load(experimental_pattern_filename, lazy=True).inav[0:1, 0:1] dp = pxm.ElectronDiffraction(dp) pattern_indexer = IndexationGenerator(dp, diffraction_library) template_matching_results = pattern_indexer.correlate( n_largest=structure_library.orientations[0].shape[0], keys=[structure_info['name']], parallel=False) # This is slower in parallel global current_rotation_list print(template_matching_results.data[0, 0].shape) current_rotation_list = template_matching_results.isig[1:4, :].data[0, 0] correlations = template_matching_results.isig[4, :].data[0, 0] global current_rotation_list_signals current_rotation_list_signals = [] print(correlations.argmax(), current_rotation_list[correlations.argmax()]) update_rotation(current_rotation_list, correlations) fig.canvas.draw_idle()
dps[2:]]) #now from a 2x2 array of patterns for alpha in np.arange(0, 10, 1): rotation = (alpha, 0, 0) if rotation[0] < 4: library = create_library_entry(library, rotation, dp_sim_list[rotation[0]]) else: local_cords = np.random.rand(5, 2) pat = DiffractionSimulation(coordinates=local_cords, intensities=np.ones_like(local_cords[:, 0])) library = create_library_entry(library, rotation, pat) indexer = IndexationGenerator(dp, library) match_results = indexer.correlate() def test_match_results(): # Note the random number generator may give a different assertion failure # This should always work regardless of the RNG. assert match_results.inav[0, 0].data[0][1] == 0 assert match_results.inav[1, 0].data[0][1] == 1 assert match_results.inav[0, 1].data[0][1] == 2 assert match_results.inav[1, 1].data[0][1] == 3 def test_visuals(): ## This functions will need to abuse globals. ## & Can be removed if we trust the other tests from pyxem.utils.sim_utils import peaks_from_best_template
def get_template_match_results(structure,edc, rot_list, mask=None): dp = generate_diffraction_patterns(structure,edc) library = get_template_library(structure, rot_list, edc) indexer = IndexationGenerator(dp, library) return indexer.correlate(mask=mask,method='zero_mean_normalized_correlation')
library = DiffractionLibrary() library["Phase"] = { 'simulations': simulations, 'orientations': orientations, 'pixel_coords': pixel_coords, 'intensities': intensities, } dp = pxm.ElectronDiffraction2D([dps[0:2], dps[2:] ]) # now from a 2x2 array of patterns return dp, library dp, library = create_library() indexer = IndexationGenerator(dp, library) match_results = indexer.correlate(inplane_rotations=[0]) def test_match_results(): # Note the random number generator may give a different assertion failure # This should always work regardless of the RNG. assert match_results.inav[0, 0].data[0][1][0] == 0 assert match_results.inav[1, 0].data[0][1][0] == 1 assert match_results.inav[0, 1].data[0][1][0] == 2 assert match_results.inav[1, 1].data[0][1][0] == 3 def test_plot_best_matching_results_on_signal(): match_results.plot_best_matching_results_on_signal(dp, library=library)
dps.loc[image,'template_library'] = library_name ## let's take a look at the generated pattern #pattern0 = sim_as_signal(template_library.get_library_entry(phase='Aug', angle=(0, 0, 0))["Sim"], # pattern_size, 0.03, reciprocal_radius) # ### 2.2 start indexing # indexer = IndexationGenerator(dp, template_library) match_results = indexer.correlate(n_largest=3, inplane_rotations=np.arange(0, 360, 1)) ''' match_results.plot_best_matching_results_on_signal(dp, template_library, permanent_markers=False, cmap='viridis') ''' cryst_map = match_results.get_crystallographic_map() mtex_file = image.split('.')[0]+"_pattern_match_results_tile"+str(number_of_tiles)+"_"+today+".csv" cryst_map.save_mtex_map(mtex_file) dps.loc[image, 'mtex_file'] = mtex_file