Ejemplo n.º 1
0
def get_library(default_structure):
    diffraction_calculator = DiffractionGenerator(300., 0.02)
    dfl = DiffractionLibraryGenerator(diffraction_calculator)
    structure_library = StructureLibrary(['Phase'], [default_structure],
                                         [np.array([(0, 0, 0), (0, 0.2, 0)])])

    return dfl.get_diffraction_library(structure_library, 0.017, 2.4, (72, 72))
def create_diffraction_library(specimen_thickness, beam_energy_keV,
                               reciprocal_angstrom_per_pixel,
                               rotation_list_resolution, phase_descriptions,
                               inplane_rotations, pattern_size):
    """Create a diffraction library.

    Parameters
    ----------
    specimen_thickness : float
        Specimen thickness in angstrom, used to calculate max excitation eror.
    beam_energy_keV : float
        Beam energy in keV.
    reciprocal_angstrom_per_pixel : float
        Calibration in reciprocal space, (Å^-1)/px.
    rotation_list_resolution : float
        Rotation list resolution in radians.
    phase_descriptions : list
        List with one phase description for each phase. A phase description is
        a triplet of (phase_name, structure, crystal system).
    inplane_rotations : list
        List with one list of inplane rotations in radians for each phase.
    pattern_size : int
        Side length in pixels of the generated diffraction patterns.

    Returns
    -------
    diffraction_library : DiffractionLibrary
        Diffraction library created using given parameters.
    structure_library : StructureLibrary
        Structure library with orientations from a stereographic triangle used
        to create the diffraction library.

    """
    half_pattern_size = pattern_size // 2
    max_excitation_error = 1 / specimen_thickness

    # Create a pyxem.StructureLibrary from the phase descriptions using a
    # stereographic projection.
    structure_library_generator = StructureLibraryGenerator(phase_descriptions)
    structure_library = structure_library_generator.get_orientations_from_stereographic_triangle(
        inplane_rotations, rotation_list_resolution)

    # Set up the diffraction generator from the given parameters
    gen = pxm.DiffractionGenerator(beam_energy_keV,
                                   max_excitation_error=max_excitation_error)
    library_generator = DiffractionLibraryGenerator(gen)
    reciprocal_radius = reciprocal_angstrom_per_pixel * (half_pattern_size - 1)

    # Finally, actually create the DiffractionLibrary. The library is created
    # without the direct beam since it does not contribute to matching.
    diffraction_library = library_generator.get_diffraction_library(
        structure_library,
        calibration=reciprocal_angstrom_per_pixel,
        reciprocal_radius=reciprocal_radius,
        half_shape=(half_pattern_size, half_pattern_size),
        with_direct_beam=False)

    return diffraction_library, structure_library
Ejemplo n.º 3
0
 def test_get_diffraction_library(
         self, library_generator: DiffractionLibraryGenerator,
         structure_library, calibration, reciprocal_radius, half_shape,
         with_direct_beam):
     library = library_generator.get_diffraction_library(
         structure_library, calibration, reciprocal_radius, half_shape,
         with_direct_beam)
     assert isinstance(library, DiffractionLibrary)
Ejemplo n.º 4
0
def test_TemplateIndexationGenerator(default_structure, method):
    identifiers = ["a", "b"]
    structures = [default_structure, default_structure]
    orientations = [[(0, 0, 0), (0, 1, 0), (1, 0, 0)],
                    [(0, 0, 1), (0, 0, 2), (0, 0, 3)]]
    structure_library = StructureLibrary(identifiers, structures, orientations)
    libgen = DiffractionLibraryGenerator(DiffractionGenerator(300))
    library = libgen.get_diffraction_library(structure_library, 0.017, 0.02,
                                             (100, 100), False)

    edp = ElectronDiffraction2D(np.random.rand(2, 2, 200, 200))
    indexer = TemplateIndexationGenerator(edp, library)

    z = indexer.correlate(method=method, n_largest=2)
    assert isinstance(z, TemplateMatchingResults)
    assert isinstance(z.data, Signal2D)
    assert z.data.data.shape[0:2] == edp.data.shape[0:2]
    assert z.data.data.shape[3] == 5
Ejemplo n.º 5
0
def test_lib_gen():
    diff_gen = DiffractionGenerator(
        accelerating_voltage=200,
        precession_angle=1,
        scattering_params="lobato",
        shape_factor_model="linear",
        minimum_intensity=0.05,
    )
    lib_gen = DiffractionLibraryGenerator(diff_gen)
    return lib_gen
Ejemplo n.º 6
0
def test_TemplateMatchingResults_plot_best_results_on_signal(
        diffraction_pattern, default_structure):
    """ Coverage testing """
    edc = DiffractionGenerator(300)
    half_side_length = 4
    rot_list = [[0, 1, 0], [1, 0, 0]]

    diff_gen = DiffractionLibraryGenerator(edc)
    struc_lib = StructureLibrary(["A"], [default_structure], [rot_list])
    library = diff_gen.get_diffraction_library(
        struc_lib,
        calibration=1 / half_side_length,
        reciprocal_radius=0.8,
        half_shape=(half_side_length, half_side_length),
        with_direct_beam=True,
    )
    indexer = TemplateIndexationGenerator(diffraction_pattern, library)
    match_results = indexer.correlate()
    match_results.plot_best_matching_results_on_signal(diffraction_pattern,
                                                       library=library)
    plt.close("all")
Ejemplo n.º 7
0
def library_generator(diffraction_calculator):
    return DiffractionLibraryGenerator(diffraction_calculator)
Ejemplo n.º 8
0
        dp = pxm.ElectronDiffraction2D(im.data)
        dp.set_diffraction_calibration(im.axes_manager['kx'].scale)
        dp.set_scan_calibration(im.axes_manager['x'].scale)


        pattern_size = dp.axes_manager['x'].size
        calibration = dp.axes_manager['kx'].scale

        diffraction_calibration = calibration
        half_pattern_size = pattern_size // 2
        reciprocal_radius = diffraction_calibration*(half_pattern_size - 1)

        beam_energy = 300.0

        ediff = DiffractionGenerator(beam_energy, 0.025)
        diff_gen = DiffractionLibraryGenerator(ediff)
        template_library = diff_gen.get_diffraction_library(structure_library,
                                                            calibration=diffraction_calibration,
                                                            reciprocal_radius=reciprocal_radius-0.1,
                                                            half_shape=(half_pattern_size, half_pattern_size),
                                                            with_direct_beam=False)




        library_name = image.split('.')[0]+"_template_"+str(angular_resolution)+"_deg.pickle"
        template_library.pickle_library(library_name)
        dps.loc[image,'template_library'] = library_name