TAS (Triple-Axis)

TAS is the top-level entry point of the TAVI library. It ties together an Instrument, a Sample, and an Experiment, and exposes the high-level operations: UB-matrix determination, resolution calculation, and scan browsing.

Overview

Source module:

tavi.library.tas.triple_axis

Primary class:

class tavi.library.tas.triple_axis.TAS(instrument: Instrument, sample: Sample, experiment: Experiment | None = None, ub_convention: UBConvention = UBConvention.Spice, plugin: Any = None)[source]

Triple-axis class. Main function for tavi library.

Next step is implement resolution calculation from tavi.library.resolution module.

browse(scan_list: list[int], show_fits: bool = True, fit_package: FitPackage = FitPackage.lmfit, model_dict: List[Tuple] = [], with_resolution_bar: bool = False, show_components: bool = False, def_x: str = None, def_y: str = None, xlim: float | list[float] = None, ylim: float | list[float] = None, projection_axis: int = 0) None[source]

Browse scan with options to show resolution bar.

If resolution bar is set, show_fits must be true as reso bar’s positions are determined by fit center. When show_components is set, each fitted component (peak, linear background, …) is also plotted separately. A scalar xlim/ylim pads the axis symmetrically around the data range (e.g. 1.1 widens the x-axis to 1.1x the data span about its midpoint); a [min, max] list sets it directly.

Parameters:
  • scan_list – Scan numbers to browse.

  • show_fits – Overlay the fitted curve on each scan. Must be True when with_resolution_bar is set.

  • fit_package – Fitting backend used to fit each scan.

  • model_dict – Models passed to the fit (peak, background, …).

  • with_resolution_bar – Overlay a resolution bar whose position is taken from the fit center; returns fit results and the 4D resolution for intensity export.

  • show_components – Plot each fitted component separately in addition to the total fit.

  • def_x – Name of the motor/field to use for the x-axis. Defaults to the scan’s default if None.

  • def_y – Name of the detector/field to use for the y-axis. Defaults to the scan’s default if None.

  • xlim – x-axis limits. A scalar pads symmetrically about the data midpoint; a [min, max] list sets the range directly.

  • ylim – y-axis limits, interpreted like xlim.

  • projection_axis – Axis along which the resolution bar is projected.

browse_resolution_ellipse(scan_list: list[int], xlabel: str | None = None, ylabel: str | None = None, fit_package: FitPackage = FitPackage.lmfit, model_dict: List[Tuple] = [(ModelName.Gaussian, {'guess': True})]) None[source]

Plot the resolution ellipse for each scan in a grid of subplots.

Parameters:
  • scan_list – Scan numbers to plot.

  • xlabel – Custom x-axis label for each subplot. Left unlabeled if None.

  • ylabel – Custom y-axis label for each subplot. Left unlabeled if None.

  • fit_package – Fitting backend used to locate each peak center.

  • model_dict – Models passed to the fit when locating peak centers.

calculate_resolution(model: ResolutionModel = ResolutionModel.CooperNathans, axes: tuple | None = None) None[source]

Utilize Resolution class.

resolution_bar(scan_list: list[int], ax: int = 0, model_dict: List[Tuple] = [(ModelName.Gaussian, {'guess': True})]) tuple[list[float], list][source]

Compute the coherent FWHM resolution bar for each scan.

ub(peaks: tuple[DataPoint, ...], scattering_plane: tuple[tuple, tuple] | None = None, reset_ub: bool = False) ndarray[source]

Calculate ub matrix from 1,2,3 or multiple peaks.

UB convention:

class tavi.library.tas.triple_axis.UBConvention(*values)[source]

Convention used to define the UB matrix.

Mantid = 'Mantid convention.'
Spice = 'Spice convention.'

Method Notes

ub

  • Determines the UB matrix from 1, 2, 3, or more peaks. With a single peak a scattering_plane must be supplied. Delegates to UBAlgorithm.

calculate_resolution

  • Builds the Resolution object (default Cooper-Nathans) used by downstream resolution-ellipse calculations.

browse / browse_resolution_ellipse / resolution_bar

  • Plot a grid of scans (optionally with fits and resolution bars) and visualize per-scan resolution ellipses. fit_package and model_dict control how each scan is fit.

Minimal Example

from tavi.library.Instrument.instrument import Instrument, InstrumentCatalog
from tavi.library.experiment.experiment import Experiment
from tavi.library.experiment.enum import FixedEnergyMode
from tavi.library.tas.triple_axis import TAS

experiment = Experiment(mode=FixedEnergyMode.FIX_Ef, fixed_energy=14.503)
sample = experiment.create_sample("/path/to/UBConf/UBmatrix.dat")
tas = TAS(Instrument(instrument_catalog=InstrumentCatalog.HB1A4C), sample, experiment)

# Refine the UB matrix from two indexed peaks.
ub = tas.ub(peaks=(peaks[0], peaks[1]))