CHAP.edd.models
¶
Module Contents¶
Classes¶
Baseline model configuration |
|
Model for parameters to characterize a sample material. |
|
Class representing metadata required to configure a single MCA detector element. |
|
Class representing metadata required to calibrate a single MCA detector element. |
|
Class representing metadata required to perform a diffraction volume length measurement for a single MCA detector element. |
|
Class representing metadata required to perform a strain analysis fitting for a single MCA detector element. |
|
Class representing metadata required to locate raw MCA data for a single scan and construct a mask for it. |
|
Class representing metadata required to perform a diffraction volume length calculation for an EDD setup using a steel-foil raster scan. |
|
Class representing metadata required to perform an energy calibration for an MCA detector. |
|
Class representing metadata required to perform a tth calibration for an MCA detector. |
|
Class representing input parameters required to perform a strain analysis. |
API¶
- class CHAP.edd.models.BaselineConfig¶
Bases:
pydantic.BaseModel
Baseline model configuration
- Variables:
tol – The convergence tolerence, defaults to
1.e-6
.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: confloat(gt=0, allow_inf_nan=False)¶
1e-06
- lam: confloat(gt=0, allow_inf_nan=False)¶
1000000.0
- max_iter: conint(gt=0)¶
100
- attrs: Optional[dict]¶
None
- class CHAP.edd.models.MaterialConfig¶
Bases:
pydantic.BaseModel
Model for parameters to characterize a sample material.
- Variables:
material_name – Sample material name.
lattice_parameters – Lattice spacing(s) in angstroms.
sgnum – Space group of the material.
- material_name: Optional[constr(strip_whitespace=True, min_length=1)]¶
None
- lattice_parameters: Optional[Union[confloat(gt=0), conlist(min_length=1, max_length=6, item_type=confloat(gt=0))]]¶
None
- sgnum: Optional[conint(ge=0)]¶
None
- _material: Optional[hexrd.material.Material]¶
None
- validate_material()¶
Create and validate the private attribute _material.
- Returns:
The validated list of class properties.
- Return type:
dict
- unique_hkls_ds(tth_tol=0.15, tth_max=90.0)¶
Get a list of unique HKLs and their lattice spacings.
- Parameters:
tth_tol (float, optional) – Minimum resolvable difference in 2&theta between two unique HKL peaks, defaults to
0.15
.tth_max (float, optional) – Detector rotation about hutch x axis, defaults to
90.0
.
- Returns:
Unique HKLs and their lattice spacings in angstroms.
- Return type:
numpy.ndarray, numpy.ndarray
- dict(*args, **kwargs)¶
Return a representation of this configuration in a dictionary that is suitable for dumping to a YAML file.
- Returns:
Dictionary representation of the configuration.
- Return type:
dict
- class CHAP.edd.models.MCAElementConfig¶
Bases:
pydantic.BaseModel
Class representing metadata required to configure a single MCA detector element.
- Variables:
detector_name – Name of the MCA detector element in the scan, defaults to
'mca1'
.num_bins – Number of MCA channels.
- detector_name: constr(strip_whitespace=True, min_length=1)¶
‘mca1’
- num_bins: Optional[conint(gt=0)]¶
None
- classmethod validate_detector_name(detector_name)¶
Validate the specified detector name.
- Variables:
detector_name – Name of the MCA detector element in the scan.
- Raises:
ValueError – Invalid detector_name.
- Returns:
detector_name.
- Return type:
str
- dict(*args, **kwargs)¶
Return a representation of this configuration in a dictionary that is suitable for dumping to a YAML file.
- Returns:
Dictionary representation of the configuration.
- Return type:
dict
- class CHAP.edd.models.MCAElementCalibrationConfig¶
Bases:
CHAP.edd.models.MCAElementConfig
Class representing metadata required to calibrate a single MCA detector element.
- Variables:
tth_max – Detector rotation about lab frame x axis, defaults to
90
.hkl_tth_tol – Minimum resolvable difference in 2&theta between two unique Bragg peaks, defaults to
0.15
.energy_calibration_coeffs – Detector channel index to energy polynomial conversion coefficients ([a, b, c] with E_i = ai^2 + bi + c), defaults to
[0, 0, 1]
.background – Background model for peak fitting.
baseline – Automated baseline subtraction configuration, defaults to
False
.tth_initial_guess – Initial guess for 2&theta, defaults to
5.0
.tth_calibrated – Calibrated value for 2&theta.
include_energy_ranges – List of MCA channel energy ranges in keV whose data should be included after applying a mask (bounds are inclusive), defaults to
[[50, 150]]
- tth_max: confloat(gt=0, allow_inf_nan=False)¶
90.0
- hkl_tth_tol: confloat(gt=0, allow_inf_nan=False)¶
0.15
- energy_calibration_coeffs: conlist(min_length=3, max_length=3, item_type=confloat(allow_inf_nan=False))¶
[0, 0, 1]
- background: Optional[Union[str, list]]¶
None
- baseline: Optional[Union[bool, CHAP.edd.models.BaselineConfig]]¶
False
- tth_initial_guess: confloat(gt=0, le=tth_max, allow_inf_nan=False)¶
5.0
- tth_calibrated: Optional[confloat(gt=0, allow_inf_nan=False)]¶
None
- include_energy_ranges: typing_extensions.Annotated[conlist(min_length=1, item_type=conlist(min_length=2, max_length=2, item_type=confloat(ge=25))), Field(validate_default=True)]¶
[[50, 150]]
- _hkl_indices: list¶
‘PrivateAttr(…)’
- classmethod validate_include_energy_range(include_energy_ranges, info)¶
Ensure that no energy ranges are outside the boundary of the detector.
- Parameters:
include_energy_ranges (dict) – The value of
include_energy_ranges
to validate.info (pydantic_core._pydantic_core.ValidationInfo) – Pydantic validator info object.
- Return type:
dict
- property energies¶
Return calibrated bin energies.
- property include_bin_ranges¶
Return the value of
include_energy_ranges
represented in terms of channel indices instead of channel energies.
- property hkl_indices¶
Return the hkl_indices consistent with the selected energy ranges (include_energy_ranges).
- get_include_energy_ranges(include_bin_ranges)¶
Given a list of channel index ranges, return the corresponding list of channel energy ranges.
- Parameters:
include_bin_ranges (list[list[int]]) – A list of channel bin ranges to convert to energy ranges.
- Returns:
Energy ranges
- Return type:
list[list[float]]
- mca_mask()¶
Get a boolean mask array to use on this MCA element’s data. Note that the bounds of self.include_energy_ranges are inclusive.
- Returns:
Boolean mask array.
- Return type:
numpy.ndarray
- set_hkl_indices(hkl_indices)¶
Set the private attribute
hkl_indices
.
- dict(*args, **kwargs)¶
Return a representation of this configuration in a dictionary that is suitable for dumping to a YAML file.
- Returns:
Dictionary representation of the configuration.
- Return type:
dict
- class CHAP.edd.models.MCAElementDiffractionVolumeLengthConfig¶
Bases:
CHAP.edd.models.MCAElementConfig
Class representing metadata required to perform a diffraction volume length measurement for a single MCA detector element.
- Variables:
include_bin_ranges – List of MCA channel index ranges whose data is included in the measurement.
measurement_mode – Placeholder for recording whether the measured DVL value was obtained through the automated calculation or a manual selection, defaults to
'auto'
.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 to3.5
.dvl_measured – Placeholder for the measured diffraction volume length before writing the data to file.
fit_amplitude – Placeholder for amplitude of the gaussian fit.
fit_center – Placeholder for center of the gaussian fit.
fit_sigma – Placeholder for sigma of the gaussian fit.
- include_bin_ranges: Optional[conlist(min_length=1, item_type=conlist(min_length=2, max_length=2, item_type=conint(ge=0)))]¶
None
- measurement_mode: Optional[Literal[manual, auto]]¶
‘auto’
- sigma_to_dvl_factor: Optional[Literal[3.5, 2.0, 4.0]]¶
3.5
- dvl_measured: Optional[confloat(gt=0)]¶
None
- fit_amplitude: Optional[float]¶
None
- fit_center: Optional[float]¶
None
- fit_sigma: Optional[float]¶
None
- mca_mask()¶
Get a boolean mask array to use on this MCA element’s data. Note that the bounds of self.include_energy_ranges are inclusive.
- Returns:
Boolean mask array.
- Return type:
numpy.ndarray
- dict(*args, **kwargs)¶
Return a representation of this configuration in a dictionary that is suitable for dumping to a YAML file. Exclude
sigma_to_dvl_factor
from the dict representation ifmeasurement_mode
is'manual'
.- Returns:
Dictionary representation of the configuration.
- Return type:
dict
- class CHAP.edd.models.MCAElementStrainAnalysisConfig¶
Bases:
CHAP.edd.models.MCAElementConfig
Class representing metadata required to perform a strain analysis fitting for a single MCA detector element.
- Parameters:
tth_max (float, optional) – Detector rotation about hutch x axis, defaults to
90.0
.- Variables:
hkl_tth_tol – Minimum resolvable difference in 2&theta between two unique HKL peaks, defaults to
0.15
.hkl_indices – List of unique HKL indices to fit peaks for in the calibration routine, defaults to
[]
.background – Background model for peak fitting.
baseline – Automated baseline subtraction configuration, defaults to
False
.num_proc – Number of processors used for peak fitting.
peak_models – Peak model for peak fitting, defaults to
'gaussian'
.fwhm_min – Minimum FWHM for peak fitting, defaults to
0.25
.fwhm_max – Maximum FWHM for peak fitting, defaults to
2.0
.centers_range – Peak centers range for peak fitting. The allowed range the peak centers will be the initial values ±
centers_range
. Defaults to2.0
.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 toNone
.tth_calibrated – Calibrated value for 2&theta.
energy_calibration_coeffs – Detector channel index to energy polynomial conversion coefficients ([a, b, c] with E_i = ai^2 + bi + c), defaults to
[0, 0, 1]
.calibration_bin_ranges – List of MCA channel index ranges whose data is included in the calibration.
tth_file – Path to the file with the 2&theta map.
tth_map – Map of the 2&theta values.
include_energy_ranges – List of MCA channel energy ranges in keV whose data should be included after applying a mask (bounds are inclusive), defaults to
[[50, 150]]
- tth_max: confloat(gt=0, allow_inf_nan=False)¶
90.0
- hkl_tth_tol: confloat(gt=0, allow_inf_nan=False)¶
0.15
- hkl_indices: Optional[conlist(item_type=conint(ge=0))]¶
[]
- background: Optional[Union[str, list]]¶
None
- baseline: Optional[Union[bool, CHAP.edd.models.BaselineConfig]]¶
False
- num_proc: Optional[conint(gt=0)]¶
‘cpu_count(…)’
- peak_models: Union[conlist(min_length=1, item_type=Literal['gaussian', 'lorentzian']), Literal[gaussian, lorentzian]]¶
‘gaussian’
- fwhm_min: confloat(gt=0, allow_inf_nan=False)¶
0.25
- fwhm_max: confloat(gt=0, allow_inf_nan=False)¶
2.0
- centers_range: confloat(gt=0, allow_inf_nan=False)¶
2.0
- rel_height_cutoff: Optional[confloat(gt=0, lt=1.0, allow_inf_nan=False)]¶
None
- tth_calibrated: Optional[confloat(gt=0, allow_inf_nan=False)]¶
None
- energy_calibration_coeffs: conlist(min_length=3, max_length=3, item_type=confloat(allow_inf_nan=False))¶
[0, 0, 1]
- calibration_bin_ranges: Optional[conlist(min_length=1, item_type=conlist(min_length=2, max_length=2, item_type=conint(ge=0)))]¶
None
- tth_file: Optional[pydantic.FilePath]¶
None
- tth_map: Optional[numpy.ndarray]¶
None
- include_energy_ranges: conlist(min_length=1, item_type=conlist(min_length=2, max_length=2, item_type=confloat(ge=25)))¶
[[50, 150]]
- classmethod validate_hkl_indices(hkl_indices)¶
- property energies¶
Return calibrated bin energies.
- property include_bin_ranges¶
Return the value of
include_energy_ranges
represented in terms of channel indices instead of channel energies.
- get_include_energy_ranges(include_bin_ranges)¶
Given a list of channel index ranges, return the corresponding list of channel energy ranges.
- Parameters:
include_bin_ranges (list[list[int]]) – A list of channel bin ranges to convert to energy ranges.
- Returns:
Energy ranges
- Return type:
list[list[float]]
- mca_mask()¶
Get a boolean mask array to use on this MCA element’s data. Note that the bounds of self.include_energy_ranges are inclusive.
- Returns:
Boolean mask array.
- Return type:
numpy.ndarray
- add_calibration(calibration)¶
Finalize values for some fields using a completed MCAElementCalibrationConfig that corresponds to the same detector.
- Parameters:
calibration (MCAElementCalibrationConfig) – Existing calibration configuration to use by MCAElementStrainAnalysisConfig.
- Returns:
None
- 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
- dict(*args, **kwargs)¶
Return a representation of this configuration in a dictionary that is suitable for dumping to a YAML file.
- Returns:
Dictionary representation of the configuration.
- Return type:
dict
- class CHAP.edd.models.MCAScanDataConfig¶
Bases:
pydantic.BaseModel
Class representing metadata required to locate raw MCA data for a single scan and construct a mask for it.
- Variables:
inputdir – Input directory, used only if any file in the configuration is not an absolute path.
spec_file – Path to the SPEC file containing the scan.
scan_number – Number of the scan in
spec_file
.par_file – Path to the par file associated with the scan.
scan_column – Required column name in
par_file
.detectors – List of MCA detector element metadata configurations.
- inputdir: Optional[pydantic.DirectoryPath]¶
None
- spec_file: Optional[pydantic.FilePath]¶
None
- scan_number: Optional[conint(gt=0)]¶
None
- par_file: Optional[pydantic.FilePath]¶
None
- scan_column: Optional[str]¶
None
- detectors: conlist(min_length=1, item_type=MCAElementConfig)¶
None
- _parfile: Optional[CHAP.utils.parfile.ParFile]¶
None
- _scanparser: Optional[chess_scanparsers.SMBMCAScanParser]¶
None
- classmethod validate_scan(data)¶
Finalize file paths for spec_file and par_file.
- Parameters:
data (MCAScanDataConfig, pydantic_core._pydantic_core.ValidationInfo) – Pydantic validator data object.
- Raises:
ValueError – Invalid SPEC or par file.
- Returns:
The validated list of class properties.
- Return type:
dict
- validate_detectors()¶
Fill in values for _scanparser / _parfile (if applicable). Fill in each detector’s num_bins field, if needed. Check each detector’s include_energy_ranges field against the flux file, if available.
- Raises:
ValueError – Unable to obtain a value for num_bins.
- Returns:
The validated list of class properties.
- Return type:
dict
- property scanparser¶
Return the scanparser.
- dict(*args, **kwargs)¶
Return a representation of this configuration in a dictionary that is suitable for dumping to a YAML file.
- Returns:
Dictionary representation of the configuration.
- Return type:
dict
- class CHAP.edd.models.DiffractionVolumeLengthConfig¶
Bases:
CHAP.edd.models.MCAScanDataConfig
Class representing metadata required to perform a diffraction volume length calculation for an EDD setup using a steel-foil raster scan.
- Variables:
sample_thickness – Thickness of scanned foil sample. Quantity must be provided in the same units as the values of the scanning motor.
detectors – Individual detector element DVL measurement configurations
- sample_thickness: float¶
None
- detectors: conlist(min_length=1, item_type=MCAElementDiffractionVolumeLengthConfig)¶
None
- property scanned_vals¶
Return the list of values visited by the scanning motor over the course of the raster scan.
- Returns:
List of scanned motor values
- Return type:
numpy.ndarray
- class CHAP.edd.models.MCAEnergyCalibrationConfig¶
Bases:
pydantic.BaseModel
Class representing metadata required to perform an energy calibration for an MCA detector.
- Variables:
inputdir – Input directory, used only if any file in the configuration is not an absolute path.
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.
detectors – List of individual MCA detector element calibration configurations.
flux_file – File name of the csv flux file containing station beam energy in eV (column 0) versus flux (column 1).
material – Material configuration for the calibration, defaults to
Ceria
.peak_energies – Theoretical locations of peaks in keV to use for calibrating the MCA channel energies. It is strongly recommended to use fluorescence peaks for the energy calibration.
max_peak_index – Index of the peak in
peak_energies
with the highest amplitude.fit_index_ranges – Explicit ranges of uncalibrated MCA channel index ranges to include during energy calibration when the given peaks are fitted to the provied MCA spectrum. Use this parameter or select it interactively by running a pipeline with
config.interactive: True
.
- inputdir: Optional[pydantic.DirectoryPath]¶
None
- scan_step_indices: Optional[typing_extensions.Annotated[conlist(min_length=1, item_type=conint(ge=0)), Field(validate_default=True)]]¶
None
- detectors: Optional[conlist(item_type=MCAElementCalibrationConfig)]¶
None
- flux_file: Optional[pydantic.FilePath]¶
None
- material: Optional[CHAP.edd.models.MaterialConfig]¶
‘MaterialConfig(…)’
- peak_energies: conlist(min_length=2, item_type=confloat(gt=0))¶
None
- max_peak_index: conint(ge=0)¶
None
- fit_index_ranges: Optional[conlist(min_length=1, item_type=conlist(min_length=2, max_length=2, item_type=conint(ge=0)))]¶
None
- classmethod validate_config(data)¶
Ensure that a valid configuration was provided and finalize flux_file filepath.
- Parameters:
data (MCAEnergyCalibrationConfig, 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 of int
- classmethod validate_max_peak_index(max_peak_index, info)¶
Validate the specified index of the XRF peak with the highest amplitude.
- Variables:
max_peak_index – The index of the XRF peak with the highest amplitude.
- Parameters:
info (pydantic_core._pydantic_core.ValidationInfo) – Pydantic validator info object.
- Raises:
ValueError – Invalid max_peak_index.
- Returns:
The validated value of
max_peak_index
.- Return type:
int
- 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)
- 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
- dict(*args, **kwargs)¶
Return a representation of this configuration in a dictionary that is suitable for dumping to a YAML file.
- Returns:
Dictionary representation of the configuration.
- Return type:
dict
- class CHAP.edd.models.MCATthCalibrationConfig¶
Bases:
CHAP.edd.models.MCAEnergyCalibrationConfig
Class representing metadata required to perform a tth calibration for an MCA detector.
- Variables:
calibration_method – Type of calibration method, defaults to
'direct_fit_residual'
.max_iter – Maximum number of iterations of the calibration routine (only used for
'iterate_tth'
), defaults to10
.tune_tth_tol – Cutoff error for tuning 2&theta (only used for
'iterate_tth'
). Stop iterating the calibration routine after an iteration produces a change in the tuned value of 2&theta that is smaller than this cutoff, defaults to1e-8
.tune_tth_tol – float, optional
- calibration_method: Optional[Literal[direct_fit_residual, direct_fit_peak_energies, direct_fit_combined, iterate_tth]]¶
‘iterate_tth’
- max_iter: conint(gt=0)¶
10
- tune_tth_tol: confloat(ge=0)¶
1e-08
- 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)
- class CHAP.edd.models.StrainAnalysisConfig¶
Bases:
pydantic.BaseModel
Class representing input parameters required to perform a strain analysis.
- Variables:
inputdir – Input directory, used only if any file in the configuration is not an absolute path.
detectors – List of individual detector element strain analysis configurations, defaults to
None
(use all detectors).materials – Sample material configurations.
flux_file – File name of the csv flux file containing station beam energy in eV (column 0) versus flux (column 1).
sum_axes – Whether to sum over the fly axis or not for EDD scan types not 0, defaults to
True
.oversampling – FIX
- inputdir: Optional[pydantic.DirectoryPath]¶
None
- detectors: Optional[conlist(min_length=1, item_type=MCAElementStrainAnalysisConfig)]¶
None
- materials: list[CHAP.edd.models.MaterialConfig]¶
None
- flux_file: Optional[pydantic.FilePath]¶
None
- sum_axes: Optional[bool]¶
True
- oversampling: Optional[typing_extensions.Annotated[dict, Field(validate_default=True)]]¶
None
- classmethod validate_config(data)¶
Ensure that a valid configuration was provided and finalize flux_file filepath.
- Parameters:
data (MCAEnergyCalibrationConfig, pydantic_core._pydantic_core.ValidationInfo) – Pydantic validator data object.
- Returns:
The currently validated list of class properties.
- Return type:
dict
- classmethod validate_tth_file(detectors, info)¶
Finalize value for tth_file for each detector
- 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
- dict(*args, **kwargs)¶
Return a representation of this configuration in a dictionary that is suitable for dumping to a YAML file.
- Returns:
Dictionary representation of the configuration.
- Return type:
dict