CHAP.giwaxs package

Submodules

CHAP.giwaxs.models module

GIWAXS Pydantic model classes.

class AzimuthalIntegratorConfig(*, 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 = {}, mask_file: Annotated[Path, PathType(path_type=file)] | None = None, params: dict | None = None, poni_file: Annotated[Path, PathType(path_type=file)] | None = None)

Bases: Detector, CHAPBaseModel

Azimuthal integrator configuration class to represent a single detector used in the experiment.

Parameters:
  • mask_file (FilePath, optional) – Path to the mask file.

  • poni_file (FilePath, optional) – Path to the PONI file, specify either poni_file or params, not both.

  • params (dict, optional) – Azimuthal integrator configuration parameters, specify either poni_file or params, not both.

property ai

Return the azimuthal integrator.

mask_file: Annotated[Path, PathType(path_type=file)] | 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.

params: dict | None
poni_file: Annotated[Path, PathType(path_type=file)] | None
validate_azimuthalintegratorconfig_after()

Set the default azimuthal integrator.

Returns:

Validated configuration class.

Return type:

AzimuthalIntegratorConfig

classmethod validate_azimuthalintegratorconfig_before(data)
class GiwaxsConversionConfig(*, azimuthal_integrators: Annotated[list[AzimuthalIntegratorConfig], Len(min_length=1, max_length=None)], scan_step_indices: Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=1, max_length=None)] | None = None, save_raw_data: bool | None = False)

Bases: CHAPBaseModel

Class representing metadata required to locate GIWAXS image files for a single scan to convert to q_par/q_perp coordinates.

Variables:
  • azimuthal_integrators – List of azimuthal integrator configurations.

  • scan_step_indices – Optional scan step indices to convert. If not specified, all images will be converted.

  • save_raw_data – Save the raw data in the NeXus output, defaults to False.

azimuthal_integrators: Annotated[list[AzimuthalIntegratorConfig], Len(min_length=1, max_length=None)]
model_config: ClassVar[ConfigDict] = {}

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

save_raw_data: bool | None
scan_step_indices: Annotated[list[Annotated[int, None, Interval(gt=None, ge=0, lt=None, le=None), None]], Len(min_length=1, max_length=None)] | None
classmethod validate_scan_step_indices(scan_step_indices)

Ensure that a valid configuration was provided and finalize PONI filepaths.

Parameters:

data (GiwaxsConversionConfig, pydantic_core._pydantic_core.ValidationInfo) – Pydantic validator data object.

Returns:

The currently validated list of class properties.

Return type:

dict

class Integrate1dConfig(*, error_model: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, method: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]], Len(min_length=3, max_length=3)] | None = ['bbox', 'csr', 'cython'], npt: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None = 1800, attrs: dict | None = {})

Bases: CHAPBaseModel

Class with the input parameters to performs 1D azimuthal integration with pyFAI.

Variables:
  • error_model – When the variance is unknown, an error model can be given: poisson (variance = I) or azimuthal (variance = (I-<I>)^2).

  • method – IntegrationMethod instance or 3-tuple with (splitting, algorithm, implementation)

  • npt – Number of integration points, defaults to 1800.

attrs: dict | None
error_model: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None
method: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]], Len(min_length=3, max_length=3)] | None
model_config: ClassVar[ConfigDict] = {}

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

npt: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None
class Integrate2dConfig(*, error_model: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = None, method: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]], Len(min_length=3, max_length=3)] | None = ['bbox', 'csr', 'cython'], npt_azim: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None = 3600, npt_rad: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None = 1800, attrs: dict | None = {})

Bases: CHAPBaseModel

Class with the input parameters to performs 2D azimuthal integration with pyFAI.

Variables:
  • error_model – When the variance is unknown, an error model can be given: poisson (variance = I) or azimuthal (variance = (I-<I>)^2).

  • method – IntegrationMethod instance or 3-tuple with (splitting, algorithm, implementation)

  • npt_azim – Number of points for the integration in the azimuthal direction, defaults to 3600.

  • npt_rad – Number of points for the integration in the radial direction, defaults to 1800.

attrs: dict | None
error_model: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None
method: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]], Len(min_length=3, max_length=3)] | None
model_config: ClassVar[ConfigDict] = {}

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

npt_azim: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None
npt_rad: Annotated[int, None, Interval(gt=0, ge=None, lt=None, le=None), None] | None
class MultiGeometryConfig(*, ais: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]], Len(min_length=1, max_length=None)], azimuth_range: Annotated[list[Annotated[float, None, Interval(gt=None, ge=-180, lt=None, le=360), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)] | None = [-180.0, 180.0], radial_range: Annotated[list[Annotated[float, None, Interval(gt=None, ge=0, lt=None, le=180), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)] | None = [0.0, 180.0], unit: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None = 'q_A^-1', chi_disc: int | None = 180, empty: Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = 0.0, wavelength: Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None = None)

Bases: CHAPBaseModel

Class representing the configuration for treating simultaneously multiple detector configuration within a single integration

Variables:
  • ais – List of detector IDs of azimuthal integrators

  • azimuth_range – Common azimuthal range for integration, defaults to [-180.0, 180.0].

  • radial_range – Common range for integration, defaults to [0.0, 180.0].

ais: Annotated[list[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]], Len(min_length=1, max_length=None)]
azimuth_range: Annotated[list[Annotated[float, None, Interval(gt=None, ge=-180, lt=None, le=360), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)] | None
chi_disc: int | None
empty: Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
model_config: ClassVar[ConfigDict] = {}

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

radial_range: Annotated[list[Annotated[float, None, Interval(gt=None, ge=0, lt=None, le=180), None, AllowInfNan(allow_inf_nan=False)]], Len(min_length=2, max_length=2)] | None
unit: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)] | None
classmethod validate_ais(ais)

Validate the detector IDs of the azimuthal integrators.

Parameters:

ais (str, list[str]) – The detector IDs.

Returns:

The detector ais.

Return type:

list[str]

wavelength: Annotated[float, None, Interval(gt=None, ge=None, lt=None, le=None), None, AllowInfNan(allow_inf_nan=False)] | None
class PyfaiIntegrationConfig(*, azimuthal_integrators: Annotated[list[AzimuthalIntegratorConfig], Len(min_length=1, max_length=None)] | None = None, integrations: Annotated[list[PyfaiIntegratorConfig], Len(min_length=1, max_length=None)], sum_axes: bool | None = False)

Bases: CHAPBaseModel

azimuthal_integrators: Annotated[list[AzimuthalIntegratorConfig], Len(min_length=1, max_length=None)] | None
integrations: Annotated[list[PyfaiIntegratorConfig], Len(min_length=1, max_length=None)]
model_config: ClassVar[ConfigDict] = {}

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

sum_axes: bool | None
classmethod validate_pyfaiintegrationconfig_before(data)

Ensure that a valid configuration was provided and finalize PONI filepaths.

Parameters:

data (GiwaxsConversionConfig, pydantic_core._pydantic_core.ValidationInfo) – Pydantic validator data object.

Returns:

The currently validated list of class properties.

Return type:

dict

class PyfaiIntegratorConfig(*, name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)], integration_method: Literal['integrate1d', 'integrate2d', 'integrate_radial'], multi_geometry: MultiGeometryConfig | None = None, integration_params: Integrate1dConfig | Integrate2dConfig | None = None, right_handed: bool = True)

Bases: CHAPBaseModel

Class representing the configuration for detector data integrater for pyFAI.

Variables:

right_handed – For radial and cake integration, reverse the direction of the azimuthal coordinate from pyFAI’s convention, defaults to True.

integrate(ais, data, masks=None)
integration_method: Literal['integrate1d', 'integrate2d', 'integrate_radial']
integration_params: Integrate1dConfig | Integrate2dConfig | None
model_config: ClassVar[ConfigDict] = {}

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

multi_geometry: MultiGeometryConfig | None
name: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]
right_handed: bool
validate_pyfaiintegratorconfig_after()

Choose the integration_params type depending on the integration_method value.

Parameters:

data (pydantic_core._pydantic_core.ValidationInfo) – Pydantic validator data object.

Raises:

ValueError – Invalid integration_method.

Returns:

The validated list of class properties.

Return type:

dict

classmethod validate_pyfaiintegratorconfig_before(data)

Validate the integration parameters.

Parameters:

data (PyfaiIntegratorConfig, pydantic_core._pydantic_core.ValidationInfo) – Pydantic validator data object.

Returns:

The currently validated list of class properties.

Return type:

dict

CHAP.giwaxs.processor module

File : processor.py Author : Rolf Verberg Description: Module for Processors used only by GIWAXS experiments

class GiwaxsConversionProcessor(*, 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: Processor

A processor for converting GIWAXS images from curved to rectangular coordinates.

convert_q_rect(nxroot, config, save_figures=False, interactive=False, outputdir='.')

Return NXroot containing the converted GIWAXS images.

Parameters:
  • nxroot (nexusformat.nexus.NXroot) – GIWAXS map with the raw detector data.

  • config (CHAP.giwaxs.models.GiwaxsConversionConfig) – GIWAXS conversion configuration.

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

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

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

Returns:

Converted GIWAXS images.

Return type:

nexusformat.nexus.NXroot

static curved_to_rect(data_curved, q_par, q_perp, q_par_rect, q_perp_rect, return_maps=False, normalize=True)
data_rect = curved_to_rect(...):
    distributes counts from a curvilinear grid
    (data_curved), e.g. x-ray data collected in angular
    space, into a rectilinear grid (reciprocal space). 

data_rect, norm, xmap, ymap, xwid, ywid =
        curved_to_rect(..., return_maps=True):
    distributes counts from a curvilinear grid
    (data_curved), e.g. x-ray data collected in angular
    space, into a rectilinear grid (reciprocal space). 

q_par, q_perp, and data_curved are M x N following the
    normal convention where the the first & second index
    corrspond to the vertical (y) and horizontal (x)
    locations of the scattering pattern.
q_par, q_perp represent the q coordinates of the center of
    pixels whose intensities are stored in data_curved.
    Reiterating the convention above, q_par and q_perp vary
    primarilly along the 2nd and 1st index, respectively.
q_par_rect and q_perp_rect are evenly-spaced, monotonically
    increasing, arrays determining the new grid.

data_rect : the new matrix with intensity from data_curved
            disctributed into a regular grid defined by
            q_par_rect, q_perp_rect.
norm : a matrix with the same shape of data_rect
       representing the area of the pixel in the original
       angular units. It should be used to normalize the
       resulting array as norm_z = data_rect / norm.

Algorithm:
   Step 1 : Compute xmap, ymap, which containt the values
            of q_par and q_perp, but represented in pixel
            units of the target coordinates q_par_rect,
            q_perp_rect.
            In other words, xmap(i,j) = 3.4 means that
            q_par(i,j) lands 2/5 of the q_distance between
            q_par_rect(3) and q_par_rect(4). Intensity in
            qpar(i,j) should thus be distributed in a 2:3
            ratio among neighboring mini-columns of pixels
            3 and 4.
   Step 2 : Use the procedure described by Barna et al
            (RSI v.70, p. 2927, 1999) to distribute
            intensity from each source pixel i,j into each
            of 9 destination pixels around the xmap(i,j)
            and ymap(i,j). Keep track of how many source
            "pixels" are placed into each bin in the
            variable, "norm". Note also that if
            xmap(i,j)-floor(xmap(i,j)) > 0.5,
            the "center" pixel of the 9 destination pixels
            is floor(xmap+0.5).
   (Outside this function): The normalized intensity in
       each new pixel can be obtained as
       I = data_rect./norm, but with the caveat that zero
       values of "norm" should be changed to ones first,
       norm(data_rect == 0) = 1.0.

Example Usage: 
    1. Compute the values of q_par and q_perp for each
       pixel in the image z (according to scattering
       geometry).
    2. Set or determing a good target grid, e.g.:        
       min_qpar, max_qpar = q_par.mix(), q_par.max()
       min_qperp, max_qperp = q_perp.mix(), q_perp.max()
       q_par_rect, q_par_step = np.linspace(min_qpar ,
           max_qpar, image_dim[1], retstep=True)
       q_perp_rect, q_perp_step = np.linspace(min_qperp,
           max_qperp, image_dim[0], retstep=True)
   3. data_rect = curved_to_rect(data_curved, q_par,
          q_perp, q_par_rect, q_perp_rect)
   4. plt.imshow(data_rect, extent = [
          q_par_rect[0], q_par_rect[-1],
          q_perp_rect[-1], q_perp_rect[0]])
      xlabel(r'q$_\parallel$'' [Å$^{-1}$]')
      ylabel(r'q$_\perp$'' [Å$^{-1}$]')
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.

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

Process the GIWAXS input images & configuration and returns a map of the images in rectangular coordinates as a nexusformat.nexus.NXroot object.

Parameters:
  • data (list[PipelineData]) – Results of common.MapProcessor containing the map of GIWAXS input images.

  • config (dict) – Initialization parameters for an instance of giwaxs.models.GiwaxsConversionConfig.

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

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

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

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

Returns:

Converted GIWAXS images.

Return type:

nexusformat.nexus.NXroot

class PyfaiIntegrationProcessor(*, 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: Processor

A processor for azimuthally integrating images.

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.

process(data, config, inputdir='.')

Process the input images & configuration and return a map of the azimuthally integrated images.

Parameters:
  • data (list[PipelineData]) – Results of common.MapProcessor or other suitable preprocessor of the raw detector data containing the map of input images.

  • config (dict) – Initialization parameters for an instance of giwaxs.models.PyfaiIntegrationConfig.

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

Returns:

Integrated images.

Return type:

nexusformat.nexus.NXroot

CHAP.giwaxs.reader module

GIWAXS command line reader.

CHAP.giwaxs.writer module

GIWAXS command line writer.

Module contents

This subpackage contains PipelineItems unique to GIWAXS data processing workflows.