UB Algorithm

UBAlgorithm implements the orientation-matrix (UB) determination used by TAS. It builds the U matrix from indexed peaks and the sample’s B matrix, supporting one-, two-, three-, and many-peak determinations.

Overview

Source module:

tavi.library.ubalgorithm.ub

Primary class:

class tavi.library.ubalgorithm.ub.UBAlgorithm(sample: Sample, instrument: Instrument)[source]

Calculate UB.

find_u_from_one_peak_and_scattering_plane(peak: DataPoint, scattering_plane: tuple[tuple, tuple], ei: float, ef: float) ndarray[source]

Calculate U matrix from one peak and a scattering plane.

find_u_from_two_peaks(peaks: tuple[DataPoint, DataPoint]) ndarray[source]

Calculate U matrix from two peaks.

r_mat can be removed later when goniometer is implemented as it can be calculated from peak.angles.

Follow Eq.76-81 and Eq.83-88. We assume q_3 is perpendicular from the two peaks

find_ub_from_multiple_peaks(peaks: tuple[DataPoint, ...]) ndarray[source]

Calculate U matrix from three peaks.

r_mat can be removed later when goniometer is implemented as it can be calculated from peak.angles.

Follow Eq.89-98.

find_ub_from_three_peaks(peaks: tuple[DataPoint, DataPoint, DataPoint]) ndarray[source]

Calculate U matrix from three peaks.

r_mat can be removed later when goniometer is implemented as it can be calculated from peak.angles.

Follow Eq.83-90.

plane_normal_from_two_peaks(peaks: tuple[DataPoint, DataPoint]) tuple[ndarray, ndarray][source]

Calculate plane_normal and in_plane reflection.

Both are vectors representing peaks in Q_lab.

Method Notes

find_u_from_one_peak_and_scattering_plane

  • Determines U from a single peak plus a defined scattering plane. The second in-plane reference is chosen to be as orthogonal as possible to the peak.

find_u_from_two_peaks

  • Determines U from two non-collinear peaks, assuming the cross product defines the out-of-plane direction.

find_ub_from_three_peaks / find_ub_from_multiple_peaks

  • Determine the full UB from three peaks, or a least-squares UB from many peaks.

plane_normal_from_two_peaks

  • Returns the scattering-plane normal implied by two peaks.

Coordinate Conventions

The library computes UB in the Mantid frame. Use tavi.library.experiment.utilities.mantid_to_spice() (and its inverse spice_to_mantid) to convert to/from the SPICE frame. Both accept a version argument ("new" by default, "old" for the legacy transform).

Minimal Example

from tavi.library.experiment.utilities import mantid_to_spice

# tas.ub returns the UB matrix in the Mantid frame.
ub_mantid = tas.ub(peaks=(peaks[0], peaks[1]))
ub_spice = mantid_to_spice(ub_mantid)