CHAP.edd.utils

Utility functions for EDD workflows

Module Contents

Functions

get_peak_locations

Return the peak locations for a given set of lattice spacings and 2&theta value.

make_material

Return a hexrd.material.Material with the given properties.

get_unique_hkls_ds

Return the unique HKLs and lattice spacings for the given list of materials.

select_tth_initial_guess

Show a matplotlib figure of a reference MCA spectrum on top of HKL locations. The figure includes an input field to adjust the initial 2&theta guess and responds by updating the HKL locations based on the adjusted value of the initial 2&theta guess.

select_material_params_old

Interactively select the lattice parameters and space group for a list of materials. A matplotlib figure will be shown with a plot of the reference data (x and y). The figure will contain widgets to add / remove materials and update selections for space group number and lattice parameters for each one. The HKLs for the materials defined by the widgets’ values will be shown over the reference data and updated when the widgets’ values are updated.

select_material_params

Interactively select the lattice parameters and space group for a list of materials. A matplotlib figure will be shown with a plot of the reference data (x and y). The figure will contain widgets to add / remove materials and update selections for space group number and lattice parameters for each one. The HKLs for the materials defined by the widgets’ values will be shown over the reference data and updated when the widgets’ values are updated.

select_mask_and_hkls

Return a matplotlib figure to indicate data ranges and HKLs to include for fitting in EDD energy/tth calibration and/or strain analysis.

get_rolling_sum_spectra

Return the rolling sum of the spectra over a specified axis.

get_spectra_fits

Return twenty arrays of fit results for the map of spectra provided: uniform centers, uniform center errors, uniform amplitudes, uniform amplitude errors, uniform sigmas, uniform sigma errors, uniform best fit, uniform residuals, uniform reduced chi, uniform success codes, unconstrained centers, unconstrained center errors, unconstrained amplitudes, unconstrained amplitude errors, unconstrained sigmas, unconstrained sigma errors, unconstrained best fit, unconstrained residuals, unconstrained reduced chi, and unconstrained success codes.

API

CHAP.edd.utils.get_peak_locations(ds, tth)

Return the peak locations for a given set of lattice spacings and 2&theta value.

Parameters:
  • ds (list[float]) – A set of lattice spacings in angstroms.

  • tth (float) – Diffraction angle 2&theta.

Returns:

The peak locations in keV.

Return type:

numpy.ndarray

CHAP.edd.utils.make_material(name, sgnum, lattice_parameters, dmin=0.6)

Return a hexrd.material.Material with the given properties.

Parameters:
  • name (str) – Material name.

  • sgnum (int) – Space group of the material.

  • lattice_parameters (list[float]) – The material’s lattice parameters ([a, b, c, α, β, γ], or fewer as the symmetry of the space group allows — for instance, a cubic lattice with space group number 225 can just provide [a, ]).

  • dmin (float, optional) – Materials’s dmin value in angstroms (Å), defaults to 0.6.

Returns:

A hexrd material.

Return type:

heard.material.Material

CHAP.edd.utils.get_unique_hkls_ds(materials, tth_tol=None, tth_max=None, round_sig=8)

Return the unique HKLs and lattice spacings for the given list of materials.

Parameters:
  • materials (list[hexrd.material.Material]) – Materials to get HKLs and lattice spacings for.

  • tth_tol (float, optional) – Minimum resolvable difference in 2&theta between two unique HKL peaks.

  • tth_max (float, optional) – Detector rotation about hutch x axis.

  • round_sig (int, optional) – The number of significant figures in the unique lattice spacings, defaults to 8.

Returns:

Unique HKLs, unique lattice spacings.

Return type:

tuple[np.ndarray, np.ndarray]

CHAP.edd.utils.select_tth_initial_guess(x, y, hkls, ds, tth_initial_guess=5.0, interactive=False, filename=None)

Show a matplotlib figure of a reference MCA spectrum on top of HKL locations. The figure includes an input field to adjust the initial 2&theta guess and responds by updating the HKL locations based on the adjusted value of the initial 2&theta guess.

Parameters:
  • x (np.ndarray) – MCA channel energies.

  • y (np.ndarray) – MCA intensities.

  • hkls – List of unique HKL indices to fit peaks for in the calibration routine.

  • ds (Union(numpy.ndarray, list[float])) – Lattice spacings in angstroms associated with the unique HKL indices.

  • interactive (bool, optional) – Show the plot and allow user interactions with the matplotlib figure, defaults to True.

  • filename (str, optional) – Save a .png of the plot to filename, defaults to None, in which case the plot is not saved.

Variables:

tth_initial_guess – Initial guess for 2&theta, defaults to 5.0.

Returns:

The selected initial guess for 2&theta.

Type:

float

CHAP.edd.utils.select_material_params_old(x, y, tth, materials=[], label='Reference Data', interactive=False, filename=None)

Interactively select the lattice parameters and space group for a list of materials. A matplotlib figure will be shown with a plot of the reference data (x and y). The figure will contain widgets to add / remove materials and update selections for space group number and lattice parameters for each one. The HKLs for the materials defined by the widgets’ values will be shown over the reference data and updated when the widgets’ values are updated.

Parameters:
  • x (np.ndarray) – MCA channel energies.

  • y (np.ndarray) – MCA intensities.

  • tth (float) – The (calibrated) 2&theta angle.

  • materials (list[hexrd.material.Material]) – Materials to get HKLs and lattice spacings for.

  • label (str, optional) – Legend label for the 1D plot of reference MCA data from the parameters x, y, defaults to "Reference Data"

  • interactive (bool, optional) – Show the plot and allow user interactions with the matplotlib figure, defaults to False.

  • filename (str, optional) – Save a .png of the plot to filename, defaults to None, in which case the plot is not saved.

Returns:

The selected materials for the strain analyses.

Return type:

list[CHAP.edd.models.MaterialConfig]

CHAP.edd.utils.select_material_params(x, y, tth, preselected_materials=[], label='Reference Data', interactive=False, filename=None)

Interactively select the lattice parameters and space group for a list of materials. A matplotlib figure will be shown with a plot of the reference data (x and y). The figure will contain widgets to add / remove materials and update selections for space group number and lattice parameters for each one. The HKLs for the materials defined by the widgets’ values will be shown over the reference data and updated when the widgets’ values are updated.

Parameters:
  • x (np.ndarray) – MCA channel energies.

  • y (np.ndarray) – MCA intensities.

  • tth (float) – The (calibrated) 2&theta angle.

  • materials (list[hexrd.material.Material], optional) – Materials to get HKLs and lattice spacings for, default to [].

  • label (str, optional) – Legend label for the 1D plot of reference MCA data from the parameters x, y, defaults to "Reference Data"

  • interactive (bool, optional) – Show the plot and allow user interactions with the matplotlib figure, defaults to False.

  • filename (str, optional) – Save a .png of the plot to filename, defaults to None, in which case the plot is not saved.

Returns:

The selected materials for the strain analyses.

Return type:

list[CHAP.edd.models.MaterialConfig]

CHAP.edd.utils.select_mask_and_hkls(x, y, hkls, ds, tth, preselected_bin_ranges=[], preselected_hkl_indices=[], num_hkl_min=1, detector_name=None, ref_map=None, flux_energy_range=None, calibration_bin_ranges=None, label='Reference Data', interactive=False, filename=None)

Return a matplotlib figure to indicate data ranges and HKLs to include for fitting in EDD energy/tth calibration and/or strain analysis.

Parameters:
  • x (np.ndarray) – MCA channel energies.

  • y (np.ndarray) – MCA intensities.

  • hkls (list[list[int]]) – Avaliable Unique HKL values to fit peaks for in the calibration routine.

  • ds (list[float]) – Lattice spacings associated with the unique HKL indices in angstroms.

  • tth (float) – The (calibrated) 2&theta angle.

  • preselected_bin_ranges (list[list[int]], optional) – Preselected MCA channel index ranges whose data should be included after applying a mask, defaults to []

  • preselected_hkl_indices (list[int], optional) – Preselected unique HKL indices to fit peaks for in the calibration routine, defaults to [].

  • num_hkl_min (int, optional) – Minimum number of HKLs to select, defaults to 1.

  • detector_name (str, optional) – Name of the MCA detector element.

  • ref_map (np.ndarray, optional) – Reference map of MCA intensities to show underneath the interactive plot.

  • flux_energy_range (tuple(float, float), optional) – Energy range in eV in the flux file containing station beam energy in eV versus flux

  • calibration_bin_ranges (list[[int, int]], optional) – MCA channel index ranges included in the detector calibration.

  • label (str, optional) – Legend label for the 1D plot of reference MCA data from the parameters x, y, defaults to "Reference Data"

  • interactive (bool, optional) – Show the plot and allow user interactions with the matplotlib figure, defaults to True.

  • filename (str, optional) – Save a .png of the plot to filename, defaults to None, in which case the plot is not saved.

Returns:

The list of selected data index ranges to include, and the list of HKL indices to include

Return type:

list[list[int]], list[int]

CHAP.edd.utils.get_rolling_sum_spectra(y, bin_axis, start=0, end=None, width=None, stride=None, num=None, mode='valid')

Return the rolling sum of the spectra over a specified axis.

CHAP.edd.utils.get_spectra_fits(spectra, energies, peak_locations, detector)

Return twenty arrays of fit results for the map of spectra provided: uniform centers, uniform center errors, uniform amplitudes, uniform amplitude errors, uniform sigmas, uniform sigma errors, uniform best fit, uniform residuals, uniform reduced chi, uniform success codes, unconstrained centers, unconstrained center errors, unconstrained amplitudes, unconstrained amplitude errors, unconstrained sigmas, unconstrained sigma errors, unconstrained best fit, unconstrained residuals, unconstrained reduced chi, and unconstrained success codes.

Parameters:
  • spectra (numpy.ndarray) – Array of intensity spectra to fit.

  • energies (numpy.ndarray) – Bin energies for the spectra provided.

  • peak_locations – Initial guesses for peak ceneters to use for the uniform fit.

Returns:

Uniform and unconstrained centers, amplitdues, sigmas (and errors for all three), best fits, residuals between the best fits and the input spectra, reduced chi, and fit success statuses.

Return type:

tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]