CHAP.edd package
Submodules
CHAP.edd.models module
EDD Pydantic model classes.
- class BaselineConfig(*, attrs: dict | None = {}, lam: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] = 1000000.0, max_iter: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] = 100, tol: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] = 1e-06)
Bases:
CHAPBaseModelBaseline model configuration class.
- Variables:
lam – The &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 – The maximum number of iterations, defaults to 100.
tol – The 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] = {}
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)]], 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)
Bases:
FitConfigClass representing metadata required to perform a diffraction volume length calculation for an EDD setup using a steel-foil raster scan.
- Variables:
max_energy_kev – Maximum channel energy of the MCA in keV, defaults to 200.0.
measurement_mode – Placeholder for recording whether the measured DVL value was obtained through the automated calculation or a manual selection, defaults to ‘auto’.
sample_thickness – Thickness of scanned foil sample. Quantity must be provided in the same units as the values of the scanning motor.
sigma_to_dvl_factor – 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] = {}
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 initialise 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()
Update the configuration with costum defaults after the normal native pydantic validation.
- Returns:
Updated energy calibration configuration class.
- Return type:
- 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)]], 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)
Bases:
CHAPBaseModelFit parameters configuration class for peak fitting.
- Variables:
background – Background model for peak fitting, defaults to constant.
baseline – Automated baseline subtraction configuration, defaults to False.
centers_range – 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 of 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 – 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 – 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 of 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 – 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)]], Len(min_length=0, max_length=None)] | 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] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod validate_background(background)
Validate the background model.
- Variables:
background – Background model for peak fitting.
- Returns:
List of validated background models.
- Return type:
list[str]
- classmethod validate_baseline(baseline)
Validate the baseline configuration.
- Variables:
baseline – Automated baseline subtraction configuration.
- Returns:
Validated baseline subtraction configuration.
- Return type:
bool, BaselineConfig
- classmethod validate_energy_mask_ranges(energy_mask_ranges)
Validate the mask ranges for selecting the data to include.
- Variables:
energy_mask_ranges – List of 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)
Validate the mask ranges for selecting the data to include.
- Variables:
mask_ranges – List of 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)], 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), FieldInfo(annotation=NoneType, required=True, validate_default=True)] | None = None)
Bases:
CHAPBaseModelBase class representing metadata required to perform an energy or 2&theta calibration of an MCA detector.
- Variables:
flux_file – File name of the csv flux file containing station beam energy in eV (column 0) versus flux (column 1).
materials – Material configurations for the calibration, defaults to [Ceria].
peak_energies – Theoretical locations of the fluorescence peaks in keV to use for calibrating the MCA channel energies.
scan_step_indices – 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.
- Note: Fluorescence data:
https://physics.nist.gov/PhysRefData/XrayTrans/Html/search.html
- flux_correction_interpolation_function()
Get an interpolation function to correct MCA data for the relative energy flux of the incident beam.
- Returns:
Energy flux correction interpolation function.
- Return type:
scipy.interpolate._polyint._Interpolator1D
- flux_file: Annotated[Path, PathType(path_type=file)] | None
- flux_file_energy_range()
Get the energy range in the flux correction file.
- Returns:
The energy range in the flux correction file.
- Return type:
tuple(float, float)
- materials: Annotated[list[MaterialConfig], Len(min_length=0, max_length=None)] | None
- model_config: ClassVar[ConfigDict] = {}
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), FieldInfo(annotation=NoneType, required=True, validate_default=True)] | None
- classmethod validate_mcacalibrationconfig_before(data)
Ensure that a valid configuration was provided and finalize flux_file filepath.
- Parameters:
data (MCACalibrationConfig, pydantic_core._pydantic_core.ValidationInfo) – Pydantic validator data object.
- Returns:
The currently validated list of class properties.
- Return type:
dict
- classmethod validate_scan_step_indices(scan_step_indices)
Validate the specified list of scan numbers.
- Variables:
scan_step_indices – 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:
List of 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)]], 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, id: Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], attrs: Annotated[dict, FieldInfo(annotation=NoneType, required=True, validate_default=True)] | None = {}, processor_type: Literal['calibration'], 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 = None, num_bins: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None = None, tth_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, tth_tol: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, tth_calibrated: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, tth_initial_guess: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None)
-
Class representing metadata required to configure a single MCA detector element to perform detector calibration.
- Variables:
energy_calibration_coeffs – Detector channel index to energy polynomial conversion coefficients ([a, b, c] with E_i = a*i^2 + b*i + c).
num_bins – Number of MCA channels.
tth_max – Detector rotation about lab frame x axis.
tth_tol – Minimum resolvable difference in 2&theta between two unique Bragg peaks,
tth_calibrated – Calibrated value for 2&theta.
tth_initial_guess – Initial guess for 2&theta superseding the global one in MCATthCalibrationConfig.
- convert_mask_ranges(mask_ranges)
Given a list of mask ranges in channel bins, set the corresponding list of channel energy mask ranges.
- Parameters:
mask_ranges (list[[int,int]]) – A list of mask ranges to convert to energy mask ranges.
- property energies
Return calibrated bin energies.
- 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()
Return the value of mask_ranges if set or convert the energy_mask_ranges from channel energies to channel indices.
- property hkl_indices
Return the hkl_indices consistent with the selected energy ranges (include_energy_ranges).
- mca_mask()
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] = {}
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 initialise 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()
- 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)]], 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, processor_type: Literal['calibration', 'diffractionvolumelength', 'strainanalysis'], detectors: Annotated[list[Annotated[MCADetectorCalibration | MCADetectorDiffractionVolumeLength | MCADetectorStrainAnalysis, FieldInfo(annotation=NoneType, required=True, discriminator='processor_type')]], Len(min_length=1, max_length=None)] | None = [])
Bases:
FitConfigClass representing metadata required to configure a full MCA detector.
- Variables:
detectors – List of 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] = {}
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 initialise 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()
Update individual detector parameters with any non-default values from the global detector configuration.
- validate_mcadetectorconfig_after()
- classmethod validate_mcadetectorconfig_before(data)
- 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)]], 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, id: Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], attrs: Annotated[dict, FieldInfo(annotation=NoneType, required=True, validate_default=True)] | None = {}, processor_type: Literal['diffractionvolumelength'], 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 = None, num_bins: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None = None, tth_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, tth_tol: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, tth_calibrated: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, tth_initial_guess: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, dvl: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, fit_amplitude: float | None = None, fit_center: float | None = None, fit_sigma: float | None = None)
Bases:
MCADetectorCalibrationClass representing metadata required to perform a diffraction volume length measurement for a single MCA detector element.
- Variables:
dvl – Measured diffraction volume length.
fit_amplitude – Amplitude of the Gaussian fit.
fit_center – Center of the Gaussian fit.
fit_sigma – 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] = {}
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 initialise 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)]], 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 = 2, 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 = 0.25, fwhm_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 2.0, 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, id: Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], attrs: Annotated[dict, FieldInfo(annotation=NoneType, required=True, validate_default=True)] | None = {}, processor_type: Literal['strainanalysis'], 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 = None, num_bins: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None = None, tth_max: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, tth_tol: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, tth_calibrated: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, tth_initial_guess: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None, peak_models: Annotated[list[Literal['gaussian', 'lorentzian']], Len(min_length=1, max_length=None)] | Literal['gaussian', 'lorentzian'] = 'gaussian', rel_height_cutoff: Annotated[float, None, Interval(gt=0, ge=None, lt=1.0, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None)
Bases:
MCADetectorCalibrationClass representing metadata required to perform a strain analysis.
- Variables:
centers_range – 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 – Minimum FWHM for peak fitting (in keV), defaults to 0.25.
fwhm_max – Maximum FWHM for peak fitting (in keV), defaults to 2.0.
peak_models – Peak model for peak fitting, defaults to ‘gaussian’.
rel_height_cutoff – 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_file – Path to the file with the 2&theta map.
tth_map – Map of the 2&theta values.
- add_calibration(calibration)
Finalize values for some fields using a tth calibration MCADetectorStrainAnalysis corresponding to the same detector.
- Parameters:
calibration (MCADetectorStrainAnalysis) – Existing calibration configuration to use by MCAElementStrainAnalysisConfig.
- 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()
Return the _calibration_energy_mask_ranges converted from channel energies to channel indices.
- get_tth_map(map_shape)
Return the map of 2&theta values to use – may vary at each point in the map.
- Parameters:
map_shape – The shape of the suplied 2&theta map.
- Returns:
Map of 2&theta values.
- Return type:
numpy.ndarray
- model_config: ClassVar[ConfigDict] = {}
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 initialise 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']], Len(min_length=1, max_length=None)] | Literal['gaussian', 'lorentzian']
- 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
- 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)], 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), FieldInfo(annotation=NoneType, required=True, validate_default=True)] | 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, max_peak_index: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None, FieldInfo(annotation=NoneType, required=True, validate_default=True)] | None = None)
Bases:
MCACalibrationConfigBase class representing metadata required to perform an energy calibration of an MCA detector.
- Variables:
max_energy_kev – Maximum channel energy of the MCA in keV, defaults to 200.0.
max_peak_index – 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, FieldInfo(annotation=NoneType, required=True, validate_default=True)] | None
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod validate_max_peak_index(max_peak_index, info)
- validate_mcaenergycalibrationconfig_after()
Validate the detector (energy) mask ranges and update any detector configuration parameters not superseded by their individual values.
- Returns:
Updated energy calibration configuration class.
- Return type:
- classmethod validate_mcaenergycalibrationconfig_before(data)
- 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)], 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), FieldInfo(annotation=NoneType, required=True, validate_default=True)] | None = None, calibration_method: Literal['direct_fit_bragg', 'direct_fit_tth_ecc'] | None = 'direct_fit_bragg', quadratic_energy_calibration: bool | None = False, tth_initial_guess: Annotated[float, None, Interval(gt=0, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None)
Bases:
MCACalibrationConfigClass representing metadata required to perform a 2&theta calibration of an MCA detector.
- Variables:
calibration_method – Type of calibration method, defaults to ‘direct_fit_bragg’.
detectors – List of individual MCA detector element calibration configurations.
quadratic_energy_calibration – Adds a quadratic term to the detector channel index to energy conversion, defaults to False (linear only).
tth_initial_guess – Initial guess for 2&theta.
- calibration_method: Literal['direct_fit_bragg', 'direct_fit_tth_ecc'] | None
- flux_file_energy_range()
Get the energy range in the flux corection file.
- Returns:
The energy range in the flux corection file.
- Return type:
tuple(float, float)
- model_config: ClassVar[ConfigDict] = {}
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)] | 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)
Bases:
CHAPBaseModelSample material parameters configuration class.
- Variables:
material_name – Sample material name.
lattice_parameters – Lattice spacing(s) in angstroms.
sgnum – Space group of the material.
- 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)] | None
- model_config: ClassVar[ConfigDict] = {}
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 initialise 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()
Create and validate the private attribute _material.
- Returns:
The validated list of class properties.
- Return type:
- 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)], 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), FieldInfo(annotation=NoneType, required=True, validate_default=True)] | None = None, find_peaks: bool | None = True, num_proc: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None = 1, oversampling: Annotated[Dict, FieldInfo(annotation=NoneType, required=True, validate_default=True)] | None = {'num': 10}, 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)
Bases:
MCACalibrationConfigClass representing input parameters required to perform a strain analysis.
- Variables:
find_peaks – Exclude peaks where the average spectrum is below the rel_height_cutoff cutoff relative to the maximum value of the average spectrum, defaults to True.
oversampling – FIX
rel_height_cutoff – 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 CHAP.edd.models.MCADetectorStrainAnalysis). Defaults to `None.
skip_animation – Skip the animation and plotting of the strain analysis fits, defaults to False.
sum_axes – Whether to sum over the fly axis or not for EDD scan types not 0, defaults to True.
- find_peaks: bool | None
- model_config: ClassVar[ConfigDict] = {}
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
- oversampling: Annotated[Dict, FieldInfo(annotation=NoneType, required=True, validate_default=True)] | 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
- classmethod validate_oversampling(oversampling, info)
Validate the oversampling field.
- Parameters:
oversampling (dict) – The value of oversampling to validate.
info (StrainAnalysisConfig, pydantic_core._pydantic_core.ValidationInfo) – Pydantic validator info object.
- Returns:
The validated value for oversampling.
- Return type:
bool
CHAP.edd.processor module
File : processor.py Author : Keara Soloway, Rolf Verberg Description: Module for Processors used only by EDD experiments
- class BaseEddProcessor(*, 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', logger: Logger | None = None, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None)
Bases:
ProcessorBase processor for the EDD processors.
- 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 initialise 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.
- class BaseStrainProcessor(*, 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', logger: Logger | None = None, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None)
Bases:
BaseEddProcessorBase processor for LatticeParameterRefinementProcessor and StrainAnalysisProcessor.
- 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 initialise 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.
- class DiffractionVolumeLengthProcessor(*, root: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = None, outputdir: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: ~typing.Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO', logger: ~logging.Logger | None = None, name: ~typing.Annotated[str, ~pydantic.types.StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: ~typing.Annotated[str, ~pydantic.types.StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, pipeline_fields: dict = {'config': 'edd.models.DiffractionVolumeLengthConfig', 'detector_config': {'merge_key_paths': {'key_path': 'detectors/id', 'type': <class 'int'>}, 'schema': ['edd.models.DiffractionVolumeLengthConfig', 'edd.models.MCADetectorConfig']}}, config: ~CHAP.edd.models.DiffractionVolumeLengthConfig | None = DiffractionVolumeLengthConfig(background=['constant'], baseline=None, centers_range=20, energy_mask_ranges=None, fwhm_min=3, fwhm_max=25, mask_ranges=None, backgroundpeaks=None, max_energy_kev=200.0, measurement_mode='auto', sample_thickness=None, sigma_to_dvl_factor=3.5), detector_config: ~CHAP.edd.models.MCADetectorConfig, save_figures: bool | None = False)
Bases:
BaseEddProcessorA Processor using a steel foil raster scan to calculate the diffraction volume length for an EDD setup.
- Variables:
config – Initialization parameters for an instance of CHAP.edd.models.DiffractionVolumeLengthConfig.
detector_config – Initialization parameters for an instance of CHAP.edd.models.MCADetectorConfig. Defaults to the detector configuration of the raw detector data.
save_figures – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.
- 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 initialise 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)
Return the calculated value of the DVL.
- Parameters:
data (list[PipelineData]) – DVL calculation input configuration.
- Raises:
RuntimeError – Unable to get a valid DVL configuration.
- Returns:
DVL configuration.
- Return type:
dict, PipelineData
- save_figures: bool | None
- validate_diffractionvolumeLengthprocessor_after()
- classmethod validate_diffractionvolumeLengthprocessor_before(data)
- class LatticeParameterRefinementProcessor(*, root: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = None, outputdir: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: ~typing.Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO', logger: ~logging.Logger | None = None, name: ~typing.Annotated[str, ~pydantic.types.StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: ~typing.Annotated[str, ~pydantic.types.StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, pipeline_fields: dict = {'config': 'edd.models.StrainAnalysisConfig', 'detector_config': {'merge_key_paths': {'key_path': 'detectors/id', 'type': <class 'int'>}, 'schema': 'edd.models.MCADetectorConfig'}}, config: ~CHAP.edd.models.StrainAnalysisConfig | None = StrainAnalysisConfig(flux_file=None, materials=[MaterialConfig(material_name='CeO2', lattice_parameters=[5.41153, 5.41153, 5.41153, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966], sgnum=225)], peak_energies=[34.279, 34.72, 39.258, 40.233], scan_step_indices=None, find_peaks=True, num_proc=1, oversampling={'num': 10}, rel_height_cutoff=None, skip_animation=False, sum_axes=True), detector_config: ~CHAP.edd.models.MCADetectorConfig, save_figures: bool | None = False)
Bases:
BaseStrainProcessorProcessor to get a refined estimate for a sample’s lattice parameters.
- Variables:
config – Initialization parameters for an instance of CHAP.edd.models.StrainAnalysisConfig.
detector_config – Initialization parameters for an instance of CHAP.edd.models.MCADetectorConfig. Defaults to the detector configuration of the raw detector data merged with that of the 2&theta calibration step..
save_figures – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.
- 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 initialise 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)
Given a strain analysis configuration, return a copy contining refined values for the materials’ lattice parameters.
- Parameters:
data (list[PipelineData]) – Input data for the lattice parameter refinement procedure.
- Raises:
RuntimeError – Unable to refine the lattice parameters.
- Returns:
The strain analysis configuration with the refined lattice parameter configuration and, optionally, a list of byte stream representions of Matplotlib figures.
- Return type:
dict, PipelineData
- save_figures: bool | None
- classmethod validate_latticeparameterrefinementprocessor_before(data)
- class MCAEnergyCalibrationProcessor(*, root: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = None, outputdir: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: ~typing.Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO', logger: ~logging.Logger | None = None, name: ~typing.Annotated[str, ~pydantic.types.StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: ~typing.Annotated[str, ~pydantic.types.StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, pipeline_fields: dict = {'config': 'edd.models.MCAEnergyCalibrationConfig', 'detector_config': {'merge_key_paths': {'key_path': 'detectors/id', 'type': <class 'int'>}, 'schema': ['edd.models.MCAEnergyCalibrationConfig', 'edd.models.MCADetectorConfig']}}, config: ~CHAP.edd.models.MCAEnergyCalibrationConfig | None = MCAEnergyCalibrationConfig(flux_file=None, materials=[MaterialConfig(material_name='CeO2', lattice_parameters=[5.41153, 5.41153, 5.41153, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966], sgnum=225)], peak_energies=[34.279, 34.72, 39.258, 40.233], scan_step_indices=None, max_energy_kev=200.0, max_peak_index=None), detector_config: ~CHAP.edd.models.MCADetectorConfig, save_figures: bool | None = False)
Bases:
BaseEddProcessorProcessor 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 – Initialization parameters for an instance of CHAP.edd.models.MCAEnergyCalibrationConfig.
detector_config – Initialization parameters for an instance of CHAP.edd.models.MCADetectorConfig. Defaults to the detector configuration of the raw detector data.
save_figures – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.
- config: MCAEnergyCalibrationConfig | 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 initialise 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)
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 (list[PipelineData]) – Energy calibration configuration.
- 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
- save_figures: bool | None
- classmethod validate_mcaenergycalibrationprocessor_before(data)
- class MCATthCalibrationProcessor(*, root: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = None, outputdir: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: ~typing.Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO', logger: ~logging.Logger | None = None, name: ~typing.Annotated[str, ~pydantic.types.StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: ~typing.Annotated[str, ~pydantic.types.StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, pipeline_fields: dict = {'config': ['edd.models.MCAEnergyCalibrationConfig', 'edd.models.MCATthCalibrationConfig'], 'detector_config': {'merge_key_paths': {'key_path': 'detectors/id', 'type': <class 'int'>}, 'schema': ['edd.models.MCAEnergyCalibrationConfig', 'edd.models.MCATthCalibrationConfig', 'edd.models.MCADetectorConfig']}}, config: ~CHAP.edd.models.MCATthCalibrationConfig | None = MCATthCalibrationConfig(flux_file=None, materials=[MaterialConfig(material_name='CeO2', lattice_parameters=[5.41153, 5.41153, 5.41153, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966], sgnum=225)], peak_energies=[34.279, 34.72, 39.258, 40.233], scan_step_indices=None, calibration_method='direct_fit_bragg', quadratic_energy_calibration=False, tth_initial_guess=None), detector_config: ~CHAP.edd.models.MCADetectorConfig, save_figures: bool | None = False)
Bases:
BaseEddProcessorProcessor to calibrate the 2&theta angle and fine tune the energy calibration coefficients for an EDD experimental setup.
- Variables:
config – Initialization parameters for an instance of CHAP.edd.models.MCATthCalibrationConfig.
detector_config – Initialization parameters for an instance of CHAP.edd.models.MCADetectorConfig. Defaults to the detector configuration of the raw detector data merged with that of the energy calibration step..
save_figures – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.
- config: MCATthCalibrationConfig | 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 initialise 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)
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]) – 2&theta calibration configuration.
- 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
- save_figures: bool | None
- classmethod validate_mcatthcalibrationprocessor_before(data)
- class StrainAnalysisProcessor(*, root: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = '/home/runner/work/ChessAnalysisPipeline/ChessAnalysisPipeline/docs', inputdir: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = None, outputdir: ~pathlib.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] | None = None, interactive: bool | None = False, log_level: ~typing.Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = 'INFO', logger: ~logging.Logger | None = None, name: ~typing.Annotated[str, ~pydantic.types.StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: ~typing.Annotated[str, ~pydantic.types.StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, pipeline_fields: dict = {'config': 'edd.models.StrainAnalysisConfig', 'detector_config': {'merge_key_paths': {'key_path': 'detectors/id', 'type': <class 'int'>}, 'schema': 'edd.models.MCADetectorConfig'}}, config: ~CHAP.edd.models.StrainAnalysisConfig | None = StrainAnalysisConfig(flux_file=None, materials=[MaterialConfig(material_name='CeO2', lattice_parameters=[5.41153, 5.41153, 5.41153, 1.5707963267948966, 1.5707963267948966, 1.5707963267948966], sgnum=225)], peak_energies=[34.279, 34.72, 39.258, 40.233], scan_step_indices=None, find_peaks=True, num_proc=1, oversampling={'num': 10}, rel_height_cutoff=None, skip_animation=False, sum_axes=True), detector_config: ~CHAP.edd.models.MCADetectorConfig, save_figures: bool | None = False, setup: bool | None = True, update: bool | None = True)
Bases:
BaseStrainProcessorProcessor that takes a map of MCA data and returns a map of sample strains.
- Variables:
config – Initialization parameters for an instance of CHAP.edd.models.StrainAnalysisConfig.
detector_config – Initialization parameters for an instance of CHAP.edd.models.MCADetectorConfig. Defaults to the detector configuration of the raw detector data merged with that of the 2&theta calibration step..
save_figures – Save .pngs of plots for checking inputs & outputs of this Processor, defaults to False.
setup – Setup the strain analysis nexusformat.nexus.NXroot object, defaults to True.
update – 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)
Add or update the strain analysis for a set of map points in a nexusformat.nexus.NXroot object.
- Parameters:
nxroot (nexusformat.nexus.NXroot) – The strain analysis object to add/update the points to.
points (list[dict[str, object]) – The 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 initialise 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)
Setup the strain analysis and/or return the strain analysis results as a list of updated points or a nexusformat.nexus.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:
The strain analysis setup or results, a list of byte stream representions of Matplotlib figures and an animation of the fit results.
- Return type:
Union[list[dict[str, object]], nexusformat.nexus.NXroot], PipelineData, PipelineData
- save_figures: bool | None
- setup: bool | None
- update: bool | None
- classmethod validate_strainanalysisprocessor_before(data)
- get_axes(nxdata, skip_axes=None)
Get the axes of an NXdata object used in EDD.
CHAP.edd.reader module
EDD specific readers.
- 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', logger: Logger | None = None, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, filename: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], dataset_id: Annotated[int, None, Interval(gt=None, ge=1, lt=None, le=None), None] | None = 1, detector_ids: Annotated[list[Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None]], Len(min_length=1, max_length=None)])
Bases:
ReaderReader for taking an EDD-style .par file and returning a representing one of the datasets in the file as a NeXus NXentry object. Independent dimensions are determined automatically, and a specific set of items to use for extra scalar datasets to include are hard-coded in.
- Variables:
dataset_id – Dataset ID value in the .par file to return as a map, defaults to 1.
detector_ids – 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 initialise 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()
Return a NeXus NXentry object after validating the MapConfig object representing an EDD dataset.
- Returns:
The EDD map including the raw data packaged.
- Return type:
- classmethod validate_detector_ids(detector_ids)
Validate the specified list of detector IDs.
- Parameters:
detector_ids (Union(int, list[int], 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', logger: Logger | None = None, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, filename: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], 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 = None, dataset_id: Annotated[int, None, Interval(gt=None, ge=1, lt=None, le=None), None] | None = 1)
Bases:
ReaderReader for taking an EDD-style .par file and returning a MapConfig 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_names are specified.
- Variables:
scan_numbers – List of scan numbers to use.
dataset_id – 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 initialise 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()
Return a validated MapConfig object representing an EDD dataset.
- Returns:
Map configuration.
- Return type:
- 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)
Validate the specified list of scan numbers.
- Parameters:
scan_numbers (Union(int, list[int], str)) – List of scan numbers.
- Raises:
ValueError – If a specified scan number is not found in the SPEC file.
- Returns:
List of 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', logger: Logger | None = None, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, filename: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], nxpath: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], 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)])
Bases:
ReaderReader for returning a sliced verison of an NXdata (which represents a full EDD dataset) that contains data from just a single SPEC scan.
- Variables:
nxpath – Path to the existing full EDD dataset’s NXdata group in filename.
scan_number – Number of the SPEC scan.
- Ivat spec_file:
Name of the spec file containing 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 initialise 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)]
- read()
Return a “slice” of an EDD dataset’s NXdata that represents just the data from one scan in the dataset.
- Returns:
An NXdata 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)]
- 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', logger: Logger | None = None, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, filename: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], scan_number: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None])
Bases:
ReaderReader for turning a single SPEC scan into a MapConfig.
- Parameters:
scan_number (int) – Number of the SPEC scan.
- 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 initialise 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()
Return a dictionary representing a valid map configuration consisting of the single SPEC scan specified.
- Returns:
Map configuration dictionary.
- 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', logger: Logger | None = None, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, filename: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], dataset_id: Annotated[int, None, Interval(gt=None, ge=1, lt=None, le=None), None], detectors: DetectorConfig)
Bases:
ReaderReader for converting the SPEC input .txt file for EDD dataset collection to an approporiate input argument for CHAP.common.SetupNXdataProcessor.
- Variables:
dataset_id – Dataset ID value in the .txt file to return CHAP.common.SetupNXdataProcessor.process arguments for.
detectors – 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 initialise 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()
Return a dictionary containing the coords, signals, and attrs arguments appropriate for use with CHAP.common.SetupNXdataProcessor.process to set up an initial NXdata object representing a complete and organized structured EDD dataset.
- Returns:
The dataset’s coordinate names, values, attributes, and signal names, shapes, and attributes.
- Return type:
dict
- classmethod validate_detectors(detectors)
Validate the specified list of detectors.
- Parameters:
detectors (list[CHAP.common.models.map.Detector]) – Detectors list.
- Returns:
Detectors list.
- Return type:
- 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', logger: Logger | None = None, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, filename: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], scan_number: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None])
Bases:
ReaderA reader class to load and slice an NXdata field from a NeXus file. This class reads EDD (Energy Dispersive Diffraction) data from an NXdata group and slices all fields according to the provided slicing parameters.
- Parameters:
scan_number (int) – Number of the SPEC scan.
- 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 initialise 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()
Reads an NXdata group from a NeXus file and slices the fields within it based on the provided scan number.
- Raises:
ValueError – If no NXdata group is found in the file.
- Returns:
The root object of the NeXus file with sliced NXdata fields.
- Return type:
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', logger: Logger | None = None, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, filename: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=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)] | None = None, scan_number: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None])
Bases:
ReaderCompanion to edd.SetupNXdataReader and common.UpdateNXDataProcessor. Constructs a list of data points to pass as pipeline data to common.UpdateNXDataProcessor so that an NXdata constructed by edd.SetupNXdataReader and common.SetupNXdataProcessor can be updated live as individual scans in an EDD dataset are completed.
- Variables:
detector_ids – Detector IDs for the raw data.
- Parameters:
scan_number (int) – Number of the SPEC scan.
- 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 initialise 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()
Return a list of data points containing raw data values for a single EDD spec scan. The returned values can be passed along to common.UpdateNXdataProcessor to fill in an existing NXdata set up with common.SetupNXdataProcessor.
- Returs:
List of data points appropriate for input to common.UpdateNXdataProcessor.
- Return type:
list[dict[str, object]]
- scan_number: Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]
CHAP.edd.select_material_params_gui module
- class MaterialParamSelector(root, x, y, tth, preselected_materials, label, on_complete)
Bases:
object- add_material(new_material=None)
- clear_fields()
- on_close()
Handle closing the GUI and triggering the on_complete callback.
- on_material_select(event)
- plot_reference_data()
- remove_material()
- update_material()
- update_plot()
- run_material_selector(x, y, tth, preselected_materials=None, label='Reference Data', on_complete=None, interactive=False)
Run the MaterialParamSelector tkinter application.
- Parameters:
x (np.ndarray) – MCA channel energies.
y (np.ndarray) – MCA intensities.
tth (float) – The (calibrated) 2θ angle.
preselected_materials (list[hexrd.material.Material], 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:
The selected materials for the strain analyses.
- Return type:
- select_material_params(x, y, tth, preselected_materials=None, label='Reference Data', interactive=False, return_buf=False)
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 (np.ndarray) – MCA channel energies.
y (np.ndarray) – MCA intensities.
tth (float) – The (calibrated) 2&theta angle.
preselected_materials (list[hexrd.material.Material], 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 :param return_buf: Return an in-memory object as a byte stream represention of the Matplotlib figure, defaults to False.) – Show the plot and allow user interactions with the matplotlib figure, defaults to False.
- Returns:
The 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[CHAP.edd.models.MaterialConfig], Union[io.BytesIO, None]
CHAP.edd.utils module
Utility functions for EDD workflows.
- get_peak_locations(ds, tth)
Return the peak locations for a given set of lattice spacings and 2&theta value.
- Parameters:
ds (list[float]) – A set of lattice spacings in angstroms.
tth (float) – Diffraction angle 2&theta in degrees.
- Returns:
The 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')
Return the rolling sum of the spectra over a specified axis.
- get_spectra_fits(spectra, energies, peak_locations, detector, **kwargs)
Return twenty arrays of fit results for the map of spectra provided: uniform centers, uniform center errors, uniform amplitudes, uniform amplitude errors, uniform sigmas, uniform sigma errors, uniform best fit, uniform residuals, uniform reduced chi, uniform success codes, unconstrained centers, unconstrained center errors, unconstrained amplitudes, unconstrained amplitude errors, unconstrained sigmas, unconstrained sigma errors, unconstrained best fit, unconstrained residuals, unconstrained reduced chi, and unconstrained success codes.
- Parameters:
spectra (numpy.ndarray) – Array of intensity spectra to fit.
energies (numpy.ndarray) – Bin energies for the spectra provided.
peak_locations (list[float]) – Initial guesses for peak ceneters to use for the uniform fit.
detector (CHAP.edd.models.MCAElementStrainAnalysisConfig) – A single MCA detector element configuration.
- Returns:
Uniform and unconstrained centers, amplitdues, sigmas (and errors for all three), best fits, residuals between the best fits and the input spectra, reduced chi, and fit success statuses.
- Return type:
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]
- get_unique_hkls_ds(materials, tth_max=None, tth_tol=None, round_sig=8)
Return the unique HKLs and lattice spacings for the given list of materials.
- Parameters:
materials (list[hexrd.material.Material]) – Materials to get HKLs and lattice spacings for.
tth_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) – The number of significant figures in the unique lattice spacings, defaults to 8.
- Returns:
Unique HKLs, unique lattice spacings.
- Return type:
tuple[np.ndarray, np.ndarray]
- make_material(name, sgnum, lattice_parameters, dmin=0.6)
Return a hexrd.material.Material with the given properties.
- Parameters:
name (str) – Material name.
sgnum (int) – Space group of the material.
lattice_parameters (list[float]) – The material’s lattice parameters ([a, b, c, α, β, γ], or fewer as the symmetry of the space group allows — for instance, a cubic lattice with space group number 225 can just provide [a, ]).
dmin (float, optional) – Materials’s dmin value in angstroms (Å), defaults to 0.6.
- Returns:
A hexrd material.
- Return type:
heard.material.Material
- 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)
Return a matplotlib figure to indicate data ranges and HKLs to include for fitting in EDD energy/tth calibration and/or strain analysis.
- Parameters:
x (np.ndarray) – MCA channel energies.
y (np.ndarray) – MCA intensities.
hkls (list[list[int]]) – Avaliable Unique HKL values to fit peaks for in the calibration routine.
ds (list[float]) – Lattice spacings associated with the unique HKL indices in angstroms.
tth (float) – The (calibrated) 2&theta angle.
preselected_bin_ranges (list[list[int]], optional) – Preselected MCA channel index ranges whose data should be included after applying a mask.
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 (np.ndarray, optional) – Reference map of MCA intensities to show underneath the interactive plot.
flux_energy_range (tuple(float, float), optional) – Energy range in eV in the flux file containing station beam energy in eV versus flux
calibration_bin_ranges (list[[int, int]], optional) – MCA channel index ranges included in the detector calibration.
label (str, optional) – Legend label for the 1D plot of reference MCA data from the parameters x, y, defaults to “Reference Data”
interactive (bool, optional) – Show the plot and allow user interactions with the matplotlib figure, defaults to True.
return_buf (bool, optional) – Return an in-memory object as a byte stream represention of the Matplotlib figure, defaults to False.
- Returns:
The list of 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], Union[io.BytesIO, None]
- select_material_params(x, y, tth, preselected_materials=None, label='Reference Data', interactive=False, return_buf=False)
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 (np.ndarray) – MCA channel energies.
y (np.ndarray) – MCA intensities.
tth (float) – The (calibrated) 2&theta angle.
preselected_materials (list[hexrd.material.Material], 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:
The 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[CHAP.edd.models.MaterialConfig], Union[io.BytesIO, None]
- select_material_params_gui(x, y, tth, preselected_materials=None, label='Reference Data', interactive=False, return_buf=False)
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 (np.ndarray) – MCA channel energies.
y (np.ndarray) – MCA intensities.
tth (float) – The (calibrated) 2&theta angle.
preselected_materials (list[hexrd.material.Material], 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:
The 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[CHAP.edd.models.MaterialConfig], Union[io.BytesIO, None]
- select_tth_initial_guess(x, y, hkls, ds, tth_initial_guess=5.0, detector_id=None, interactive=False, return_buf=False)
Show a matplotlib figure of a reference MCA spectrum on top of HKL locations. The figure includes an input field to adjust the initial 2&theta guess and responds by updating the HKL locations based on the adjusted value of the initial 2&theta guess.
- Parameters:
x (np.ndarray) – MCA channel energies.
y (np.ndarray) – MCA intensities.
hkls (Union(numpy.ndarray, list[list[int, int,int]])) – List of unique HKL indices to fit peaks for in the calibration routine.
ds (Union(numpy.ndarray, list[float])) – Lattice spacings in angstroms associated with the unique HKL indices.
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:
The 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, Union[io.BytesIO, None]
CHAP.edd.writer module
EDD specific writers.
- 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', logger: Logger | None = None, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, schema: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, filename: str, force_overwrite: bool | None = False, remove: bool | None = False)
Bases:
Writer- 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 initialise 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)
Write the last CHAP.pipeline.PipelineData item in data as text to a file.
- Parameters:
data (list[CHAP.pipeline.PipelineData]) – Input data.
- Returns:
Contents of the input data.
- Return type:
list[PipelineData]
Module contents
This subpackage contains PipelineItems unique to EDD data processing workflows.