CHAP.edd package

PipelineItems unique to EDD data processing workflows.

This module contains all the PipelineItems (Processors, Readers and Writers) that are unique to the EDD workflow. Any of these PipelineItems can be used as items in a CHAP Pipeline or instantiated from a user Python script.

Note

Using the EDD workflow pipeline items in a CHAP Pipeline and running it, requires a EDD conda environent or access to the appropriate CHAP EDD executable, see EDD subpackage (CHAP.edd)

Submodules summary

models

Pydantic model configuration classes unique to the EDD workflow.

processor

Processors unique to the EDD workflow.

reader

Readers unique to the EDD workflow.

select_material_params_gui

Model class and functions to create a GUI to interactively update the material properties for an EDD workflow.

utils

Generic utility functions for EDD workflows.

writer

Writers unique to the EDD workflow.

Submodules

CHAP.edd.models module

Pydantic model configuration classes unique to the the EDD workflow.

class BaselineConfig[source]

Bases: CHAPBaseModel

Baseline model configuration class.

Variables:
  • attrs (dict, optional) – Additional baseline model configuration attributes.

  • lam (float, optional) – &lambda (smoothness) parameter (the balance between the residual of the data and the baseline and the smoothness of the baseline). The suggested range is between 100 and 10^8, defaults to 10^6.

  • max_iter (int, optional) – Maximum number of iterations, defaults to 100.

  • tol (float, optional) – Convergence tolerence, defaults to 1.e-6.

attrs: dict | None
lam: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]
max_iter: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None]
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

tol: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]
class DiffractionVolumeLengthConfig(*, background: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=True, strict=True, min_length=None, max_length=None, pattern=None, ascii_only=None)]], Len(min_length=0, max_length=None)] | None = ['constant'], baseline: bool | BaselineConfig | None = None, centers_range: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 20, energy_mask_ranges: Annotated[list[Annotated[list[Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, fwhm_min: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 3, fwhm_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 25, mask_ranges: Annotated[list[Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, backgroundpeaks: Multipeak | None = None, max_energy_kev: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 200.0, measurement_mode: Literal['manual', 'auto'] | None = 'auto', sample_thickness: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, sigma_to_dvl_factor: Literal[2.0, 3.5, 4.0] | None = 3.5)[source]

Bases: FitConfig

Configuration for the differential volume length processor DiffractionVolumeLengthProcessor for an EDD setup using a steel-foil raster scan.

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

  • measurement_mode (Literal['manual', 'auto'], optional) – Placeholder for recording whether the measured DVL value was obtained through the automated calculation or a manual selection, defaults to ‘auto’.

  • sample_thickness (float) – Thickness of scanned foil sample. Quantity must be provided in the same units as the values of the scanning motor.

  • sigma_to_dvl_factor (Literal[2.0, 3.5, 4.0], optional) – The DVL is obtained by fitting a reduced form of the MCA detector data. sigma_to_dvl_factor is a scalar value that converts the standard deviation of the gaussian fit to the measured DVL, defaults to 3.5.

max_energy_kev: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
measurement_mode: Literal['manual', 'auto'] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

sample_thickness: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
sigma_to_dvl_factor: Literal[2.0, 3.5, 4.0] | None
validate_diffractionvolumelengthconfig_after()[source]

Update the configuration with costum defaults after the normal native pydantic validation.

Returns:

Updated DVL configuration class.

Return type:

DiffractionVolumeLengthConfig

class FitConfig(*, background: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=True, strict=True, min_length=None, max_length=None, pattern=None, ascii_only=None)]], Len(min_length=0, max_length=None)] | None = ['constant'], baseline: bool | BaselineConfig | None = None, centers_range: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 20, energy_mask_ranges: Annotated[list[Annotated[list[Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, fwhm_min: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 3, fwhm_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 25, mask_ranges: Annotated[list[Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, backgroundpeaks: Multipeak | None = None)[source]

Bases: CHAPBaseModel

Fit parameters configuration class for peak fitting.

Variables:
  • background (str, list[str], optional) – Background model for peak fitting, defaults to constant.

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

  • centers_range (float, optional) – Peak centers range for peak fitting. The allowed range for the peak centers will be the initial values ± centers_range (in MCA channels for calibration or keV for strain analysis). Defaults to 20 for calibration and 2.0 for strain analysis.

  • energy_mask_ranges (list[[float, float]], optional) – MCA energy mask ranges in keV for selecting the data to be included after applying a mask (bounds are inclusive). Specify either energy_mask_ranges or mask_ranges, not both.

  • fwhm_min (float, optional) – Minimum FWHM for peak fitting (in MCA channels for calibration or keV for strain analysis). Defaults to 3 for calibration and 0.25 for strain analysis.

  • fwhm_max (float, optional) – Maximum FWHM for peak fitting (in MCA channels for calibration or keV for strain analysis). Defaults to 25 for calibration and 2.0 for strain analysis.

  • mask_ranges (list[[int, int]], optional) – MCA channel bin ranges for selecting the data to be included in the energy calibration after applying a mask (bounds are inclusive). Specify for energy calibration only.

  • backgroundpeaks (Multipeak, optional) – Additional background peaks (their associated fit parameters in units of keV).

background: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=True, strict=True, min_length=None, max_length=None, pattern=None, ascii_only=None)]], Len(min_length=0, max_length=None)] | None
backgroundpeaks: Multipeak | None
baseline: bool | BaselineConfig | None
centers_range: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
energy_mask_ranges: Annotated[list[Annotated[list[Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None
fwhm_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
fwhm_min: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
mask_ranges: Annotated[list[Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

classmethod validate_background(background)[source]

Validate the background model.

Parameters:

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

Returns:

Validated background models.

Return type:

list[str]

classmethod validate_baseline(baseline)[source]

Validate the baseline configuration.

Parameters:

baseline (BaselineConfig, optional) – Automated baseline subtraction configuration.

Returns:

Validated baseline subtraction configuration.

Return type:

BaselineConfig or None

classmethod validate_energy_mask_ranges(energy_mask_ranges)[source]

Validate the mask ranges for selecting the data to include.

Parameters:

energy_mask_ranges (list[[float, float]], optional) – MCA energy mask ranges in keV for selecting the data to be included after applying a mask (bounds are inclusive).

Returns:

Validated energy mask ranges.

Return type:

list[[float, float]]

classmethod validate_mask_ranges(mask_ranges)[source]

Validate the mask ranges for selecting the data to include.

Parameters:

mask_ranges (list[[int, int]], optional) – MCA channel bin ranges for selecting the data to be included after applying a mask (bounds are inclusive).

Returns:

Validated mask ranges.

Return type:

list[[int, int]]

class MCACalibrationConfig(*, flux_file: Annotated[Path, PathType(path_type=file)] | None = None, materials: Annotated[list[MaterialConfig], Len(min_length=0, max_length=None)] | None = [MaterialConfig(material_name='CeO2', lattice_parameters=[5.41153, 5.41153, 5.41153, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966], sgnum=225, dmin=0.35)], peak_energies: Annotated[list[Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=None)] | None = [34.279, 34.72, 39.258, 40.233], scan_step_indices: Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=1, max_length=None)] | None = None)[source]

Bases: CHAPBaseModel

Base class configuration for energy and 2&theta calibration processors.

Variables:
  • flux_file (str, optional) – File name of the csv flux file containing station beam energy in eV (column 0) versus flux (column 1).

  • materials (list[MaterialConfig], optional) – Material configurations for the calibration, defaults to [Ceria].

  • peak_energies (list[float], optional for energy calibration) – Theoretical locations of the fluorescence peaks in keV to use for calibrating the MCA channel energies.

  • scan_step_indices (int, str, list[int], optional) – Optional scan step indices to use for the calibration. If not specified, the calibration will be performed on the average of all MCA spectra for the scan.

flux_correction_interpolation_function()[source]

Get an interpolation function to correct MCA data for the relative energy flux of the incident beam.

Type:

scipy.interpolate._polyint._Interpolator1D

flux_file: Annotated[Path, PathType(path_type=file)] | None
flux_file_energy_range()[source]

Get the energy range in the flux correction file.

Type:

tuple(float, float)

materials: Annotated[list[MaterialConfig], Len(min_length=0, max_length=None)] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

peak_energies: Annotated[list[Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=None)] | None
scan_step_indices: Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=1, max_length=None)] | None
classmethod validate_mcacalibrationconfig_before(data)[source]

Ensure that a valid configuration was provided and finalize flux_file filepath.

Parameters:

data (dict) – Pydantic validator data object.

Returns:

Currently validated class attributes.

Return type:

dict

classmethod validate_scan_step_indices(scan_step_indices)[source]

Validate the specified list of scan numbers.

Parameters:

scan_step_indices (int or str or list[int], optional) – Optional scan step indices to use for the calibration. If not specified, the calibration will be performed on the average of all MCA spectra for the scan.

Raises:

ValueError – Invalid experiment type.

Returns:

Validated scan step indices.

Return type:

list[int]

class MCADetectorCalibration(*, background: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=True, strict=True, min_length=None, max_length=None, pattern=None, ascii_only=None)]], Len(min_length=0, max_length=None)] | None = ['constant'], baseline: bool | BaselineConfig | None = None, centers_range: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 20, energy_mask_ranges: Annotated[list[Annotated[list[Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, fwhm_min: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 3, fwhm_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 25, mask_ranges: Annotated[list[Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, backgroundpeaks: Multipeak | None = None)[source]

Bases: Detector, FitConfig

Class representing the configuration for a single MCA detector element to perform detector calibration.

Variables:
  • energy_calibration_coeffs (list[float, float, float], optional) – Detector channel index to energy polynomial conversion coefficients ([a, b, c] with E_i = a*i^2 + b*i + c).

  • num_bins (int, optional) – Number of MCA channels.

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

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

  • tth_calibrated (float, optional) – Calibrated value for 2&theta.

  • tth_initial_guess (float, optional) – Initial guess for 2&theta superseding the global one in MCATthCalibrationConfig.

convert_mask_ranges(mask_ranges)[source]

Given a list of mask ranges in channel bins, set the corresponding list of channel energy mask ranges.

Parameters:

mask_ranges (list[[int, int]]) – Mask ranges to convert to energy mask ranges.

property energies

Return the calibrated bin energies.

Type:

numpy.ndarray

energy_calibration_coeffs: Annotated[list[Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=3, max_length=3)] | None
get_mask_ranges()[source]

Return the list of mask ranges if set or convert the energy mask ranges from channel energies to channel indices and return those.

Type:

list[[float, float]]

property hkl_indices

Return the HKL indices consistent with the selected energy ranges (include_energy_ranges).

Type:

list

mca_mask()[source]

Get a boolean mask array to use on this MCA element’s data. Note that the bounds of the mask ranges are inclusive.

Returns:

Boolean mask array.

Return type:

numpy.ndarray

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

num_bins: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None
processor_type: Literal['calibration']
set_energy_calibration_mask_ranges()[source]

Set the value of the private attribite _energy_calibration_mask_ranges to value of mask_ranges.

tth_calibrated: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
tth_initial_guess: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
tth_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
tth_tol: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
class MCADetectorConfig(*, background: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=True, strict=True, min_length=None, max_length=None, pattern=None, ascii_only=None)]], Len(min_length=0, max_length=None)] | None = ['constant'], baseline: bool | BaselineConfig | None = None, centers_range: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 20, energy_mask_ranges: Annotated[list[Annotated[list[Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, fwhm_min: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 3, fwhm_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 25, mask_ranges: Annotated[list[Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, backgroundpeaks: Multipeak | None = None)[source]

Bases: FitConfig

Class representing metadata required to configure a full MCA detector.

Variables:

detectors (list[MCADetector], optional) – Individual MCA detector elements.

detectors: Annotated[list[Annotated[MCADetectorCalibration | MCADetectorDiffractionVolumeLength | MCADetectorStrainAnalysis, FieldInfo(annotation=NoneType, required=True, discriminator='processor_type')]], Len(min_length=1, max_length=None)] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

processor_type: Literal['calibration', 'diffractionvolumelength', 'strainanalysis']
update_detectors()[source]

Update individual detector parameters with any non-default values from the global detector configuration.

validate_mcadetectorconfig_after()[source]

Validate and update the detectors.

Returns:

Validated detectors.

Return type:

MCADetectorConfig

classmethod validate_mcadetectorconfig_before(data)[source]

Validate the MCADetectorConfig class attributes.

Parameters:

data (dict) – Pydantic validator data object.

Returns:

Currently validated class attributes.

Return type:

dict

class MCADetectorDiffractionVolumeLength(*, background: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=True, strict=True, min_length=None, max_length=None, pattern=None, ascii_only=None)]], Len(min_length=0, max_length=None)] | None = ['constant'], baseline: bool | BaselineConfig | None = None, centers_range: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 20, energy_mask_ranges: Annotated[list[Annotated[list[Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, fwhm_min: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 3, fwhm_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 25, mask_ranges: Annotated[list[Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, backgroundpeaks: Multipeak | None = None)[source]

Bases: MCADetectorCalibration

Class representing the configuration for a single MCA detector element to perform a diffraction volume length measurement.

Variables:
  • dvl (float, optional) – Measured diffraction volume length.

  • fit_amplitude (float, optional) – Amplitude of the Gaussian fit.

  • fit_center (float, optional) – Center of the Gaussian fit.

  • fit_sigma (float, optional) – Sigma of the Gaussian fit.

dvl: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
fit_amplitude: float | None
fit_center: float | None
fit_sigma: float | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

processor_type: Literal['diffractionvolumelength']
class MCADetectorStrainAnalysis(*, background: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=True, strict=True, min_length=None, max_length=None, pattern=None, ascii_only=None)]], Len(min_length=0, max_length=None)] | None = ['constant'], baseline: bool | BaselineConfig | None = None, centers_range: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 20, energy_mask_ranges: Annotated[list[Annotated[list[Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, fwhm_min: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 3, fwhm_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 25, mask_ranges: Annotated[list[Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=2, max_length=2)]], Len(min_length=1, max_length=None)] | None = None, backgroundpeaks: Multipeak | None = None)[source]

Bases: MCADetectorCalibration

Class representing the configuration to perform a strain analysis.

Variables:
  • centers_range (float, optional) – Peak centers range for peak fitting. The allowed range for the peak centers will be the initial values ± centers_range (in keV), defaults to 2.0.

  • fwhm_min (float, optional) – Minimum FWHM for peak fitting (in keV), defaults to 0.25.

  • fwhm_max (float, optional) – Maximum FWHM for peak fitting (in keV), defaults to 2.0.

  • peak_models (Literal['gaussian', 'lorentzian', 'pvoigt']], list[Literal['gaussian', 'lorentzian', 'pvoigt']]], optional) – Peak model(s) for peak fitting, defaults to ‘gaussian’.

  • rel_height_cutoff (float, optional) – Relative peak height cutoff for peak fitting (any peak with a height smaller than rel_height_cutoff times the maximum height of all peaks gets removed from the fit model), defaults to None.

  • tth_map (numpy.ndarray, optional) – Map of the 2&theta values.

add_calibration(calibration)[source]

Transfer certain 2&theta calibration parameters for use by LatticeParameterRefinementProcessor or StrainAnalysisProcessor.

Parameters:

calibration (MCADetectorCalibration) – Existing calibration configuration.

centers_range: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
fwhm_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
fwhm_min: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
get_calibration_mask_ranges()[source]

Return the MCA channel bin ranges for the data used during the 2&theta calibration.

Type:

list[[int, int]]

get_tth_map(map_shape)[source]

Return the map of 2&theta values to use – may vary at each point in the map.

Parameters:

map_shape (tuple) – Shape of the suplied 2&theta map.

Returns:

Map of 2&theta values.

Return type:

numpy.ndarray

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

peak_models: Annotated[list[Literal['gaussian', 'lorentzian', 'pvoigt']], Len(min_length=1, max_length=None)] | Literal['gaussian', 'lorentzian', 'pvoigt']
processor_type: Literal['strainanalysis']
rel_height_cutoff: Annotated[float, None, Interval(gt=0, ge=None, lt=1.0, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
tth_map: ndarray | None
classmethod validate_peak_models(peak_models)[source]

Validate the specified peak_models.

Parameters:

peak_models (Literal['gaussian', 'lorentzian', 'pvoigt']] or list[Literal['gaussian', 'lorentzian', 'pvoigt']]], optional) – Peak model(s) for peak fitting.

Returns:

Validated peak_models

Return type:

Literal[‘gaussian’, ‘lorentzian’, ‘pvoigt’]] or list[Literal[‘gaussian’, ‘lorentzian’, ‘pvoigt’]]]

class MCAEnergyCalibrationConfig(*, flux_file: Annotated[Path, PathType(path_type=file)] | None = None, materials: Annotated[list[MaterialConfig], Len(min_length=0, max_length=None)] | None = [MaterialConfig(material_name='CeO2', lattice_parameters=[5.41153, 5.41153, 5.41153, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966], sgnum=225, dmin=0.35)], peak_energies: Annotated[list[Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=None)] | None = [34.279, 34.72, 39.258, 40.233], scan_step_indices: Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=1, max_length=None)] | None = None)[source]

Bases: MCACalibrationConfig

Configuration for the energy calibration processor MCAEnergyCalibrationProcessor.

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

  • max_peak_index (int, optional) – Index of the peak in peak_energies with the highest amplitude, defaults to 1 (the second peak) for CeO2 calibration. Required for any other materials.

max_energy_kev: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
max_peak_index: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

classmethod validate_max_peak_index(max_peak_index, info)[source]

Validate max_peak_index.

Parameters:
  • max_peak_index (int, optional) – Index of the peak in peak_energies with the highest amplitude, defaults to 1 (the second peak) for CeO2 calibration. Required for any other materials.

  • info (pydantic.ValidationInfo) – Model parameter validation information.

Returns:

Validated max_peak_index.

Return type:

int

validate_mcaenergycalibrationconfig_after()[source]

Validate the detector (energy) mask ranges and update any detector configuration parameters not superseded by their individual values.

Returns:

Validated energy calibration configuration class.

Return type:

MCAEnergyCalibrationConfig

classmethod validate_mcaenergycalibrationconfig_before(data)[source]

Validate the MCAEnergyCalibrationConfig class attributes.

Parameters:

data (dict) – Pydantic validator data object.

Returns:

Currently validated class attributes.

Return type:

dict

class MCATthCalibrationConfig(*, flux_file: Annotated[Path, PathType(path_type=file)] | None = None, materials: Annotated[list[MaterialConfig], Len(min_length=0, max_length=None)] | None = [MaterialConfig(material_name='CeO2', lattice_parameters=[5.41153, 5.41153, 5.41153, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966], sgnum=225, dmin=0.35)], peak_energies: Annotated[list[Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=None)] | None = [34.279, 34.72, 39.258, 40.233], scan_step_indices: Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=1, max_length=None)] | None = None)[source]

Bases: MCACalibrationConfig

Configuration for the 2&theta calibration and the reduced data processors, MCATthCalibrationProcessor and ReducedDataProcessor, respectively.

Variables:
  • calibration_method (Literal['direct_fit_bragg', 'direct_fit_tth_ecc'], optional) – Type of calibration method, defaults to ‘direct_fit_bragg’.

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

  • tth_initial_guess (float, optional) – Initial guess for 2&theta.

calibration_method: Literal['direct_fit_bragg', 'direct_fit_tth_ecc'] | None
flux_file_energy_range()[source]

Get the energy range in the flux corection file.

Type:

tuple(float, float)

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

quadratic_energy_calibration: bool | None
tth_initial_guess: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
class MaterialConfig(*, material_name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None, ascii_only=None)] | None = None, lattice_parameters: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | Annotated[list[Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=1, max_length=6)] | None = None, sgnum: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None] | None = None, dmin: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 0.35)[source]

Bases: CHAPBaseModel

Sample material parameters configuration class.

Variables:
  • material_name (str, optional) – Sample material name.

  • lattice_parameters (float, list[float], optional) – Lattice spacing(s) in angstroms.

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

  • dmin (float, optional) – Minimum d-spacing for selecting the available HKLs, defaults to 0.35.

dmin: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
lattice_parameters: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | Annotated[list[Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=1, max_length=6)] | None
material_name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None, ascii_only=None)] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

sgnum: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None] | None
validate_materialconfig_after()[source]

Create and validate the private attribute _material.

Returns:

Validated configuration class.

Return type:

MaterialConfig

class StrainAnalysisConfig(*, flux_file: Annotated[Path, PathType(path_type=file)] | None = None, materials: Annotated[list[MaterialConfig], Len(min_length=0, max_length=None)] | None = [MaterialConfig(material_name='CeO2', lattice_parameters=[5.41153, 5.41153, 5.41153, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966], sgnum=225, dmin=0.35)], peak_energies: Annotated[list[Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=None)] | None = [34.279, 34.72, 39.258, 40.233], scan_step_indices: Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=1, max_length=None)] | None = None, find_peak_cutoff: Annotated[float, None, Interval(gt=None, ge=0.0, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 0.0, num_proc: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None = 1, rel_height_cutoff: Annotated[float, None, Interval(gt=0, ge=None, lt=1.0, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, skip_animation: bool | None = False, sum_axes: bool | Annotated[list[str], Len(min_length=1, max_length=None)] | None = True)[source]

Bases: MCACalibrationConfig

Configuration for the lattice parameter refinement and strain analysis processors, LatticeParameterRefinementProcessor and StrainAnalysisProcessor, respectively.

Variables:
  • find_peak_cutoff (float, optional) – Use scipy.signal.find_peaks to exclude peaks for all spectra for a given detector and user specified mask. A particular HKL peak is removed from the set of HKLs, when its mean peak height is below find_peak_cutoff times the maximum mean intensity for that detector. Defaults to 0 in which case this step is ignored.

  • num_proc (int) – Number of processors to be used by the strain analysis peak fitting routine.

  • rel_height_cutoff (float, optional) – Used to excluded peaks based on the find_peak parameter as well as for peak fitting exclusion of the individual detector spectra (see the strain detector configuration MCADetectorStrainAnalysis). Defaults to None.

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

  • sum_axes (bool or list[str], optional) – Whether to sum over the fly axis or not for EDD scan types not 0, defaults to True.

find_peak_cutoff: Annotated[float, None, Interval(gt=None, ge=0.0, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

num_proc: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None
rel_height_cutoff: Annotated[float, None, Interval(gt=0, ge=None, lt=1.0, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
skip_animation: bool | None
sum_axes: bool | Annotated[list[str], Len(min_length=1, max_length=None)] | None

CHAP.edd.processor module

Module for Processors unique to the EDD workflow.

Add discription of EDD

class DiffractionVolumeLengthProcessor(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: _BaseEddProcessor

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

Variables:
  • config (dict, optional) – Initialization parameters for an instance of DiffractionVolumeLengthConfig.

  • detector_config (dict, optional) – Initialization parameters for an instance of MCADetectorConfig. Defaults to the detector configuration of the raw detector data.

config: DiffractionVolumeLengthConfig | None
detector_config: MCADetectorConfig
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

pipeline_fields: dict
process(data)[source]

Return the calculated value of the differential volume length (DVL).

Parameters:

data (list[PipelineData]) – Input data.

Raises:

RuntimeError – Unable to get a valid DVL configuration.

Returns:

DVL configuration.

Return type:

dict, PipelineData

validate_diffractionvolumelengthprocessor_after()[source]

Validate the presence of sample thickness in the processor configuration.

Returns:

Validated configuration class.

Return type:

DiffractionVolumelengthProcessor

classmethod validate_diffractionvolumelengthprocessor_before(data)[source]

Validate the DiffractionVolumelengthProcessor class attributes.

Parameters:

data (dict) – Pydantic validator data object.

Returns:

Currently validated class attributes.

Return type:

dict

class HKLProcessor(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: _BaseStrainProcessor

Processor that plots the HKLs for a given material against the calibrated energy channels.

Variables:
  • config (dict) – Initialization parameters for an instance of MCACalibrationConfig. Only the materials field is actually used, the others are ignored.

  • detector_config (dict, optional) – Initialization parameters for an instance of MCADetectorConfig. Defaults to the detector configuration of the energy/2&theta calibration step.

config: MCACalibrationConfig | None
detector_config: MCADetectorConfig
lower_cutoff: Annotated[float, None, Interval(gt=None, ge=0.0, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

pipeline_fields: dict
process(data)[source]

Plot the HKLs for a given material against the calibrated energy channels.

Parameters:

data (list[PipelineData]) – Input data.

Returns:

List of byte stream representions of Matplotlib figures.

Return type:

PipelineData

upper_cutoff: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
classmethod validate_hklprocessor_before(data)[source]

Validate the HKLProcessor class attributes.

Parameters:

data (dict) – Pydantic validator data object.

Returns:

Currently validated class attributes.

Return type:

dict

class LatticeParameterRefinementProcessor(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: _BaseStrainProcessor

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

Variables:
  • config (dict, optional) – Initialization parameters for an instance of StrainAnalysisConfig.

  • detector_config (dict, optional) – Initialization parameters for an instance of MCADetectorConfig. Defaults to the detector configuration of the raw detector data merged with that of the energy/2&theta calibration step.

config: StrainAnalysisConfig | None
detector_config: MCADetectorConfig
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

pipeline_fields: dict
process(data)[source]

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

Parameters:

data (list[PipelineData]) – Input data.

Raises:

RuntimeError – Unable to refine the lattice parameters.

Returns:

Strain analysis configuration with the refined lattice parameter configuration and, optionally, a list of byte stream representions of Matplotlib figures.

Return type:

dict or dict, PipelineData

classmethod validate_latticeparameterrefinementprocessor_before(data)[source]

Validate the LatticeParameterRefinementProcessor class attributes.

Parameters:

data (dict) – Pydantic validator data object.

Returns:

Currently validated class attributes.

Return type:

dict

class MCAEnergyCalibrationProcessor(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: _BaseEddProcessor

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.

Variables:
  • config (dict, optional) – Initialization parameters for an instance of MCAEnergyCalibrationConfig.

  • detector_config (dict, optional) – Initialization parameters for an instance of MCADetectorConfig. Defaults to the detector configuration of the raw detector data.

config: MCAEnergyCalibrationConfig
detector_config: MCADetectorConfig
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

pipeline_fields: dict
process(data)[source]

For each detector in the MCAEnergyCalibrationConfig provided with data or through the processors config attribute, fit the specified peaks in the MCA spectrum. 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 and return the updated configuration.

Parameters:

data (list[PipelineData]) – Input data.

Returns:

Dictionary representing the energy-calibrated version of the calibrated configuration and a list of byte stream representions of Matplotlib figures.

Return type:

dict, PipelineData

classmethod validate_mcaenergycalibrationprocessor_before(data)[source]

Validate the MCAEnergyCalibrationProcessor class attributes.

Parameters:

data (dict) – Pydantic validator data object.

Returns:

Currently validated class attributes.

Return type:

dict

class MCATthCalibrationProcessor(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: _BaseEddProcessor

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

Variables:
  • config (dict, optional) – Initialization parameters for an instance of MCATthCalibrationConfig.

  • detector_config (dict, optional) – Initialization parameters for an instance of MCADetectorConfig. Defaults to the detector configuration of the raw detector data merged with that of the energy calibration step..

config: MCATthCalibrationConfig
detector_config: MCADetectorConfig
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

pipeline_fields: dict
process(data)[source]

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 data.

Raises:

RuntimeError – Invalid or missing input configuration.

Returns:

Original configuration with the tuned values for 2&theta and the linear correction parameters added and a list of byte stream representions of Matplotlib figures.

Return type:

dict, PipelineData

classmethod validate_mcatthcalibrationprocessor_before(data)[source]

Validate the MCATthCalibrationProcessor class attributes.

Parameters:

data (dict) – Pydantic validator data object.

Returns:

Currently validated class attributes.

Return type:

dict

class ReducedDataProcessor(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: _BaseStrainProcessor

Processor that takes a map of MCA data and returns a map of reduced data.

lower_cutoff: Annotated[float, None, Interval(gt=None, ge=0.0, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

process(data)[source]

Map the raw data onto the tth/energy calibration axes.

Parameters:

data (list[PipelineData]) – Input data containing configurations for a map and a completed energy/tth calibration.

Returns:

Reduced data.

Return type:

nexusformat.nexus.NXroot

upper_cutoff: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
class StrainAnalysisProcessor(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: _BaseStrainProcessor

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

Variables:
  • config (dict, optional) – Initialization parameters for an instance of StrainAnalysisConfig.

  • detector_config (dict, optional) – Initialization parameters for an instance of MCADetectorConfig. Defaults to the detector configuration of the raw detector data merged with that of the energy/2&theta calibration step..

  • setup (bool, optional) – Setup the strain analysis NeXus style NXroot object object, defaults to True.

  • update (bool, optional) – Perform the strain analysis and return the results as a list of updated points or update the result from the setup stage, defaults to True.

static add_points(nxroot, points, logger=None)[source]

Add or update the strain analysis for a set of map points in a NXroot object.

Parameters:
  • nxroot (nexusformat.nexus.NXroot) – Strain analysis object to add/update the points to.

  • points (list[dict[str, object]) – Strain analysis results for a set of points.

config: StrainAnalysisConfig | None
detector_config: MCADetectorConfig
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

pipeline_fields: dict
process(data)[source]

Setup the strain analysis and/or return the strain analysis results as a list of updated points or a NeXus style NXroot object.

Parameters:

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

Raises:

RuntimeError – Unable to get a valid strain analysis configuration.

Returns:

Strain analysis setup or results, a list of byte stream representions of Matplotlib figures and an animation of the fit results.

Return type:

list[dict[str, object]] or nexusformat.nexus.NXroot, PipelineData, PipelineData

setup: bool | None
update: bool | None
classmethod validate_strainanalysisprocessor_before(data)[source]

Validate the StrainAnalysisProcessor class attributes.

Parameters:

data (dict) – Pydantic validator data object.

Returns:

Currently validated class attributes.

Return type:

dict

CHAP.edd.reader module

Module for Readers unique to the EDD workflow.

class EddMPIMapReader(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: Reader

Reader for taking an EDD-style par file and returning a MapConfig object representing one of the datasets in the file. Independent dimensions are determined automatically, and a specific set of items to use for extra scalar datasets to include are hard-coded in. The raw data is read if detector ID’s are specified.

Variables:
  • dataset_id (int, optional) – Dataset ID value in the par file to return as a map, defaults to 1.

  • detector_ids (int or list[int] or str) – Detector IDs for the raw data.

dataset_id: Annotated[int, None, Interval(gt=None, ge=1, lt=None, le=None), None] | None
detector_ids: Annotated[list[Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None]], Len(min_length=1, max_length=None)]
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

read()[source]

Return a validated serialized MapConfig object representing an EDD dataset.

Returns:

Map configuration.

Return type:

dict

classmethod validate_detector_ids(detector_ids)[source]

Validate the specified list of detector IDs.

Parameters:

detector_ids (int or list[int] or str) – Detector IDs.

Returns:

List of Detector IDs.

Return type:

list[int]

class EddMapReader(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: Reader

Reader for taking an EDD-style par file and returning a MapConfig object representing one of the datasets in the file. Independent dimensions are determined automatically, and a specific set of items to use for extra scalar datasets to include are hard-coded in. The raw data is read if detector ID’s are specified.

Variables:
  • scan_numbers (int or list[int] or str, optional) – List of scan numbers to use.

  • dataset_id (int, optional) – Dataset ID value in the par file to return as a map, defaults to 1.

dataset_id: Annotated[int, None, Interval(gt=None, ge=1, lt=None, le=None), None] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

read()[source]

Return a validated serialized MapConfig object representing an EDD dataset.

Returns:

Map configuration.

Return type:

dict

scan_numbers: Annotated[list[Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None]], Len(min_length=1, max_length=None)] | None
classmethod validate_scan_numbers(scan_numbers)[source]

Validate the specified list of scan numbers.

Parameters:

scan_numbers (int or list[int] or str) – Scan numbers.

Raises:

ValueError – If a specified scan number is not found in the SPEC file.

Returns:

Scan numbers.

Return type:

list[int]

class NXdataSliceReader(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: Reader

Reader for returning a sliced verson of a NeXus style NXdata object (which represents a full EDD dataset) that contains data from just a single SPEC scan.

Variables:
  • nxpath (str) – Path to the existing full EDD dataset’s NXdata object in filename.

  • scan_number (int) – SPEC scan number.

  • spec_file (str) – Name of the spec file whose data will be the only contents of the returned NXdata.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

nxpath: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None, ascii_only=None)]
read()[source]

Return a “slice” of an EDD dataset’s NeXus style NXdata object that represents just the data from one scan in the dataset.

Returns:

NXdata object similar to the one at nxpath in filename, but containing only the data collected by the specified spec scan.

Return type:

nexusformat.nexus.NXdata

scan_number: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]
spec_file: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None, ascii_only=None)]
class ScanToMapReader(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: Reader

Reader for turning a single SPEC scan into a MapConfig object.

Variables:

scan_number (int) – SPEC scan number.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

read()[source]

Return a validated serialized MapConfig object representing an EDD dataset.

Returns:

Map configuration.

Return type:

dict

scan_number: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]
class SetupNXdataReader(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: Reader

Reader for converting the SPEC input txt file for EDD dataset collection to an approporiate input argument for SetupNXdataProcessor.

Variables:
  • dataset_id (int) – Dataset ID value in the txt file to return process() arguments for.

  • detectors (DetectorConfig) – Detector list.

dataset_id: Annotated[int, None, Interval(gt=None, ge=1, lt=None, le=None), None]
detectors: DetectorConfig
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

read()[source]

Return a dictionary containing the coords, signals, and attrs arguments appropriate for use with process() to set up an initial NeXus style NXdata object representing a complete and organized structured EDD dataset.

Returns:

Dataset’s coordinate names, values, attributes, and signal names, shapes, and attributes.

Return type:

dict

classmethod validate_detectors(detectors)[source]

Validate the specified list of detectors.

Parameters:

detectors (list[CHAP.common.models.map.Detector]) – Detectors list.

Returns:

Detectors list.

Return type:

list[CHAP.common.models.map.Detector]

class SliceNXdataReader(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: Reader

A reader class to load and slice a NeXus style NXdata field from a NeXus file. This class reads EDD data from a NXdata object and slices all fields according to the provided slicing parameters.

Variables:

scan_number (int) – SPEC scan number.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

read()[source]

Reads a NeXus style NXdata object from a NeXus file and slices the fields within it based on the provided scan number.

Raises:

ValueError – If no NXdata object is found in the file.

Returns:

Root object of the NeXus file with sliced NXdata fields.

Return type:

nexusformat.nexus.NXroot

scan_number: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]
class UpdateNXdataReader(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: Reader

Companion to SetupNXdataReader and UpdateNXDataProcessor. Constructs a list of data points to pass as pipeline data to UpdateNXDataProcessor so that a NeXus style NXdata constructed by SetupNXdataReader and UpdateNXDataProcessor can be updated live as individual scans in an EDD dataset are completed.

Variables:
  • detector_ids (int or list[int] or str, optional) – Detector IDs.

  • scan_number (int) – SPEC scan number.

detector_ids: Annotated[list[Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None]], Len(min_length=1, max_length=None)] | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

read()[source]

Return a list of data points containing raw data values for a single EDD spec scan. The returned values can be passed along to UpdateNXdataProcessor to fill in an existing NeXus Style NXdata object up with SetupNXdataProcessor.

Returs:

Data points appropriate for input to UpdateNXdataProcessor.

Return type:

list[dict[str, Any]]

scan_number: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]

CHAP.edd.select_material_params_gui module

Model class and functions to create a GUI to interactively update the material properties for an EDD workflow.

class MaterialParamSelector(root, x, y, tth, preselected_materials, label, on_complete)[source]

Bases: object

A processor that creates and opens a GUI to interactively check and if needed update the material properties for an EDD workflow.

add_material(new_material=None)[source]

Callback function for the “Add Material” botton.

on_close()[source]

Callback function for the “Confirm All Selected Material Properties” button. Closes the GUI and triggers the on_complete callback function.

on_material_select(event)[source]

Callback function for the “Select Material” ListBox.

remove_material()[source]

Callback function for the “Remove Material” botton.

update_material()[source]

Callback function for the “Update Material Properties” botton.

run_material_selector(x, y, tth, preselected_materials=None, label='Reference Data', on_complete=None, interactive=False)[source]

Run the MaterialParamSelector tkinter application.

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

  • y (numpy.ndarray) – MCA intensities.

  • tth (float) – (calibrated) 2θ angle.

  • preselected_materials (list[MaterialConfig], optional) – 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”.

  • on_complete (Callable, optional) – Callback function to handle completion of the material selection, defaults to None.

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

Returns:

Selected materials for the strain analyses.

Return type:

list[MaterialConfig]

select_material_params_gui(x, y, tth, preselected_materials=None, label='Reference Data', interactive=False, return_buf=False)[source]

Interactively adjust the lattice parameters and space group for a list of materials. It is possible to add / remove materials from the list.

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

  • y (numpy.ndarray) – MCA intensities.

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

  • preselected_materials (list[MaterialConfig], optional) – 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.

  • return_buf (bool, optional) – Return an in-memory object as a byte stream represention of the Matplotlib figure, defaults to False.

Returns:

Selected materials for the strain analyses and a byte stream represention of the Matplotlib figure if return_buf is True (None otherwise).

Return type:

list[MaterialConfig], io.BytesIO or None

CHAP.edd.utils module

Generic utility functions for EDD workflows.

get_peak_locations(ds, tth)[source]

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

Parameters:
  • ds (list[float]) – Lattice spacings in angstrom.

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

Returns:

Peak locations in keV.

Return type:

numpy.ndarray

get_rolling_sum_spectra(y, bin_axis, start=0, end=None, width=None, stride=None, num=None, mode='valid')[source]

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

Parameters:
  • y (array-like) – Input data.

  • x (array-like, optional) – Independent dimension.

  • start (int, optional) – First array index, defaults to 0.

  • end (int, optional) – Last array index.

  • width (int, optional) – Number of elements in rolling sum or average.

  • stride (int, optional) – Stride in rolling sum or average.

  • num (int, optional) – Number of outputs of rolling sum or average.

  • mode (Literal['valid', 'full'], optional) – Only return results for full sized windows if “valid”, include partial windows if “full”, defaults to “valid”.

Note

Specify only one or two of width, stride, and num.

get_spectra_fits(spectra, energies, peak_locations, detector, **kwargs)[source]

Return twenty arrays of fit results for the map of spectra provided: uniform centers, uniform center errors, uniform amplitudes, uniform amplitude errors, uniform amplitude vary, 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 amplitude vary, unconstrained sigmas, unconstrained sigma errors, unconstrained best fit, unconstrained residuals, unconstrained reduced chi, and unconstrained success codes.

Parameters:
  • spectra (numpy.ndarray) – Intensity spectra to fit.

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

  • peak_locations (list[float]) – Initial guesses for peak centers to use for the uniform fit.

  • detector (MCAElementStrainAnalysisConfig) – MCA detector element configuration.

Returns:

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

Return type:

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, numpy.ndarray, numpy.ndarray

get_unique_hkls_ds(materials, tth_max=None, tth_tol=None, round_sig=8)[source]

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

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

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

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

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

Returns:

Unique HKLs and lattice spacings.

Return type:

numpy.ndarray, numpy.ndarray

select_mask_and_hkls(x, y, hkls, ds, tth, preselected_bin_ranges=None, preselected_hkl_indices=None, num_hkl_min=1, detector_id=None, ref_map=None, flux_energy_range=None, calibration_bin_ranges=None, label='Reference Data', interactive=False, return_buf=False)[source]

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 (numpy.ndarray) – MCA channel energies.

  • y (numpy.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 angstrom.

  • tth (float) – (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.

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

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

  • detector_id (str, optional) – MCA detector channel index.

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

  • flux_energy_range (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.

  • return_buf (bool, optional) – Return an in-memory object as a byte stream represention of the Matplotlib figure, defaults to False.

Returns:

Selected data index ranges to include, the list of HKL indices to include and a byte stream represention of the Matplotlib figure if return_buf is True (None otherwise).

Return type:

list[list[int]], list[int], io.BytesIO or None

select_material_params(x, y, tth, preselected_materials=None, label='Reference Data', interactive=False, return_buf=False)[source]

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 modify, add, or remove materials. 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 (numpy.ndarray) – MCA channel energies.

  • y (numpy.ndarray) – MCA intensities.

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

  • preselected_materials (list[MaterialConfig], optional) – 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.

  • return_buf (bool, optional) – Return an in-memory object as a byte stream represention of the Matplotlib figure, defaults to False.

Returns:

Selected materials for the strain analyses and a byte stream represention of the Matplotlib figure if return_buf is True (None otherwise).

Return type:

list[MaterialConfig], io.BytesIO or None

select_tth_initial_guess(x, y, hkls, ds, tth_initial_guess=5.0, detector_id=None, interactive=False, return_buf=False)[source]

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 (numpy.ndarray) – MCA channel energies.

  • y (numpy.ndarray) – MCA intensities.

  • hkls (numpy.ndarray or list[list[int, int,int]]) – Unique HKL indices to fit peaks for in the calibration routine.

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

  • tth_initial_guess (float, optional) – Initial guess for 2&theta, defaults to 5.0.

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

  • detector_id (str, optional) – Detector ID.

  • return_buf (bool, optional) – Return an in-memory object as a byte stream represention of the Matplotlib figure, defaults to False.

Returns:

Selected initial guess for 2&theta and a byte stream represention of the Matplotlib figure if return_buf is True (None otherwise).

Return type:

float, io.BytesIO or None

CHAP.edd.writer module

Module for Writers unique to the EDD workflow.

class StrainAnalysisUpdateWriter(*, root: Annotated[Path, PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: Annotated[Path, PathType(path_type=dir)] | None = None, outputdir: Annotated[Path, PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO')[source]

Bases: Writer

Writer to add or update the strain analysis for a set of map points.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

write(data)[source]

Write or update strain analysis results for a set of points.

Parameters:

data (list[PipelineData]) – Input data.