CBCTable#

class cbclib.CBCTable(table, setup, crop=None)[source]#

Convergent beam crystallography tabular data. The data is stored in pandas.DataFrame table. A table must contain the following columns:

  • frames : Frame index.

  • index : Diffraction streak index.

  • x, y : x and y pixel coordinate.

  • p : Normalised pattern value. The value lies in (0.0 - 1.0) interval.

  • rp : Reflection profiles.

  • I_raw : Raw photon count.

  • bgd : Background intensity.

  • h, k, l : Miller indices.

  • sfac : Crystal structure factors.

  • xtal : Crystal diffraction efficiencies.

Parameters
drop_duplicates(method='keep_best')[source]#

Discard the pixel data, that has duplicate x, y coordinates.

Parameters

method (str) –

Choose the policy of dealing with the pixel data that has duplicate x and y coordinates:

  • keep_all : Keep duplicated data.

  • keep_best : Keep the pixels that have higher likelihood value p.

  • ignore : Discard duplicated data.

Return type

DataFrame

Returns

New CBC table with the duplicate data discarded.

fourier_index(samples, qx_arr, qy_arr, qz_arr, num_threads=1)[source]#

Map the measured normalised intensities to the reciprocal space. Returns a cbclib.Map3D 3D data container capable of performing the auto Fourier indexing.

Parameters
  • samples (ScanSamples) – Set of scan samples.

  • qx_arr (ndarray) – Array of reciprocal x coordinates.

  • qy_arr (ndarray) – Array of reciprocal y coordinates.

  • qz_arr (ndarray) – Array of reciprocal z coordinates.

  • num_threads (int) – Number of threads used in the calculations.

Return type

FourierIndexer

Returns

3D data container of measured normalised intensities.

generate_kins(basis, samples, num_threads=1)[source]#

Convert diffraction pattern locations to incoming wavevectors. The incoming wavevectors are normalised and specify the spatial frequencies of the incoming beam that bring about the diffraction signal measured on the detector.

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

  • samples (ScanSamples) – Set of scan samples.

  • num_threads (int) – Number of threads used in the calculations.

Raises

AttributeError – If Miller indices (‘h’, ‘k’, ‘l’) are not present in the CBC table.

Return type

ndarray

Returns

A set of incoming wavevectors.

get_crop()[source]#

Return the region of interest on the detector plane.

Return type

Crop

Returns

A new crop object with the ROI, inferred from the CBC table.

get_frames(frames)[source]#

Return a subset of frames frames.

Parameters

frames (Union[int, slice, ndarray, List[int], Tuple[int]]) – Frame indices.

Return type

CBCTable

Returns

A new CBCTable with a subset of frames.

classmethod import_csv(path, setup)[source]#

Initialize a CBC table with a CSV file path and an experimental geometry object setup.

Parameters
  • path (str) – Path to the CSV file.

  • setup (ScanSetup) – Experimental geometry.

Return type

CBCTable

Returns

A new CBC table object.

classmethod import_hdf(path, key, setup)[source]#

Initialize a CBC table with data saved in a HDF5 file path at a key key inside the file and an experimental geometry object setup.

Parameters
  • path (str) – Path to the HDF5 file.

  • key (str) – The group identifier in the HDF5 file.

  • setup (ScanSetup) – Experimental geometry.

Return type

CBCTable

Returns

A new CBC table object.

pattern_dataframe(frame)[source]#

Return a single pattern table. The x, y coordinates are transformed by the crop attribute.

Parameters

frame (int) – Frame index.

Return type

DataFrame

Returns

A pandas.DataFrame table.

pattern_dict(frame)[source]#

Return a single pattern table in dict format. The x, y coordinates are transformed by the crop attribute.

Parameters

frame (int) – Frame index.

Return type

Dict[str, ndarray]

Returns

A pattern table in dict format.

pattern_image(frame, key='rp')[source]#

Return a CBC pattern image array of the given attribute key. The x, y coordinates are transformed by the crop attribute.

Parameters
  • frame (int) – Frame index.

  • key (str) – Attribute’s name.

Return type

ndarray

Returns

A pattern image array.

refine_samples(bounds, basis, hkl, samples, width, alpha=0.0)[source]#

Return a SampleRefiner object designed to perform the sample refinement. The sample refinement yields a set of sample parameters, that attain the best fit between simulated and experimentally measured patterns. The refinement is performed for each pattern separately.

Parameters
  • bounds (ndarray) – 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 crystal lattice unit cell.

  • hkl (ndarray) – Array of Miller indices used in the refinement.

  • samples (ScanSamples) – Sample object. The object is given by the rotation matrix and a sample position.

  • 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.

Return type

SampleRefiner

Returns

A CBC sample refinement object.

See also

cbclib.SampleRefiner : CBC sample refiner class.

refine_setup(bounds, basis, hkl, tilts, width, alpha=0.0)[source]#

Return a SetupRefiner object designed to perform the setup refinement. Setup refinement yields a scattering geometry parameters, that attain the best fit between simulated and experimentally measured patterns. The refinement is performed for the whole scan in one go.

Parameters
  • bounds (ndarray) – 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 crystal lattice unit cell.

  • sample – Sample object. The object is given by the rotation matrix and a sample position.

  • q_abs – Size of the recpirocal space. Reciprocal vectors are normalised, and span in [0.0 - 1.0] interval.

  • 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.

Return type

SetupRefiner

Returns

A CBC setup refinement object.

See also

cbclib.SetupRefiner : CBC setup refinement class.

scale(xtal_shape, basis, samples, num_threads=1)[source]#

Return a IntensityScaler CBC dataset intensity scaler. The scaler generates a crystal diffraction efficiency map and structure factors based on diffraction signal. The intensity scaling algorithm uses the crystal basis and sample objects to project the diffraction signal onto the crystal plane.

Parameters
  • xtal_shape (Tuple[int, int]) – Crystal plane grid shape.

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

  • samples (ScanSamples) – Set of scan samples.

  • num_threads (int) – Number of threads to be used in the calculations.

Raises

AttributeError – If Miller indices (‘h’, ‘k’, ‘l’) are not present in the CBC table.

Return type

IntensityScaler

Returns

A CBC dataset intensity scaler.

update_crop(crop=None)[source]#

Return a new CBC table with the updated region of interest.

Parameters

crop (Optional[Crop]) – A new region of interest.

Return type

CBCTable

Returns

A new CBC table with the updated ROI.