SetupRefiner#

class cbclib.SetupRefiner(parent, bounds, basis, fidxs, frames, hkl, tilts, width, alpha=0.0)[source]#

Setup refinement class. It employs cbclib.CBDModel CBD pattern prediction to find how well the current estimate of scattering geometry parameters fits with the experimentally measured patterns. The class provides a method to calculate the fitness criterion, which is based on cross-entropy between the experimentally measured and predicted patterns.

Parameters
  • parent (ReferenceType[CBCTable]) – Reference to the parent CBC table.

  • bounds (InitVar) – Bounds for setup refinement variables. A set of (min, max) pairs of the shape (N, 2), where N is the number of variables. Each of the terms is diregarded in the refinement process, if the corresponding bounds are equal to 0.

  • basis (Basis) – Basis vectors of lattice unit cell.

  • fidxs (ndarray) – Array of first indices pertaining to different patterns.

  • frames (ndarray) – Frame indices of the measured patterns.

  • hkl (ndarray) – Set of reciprocal lattice points used in the prediction.

  • tilts (ndarray) – A set of tilt angles of sample rotation.

  • width (float) – Diffraction streak width in pixels. The value is used to generate a predicted CBC pattern.

  • alpha (float) – Regularisation term in the loss function.

filter_hkl(x)#

Update a set of reciprocal lattice points used in the prediction. The points are taken from inside the sphere of radius q_abs, that fall into the Bragg condition.

Parameters

x (ndarray) – Refinement solution.

fitness(x, num_threads=1)#

Calculate the marginal log-likelihood, that the experimentally measured pattern corresponds to the predicted CBD pattern.

Parameters

x (ndarray) – Refinement solution.

Return type

List[float]

Returns

Marginal log-likelihood.

generate_basis(x)[source]#

Return an experimental setup.

Parameters

x (ndarray) – Refinementa solution.

Return type

Basis

Returns

A new experimental setup.

classmethod generate_bounds(lat_tol, foc_tol, rot_tol, z_tol, tilt_tol, frames, x0=None)[source]#

Return a set of bounds for setup refinement variables based on the given set of tolerances.

Parameters
  • lat_tol (Tuple[float, float]) – A tuple of (d_tol, ang_tol) tolerances, where d_tol is the tolerance of lattice constants [0.0 - 1.0] and ang_tol is the tolerance of lattice angles in radians.

  • foc_tol (float) – Tolerance of the focal point [0.0 - 1.0].

  • rot_tol (float) – Tolerance of the sample rotation axis in radians. The rotation axis is defined by azymuth and inclination.

  • z_tol (float) – Tolerance of focus-to-sample distance [0.0 - 1.0].

  • tilt_tol (float) – Tolerance of sample tilt angles.

  • frames (Union[int, slice, ndarray, List[int], Tuple[int]]) – A set of frames indices.

  • x0 (Optional[ndarray]) – Initial set of refinement variables.

Return type

ndarray

Returns

A set of (min, max) pairs for setup refinement variables.

generate_models(x)#

Return a CBD pattern prediction model, that provides an interface to generate a CBD pattern in different formats.

Parameters

x (ndarray) – Refinement solution.

Return type

Dict[int, CBDModel]

Returns

A new CBD pattern prediction model.

generate_samples(x)[source]#

Return a sample position and alignment.

Parameters

x (ndarray) – Refinement solution.

Return type

ScanSamples

Returns

A new sample object.

generate_setup(x)[source]#

Return an experimental setup.

Parameters

x (ndarray) – Refinement solution.

Return type

ScanSetup

Returns

A new experimental setup.

generate_streaks(x)#

Generate a CBD pattern and return a set of predicted diffraction streaks.

Parameters

x (ndarray) – Refinement solution.

Return type

Dict[int, Streaks]

Returns

A set of predicted diffraction streaks.

get_bounds()#

Return lower and upper sample refinement bounds.

Return type

Tuple[ndarray, ndarray]

Returns

A tuple of two sets of bounds, lower and upper respectively.

patterns_dataframe(x)#

Generate a CBD pattern in pandas.DataFrame table format.

Parameters

x (ndarray) – Refinement solution.

Return type

DataFrame

Returns

A predicted CBD pattern.

patterns_image(x)#

Generate a CBD pattern and return a mask where the streaks are located on the detector.

Parameters

x (ndarray) – Refinement solution.

Return type

ndarray

Returns

A predicted CBD pattern mask.