SampleRefiner#

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

Sample refinement class. It employs cbclib.CBDModel CBD pattern prediction to find how well the current estimate of sample positions and alignments 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 sample 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.

  • rmats (ndarray) – A set of sample’s rotation matrices.

  • smp_ds (ndarray) – A set of focus-to-sample distances [m].

  • 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) – Refinement solution.

Return type

Basis

Returns

A new experimental setup.

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

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

Parameters
Return type

ndarray

Returns

A set of (min, max) pairs for sample 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.