pyxem.generators package

Submodules

pyxem.generators.diffraction_generator module

Electron diffraction pattern simulation.

class pyxem.generators.diffraction_generator.DiffractionGenerator(accelerating_voltage, max_excitation_error, debye_waller_factors=None, scattering_params='lobato')[source]

Bases: object

Computes electron diffraction patterns for a crystal structure.

  1. Calculate reciprocal lattice of structure. Find all reciprocal points within the limiting sphere given by \(\frac{2}{\lambda}\).

  2. For each reciprocal point \(\mathbf{g_{hkl}}\) corresponding to lattice plane \((hkl)\), compute the Bragg condition \(\sin(\theta) = \frac{\lambda}{2d_{hkl}}\)

  3. The intensity of each reflection is then given in the kinematic approximation as the modulus square of the structure factor. \(I_{hkl} = F_{hkl}F_{hkl}^*\)

Parameters
  • accelerating_voltage (float) – The accelerating voltage of the microscope in kV.

  • max_excitation_error (float) – The maximum extent of the relrods in reciprocal angstroms. Typically equal to 1/{specimen thickness}.

  • debye_waller_factors (dict of str : float) – Maps element names to their temperature-dependent Debye-Waller factors.

calculate_ed_data(structure, reciprocal_radius, with_direct_beam=True)[source]

Calculates the Electron Diffraction data for a structure.

Parameters
  • structure (Structure) – The structure for which to derive the diffraction pattern. Note that the structure must be rotated to the appropriate orientation and that testing is conducted on unit cells (rather than supercells).

  • reciprocal_radius (float) – The maximum radius of the sphere of reciprocal space to sample, in reciprocal angstroms.

  • with_direct_beam (bool) – If True, the direct beam is included in the simulated diffraction pattern. If False, it is not.

Returns

The data associated with this structure and diffraction setup.

Return type

pyxem.DiffractionSimulation

calculate_profile_data(structure, reciprocal_radius=1.0, magnitude_tolerance=1e-05, minimum_intensity=0.001)[source]

Calculates a one dimensional diffraction profile for a structure.

Parameters
  • structure (Structure) – The structure for which to calculate the diffraction profile.

  • reciprocal_radius (float) – The maximum radius of the sphere of reciprocal space to sample, in reciprocal angstroms.

  • magnitude_tolerance (float) – The minimum difference between diffraction magnitudes in reciprocal angstroms for two peaks to be consdiered different.

  • minimum_intensity (float) – The minimum intensity required for a diffraction peak to be considered real. Deals with numerical precision issues.

Returns

The diffraction profile corresponding to this structure and experimental conditions.

Return type

pyxem.ProfileSimulation

pyxem.generators.displacement_gradient_tensor_generator module

Generating DisplacementGradientMaps from diffraction vectors

pyxem.generators.displacement_gradient_tensor_generator.get_DisplacementGradientMap(strained_vectors, unstrained_vectors)[source]

Calculates the displacement gradient tensor at each navigation position in a map by comparing vectors to determine the 2 x 2 matrix, \(\mathbf(L)\), that maps unstrained vectors, Vu, to strained vectors, Vs, using the np.lingalg.inv() function to find L that satisfies \(Vs = \mathbf(L) Vu\).

The transformation is returned as a 3 x 3 displacement gradient tensor.

Parameters
  • strained_vectors (hyperspy.Signal2D) – Signal2D with a 2 x 2 array at each navigation position containing the Cartesian components of two strained basis vectors, V and U, defined as row vectors.

  • unstrained_vectors (numpy.array) – A 2 x 2 array containing the Cartesian components of two unstrained basis vectors, V and U, defined as row vectors.

Returns

D – The 3 x 3 displacement gradient tensor (measured in reciprocal space) at every navigation position.

Return type

DisplacementGradientMap

pyxem.generators.displacement_gradient_tensor_generator.get_single_DisplacementGradientTensor(Vs, Vu=None)[source]

Calculates the displacement gradient tensor from a pairs of vectors by determining the 2 x 2 matrix, \(\mathbf(L)\), that maps unstrained vectors, Vu, onto strained vectors, Vs, using the np.lingalg.inv() function to find \(\mathbf(L)\) that satisfies \(Vs = \mathbf(L) Vu\).

The transformation is returned as a 3 x 3 displacement gradient tensor.

Parameters
  • Vs (numpy.array) – A 2 x 2 array containing the Cartesian components of two strained basis vectors, V and U, defined as row vectors.

  • Vu (numpy.array) – A 2 x 2 array containing the Cartesian components of two unstrained basis vectors, V and U, defined as row vectors.

Returns

D – A 3 x 3 displacement gradient tensor (measured in reciprocal space).

Return type

numpy.array

pyxem.generators.indexation_generator module

Indexation generator and associated tools.

class pyxem.generators.indexation_generator.IndexationGenerator(signal, diffraction_library)[source]

Bases: object

Generates an indexer for data using a number of methods.

Parameters
  • signal (ElectronDiffraction) – The signal of electron diffraction patterns to be indexed.

  • diffraction_library (DiffractionLibrary) – The library of simulated diffraction patterns for indexation.

correlate(n_largest=5, mask=None, inplane_rotations=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359]), max_peaks=100, *args, **kwargs)[source]

Correlates the library of simulated diffraction patterns with the electron diffraction signal.

Parameters
  • n_largest (int) – The n orientations with the highest correlation values are returned.

  • mask (Array) – Array with the same size as signal (in navigation) True False

  • inplane_rotations (ndarray) – Array of inplane rotation angles in degrees. Defaults to 0-360 degrees at 1 degree resolution.

  • max_peaks (int) – Maximum number of peaks to consider when comparing a template to the diffraction pattern. The strongest peaks are kept.

  • *args (arguments) – Arguments passed to map().

  • **kwargs (arguments) – Keyword arguments passed map().

Returns

matching_results – Navigation axes of the electron diffraction signal containing correlation results for each diffraction pattern, in the form [Library Number , [z, x, z], Correlation Score]

Return type

TemplateMatchingResults

class pyxem.generators.indexation_generator.ProfileIndexationGenerator(magnitudes, simulation, mapping=True)[source]

Bases: object

Generates an indexer for data using a number of methods.

Parameters
index_peaks(tolerance=0.1, *args, **kwargs)[source]

Assigns hkl indices to peaks in the diffraction profile.

Parameters
  • tolerance (float) – The n orientations with the highest correlation values are returned.

  • keys (list) – If more than one phase present in library it is recommended that these are submitted. This allows a mapping from the number to the phase. For example, keys = [‘si’,’ga’] will have an output with 0 for ‘si’ and 1 for ‘ga’.

  • *args (arguments) – Arguments passed to the map() function.

  • **kwargs (arguments) – Keyword arguments passed to the map() function.

Returns

matching_results

Return type

ProfileIndexation

class pyxem.generators.indexation_generator.VectorIndexationGenerator(vectors, vector_library)[source]

Bases: object

Generates an indexer for DiffractionVectors using a number of methods.

vectors

DiffractionVectors to be indexed.

Type

DiffractionVectors

vector_library

Library of theoretical diffraction vector magnitudes and inter-vector angles for indexation.

Type

DiffractionVectorLibrary

Parameters
index_vectors(mag_tol, angle_tol, index_error_tol, n_peaks_to_index, n_best, *args, **kwargs)[source]

Assigns hkl indices to diffraction vectors.

Parameters
  • mag_tol (float) – The maximum absolute error in diffraction vector magnitude, in units of reciprocal Angstroms, allowed for indexation.

  • angle_tol (float) – The maximum absolute error in inter-vector angle, in units of degrees, allowed for indexation.

  • index_error_tol (float) – Max allowed error in peak indexation for classifying it as indexed, calculated as \(|hkl_calculated - round(hkl_calculated)|\).

  • n_peaks_to_index (int) – The maximum number of peak to index.

  • n_best (int) – The maximum number of good solutions to be retained.

  • *args (arguments) – Arguments passed to the map() function.

  • **kwargs (arguments) – Keyword arguments passed to the map() function.

Returns

indexation_results – Navigation axes of the diffraction vectors signal containing vector indexation results for each probe position.

Return type

VectorMatchingResults

pyxem.generators.library_generator module

Diffraction pattern library generator and associated tools.

class pyxem.generators.library_generator.DiffractionLibraryGenerator(electron_diffraction_calculator)[source]

Bases: object

Computes a library of electron diffraction patterns for specified atomic structures and orientations.

get_diffraction_library(structure_library, calibration, reciprocal_radius, half_shape, with_direct_beam=True)[source]

Calculates a dictionary of diffraction data for a library of crystal structures and orientations.

Each structure in the structure library is rotated to each associated orientation and the diffraction pattern is calculated each time.

Angles must be in the Euler representation (Z,X,Z) and in degrees

Parameters
  • structure_library (pyxem:StructureLibrary Object) – Dictionary of structures and associated orientations for which electron diffraction is to be simulated.

  • calibration (float) – The calibration of experimental data to be correlated with the library, in reciprocal Angstroms per pixel.

  • reciprocal_radius (float) – The maximum g-vector magnitude to be included in the simulations.

  • half_shape (tuple) – The half shape of the target patterns, for 144x144 use (72,72) etc

  • with_direct_beam (bool) – Include the direct beam in the library.

Returns

diffraction_library – Mapping of crystal structure and orientation to diffraction data objects.

Return type

DiffractionLibrary

class pyxem.generators.library_generator.VectorLibraryGenerator(structure_library)[source]

Bases: object

Computes a library of diffraction vectors and pairwise inter-vector angles for a specified StructureLibrary.

get_vector_library(reciprocal_radius)[source]

Calculates a library of diffraction vectors and pairwise inter-vector angles for a library of crystal structures.

Parameters

reciprocal_radius (float) – The maximum g-vector magnitude to be included in the library.

Returns

vector_library – Mapping of phase identifier to phase information in dictionary format.

Return type

DiffractionVectorLibrary

pyxem.generators.structure_library_generator module

class pyxem.generators.structure_library_generator.StructureLibraryGenerator(phases)[source]

Bases: object

Generates a structure library for the given phases

Parameters

phases (list) – Array of three-component phase descriptions, where the phase description is [<phase name> : string, <structure> : diffpy.structure.Structure, <crystal system> : string], and crystal system is one of ‘cubic’, ‘hexagonal’, ‘orthorombic’, ‘tetragonal’, ‘trigonal’, ‘monoclinic’.

phase_names

List of phase names.

Type

list of string

structures

List of structures.

Type

list of diffpy.structure.Structure

systems

List of crystal systems.

Type

list of string

Examples

>>> gen = StructureLibraryGenerator([
...     ('ZB', structure_zb, 'cubic'),
...     ('WZ', structure_wz, 'hexagonal')])
get_orientations_from_list(orientations)[source]

Create a structure library from a list of rotations.

Parameters

orientations (list) – A list over identifiers of lists of euler angles (as tuples) in the rzxz convention and in degrees.

Returns

structure_library – Structure library for the given phase names, structures and orientations.

Return type

StructureLibrary

get_orientations_from_stereographic_triangle(inplane_rotations, resolution)[source]

Create a structure library from the stereographic triangles of the given crystal systems.

Parameters
  • inplane_rotations (list) – List over identifiers of lists of inplane rotations of the diffraction patterns, in degrees.

  • resolution (float) – Rotation list resolution in degrees.

Returns

structure_library – Structure library for the given phase names, structures and crystal system.

Return type

StructureLibrary

pyxem.generators.subpixelrefinement_generator module

Generating subpixel resolution on diffraction vectors.

class pyxem.generators.subpixelrefinement_generator.SubpixelrefinementGenerator(dp, vectors)[source]

Bases: object

Generates subpixel refinement of DiffractionVectors.

Parameters
  • dp (ElectronDiffraction) – The electron diffraction patterns to be refined

  • vectors (DiffractionVectors | ndarray) – Vectors (in calibrated units) to the locations of the spots to be refined. If given as DiffractionVectors, it must have the same navigation shape as the electron diffraction patterns. If an ndarray, the same set of vectors is mapped over all electron diffraction patterns.

References

[1] Pekin et al. Ultramicroscopy 176 (2017) 170-176

center_of_mass_method(square_size)[source]

Find the subpixel refinement of a peak by assuming it lies at the center of intensity.

Parameters

square_size (int) – Length (in pixels) of one side of a square the contains the peak to be refined.

Returns

vector_out – DiffractionVectors containing the refined vectors in calibrated units with the same navigation shape as the diffraction patterns.

Return type

DiffractionVectors

conventional_xc(square_size, disc_radius, upsample_factor)[source]

Refines the peaks using (phase) cross correlation.

Parameters
  • square_size (int) – Length (in pixels) of one side of a square the contains the peak to be refined.

  • disc_radius (int) – Radius (in pixels) of the discs that you seek to refine

  • upsample_factor (int) – Factor by which to upsample the patterns

Returns

vector_out – DiffractionVectors containing the refined vectors in calibrated units with the same navigation shape as the diffraction patterns.

Return type

DiffractionVectors

local_gaussian_method(square_size)[source]

Refinement based on the mathematics of a local maxima on a continious region, using the (discrete) maxima pixel as a starting point. See Notes.

Parameters

square_size (int) – Length (in pixels) of one side of a square the contains the peak to be refined.

Returns

vector_out – DiffractionVectors containing the refined vectors in calibrated units with the same navigation shape as the diffraction patterns.

Return type

DiffractionVectors

Notes

This method works by first locating the maximum intenisty value within teh square. The four adjacent pixels are then considered and used to form two independant quadratic equations. Solving these gives the x_center and y_center coordinates, which are then returned.

pyxem.generators.vdf_generator module

VDF generator and associated tools.

class pyxem.generators.vdf_generator.VDFGenerator(signal, vectors=None, *args, **kwargs)[source]

Bases: object

Generates a VDF images for a specified signal and set of aperture positions.

Parameters
  • signal (ElectronDiffraction) – The signal of electron diffraction patterns to be indexed.

  • vectors (DiffractionVectors(optional)) – The vector positions, in calibrated units, at which to position integration windows for VDF formation.

get_concentric_vdf_images(k_min, k_max, k_steps, normalize=False)[source]

Obtain the intensity scattered at each navigation position in an ElectronDiffraction Signal by summation over a series of concentric in annuli between a specified inner and outer radius in a number of steps.

Parameters
  • k_min (float) – Minimum radius of the annular integration window in reciprocal angstroms.

  • k_max (float) – Maximum radius of the annular integration window in reciprocal angstroms.

  • k_steps (int) – Number of steps within the annular integration window

Returns

vdfs – VDFImage object containing virtual dark field images for all steps within the annulus.

Return type

VDFImage

get_vector_vdf_images(radius, normalize=False)[source]

Obtain the intensity scattered to each diffraction vector at each navigation position in an ElectronDiffraction Signal by summation in a circular window of specified radius.

Parameters
  • radius (float) – Radius of the integration window in reciprocal angstroms.

  • normalize (boolean) – If True each VDF image is normalized so that the maximum intensity in each VDF is 1.

Returns

vdfs – VDFImage object containing virtual dark field images for all unique vectors.

Return type

VDFImage

Module contents