CHAP.edd.processor

File : processor.py Author : Keara Soloway, Rolf Verberg Description: Module for Processors used only by EDD experiments

Module Contents

Classes

DiffractionVolumeLengthProcessor

A Processor using a steel foil raster scan to calculate the length of the diffraction volume for an EDD setup.

LatticeParameterRefinementProcessor

Processor to get a refined estimate for a sample’s lattice parameters.

MCAEnergyCalibrationProcessor

Processor to return parameters for linearly transforming MCA channel indices to energies (in keV). Procedure: provide a spectrum from the MCA element to be calibrated and the theoretical location of at least one peak present in that spectrum (peak locations must be given in keV). It is strongly recommended to use the location of fluorescence peaks whenever possible, not diffraction peaks, as this Processor does not account for 2&theta.

MCATthCalibrationProcessor

Processor to calibrate the 2&theta angle and fine tune the energy calibration coefficients for an EDD experimental setup.

MCADataProcessor

A Processor to return data from an MCA, restuctured to incorporate the shape & metadata associated with a map configuration to which the MCA data belongs, and linearly transformed according to the results of a energy/tth calibration.

MCACalibratedDataPlotter

Convenience Processor for quickly visualizing calibrated MCA data from a single scan. Returns None!

StrainAnalysisProcessor

Processor that takes a map of MCA data and returns a map of sample strains

API

class CHAP.edd.processor.DiffractionVolumeLengthProcessor

Bases: CHAP.processor.Processor

A Processor using a steel foil raster scan to calculate the length of the diffraction volume for an EDD setup.

Initialization

Constructor of PipelineItem class

process(data, config=None, save_figures=False, inputdir='.', outputdir='.', interactive=False)

Return the calculated value of the DV length.

Parameters:
  • data (list[PipelineData]) – Input configuration for the raw scan data & DVL calculation procedure.

  • config (dict, optional) – Initialization parameters for an instance of CHAP.edd.models.DiffractionVolumeLengthConfig, defaults to None.

  • save_figures (bool, optional) – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.

  • outputdir (str, optional) – Directory to which any output figures will be saved, defaults to '.'.

  • inputdir (str, optional) – Input directory, used only if files in the input configuration are not absolute paths, defaults to '.'.

  • interactive (bool, optional) – Allows for user interactions, defaults to False.

Raises:

RuntimeError – Unable to get a valid DVL configuration.

Returns:

Complete DVL configuraiton dictionary.

Return type:

dict

measure_dvl(dvl_config, detector, save_figures=False, outputdir='.', interactive=False)

Return a measured value for the length of the diffraction volume. Use the iron foil raster scan data provided in dvl_config and fit a gaussian to the sum of all MCA channel counts vs scanned motor position in the raster scan. The computed diffraction volume length is approximately equal to the standard deviation of the fitted peak.

Parameters:
  • dvl_config (CHAP.edd.models.DiffractionVolumeLengthConfig) – Configuration for the DVL calculation procedure.

  • detector (CHAP.edd.models.MCAElementDiffractionVolumeLengthConfig) – A single MCA detector element configuration.

  • save_figures (bool, optional) – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.

  • outputdir (str, optional) – Directory to which any output figures will be saved, defaults to '.'.

  • interactive (bool, optional) – Allows for user interactions, defaults to False.

Raises:

ValueError – No value provided for included bin ranges for the MCA detector element.

Returns:

Calculated diffraction volume length.

Return type:

float

class CHAP.edd.processor.LatticeParameterRefinementProcessor

Bases: CHAP.processor.Processor

Processor to get a refined estimate for a sample’s lattice parameters.

Initialization

Constructor of PipelineItem class

process(data, config=None, save_figures=False, outputdir='.', inputdir='.', interactive=False)

Given a strain analysis configuration, return a copy contining refined values for the materials’ lattice parameters.

refine_lattice_parameters(strain_analysis_config, calibration_config, detector, mca_data, mca_data_summed, nxsubentry, interactive, save_figures, outputdir)

Return refined values for the lattice parameters of the materials indicated in strain_analysis_config. Method: given a scan of a material, fit the peaks of each MCA spectrum for a given detector. Based on those fitted peak locations, calculate the lattice parameters that would produce them. Return the averaged value of the calculated lattice parameters across all spectra.

Parameters:
  • strain_analysis_config (CHAP.edd.models.StrainAnalysisConfig) – Strain analysis configuration.

  • calibration_config (edd.models.MCATthCalibrationConfig) – Energy calibration configuration.

  • detector (CHAP.edd.models.MCAElementStrainAnalysisConfig) – A single MCA detector element configuration.

  • mca_data (numpy.ndarray) – Raw specta for the current MCA detector.

  • mca_data_summed (numpy.ndarray) – Raw specta for the current MCA detector summed over all data point.

  • nxsubentry (nexusformat.nexus.NXprocess) – NeXus subentry to store the detailed refined lattice parameters for each detector.

  • interactive (bool) – Boolean to indicate whether interactive matplotlib figures should be presented.

  • save_figures (bool) – Boolean to indicate whether figures indicating the selection should be saved.

  • outputdir (str) – Where to save figures (if save_figures is True).

Returns:

List of refined lattice parameters for materials in strain_analysis_config

Return type:

list[numpy.ndarray]

class CHAP.edd.processor.MCAEnergyCalibrationProcessor

Bases: CHAP.processor.Processor

Processor to return parameters for linearly transforming MCA channel indices to energies (in keV). Procedure: provide a spectrum from the MCA element to be calibrated and the theoretical location of at least one peak present in that spectrum (peak locations must be given in keV). It is strongly recommended to use the location of fluorescence peaks whenever possible, not diffraction peaks, as this Processor does not account for 2&theta.

Initialization

Constructor of PipelineItem class

process(data, config=None, centers_range=20, fwhm_min=None, fwhm_max=None, max_energy_kev=200.0, background=None, baseline=False, save_figures=False, interactive=False, inputdir='.', outputdir='.')

For each detector in the MCAEnergyCalibrationConfig provided with data, fit the specified peaks in the MCA spectrum specified. Using the difference between the provided peak locations and the fit centers of those peaks, compute the correction coefficients to convert uncalibrated MCA channel energies to calibrated channel energies. For each detector, set energy_calibration_coeffs in the calibration config provided to these values and return the updated configuration.

Parameters:
  • data (PipelineData) – An energy Calibration configuration.

  • config (dict, optional) – Initialization parameters for an instance of CHAP.edd.models.MCAEnergyCalibrationConfig, defaults to None.

  • centers_range (int, optional) – Set boundaries on the peak centers in MCA channels when performing the fit. The min/max possible values for the peak centers will be the initial values ± centers_range. Defaults to 20.

  • fwhm_min (float, optional) – Lower bound on the peak FWHM in MCA channels when performing the fit, defaults to None.

  • fwhm_max (float, optional) – Lower bound on the peak FWHM in MCA channels when performing the fit, defaults to None.

  • max_energy_kev (float, optional) – Maximum channel energy of the MCA in keV, defaults to 200.0.

  • background (str, list[str], optional) – Background model for peak fitting.

  • baseline (bool, BaselineConfig, optional) – Automated baseline subtraction configuration, defaults to False.

  • save_figures (bool, optional) – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.

  • interactive (bool, optional) – Allows for user interactions, defaults to False.

  • inputdir (str, optional) – Input directory, used only if files in the input configuration are not absolute paths, defaults to '.'.

  • outputdir (str, optional) – Directory to which any output figures will be saved, defaults to '.'.

Returns:

Dictionary representing the energy-calibrated version of the calibrated configuration.

Return type:

dict

calibrate(calibration_config, detector, spectrum, centers_range, fwhm_min, fwhm_max, max_energy_kev, save_figures, interactive, outputdir)

Return energy_calibration_coeffs (a, b, and c) for quadratically converting the current detector’s MCA channels to bin energies.

Parameters:
  • calibration_config (MCAEnergyCalibrationConfig) – Energy calibration configuration.

  • detector (MCAElementCalibrationConfig) – Configuration of the current detector.

  • spectrum (numpy.ndarray) – Summed MCA spectrum for the current detector.

  • centers_range (int, optional) – Set boundaries on the peak centers in MCA channels when performing the fit. The min/max possible values for the peak centers will be the initial values ± centers_range. Defaults to 20.

  • fwhm_min (float, optional) – Lower bound on the peak FWHM in MCA channels when performing the fit, defaults to None.

  • fwhm_max (float, optional) – Lower bound on the peak FWHM in MCA channels when performing the fit, defaults to None.

  • max_energy_kev (float) – Maximum channel energy of the MCA in keV, defaults to 200.0.

  • save_figures (bool) – Save .pngs of plots for checking inputs & outputs of this Processor.

  • interactive (bool) – Allows for user interactions.

  • outputdir (str) – Directory to which any output figures will be saved.

Returns:

Slope and intercept for linearly correcting the detector’s MCA channels to bin energies.

Return type:

tuple[float, float]

_get_initial_peak_positions(y, index_ranges, input_indices, input_max_peak_index, interactive, filename, detector_name, reset_flag=0)
class CHAP.edd.processor.MCATthCalibrationProcessor

Bases: CHAP.processor.Processor

Processor to calibrate the 2&theta angle and fine tune the energy calibration coefficients for an EDD experimental setup.

Initialization

Constructor of PipelineItem class

process(data, config=None, tth_initial_guess=None, include_energy_ranges=None, calibration_method='iterate_tth', quadratic_energy_calibration=False, centers_range=20, fwhm_min=None, fwhm_max=None, background=None, baseline=False, save_figures=False, inputdir='.', outputdir='.', interactive=False)

Return the calibrated 2&theta value and the fine tuned energy calibration coefficients to convert MCA channel indices to MCA channel energies.

Parameters:
  • data (list[PipelineData]) – Input configuration for the raw data & tuning procedure.

  • config (dict, optional) – Initialization parameters for an instance of CHAP.edd.models.MCATthCalibrationConfig, defaults to None.

  • tth_initial_guess (float, optional) – Initial guess for 2&theta to supercede the values from the energy calibration detector cofiguration on each of the detectors.

  • include_energy_ranges (list[[float, float]], optional) – List of MCA channel energy ranges in keV whose data should be included after applying a mask (bounds are inclusive). If specified, these supercede the values from the energy calibration detector cofiguration on each of the detectors.

  • calibration_method (Union[‘direct_fit_residual’, ‘direct_fit_peak_energies’, ‘direct_fit_combined’, ‘iterate_tth’], optional) – Type of calibration method, defaults to 'iterate_tth'.

  • quadratic_energy_calibration (bool, optional) – Adds a quadratic term to the detector channel index to energy conversion, defaults to False (linear only).

  • centers_range (int, optional) – Set boundaries on the peak centers in MCA channels when performing the fit. The min/max possible values for the peak centers will be the initial values ± centers_range. Defaults to 20.

  • fwhm_min (float, optional) – Lower bound on the peak FWHM in MCA channels when performing the fit, defaults to None.

  • fwhm_max (float, optional) – Lower bound on the peak FWHM in MCA channels when performing the fit, defaults to None.

  • background (str, list[str], optional) – Background model for peak fitting.

  • baseline (bool, BaselineConfig, optional) – Automated baseline subtraction configuration, defaults to False.

  • save_figures (bool, optional) – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.

  • outputdir (str, optional) – Directory to which any output figures will be saved, defaults to '.'.

  • inputdir (str, optional) – Input directory, used only if files in the input configuration are not absolute paths, defaults to '.'.

  • interactive (bool, optional) – Allows for user interactions, defaults to False.

Raises:

RuntimeError – Invalid or missing input configuration.

Returns:

Original configuration with the tuned values for 2&theta and the linear correction parameters added.

Return type:

dict[str,float]

calibrate(calibration_config, detector, spectrum, quadratic_energy_calibration=False, centers_range=20, fwhm_min=None, fwhm_max=None, save_figures=False, interactive=False, outputdir='.')

Iteratively calibrate 2&theta by fitting selected peaks of an MCA spectrum until the computed strain is sufficiently small. Use the fitted peak locations to determine linear correction parameters for the MCA channel energies.

Parameters:
  • calibration_config (CHAP.edd.models.MCATthCalibrationConfig) – Object configuring the CeO2 calibration procedure for an MCA detector.

  • detector (CHAP.edd.models.MCAElementCalibrationConfig) – A single MCA detector element configuration.

  • spectrum (numpy.ndarray) – Summed MCA spectrum for the current detector.

  • quadratic_energy_calibration (bool, optional) – Adds a quadratic term to the detector channel index to energy conversion, defaults to False (linear only).

  • centers_range (int, optional) – Set boundaries on the peak centers in MCA channels when performing the fit. The min/max possible values for the peak centers will be the initial values ± centers_range. Defaults to 20.

  • fwhm_min (float, optional) – Lower bound on the peak FWHM in MCA channels when performing the fit, defaults to None.

  • fwhm_max (float, optional) – Lower bound on the peak FWHM in MCA channels when performing the fit, defaults to None.

  • save_figures (bool, optional) – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.

  • interactive (bool, optional) – Allows for user interactions, defaults to False.

  • outputdir (str, optional) – Directory to which any output figures will be saved, defaults to '.'.

Raises:

ValueError – No value provided for included bin ranges or the fitted HKLs for the MCA detector element.

class CHAP.edd.processor.MCADataProcessor

Bases: CHAP.processor.Processor

A Processor to return data from an MCA, restuctured to incorporate the shape & metadata associated with a map configuration to which the MCA data belongs, and linearly transformed according to the results of a energy/tth calibration.

Initialization

Constructor of PipelineItem class

process(data, config=None, save_figures=False, inputdir='.', outputdir='.', interactive=False)

Process configurations for a map and MCA detector(s), and return the calibrated MCA data collected over the map.

Parameters:

data (list[dict[str,object]]) – Input map configuration and results of energy/tth calibration.

Returns:

Calibrated and flux-corrected MCA data.

Return type:

nexusformat.nexus.NXentry

get_nxroot(map_config, calibration_config)

Get a map of the MCA data collected by the scans in map_config. The MCA data will be calibrated and flux-corrected according to the parameters included in calibration_config. The data will be returned along with relevant metadata in the form of a NeXus structure.

Parameters:
Returns:

A map of the calibrated and flux-corrected MCA data.

Return type:

nexusformat.nexus.NXroot

class CHAP.edd.processor.MCACalibratedDataPlotter

Bases: CHAP.processor.Processor

Convenience Processor for quickly visualizing calibrated MCA data from a single scan. Returns None!

Initialization

Constructor of PipelineItem class

process(data, spec_file, scan_number, scan_step_index=None, material=None, save_figures=False, interactive=False, outputdir='.')

Show a maplotlib figure of the MCA data fom the scan provided on a calibrated energy axis. If scan_step_index is None, a plot of the sum of all spectra across the whole scan will be shown.

Parameters:
  • data (list[PipelineData]) – PipelineData containing an MCA calibration.

  • spec_file (str) – SPEC file containing scan of interest.

  • scan_number (int) – Scan number of interest.

  • scan_step_index (int, optional) – Scan step index of interest, defaults to None.

  • material (dict) – Material parameters to plot HKLs for.

  • save_figures (bool) – Save .pngs of plots for checking inputs & outputs of this Processor.

  • interactive (bool) – Allows for user interactions.

  • outputdir (str) – Directory to which any output figures will be saved.

Returns:

None

Return type:

None

class CHAP.edd.processor.StrainAnalysisProcessor

Bases: CHAP.processor.Processor

Processor that takes a map of MCA data and returns a map of sample strains

Initialization

Constructor of PipelineItem class

process(data, config=None, find_peaks=False, skip_animation=False, save_figures=False, inputdir='.', outputdir='.', interactive=False)

Return strain analysis maps & associated metadata in an NXprocess.

Parameters:
  • data (list[PipelineData]) – Input data containing configurations for a map, completed energy/tth calibration, and parameters for strain analysis.

  • config (dict, optional) – Initialization parameters for an instance of CHAP.edd.models.StrainAnalysisConfig, defaults to None.

  • find_peaks (bool, optional) – Exclude peaks where the average spectrum is below the rel_height_cutoff (in the detector configuration) cutoff relative to the maximum value of the average spectrum, defaults to False.

  • skip_animation (bool, optional) – Skip the animation and plotting of the strain analysis fits, defaults to False.

  • save_figures (bool, optional) – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.

  • inputdir (str, optional) – Input directory, used only if files in the input configuration are not absolute paths, defaults to '.'.

  • outputdir (str, optional) – Directory to which any output figures will be saved, defaults to '.'.

  • interactive (bool, optional) – Allows for user interactions, defaults to False.

Raises:

RuntimeError – Unable to get a valid strain analysis configuration.

Returns:

NXprocess containing metadata about strain analysis processing parameters and empty datasets for strain maps to be filled in later.

Return type:

nexusformat.nexus.NXprocess

strain_analysis(nxentry, strain_analysis_config, find_peaks, skip_animation)

Return NXroot containing the strain maps.

Parameters:
  • nxentry (nexusformat.nexus.NXentry) – The strain analysis map, including the raw detector data.

  • strain_analysis_config (CHAP.edd.models.StrainAnalysisConfig) – Strain analysis processing configuration.

  • find_peaks (bool, optional) – Exclude peaks where the average spectrum is below the rel_height_cutoff (in the detector configuration) cutoff relative to the maximum value of the average spectrum, defaults to False.

  • skip_animation (bool, optional) – Skip the animation and plotting of the strain analysis fits, defaults to False.

Returns:

The strain maps.

Return type:

nexusformat.nexus.NXroot

_get_sum_axes_data(nxdata, sum_axes)

Get the raw MCA data collected by the scan averaged over the sum_axes.

_get_energy_and_masks()

Get the energy mask by blanking out data below 25 keV as well as that in the last bin.

_get_baselines(mca_data_mean, energy_masks)

Get the detector baselines.

_adjust_material_props(mca_data_mean, materials, energy_masks)

Adjust the material properties.

_get_mask_hkls(mca_data, mca_data_mean, materials, energy_masks)

Get the mask and HKLs used in the strain analysis.