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.
- 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, q_summing=False)[source]
- 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, q_summing=False)[source]
Original background substration done using two pixels defining the area next to the specular peak that are considered background.
lr_reduction.event_reduction
Event based reduction for the Liquids Reflectometer
- class lr_reduction.event_reduction.EventReflectivity(scattering_workspace, direct_workspace, signal_peak, signal_bck, norm_peak, norm_bck, specular_pixel, signal_low_res, norm_low_res, q_min=None, q_step=-0.02, q_max=None, tof_range=None, theta=1.0, instrument=None, functional_background=False, dead_time=False, paralyzable=True, dead_time_value=4.2, dead_time_tof_step=100)[source]
Bases:
objectEvent based reflectivity calculation. List of items to be taken care of outside this class: - Edge points cropping - Angle offset - Putting runs together in one R(q) curve - Scaling factors
- DEFAULT_4B_SAMPLE_DET_DISTANCE = 1.83
- DEFAULT_4B_SOURCE_DET_DISTANCE = 15.75
- DELTA_KZ_VS_QZ = 3
- INSTRUMENT_4A = 0
- INSTRUMENT_4B = 1
- KZI_VS_KZF = 1
- QX_VS_QZ = 0
- THETAF_VS_WL = 4
- bck_subtraction(normalize_to_single_pixel=False, q_bins=None, wl_dist=None, wl_bins=None, q_summing=False)[source]
Higher-level call for background subtraction. Hides the ranges needed to define the ROI.
- extract_meta_data_4B()[source]
4B-specific meta data
Distance from source to sample was 13.63 meters prior to the source to detector distance being determined with Bragg edges to be 15.75 m.
- norm_bck_subtraction()[source]
Higher-level call for background subtraction for the normalization run.
- off_specular(x_axis=None, x_min=-0.015, x_max=0.015, x_npts=50, z_min=None, z_max=None, z_npts=-120, bck_in_q=None)[source]
Compute off-specular :param x_axis: Axis selection :param x_min: Min value on x-axis :param x_max: Max value on x-axis :param x_npts: Number of points in x (negative will produce a log scale) :param z_min: Min value on z-axis (if none, default Qz will be used) :param z_max: Max value on z-axis (if none, default Qz will be used) :param z_npts: Number of points in z (negative will produce a log scale)
- slice(x_min=0.002, x_max=0.004, x_bins=None, z_bins=None, refl=None, d_refl=None, normalize=False)[source]
Retrieve a slice from the off-specular data.
- specular(q_summing=False, tof_weighted=False, bck_in_q=False, clean=False, normalize=True)[source]
Compute specular reflectivity.
For constant-Q binning, it’s preferred to use tof_weighted=True.
- Parameters:
q_summing – turns on constant-Q binning
tof_weighted – if True, binning will be done by weighting each event to the DB distribution
bck_in_q – if True, the background will be estimated in Q space using the constant-Q binning approach
clean – if True, and Q summing is True, then leading artifact will be removed
normalize – if True, and tof_weighted is False, normalization will be skipped
- specular_unweighted(q_summing=False, normalize=True)[source]
Simple specular reflectivity calculation. This is the same approach as the original LR reduction, which sums up pixels without constant-Q binning. The original approach bins in TOF, then rebins the final results after transformation to Q. This approach bins directly to Q.
- lr_reduction.event_reduction.apply_dead_time_correction(ws, template_data)[source]
Apply dead time correction, and ensure that it is done only once per workspace. :param ws: workspace with raw data to compute correction for :param template_data: reduction parameters
- lr_reduction.event_reduction.compute_resolution(ws, default_dq=0.027, theta=None)[source]
Compute the Q resolution from the meta data. :param theta: scattering angle in radians
- lr_reduction.event_reduction.get_dead_time_correction(ws, template_data)[source]
Compute dead time correction to be applied to the reflectivity curve. The method will also try to load the error events from each of the data files to ensure that we properly estimate the dead time correction. :param ws: workspace with raw data to compute correction for :param template_data: reduction parameters
lr_reduction.output
Write R(q) output
lr_reduction.peak_finding
lr_reduction.reduction_template_reader
RefRed template reader. Adapted from Mantid code.
- class lr_reduction.reduction_template_reader.ReductionParameters[source]
Bases:
object- from_dict(data_dict, permissible=True)[source]
Update object’s attributes with a dictionary with entries of the type attribute_name: attribute_value.
Parameters
- permissible: bool
allow keys in data_dict that are not attribute names of ReductionParameters instances. Reading from data_dict will result in this instance having new attributes not defined in __init__()
Raises
- ValueError
when permissible=False and one entry (or more) of the dictionary is not an attribute of this object
- lr_reduction.reduction_template_reader.getBoolElement(dom, tag, true_tag='true', default=False)[source]
lr_reduction.template
Reduce a data run using a template generated by RefRed
- lr_reduction.template.process_from_template(run_number, template_path, q_summing=False, normalize=True, tof_weighted=False, bck_in_q=False, clean=False, info=False)[source]
The clean option removes leading zeros and the drop when doing q-summing
- lr_reduction.template.process_from_template_ws(ws_sc, template_data, q_summing=False, tof_weighted=False, bck_in_q=False, clean=False, info=False, normalize=True, theta_value=None, ws_db=None)[source]
lr_reduction.time_resolved
Time-resolved data reduction
- lr_reduction.time_resolved.plot_slices(reduced, title, time_interval, file_path, offset=10, show=True)[source]
- lr_reduction.time_resolved.reduce_30Hz_from_ws(meas_ws_30Hz, ref_ws_30Hz, data_60Hz, template_data, scan_index=1, template_reference=None, q_summing=False)[source]
Perform 30Hz reduction @param meas_ws_30Hz: Mantid workspace of the data we want to reduce @param ref_ws_30Hz: Mantid workspace of the reference data, take with the same config @param data_60Hz: reduced reference data at 60Hz @param template_data: template data object (for 30Hz) @param scan_index: scan index to use within the template.
- lr_reduction.time_resolved.reduce_30Hz_slices(meas_run_30Hz, ref_run_30Hz, ref_data_60Hz, template_30Hz, time_interval, output_dir, scan_index=1, create_plot=True, template_reference=None, q_summing=False)[source]
- lr_reduction.time_resolved.reduce_30Hz_slices_ws(meas_ws_30Hz, ref_run_30Hz, ref_data_60Hz, template_30Hz, time_interval, output_dir, scan_index=1, create_plot=True, template_reference=None, q_summing=False)[source]
Perform 30Hz reduction @param meas_ws_30Hz: workspace of the data we want to reduce @param ref_ws_30Hz: workspace of the reference data, take with the same config @param ref_data_60Hz: file path of the reduce data file at 60Hz @param template_30Hz: file path of the template file for 30Hz @param time_interval: time step in seconds @param scan_index: scan index to use within the template.
- lr_reduction.time_resolved.reduce_60Hz_slices(meas_run, template_file, time_interval, output_dir, scan_index=1, create_plot=True)[source]
- lr_reduction.time_resolved.reduce_60Hz_slices_ws(meas_ws, template_file, time_interval, output_dir, scan_index=1, create_plot=True)[source]
Perform 30Hz reduction @param meas_ws: workspace of the data we want to reduce @param template_file: autoreduction template file @param time_interval: time step in seconds @param scan_index: scan index to use within the template.
lr_reduction.utils
- lr_reduction.utils.amend_config(new_config: dict = None, data_dir: str | list = None, data_dir_insert_mode: str = 'prepend') None[source]
Context manager to safely modify Mantid Configuration Service while the function is executed.
Parameters
- new_config
(key, value) pairs to substitute in the configuration service
- data_dir
prepend one (when passing a string) or more (when passing a list) directories to the list of data search directories. Alternatively, replace instead of prepend.
- data_dir_insert_mode
How to insert the data directories. Options are: “prepend” (default) and “replace”.
lr_reduction.workflow
Autoreduction process for the Liquids Reflectometer
- lr_reduction.workflow.assemble_results(first_run, output_dir, average_overlap=False, is_live=False)[source]
Find related runs and assemble them in one R(q) data set
- lr_reduction.workflow.reduce(ws, template_file, output_dir, average_overlap=False, q_summing=False, bck_in_q=False, is_live=False)[source]
Function called by reduce_REFL.py, which lives in /SNS/REF_L/shared/autoreduce and is called by the automated reduction workflow.
If average_overlap is used, overlapping points will be averaged, otherwise they will be left in the final data file.
- Parameters:
average_overlap – if True, the overlapping points will be averaged
q_summing – if True, constant-Q binning will be used
bck_in_q – if True, and constant-Q binning is used, the background will be estimated along constant-Q lines rather than along TOF/pixel boundaries.
- lr_reduction.workflow.reduce_explorer(ws, ws_db, theta_pv=None, center_pixel=145, db_center_pixel=145, peak_width=10)[source]