Reference

This is the auto-generated reference from the doc strings in the source code.

Instrument

The baseline for loading a scanning instrument

Each instrument will have its own module that declares a class inheriting from ScanningInstrument. The abstract base class is used to ensure that the derived classes define the necessary methods to run any generic scripts.

class src.Instrument.ScanningInstrument[source]

The base class for scanning measurement instruments.

TIMINGS

The list of valid waitfor keywords.

check_move_pos(pos)[source]

Check whether the position is valid and return True or False

Parameters:pos (str) – The sample changer position
static convert_file(file_path)[source]

Turn a CSV run list into a full python script

This function allows the user to create simple scripts with Excel, then turn them into full Python scripts that can be edited and customised as needed.

detector_lock(state=None)[source]

Query or activate the detector lock

Parameters:state (bool or None) – If None, return the current lock state. Otherwise, set the new lock state
Returns:
  • The current lock state as a bool
  • Locking the detector prevents turning the detector on or off
  • and bypasses the detector checks.
detector_on(powered=None, delay=True)[source]

Query and set the detector’s electrical state.

Parameters:
  • on (bool or None) – If None, then return the detector’s current state. If True, turn the detector on. If False, turn the detector off.
  • delay (bool) – If changing the detector state, whether to wait for the detector to finish warming up or powering down before continuing the script.
  • Returns
  • bool – If the detector is currently on
do_sans(title, pos=None, thickness=1.0, dae=None, blank=False, aperature='', **kwargs)[source]

A wrapper around measure which ensures that the instrument is not in transmission mode

Look at the documentation for measure to see the full set of parameters accepted.

do_trans(title, pos=None, thickness=1.0, dae=None, blank=False, aperature='', **kwargs)[source]

A wrapper around measure which ensures that the instrument is not in transmission mode.

Look at the documentation for measure to see the full set of parameters accepted.

enumerate_dae()[source]

List the supported DAE modes on this beamline.

measure(title, pos=None, thickness=1.0, trans=False, dae=None, blank=False, aperature='', **kwargs)[source]

Take a sample measurement.

Parameters:
  • title (str) – The title for the measurement. This is the only required parameter.
  • pos – The sample position. This can be a string with the name of a sample position or it can be a function which moves the detector into the desired position. If left undefined, the instrument will take the measurement in its current position.
  • thickness (float) – The thickness of the sample in millimeters. The default is 1mm.
  • trans (bool) – Whether to perform a transmission run instead of a sans run.
  • dae (str or func) – This option allows setting the default dae mode. It takes a string that contains the name of the DAE mode to be used as the new default. For example, >>> measure(“Test”, frames=10, dae=”event”) Is equivalent to >>> set_default_dae(setup_dae_event) >>> measure(“Test”, frames=10) If dae is a function, then the function is set to the default >>> measure(“Test”, frames=10, dae=foo) Is equivalent to >>> set_default_dae(foo) >>> measure(“Test”, frames=10) To get a full list of the supported dae modes, run >>> enumerate_dae()
  • aperature (str) – The aperature size. e.g. “Small” or “Medium” A blank string (the default value) results in the aperature not being changed.
  • blank (bool) – If this sample should be considered a blank/can/solvent measurement
  • **kwargs – This function takes two kinds of keyword arguments. If given a block name, it will move that block to the given position. If given a time duration, then that will be the duration of the run.

Examples

>>> measure("H2O", frames=900)

Perform a SANS measurment in the current position on a 1 mm thick water sample until the proton beam has released 900 proton pulses (approx 15 minutes).

>>> measure("D2O", "LT", thickness=2.0, trans=True, Phi=3, uamps=10)

Move to sample changer position LT, then adjust the CoarseZ motor to 38 mm. Finally, take a transmission measurement on a 2 mm thick deuterium sample for 10 µA hours of proton current. (approx 15 minutes).

measure_file(file_path, forever=False)[source]

Perform a series of measurements based on a spreadsheet

The file should contain comma separated values. Excel can easily produce files of this sort. The first line of the file is the header with each field giving the name of a parameter to the measure function. As always, the title parameter is mandatory. Each subsequent line of the file represents a single measurement with the fields indicating that values to pass to their corresponding keywords. If a cell is blank, the keyword’s default parameter it used. Boolean values are represented by True and False and are not case sensitive.

The script is run through the simulator to check for errors before attempting a real run.

Parameters:
  • file_path (str) – The location of the script file
  • forever (bool) – If set to True, the instrument will repeatedly run the script manually stopped. This can be useful for an overnight run where you want to keep measureing until the users return.
static printsamplepars()[source]

Display the basic sample parameters on the console.

sanitised_timings(kwargs)[source]

Include only the keyword arguments for run timings.

Parameters:
  • kwargs (dict) –
  • dictionary of keyword arguments (A) –
Returns:

  • dict
  • Keyword arguments accepted by gen.waitfor

static set_aperature(size)[source]

Set the beam aperature to the desired size

Parameters:size (str) – The aperature size. e.g. “Small” or “Medium” A blank string (the default value) results in the aperature not being changed.
set_default_dae(mode=None, trans=False)[source]

Set the default DAE mode for SANS or TRANS measuremnts.

Parameters:
  • mode (str or function) – If the mode is a function, call that function to set the DAE mode. If the mode is a string, call the function whose name is “setup_dae_” followed by that string.
  • trans (bool) – If true, set the default transmission instead of the default SANS mode.
set_measurement_id(value)[source]

Set the measurement id in the journal.

Parameters:
  • value (str) – The new id
  • function should perform no physical changes to the (This) –
  • The only change should be in the MEASUREMENT (beamline.) –
  • stored in the journal for the next run, which should be (value) –
  • to the new value. (set) –
set_measurement_label(value)[source]

Set the sample label in the journal.

Parameters:
  • value (str) – The new sample label
  • function should perform no physical changes to the (This) –
  • The only change should be in the MEASUREMENT (beamline.) –
  • stored in the journal for the next run, which should be (value) –
  • to the new value. (set) –
set_measurement_type(value)[source]

Set the measurement type in the journal.

Parameters:
  • value (str) – The new measurement type
  • function should perform no physical changes to the (This) –
  • The only change should be in the MEASUREMENT (beamline.) –
  • stored in the journal for the next run, which should be (value) –
  • to the new value. (set) –
setup_dae_bsalignment()[source]

Configure wiring tables for beamstop alignment.

setup_dae_event()[source]

Set the wiring tables for event mode

setup_dae_histogram()[source]

Set the wiring tables for histogram mode

setup_dae_nr()[source]

Set the wiring tables for a neutron reflectivity measurement

setup_dae_nrscanning()[source]

Set the wiring tables for performing scans during neutron reflectivity

setup_dae_scanning()[source]

Set the wiring tables for a scan

setup_dae_transmission()[source]

Set the wiring tables for a transmission measurement

reduction

This module automates the creation of reduction scripts from the run log.

src.reduction.connect_samples(runs, test)[source]

Group runs with the same sample

Parameters:
  • run (list) – A list of XML nodes for the run numbers to investigate
  • test (function) – A boolean to check if the run should be included
Returns:

Return type:

A dictionary of runs with their samples as the key.

src.reduction.console_oracle(sample, blanks)[source]

Have the use identify the blank for a sample

The list of possible blanks will be enumerated and displayed to the user. The user can then pick an iterm off the list from the keyboard.

Parameters:
  • sample (str) – The name of the sample being queries
  • blanks (list) – A list of possible blank samples
src.reduction.get_echo_id(run)[source]

Get the spin echo tune id

src.reduction.get_kind(run)[source]

What type of measuremented was performed?

src.reduction.get_run_number(run)[source]

Get the run number for the measurement

src.reduction.get_sample(run)[source]

Get the name of the actual sample

src.reduction.get_sel(run)[source]

Get the spin echo constant

src.reduction.identify_pairs(data, oracle=<function console_oracle>)[source]

Find the exact blanks for a set of sample runs

Parameters:
  • data (dict) – The dictionary of possible sample/blank setups extracted from the log file.
  • oracle (function) – A function that takes a sample name and a list of possible blanks and returns the name of the correct blank. The default value will print the blanks to the console and as the user to chose the correct blank.
src.reduction.is_blank(run)[source]

Was the measurement in sesans mode and on a blank?

src.reduction.is_blank_transmission(run)[source]

Was the measurement in transmission mode and on a blank?

src.reduction.is_sample(run)[source]

Was the measurement in sesans mode and on a sample?

src.reduction.is_transmission(run)[source]

Was the measurement in transmission mode and on a sample?

src.reduction.sans_connection(start, end, path)[source]

Connect the runs for a series of sesans measurements

src.reduction.sans_reduction(outfile, data, pairs, mask, direct)[source]

Create a reduction script for sans data

Parameters:
  • outfile (str) – The path where the script should be saved
  • data (dict) – The sample dictionary extracted from the sample log
  • pairs (dict) – A dictionary with sample names as the keys and the corresponding blank samples as the values
  • mask (str) – The mask file for the reduction
  • direct (int) – The run number for the direct run
src.reduction.sesans_connection(start, end, path)[source]

Connect the runs for a series of sesans measurements

src.reduction.sesans_reduction(outfile, data, pairs)[source]

Create a reduction script for sesans data

Parameters:
  • outfile (str) – The path where the script should be saved
  • data (dict) – The sample dictionary extracted from the sample log
  • pairs (dict) – A dictionary with sample names as the keys and the corresponding blank samples as the values

Util

Useful utilities for scriping

src.Util.dae_setter(suffix, measurement_type)[source]

Declare that a method sets the DAE wiring table

Parameters:
  • suffix (str) – The footer to be put on all run titles in this mode
  • measurement_type (str) – The default measurement_type to be recorded in the journal
Returns:

  • A decorator for setting the dae mode
  • This decorator was designed to work on subclasses of the
  • src.Instrument.ScanningInstrument class. The
  • following functionality is added into the class
  • 1. If the wiring tables are already in the correct state, the function – returns immediately without taking any other actions
  • 2. If the wiring tables are in a different state, the change to the wiring – tables is printed to the prompt before performing the actual change

#1 of the above is the most important, as it allows the wiring tables to be set on any function call without worrying about wasting time reloading an existing configuration

Please note that this decorator assumes that the title of the method begins with “setup_dae”, followed by the new of the state of the wiring table.

src.Util.pretty_print_time(seconds)[source]

Given a number of seconds, generate a human readable time string.

Parameters:seconds (float) – The time in seconds that the script will require.
Returns:A string giving the time needed in hours and an approximate ETA.
Return type:str
src.Util.user_script(script)[source]

A decorator to perform some sanity checking on a user script before it is run

src.Util.wait_time(call)[source]

Calculate the time spent waiting by a mock wait call.

Parameters:call (mock.Call) – A mock call that might be a waitfor command
Returns:The approximate time in seconds needed for this command.
Return type:float

Larmor

This is the instrument implementation for the Larmor beamline.

class src.Larmor.Larmor[source]

This class handles the Larmor beamline

static BSInOut(In=True)[source]

Move the Beam Stop in and out of the beam.

Parameters:In (bool) – Whether to move the beam stop in or out
static FOMin()[source]

Put the frame overload mirror into the beam.

static LongPolariserin()[source]

Put the long polariser for short wavelengths into the beam.

static ShortPolariserin()[source]

Put the short polariser for long wavelength into the beam.

get_lrange()[source]

Return the current wavelength range

get_tof_step()[source]

Get the current TOF step for the tcb

static home_pi_rotation()[source]

Calibrate the pi flipper.

static homea1()[source]

Rehome aperature 1.

static homecoarsejaws()[source]

Rehome coarse jaws.

static homes1()[source]

Rehome slit1.

static homes2()[source]

Rehome slit2. This is currentl a no-op.

movebench(angle=0.0, delaydet=True)[source]

Safely move the downstream arm

rotatebench(angle=0.0)[source]

Move the downstream arm

set_lrange(lrange)[source]

Set the current wavelength range

set_measurement_id(value)[source]

Set the measurement id in the journal.

Parameters:
  • value (str) – The new id
  • function should perform no physical changes to the (This) –
  • The only change should be in the MEASUREMENT (beamline.) –
  • stored in the journal for the next run, which should be (value) –
  • to the new value. (set) –
set_measurement_label(value)[source]

Set the sample label in the journal.

Parameters:
  • value (str) – The new sample label
  • function should perform no physical changes to the (This) –
  • The only change should be in the MEASUREMENT (beamline.) –
  • stored in the journal for the next run, which should be (value) –
  • to the new value. (set) –
set_measurement_type(value)[source]

Set the measurement type in the journal.

Parameters:
  • value (str) – The new measurement type
  • function should perform no physical changes to the (This) –
  • The only change should be in the MEASUREMENT (beamline.) –
  • stored in the journal for the next run, which should be (value) –
  • to the new value. (set) –
set_tof_step(step)[source]

Set the current TOF step for the tcb

static setup_dae_4periods(self, *args, **kwargs)[source]

Setup the instrument with four periods.

setup_dae_bsalignment(*args, **kwargs)[source]

Configure wiring tables for beamstop alignment.

static setup_dae_diffraction(self, *args, **kwargs)[source]

Set the wiring tables for a diffraction measurement

setup_dae_event(*args, **kwargs)[source]

Set the wiring tables for event mode

setup_dae_event_fastsave(*args, **kwargs)[source]

Event mode with reduced detector histogram binning to decrease filesize.

setup_dae_histogram(*args, **kwargs)[source]

Set the wiring tables for histogram mode

static setup_dae_monitorsonly(self, *args, **kwargs)[source]

Set the wiring tables to record only the monitors.

static setup_dae_monotest(self, *args, **kwargs)[source]

Setup with a mono test?

setup_dae_nr(*args, **kwargs)[source]

Set the wiring tables for a neutron reflectivity measurement

setup_dae_nrscanning(*args, **kwargs)[source]

Set the wiring tables for performing scans during neutron reflectivity

static setup_dae_polarised(self, *args, **kwargs)[source]

Set the wiring tables for a polarisation measurement.

static setup_dae_resonantimaging(self, *args, **kwargs)[source]

Set the wiring table for resonant imaging

static setup_dae_resonantimaging_choppers(self, *args, **kwargs)[source]

Set the wiring thable for resonant imaging choppers

setup_dae_scanning(*args, **kwargs)[source]

Set the wiring tables for a scan

setup_dae_sesans(*args, **kwargs)[source]

Setup the instrument for SESANS measurements.

setup_dae_transmission(*args, **kwargs)[source]

Set the wiring tables for a transmission measurement

static setup_dae_tshift(self, *args, **kwargs)[source]

Allow m1 to count as normal but to shift the rest of the detectors in order to allow counting over the frame.

static setup_pi_rotation()[source]

Initialise the pi flipper.

src.Larmor.sleep(seconds)[source]

Override the sleep function to use genie.

We need this override to ensure that simularted runs are forced to wait for real sleeps.