SetupRefiner#
- class cbclib.SetupRefiner(parent, bounds, basis, fidxs, frames, hkl, tilts, width, alpha=0.0)[source]#
Setup refinement class. It employs
cbclib.CBDModelCBD 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), whereNis 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.
- 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, whered_tolis the tolerance of lattice constants [0.0 - 1.0] andang_tolis 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
- 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.
- generate_samples(x)[source]#
Return a sample position and alignment.
- Parameters
x (
ndarray) – Refinement solution.- Return type
- Returns
A new sample object.
- generate_streaks(x)#
Generate a CBD pattern and return a set of predicted diffraction streaks.
- get_bounds()#
Return lower and upper sample refinement bounds.
- patterns_dataframe(x)#
Generate a CBD pattern in
pandas.DataFrametable format.