PostProcessor#

class cdiutils.process.PostProcessor[source]#

Bases: object

A class to bundle all functions needed to post-process BCDI data.

Structural Properties

get_displacement(phase, g_vector)

Calculate the displacement from phase and g_vector.

get_het_normal_strain(displacement, ...[, ...])

Compute the heterogeneous normal strain, i.e. the gradient of the displacement projected along the measured Bragg peak direction.

get_structural_properties(complex_object, ...)

Main method used in the post-processing workflow.

Phase Manipulation

unwrap_phase(phase[, support])

Unwrap phase for voxels that belong to the given support.

remove_phase_ramp(phase)

Remove the phase ramp of a 2 | 3D phase object.

Post-processing

apodize(direct_space_data[, window_type, scale])

Apodization in the direct space data using Blackman window.

flip_reconstruction(data)

Flip a direct space reconstruction.

static prepare_volume(complex_object, isosurface, support_parameters=None, final_shape=None)[source]#

Prepare the volume by finding a smaller array shape, centering at the center of mass of the support, and cropping

Parameters:
  • complex_object (np.ndarray) – the complex object

  • phi}) ((rho e^{i)

  • isosurface (bool) – the isosurface that determines the

  • support

  • final_shape (np.ndarray | tuple | list, optional) – the

  • None. (final shape of the array requested. Defaults to)

Returns:

the cropped complex_object and the associated support.

Return type:

tuple[np.ndarray, np.ndarray]

static flip_reconstruction(data)[source]#

Flip a direct space reconstruction.

Parameters:

data (np.ndarray) – the 3D direct space reconstruction

Returns:

the flipped reconstruction

Return type:

np.ndarray

static apodize(direct_space_data, window_type='blackman', scale=1)[source]#

Apodization in the direct space data using Blackman window.

Parameters:
  • direct_space_data (np.ndarray) – the 3D volume data to

  • apodize.

  • scale (float, optional) – value of the integral of the

  • None. (Blackman window. Defaults to)

Returns:

Apodized 3D array.

Return type:

np.ndarray

static unwrap_phase(phase, support=None)[source]#

Unwrap phase for voxels that belong to the given support.

Parameters:
  • phase (np.ndarray) – the phase to unwrap

  • support (np.ndarray) – the support where voxels of interest are

Returns:

the unwrapped phase

Return type:

np.ndarray

static remove_phase_ramp(phase)[source]#

Remove the phase ramp of a 2 | 3D phase object.

Parameters:

phase (np.ndarray) – the 2 | 3D phase object

Returns:

the phase without the computed ramp.

Return type:

np.ndarray

static phase_offset_to_zero(phase, support=None)[source]#

Set the phase offset to the mean phase value.

static get_displacement(phase, g_vector)[source]#

Calculate the displacement from phase and g_vector.

static get_displacement_gradient(displacement, voxel_size, gradient_method='hybrid')[source]#

Calculate the gradient of the displacement.

Parameters:
  • displacement (np.ndarray) – displacement array.

  • voxel_size (np.ndarray | tuple | list) – the voxel size of

  • array. (the)

  • gradient_method (str, optional) – the method employed to

  • gradient. (compute the gradient. "numpy" is the traditional)

  • and ("hybrid" compute first order gradient at the surface)

  • reconstruction. (second order within the bulk of the)

  • "hybrid". (Defaults to)

Raises:

ValueError – If parsed method is unknown.

Returns:

the gradient of the volume in the three directions.

Return type:

np.ndarray

classmethod get_het_normal_strain(displacement, g_vector, voxel_size, gradient_method='hybrid')[source]#

Compute the heterogeneous normal strain, i.e. the gradient of the displacement projected along the measured Bragg peak direction.

Parameters:
  • displacement (np.ndarray) – the displacement array

  • g_vector (np.ndarray | tuple | list) – the position of the

  • peak (measured Bragg)

  • voxel_size (np.ndarray | tuple | list) – voxel size of the

  • array

  • gradient_method (str, optional) – the method employed to

  • gradient. (compute the gradient. "numpy" is the traditional)

  • and ("hybrid" compute first order gradient at the surface)

  • reconstruction. (second order within the bulk of the)

  • "hybrid". (Defaults to)

Returns:

the heterogeneous normal strain

Return type:

np.ndarray

classmethod get_structural_properties(complex_object, isosurface, g_vector, hkl, voxel_size, phase_factor=-1, handle_defects=False, support_parameters=None)[source]#

Main method used in the post-processing workflow. The method computes all the structural properties of interest in BCDI (amplitude, phase, displacement, displacement gradient, heterogeneous strain d-spacing and lattice parameter maps.)

Parameters:
  • complex_object (np.ndarray) – the reconstructed object (rho e^(i phi))

  • g_vector (np.ndarray | tuple | list) – the reciprocal space node on which the displacement gradient must be projected.

  • hkl (tuple | list) – the probed Bragg reflection. voxel_size (np.ndarray | tuple | list): the voxel size of the 3D array.

  • phase_factor (int, optional) – the factor the phase should should be multiplied by, depending on the FFT convention used. Defaults to -1 (PyNX convention in Phase Retrieval, in PyNX scattering, use 1).

  • handle_defects (bool, optional) – whether a defect is present in the reconstruction, in this case phasing processing and strain computation is different. Defaults to False.

Returns:

the structural properties of the object in the form of

a dictionary. Each key corresponds to one quantity of’ interest, including: amplitude, support, phase, displacement, displacement_gradient (in all three directions), het. (heterogeneous) strain using various methods, d-spacing, lattice parameter 3D maps. hkl, g_vector and voxel size are also returned.

Return type:

dict

Examples#

Post-processing is typically handled by BcdiPipeline:

from cdiutils.pipeline import BcdiPipeline

pipeline = BcdiPipeline(param_file_path="config.yml")
pipeline.preprocess()
pipeline.phase_retrieval()

# Post-processing includes strain, displacement calculation
pipeline.postprocess()

See Also#

BcdiPipeline : Uses PostProcessor for result analysis PyNXPhaser : Provides reconstructed objects for post-processing