lr_reduction package

lr_reduction.background

lr_reduction.background.find_ranges_without_overlap(r1, r2)[source]

Returns the part of r1 that does not contain r2 When summing pixels for reflectivity, include the full range, which means that for a range [a, b], b is included. The range that we return must always exclude the pixels included in r2.

Parameters

r1list

Range of pixels to consider

r2list

Range of pixels to exclude

Returns

list

List of ranges that do not overlap with r2

lr_reduction.background.functional_background(ws, event_reflectivity, peak, bck, low_res, normalize_to_single_pixel=False, q_bins=None, wl_dist=None, wl_bins=None, wl_std=None, q_summing=False)[source]

Estimate background using a linear function over a background range that may include the specular peak. In the case where the peak is included in the background range, the peak is excluded from the background.

Parameters

wsMantid workspace

Workspace containing the data

event_reflectivityEventReflectivity

EventReflectivity object

peaklist

Range of pixels that define the peak

bcklist

Range of pixels that define the background. It contains 4 pixels, defining up to two ranges.

low_reslist

Range in the x direction on the detector

normalize_to_single_pixelbool

If True, the background is normalized to the number of pixels used to integrate the signal

q_binsnumpy.ndarray

Array of Q bins

wl_distnumpy.ndarray

Wavelength distribution for the case where we use weighted events for normatization

wl_binsnumpy.ndarray

Array of wavelength bins for the case where we use weighted events for normatization

wl_std: numpy.ndarray

Array of errors for wl_dist array

q_summingbool

If True, sum the counts in Q bins

Returns

numpy.ndarray

Reflectivity background

numpy.ndarray

Reflectivity background error

lr_reduction.background.side_background(ws, event_reflectivity, peak, bck, low_res, normalize_to_single_pixel=False, q_bins=None, wl_dist=None, wl_bins=None, wl_std=None, q_summing=False)[source]

Original background substration done using two pixels defining the area next to the specular peak that are considered background.

Parameters

wsMantid workspace

Workspace containing the data

event_reflectivityEventReflectivity

EventReflectivity object

peaklist

Range of pixels that define the peak

bcklist

Range of pixels that define the background

low_reslist

Range in the x direction on the detector

normalize_to_single_pixelbool

If True, the background is normalized to the number of pixels used to integrate the signal

q_binsnumpy.ndarray

Array of Q bins

wl_distnumpy.ndarray

Wavelength distribution for the case where we use weighted events for normatization

wl_binsnumpy.ndarray

Array of wavelength bins for the case where we use weighted events for normatization

wl_stdnumpy.nparray

Array of errors for the normalization

q_summingbool

If True, sum the counts in Q bins

Returns

numpy.ndarray

Reflectivity background

numpy.ndarray

Reflectivity background error

lr_reduction.data_info

lr_reduction.event_reduction

lr_reduction.instrument_settings

class lr_reduction.instrument_settings.InstrumentSettings(apply_instrument_settings: bool = False, source_detector_distance: float = 15.75, sample_detector_distance: float = 1.83, num_x_pixels: int = 256, num_y_pixels: int = 304, pixel_width: float = 0.7, xi_reference: float = 445, s1_sample_distance: float = 1.485, wavelength_resolution_function: str = 'name=UserFunction, Formula=L - A * exp(-k * x), L=0.07564423, A=0.13093263, k=0.34918918')[source]

Bases: object

Dataclass to store the instrument geometry parameters. Default values determined from settings.json

Attributes

source_detector_distancefloat

Distance from the source to the detector in meters

sample_detector_distancefloat

Distance from the sample to the detector in meters

num_x_pixelsint

Number of pixels in the x direction

num_y_pixelsint

Number of pixels in the y direction

pixel_widthfloat

Width of the pixels in mm

xi_referencefloat

Zero-position of slit relative to sample, in mm

s1_sample_distancefloat

Distance from the sample to the s1 aperture in mm

wavelength_resolution_functionstr

The string representation of the Mantid fit function used to evaluate the wavelength resolution

apply_instrument_settings: bool = False
num_x_pixels: int = 256
num_y_pixels: int = 304
pixel_width: float = 0.7
s1_sample_distance: float = 1.485
sample_detector_distance: float = 1.83
source_detector_distance: float = 15.75
wavelength_resolution_function: str = 'name=UserFunction, Formula=L - A * exp(-k * x), L=0.07564423, A=0.13093263, k=0.34918918'
xi_reference: float = 445

lr_reduction.mantid_utils

lr_reduction.output

Write R(q) output

class lr_reduction.output.RunCollection(average_overlap=False, stitching_configuration: StitchingConfiguration | None = None)[source]

Bases: object

A collection of runs to assemble into a single R(Q)

add(q, r, dr, meta_data, dq=None)[source]

Add a partial R(q) to the collection

Parameters

qarray

Q values

rarray

R values

drarray

Error in R values

meta_datadict

Meta data for the run

dqarray, optional

Q resolution

add_from_file(file_path)[source]

Read a partial result file and add it to the collection

Parameters

file_pathstr

The path to the file to be read

calculate_scale_factors()[source]

Calculate scale factors for each run in the collection

merge()[source]

Merge the collection of runs

plot()[source]

Plot the combined reflectivity curve for a collection of runs

Returns

str

HTML div containing the combined reflectivity curve plot

save_ascii(file_path, meta_as_json=False)[source]

Save R(Q) in ASCII format. This function merges the data before saving. It writes metadata and R(Q) data to the specified file in ASCII format. The metadata includes experiment details, reduction version, run title, start time, reduction time, and other optional parameters. The R(Q) data includes Q, R, dR, and dQ values.

Parameters

file_pathstr

The path to the file where the ASCII data will be saved.

meta_as_jsonbool, optional

If True, metadata will be written in JSON format. Default is False.

lr_reduction.output.read_file(file_path)[source]

Read a data file and extract meta data

Parameters

file_pathstr

The path to the file to be read

lr_reduction.peak_finding

lr_reduction.peak_finding.fit_signal_flat_bck(x, y, x_min=110, x_max=170, center=None, sigma=None, background=None)[source]

Fit a Gaussian peak.

Parameters

xlist

List of x values.

ylist

List of y values.

x_minint, optional

Start index of the list of points, by default 110.

x_maxint, optional

End index of the list of points, by default 170.

centerfloat, optional

Estimated center position, by default None.

sigmafloat, optional

If provided, the sigma will be fixed to the given value, by default None.

backgroundfloat, optional

If provided, the value will be subtracted from y, by default None.

Returns

cfloat

Fitted center position of the Gaussian peak.

widthfloat

Fitted width (sigma) of the Gaussian peak.

fitlmfit.model.ModelResult

The result of the fit.

lr_reduction.peak_finding.process_data(workspace, summed=True, tof_step=200)[source]

Process a Mantid workspace to extract counts vs pixel.

Parameters

workspaceMantid workspace

The Mantid workspace to process.

summedbool, optional

If True, the x pixels will be summed (default is True).

tof_stepint, optional

The TOF bin size (default is 200).

Returns

tuple of numpy.ndarray

A tuple containing:

  • tof : numpy.ndarray The time-of-flight values.

  • _x : numpy.ndarray The pixel indices.

  • _y : numpy.ndarray The summed counts for each pixel.

lr_reduction.reduction_template_reader

lr_reduction.template

lr_reduction.time_resolved

lr_reduction.typing

lr_reduction.utils

lr_reduction.web_report

lr_reduction.workflow