CHAP.common.models.integration
¶
Module Contents¶
Classes¶
Detector class to represent a single detector used in the experiment. |
|
Class representing the configuration for a raw detector data integration. |
Functions¶
Return the azimuthal integrator from a PONI file |
|
Return a mask array associated with a detector loaded from a tiff file. |
|
Fix chi discontinuity at 180 degrees and return the adjusted chi range, offset, and discontinuty. |
|
Return a list of |
|
Return a |
|
Return a dictionary of coordinate arrays for the specified radial and/or azimuthal integration ranges. |
API¶
- class CHAP.common.models.integration.Detector¶
Bases:
pydantic.BaseModel
Detector class to represent a single detector used in the experiment.
- Parameters:
prefix (str) – Prefix of the detector in the SPEC file.
poni_file (str) – Path to the poni file.
mask_file (str, optional) – Optional path to the mask file.
- prefix: constr(strip_whitespace=True, min_length=1)¶
None
- poni_file: pydantic.FilePath¶
None
- mask_file: Optional[pydantic.FilePath]¶
None
- classmethod validate_poni_file(poni_file)¶
Validate the poni file by checking if it’s a valid PONI file.
- Parameters:
poni_file (str) – Path to the poni file.
- Raises:
ValueError – If poni_file is not a valid PONI file.
- Returns:
Absolute path to the poni file.
- Return type:
str
- classmethod validate_mask_file(mask_file, values)¶
Validate the mask file. If a mask file is provided, it checks if it’s a valid TIFF file.
- Parameters:
mask_file (str or None) – Path to the mask file.
values (dict) – A dictionary of the Detector fields.
- Raises:
ValueError – If mask_file is provided and it’s not a valid TIFF file.
ValueError – If
'poni_file'
is not provided invalues
.
- Returns:
Absolute path to the mask file or None.
- Return type:
str or None
- property azimuthal_integrator¶
Return the azimuthal integrator associated with this detector.
- property mask_array¶
Return the mask array assocated with this detector.
- CHAP.common.models.integration.azimuthal_integrator(poni_file: str)¶
Return the azimuthal integrator from a PONI file
- Parameters:
poni_file (str) – path to a PONI file
- Returns:
azimuthal integrator
- Return type:
pyFAI.azimuthal_integrator.AzimuthalIntegrator
- CHAP.common.models.integration.get_mask_array(mask_file: str, poni_file: str)¶
Return a mask array associated with a detector loaded from a tiff file.
- Parameters:
mask_file (str) – path to a .tiff file
poni_file (str) – path to a PONI file
- Returns:
the mask array loaded from
mask_file
- Return type:
numpy.ndarray
- class CHAP.common.models.integration.IntegrationConfig¶
Bases:
pydantic.BaseModel
Class representing the configuration for a raw detector data integration.
- Variables:
tool_type – type of integration tool; always set to “integration”
title – title of the integration
integration_type – type of integration, one of “azimuthal”, “radial”, or “cake”
detectors – list of detectors used in the integration
radial_units – radial units for the integration, defaults to
'q_A^-1'
radial_min – minimum radial value for the integration range
radial_max – maximum radial value for the integration range
radial_npt – number of points in the radial range for the integration
azimuthal_units – azimuthal units for the integration
azimuthal_min – minimum azimuthal value for the integration range
azimuthal_max – maximum azimuthal value for the integration range
azimuthal_npt – number of points in the azimuthal range for the integration
error_model – error model for the integration, one of “poisson” or “azimuthal”
- tool_type: Literal[integration]¶
‘integration’
- title: constr(strip_whitespace=True, min_length=1)¶
None
- integration_type: Literal[azimuthal, radial, cake]¶
None
- radial_units: str¶
‘q_A^-1’
- radial_min: confloat(ge=0)¶
None
- radial_max: confloat(gt=0)¶
None
- radial_npt: conint(gt=0)¶
1800
- azimuthal_units: str¶
‘chi_deg’
- azimuthal_min: confloat(ge=-180)¶
None
- azimuthal_max: confloat(le=360)¶
180
- azimuthal_npt: conint(gt=0)¶
3600
- error_model: Optional[Literal[poisson, azimuthal]]¶
None
- sequence_index: Optional[conint(gt=0)]¶
None
- classmethod validate_radial_units(radial_units)¶
Validate the radial units for the integration.
- Parameters:
radial_units (str) – unvalidated radial units for the integration
- Raises:
ValueError – if radial units are not one of the recognized radial units
- Returns:
validated radial units
- Return type:
str
- classmethod validate_azimuthal_units(azimuthal_units)¶
Validate that
azimuthal_units
is one of the keys in thepyFAI.units.AZIMUTHAL_UNITS
dictionary.- Parameters:
azimuthal_units (str) – The string representing the unit to be validated.
- Raises:
ValueError – If
azimuthal_units
is not one of the keys inpyFAI.units.AZIMUTHAL_UNITS
- Returns:
The original supplied value, if is one of the keys in
pyFAI.units.AZIMUTHAL_UNITS
.- Return type:
str
- validate_range_max()¶
Validate the maximum value of an integration range.
- Parameters:
range_name (str) – The name of the integration range (e.g. radial, azimuthal).
- Returns:
The callable that performs the validation.
- Return type:
callable
- _validate_radial_max¶
‘(…)’
- _validate_azimuthal_max¶
‘(…)’
- validate_for_map_config(map_config: pydantic.BaseModel)¶
Validate the existence of the detector data file for all scan points in
map_config
.- Parameters:
map_config (MapConfig) – The
MapConfig
instance to validate against.- Raises:
RuntimeError – If a detector data file could not be found for a scan point occurring in
map_config
.- Returns:
None
- Return type:
None
- get_azimuthal_adjustments()¶
To enable a continuous range of integration in the azimuthal direction for radial and cake integration, obtain adjusted values for this
IntegrationConfig
’sazimuthal_min
andazimuthal_max
values, the angle amount by which those values were adjusted, and the proper location of the discontinuity in the azimuthal direction.- Returns:
Adjusted chi_min, adjusted chi_max, chi_offset, chi_discontinuity
- Return type:
tuple[float,float,float,float]
- get_azimuthal_integrators()¶
Get a list of
AzimuthalIntegrator
s that correspond to the detector configurations in this instance ofIntegrationConfig
.The returned
AzimuthalIntegrator
s are (if need be) artificially rotated in the azimuthal direction to achieve a continuous range of integration in the azimuthal direction.- Returns:
A list of
AzimuthalIntegrator
s appropriate for use by thisIntegrationConfig
tool- Return type:
list[pyFAI.azimuthalIntegrator.AzimuthalIntegrator]
- get_multi_geometry_integrator()¶
Get a
MultiGeometry
integrator suitable for use by this instance ofIntegrationConfig
.- Returns:
A
MultiGeometry
integrator- Return type:
pyFAI.multi_geometry.MultiGeometry
- get_azimuthally_integrated_data(spec_scans: pydantic.BaseModel, scan_number: int, scan_step_index: int)¶
Return azimuthally-integrated data for the scan step specified.
- Parameters:
spec_scans (SpecScans) – An instance of
SpecScans
containing the scan step requested.scan_number (int) – The number of the scan containing the scan step requested.
scan_step_index (int) – The index of the scan step requested.
- Returns:
A 1D array of azimuthally-integrated raw detector intensities.
- Return type:
np.ndarray
- get_radially_integrated_data(spec_scans: pydantic.BaseModel, scan_number: int, scan_step_index: int)¶
Return radially-integrated data for the scan step specified.
- Parameters:
spec_scans (SpecScans) – An instance of
SpecScans
containing the scan step requested.scan_number (int) – The number of the scan containing the scan step requested.
scan_step_index (int) – The index of the scan step requested.
- Returns:
A 1D array of radially-integrated raw detector intensities.
- Return type:
np.ndarray
- get_cake_integrated_data(spec_scans: pydantic.BaseModel, scan_number: int, scan_step_index: int)¶
Return cake-integrated data for the scan step specified.
- Parameters:
spec_scans (SpecScans) – An instance of
SpecScans
containing the scan step requested.scan_number (int) – The number of the scan containing the scan step requested.
scan_step_index (int) – The index of the scan step requested.
- Returns:
A 2D array of cake-integrated raw detector intensities.
- Return type:
np.ndarray
- get_integrated_data(spec_scans: pydantic.BaseModel, scan_number: int, scan_step_index: int)¶
Return integrated data for the scan step specified.
- Parameters:
spec_scans (SpecScans) – An instance of
SpecScans
containing the scan step requested.scan_number (int) – The number of the scan containing the scan step requested.
scan_step_index (int) – The index of the scan step requested.
- Returns:
An array of integrated raw detector intensities.
- Return type:
np.ndarray
- property integrated_data_coordinates¶
Return a dictionary of coordinate arrays for navigating the dimension(s) of the integrated data produced by this instance of
IntegrationConfig
.- Returns:
A dictionary with either one or two keys: ‘azimuthal’ and/or ‘radial’, each of which points to a 1-D
numpy
array of coordinate values.- Return type:
dict[str,np.ndarray]
- property integrated_data_dims¶
Return a tuple of the coordinate labels for the integrated data produced by this instance of
IntegrationConfig
.
- property integrated_data_shape¶
Return a tuple representing the shape of the integrated data produced by this instance of
IntegrationConfig
for a single scan step.
- CHAP.common.models.integration.get_azimuthal_adjustments(chi_min: float, chi_max: float)¶
Fix chi discontinuity at 180 degrees and return the adjusted chi range, offset, and discontinuty.
If the discontinuity is crossed, obtain the offset to artificially rotate detectors to achieve a continuous azimuthal integration range.
- Parameters:
chi_min (float) – The minimum value of the azimuthal range.
chi_max (float) – The maximum value of the azimuthal range.
- Returns:
The following four values: the adjusted minimum value of the azimuthal range, the adjusted maximum value of the azimuthal range, the value by which the chi angle was adjusted, the position of the chi discontinuity.
- CHAP.common.models.integration.get_azimuthal_integrators(poni_files: tuple, chi_offset=0)¶
Return a list of
AzimuthalIntegrator
objects generated from PONI files.- Parameters:
poni_files (tuple) – Tuple of strings, each string being a path to a PONI file.
chi_offset (float, optional) – The angle in degrees by which the
AzimuthalIntegrator
objects will be rotated, defaults to 0.
- Returns:
List of
AzimuthalIntegrator
objects- Return type:
list[pyFAI.azimuthalIntegrator.AzimuthalIntegrator]
- CHAP.common.models.integration.get_multi_geometry_integrator(poni_files: tuple, radial_unit: str, radial_range: tuple, azimuthal_range: tuple)¶
Return a
MultiGeometry
instance that can be used for azimuthal or cake integration.- Parameters:
poni_files (tuple) – Tuple of PONI files that describe the detectors to be integrated.
radial_unit (str) – Unit to use for radial integration range.
radial_range (tuple[float,float]) – Tuple describing the range for radial integration.
azimuthal_range (tuple[float,float]) – Tuple describing the range for azimuthal integration.
- Returns:
MultiGeometry
instance that can be used for azimuthal or cake integration.- Return type:
pyFAI.multi_geometry.MultiGeometry
- CHAP.common.models.integration.get_integrated_data_coordinates(azimuthal_range: tuple = None, azimuthal_npt: int = None, radial_range: tuple = None, radial_npt: int = None)¶
Return a dictionary of coordinate arrays for the specified radial and/or azimuthal integration ranges.
- Parameters:
azimuthal_range (tuple[float,float], optional) – Tuple specifying the range of azimuthal angles over which to generate coordinates, in the format (min, max), defaults to None.
azimuthal_npt (int, optional) – Number of azimuthal coordinate points to generate, defaults to None.
radial_range (tuple[float,float], optional) – Tuple specifying the range of radial distances over which to generate coordinates, in the format (min, max), defaults to None.
radial_npt (int, optional) – Number of radial coordinate points to generate, defaults to None.
- Returns:
A dictionary with either one or two keys: ‘azimuthal’ and/or ‘radial’, each of which points to a 1-D
numpy
array of coordinate values.- Return type:
dict[str,np.ndarray]