Reference¶
This is the auto-generated reference from the doc strings in the source code.
general.scans¶
general.scans.defaults¶
This module holds the base class for the instrument defaults. This is an abstract class which will need to be overwritten for each beamline. This design was chosen because the subclass cannot be instantiated unless all of the abstract methods have been implemented. This means that we detect mistakes in the subclass the moment that the Defaults object is created, instead of in the middle of a user run when a missing method is called.
-
class
general.scans.defaults.Defaults¶ A defaults object to store the correct functions for this instrument
-
ascan(motor, start, end, intervals, time)¶ A reimplementations of ascan from spec
Example
>>> ascan(COARSEZ, -20, 20, 40, -50)
Scan the CoarseZ motor from position -20 to position 20 (inclusive) in 1 mm steps. At each point, take measure for 50 frames (about five seconds). After the plot, the CoarseZ motor will be at position 20.
Parameters: - motor –
- axis to scan (The) –
- start –
- initial position (The) –
- stop –
- final position (The) –
- intervals –
- many steps to take between the initial and final position (How) –
- time –
- positive, the measurement time at each point in seconds. If (If) –
- the measurement frames at each point. (negative,) –
-
static
detector(**kwargs)¶ The default function for pulling a count off the detector. Takes the standard time settings (e.g. seconds, frames, uamps) as keyword arguments.
-
dscan(motor, start, end, intervals, time)¶ A reimplementations of dscan from spec
Example
>>> dscan(COARSEZ, -20, 20, 40, -50)
Scan the CoarseZ motor from 20 mm below the current position to position 20 mm above the current position (inclusive) in 1 mm steps. At each point, take measure for 50 frames (about five seconds). After the plot, the CoarseZ motor will move back to its original position.
Parameters: - motor –
- axis to scan (The) –
- start –
- initial position as an offset from the current position (The) –
- stop –
- final position as an offset from the current position (The) –
- intervals –
- many steps to take between the initial and final position (How) –
- time –
- positive, the measurement time at each point in seconds. If (If) –
- the measurement frames at each point. (negative,) –
-
static
get_units(motion)¶ Get the physical measurement units associated with a block name.
-
static
log_file()¶ Returns the name of a unique log file where the scan data can be saved.
-
populate()¶ Create Motion objects in the GLOBAL namespace for each block registered with IBEX.
-
rscan(motor, before=None, after=None, step=None, frames=None, **kwargs)¶ An ISIS specific relative scan function
This function is identical to the normal scan function, but it defaults to using relative positions, instead of absolute.
Example
>>> rscan(coarsez, -20, 20, 1, 50)
Scan the CoarseZ motor from 20 mm below the current position to position 20 mm above the current position (exclusive) in 1 mm steps. At each point, take measure for 50 frames (about five seconds). After the plot, the CoarseZ motor will move back to its original position.
Parameters: - motor –
- axis to scan (The) –
- before –
- initial position as an offset from the current position (The) –
- after –
- ending position as an offset from the current position (The) –
- step –
- absolute step size (The) –
- frames –
- number of pulse frames to measure at each point (The) –
-
scan(motion, start=None, stop=None, step=None, frames=None, **kwargs)¶ scan establishes the setup for performing a measurement scan.
Examples
>>> scan(translation, -5, 5, 0.1, 50)
This will run a scan on the translation axis from -5 to 5 (exclusive) in steps of 0.1, measuring for 50 frames at each point and taking a plot
>>> scan(translation, start=-5, stop=5, stride=0.1).plot(frames=50)
This will scan the translation access from -5 to 5 inclusive in steps of 0.1. At each point, the a measurement will be taken for 50 frames and plotted.
As a different example,
>>> s = scan(coarsez, before=-50, step=5, gaps=20)
This will create a scan on the CoarseZ axis, starting at 50 mm below the current position and continuing in 5 mm increments for another 20 measurements (for a total of 21). Note that while the scan has been created, nothing will happen until we ask the scan to act.
>>> result = s.fit(PeakFit(20), uamps=0.1)
This will perform a 0.1 uamp measurement at each point on the scan and find the peak (with a presumed width of 20 mm). At the end of the measurement, the result variable will hold the position of the observed peak.
>>> scan(translation, -5, 5, 0.1, 50, detector=specfic_spectra([[3]]))
This is similar to our original scan on translation, except that the scan will be performed on monitor 3, instead of the default spectrum. You instrument scientist may have defined other detectors that you can use to perform special scans.
The scan function itself has one mandatory parameter motion but will require another three keyword parameters to define the range of the scan. In the example above, the motion parameter was TRANSLATION and the keyword parameters were start, stop, and stride. Any set of three position parameters that uniquely define a range of motions will be accepted.
Parameters: - motion – The axis on which to perform the scan
- start – An absolute starting position for the scan.
- stop – An absolute ending position for the scan
- step – The absolue step size. The final position may be skipped if it is not an integer number of steps from the starting position.
- frames – How many frames the measurement should be performed for. If set to None or 0, then no automatic plot will be started.
- before – A relative starting position for the scan.
- after – A relative ending position for the scan
- count – The number of points to measure
- gaps – The number of steps to take
- stride – The approximate step size. The scan may shrink this step size to ensure that the final point is still included in the scan.
- detector – An optional parameter to choose how to measure the dependent variable in the scan. A set of these will have already been defined by your instrument scientist. If you need something ad hoc, then check the documentation on specific_spectra for more details
Returns: A scan object that will run through the requested points.
Return type:
-
general.scans.detector¶
This module adds a helper class for detectors.
-
class
general.scans.detector.BlockDetector(blockname, unit=None)¶ A helper class for using an IBEX block as a detector.
-
class
general.scans.detector.DaePeriods(f, pre_init, period_function=<built-in function len>, unit='Intensity')¶ This helper class aids in making detector managers that perform all of their measurements in a single DAE run, instead of constantly starting and stoping the DAE.
-
class
general.scans.detector.DetectorManager(f, unit='Intensity')¶ Manage routines for pulling data from the instrument
-
general.scans.detector.dae_periods(pre_init=<function <lambda>>, period_function=<built-in function len>, unit='Intensity')¶ Decorate to add single run number support to a detector function
-
general.scans.detector.get_block(name)¶ A simple wrapper around g.cget to give a better exception message.
-
general.scans.detector.specific_spectra(spectra_list, preconfig=<function <lambda>>)¶ Create a detector that scans over a given set of spectrum numbers.
The function takes a list of list of integers. Each inner list contains the channel numbers that should be combined for one single data plot. A MonoidList of all of the combined spectra of each inner list will be returned. In the event that there is only a single inner list, then only that single average value will be returned.
Examples
>> specific_spectra([[4], range(1000,2000)]) Will create a plot with two data points on it. The first will be all of the counts in monitor four. The second will be the combined sum of the counts in channels 1000 through 1999, inclusive.
general.scans.fit¶
The Fit module holds the Fit class, which defines common parameters for fitting routines. It also contains implementations of some common fits (i.e. Linear and Gaussian).
-
class
general.scans.fit.CentreOfMassFit¶ A fit that calculates the ‘centre of mass’ of a peak over a background.
- The algorithm implemented by this class is as follows:
- Take the minimum Y value as the background, and subtract this from
all y values - Interpolate X and Y values so that all points are continuously spaced across the range we’re interested in - Find the average X position, weighted by the corresponding Y value
If the fit fails (for example, no data was provided) then NaN is returned as the centre of mass.
The interpolation is needed because otherwise the point density may not be constant.
-
fit(x, y, err)¶ The fit function takes arrays of independent and depedentend variables. It returns a set of parameters in a format that is convenient for this specific object.
-
fit_plot_action()¶ Create a function to be called in a plotting loop to live fit the data
Returns: Return type: A function to call in the plotting loop
-
get_y(x, fit)¶ get_y takes an array of independent variables and a set of model parameters and returns the expected dependent variables for those parameters
-
readable(fit)¶ Readable turns the implementation specific set of fit parameters into a human readable dictionary.
-
title(params)¶ Give the title of the fit.
Parameters: params – The list of fit method parameters
-
class
general.scans.fit.CurveFit(degree, title)¶ A class for fitting models based on the scipy curve_fit optimizer
-
fit(x, y, err)¶ The fit function takes arrays of independent and depedentend variables. It returns a set of parameters in a format that is convenient for this specific object.
-
get_y(x, fit)¶ get_y takes an array of independent variables and a set of model parameters and returns the expected dependent variables for those parameters
-
static
guess(x, y)¶ Given a set of x and y values, make a guess as to the initial parameters of the fit.
-
-
class
general.scans.fit.DampedOscillatorFit¶ A class for fitting decaying cosine curves.
-
readable(fit)¶ Readable turns the implementation specific set of fit parameters into a human readable dictionary.
-
title(params)¶ Give the title of the fit.
Parameters: params – The list of fit method parameters
-
-
class
general.scans.fit.ErfFit¶ A simple Erf edge fitter.
y = background + scale * erf(-stretch*(x-center))
>>> scan(TRANSLATION, start=-20, stop=20, step=1).Fit(Erf, uamps=1)
Will use all of the points within 5 mm of the peak when fitting the quadratic.
-
readable(fit)¶ Readable turns the implementation specific set of fit parameters into a human readable dictionary.
-
title(fit)¶ Give the title of the fit.
Parameters: params – The list of fit method parameters
-
-
class
general.scans.fit.ExactFit¶ A class for pulling the exact data points out of a plot
-
fit(x, y, err)¶ The fit function takes arrays of independent and depedentend variables. It returns a set of parameters in a format that is convenient for this specific object.
-
fit_plot_action()¶ Create a function to be called in a plotting loop to live fit the data
Returns: Return type: A function to call in the plotting loop
-
get_y(_, fit)¶ get_y takes an array of independent variables and a set of model parameters and returns the expected dependent variables for those parameters
-
readable(fit)¶ Readable turns the implementation specific set of fit parameters into a human readable dictionary.
-
title(_)¶ Give the title of the fit.
Parameters: params – The list of fit method parameters
-
-
class
general.scans.fit.Fit(degree, title)¶ The Fit class combines the common requirements needed for fitting. We need to be able to turn a set of data points into a set of parameters, get the simulated curve from a set of parameters, and extract usable information from those parameters.
-
fit(x, y, err)¶ The fit function takes arrays of independent and depedentend variables. It returns a set of parameters in a format that is convenient for this specific object.
-
fit_plot_action()¶ Create a function to be called in a plotting loop to live fit the data
Returns: Return type: A function to call in the plotting loop
-
fit_quality(x, y, err, params)¶ Find the quality of a fit for a data set
-
get_y(x, fit)¶ get_y takes an array of independent variables and a set of model parameters and returns the expected dependent variables for those parameters
-
readable(fit)¶ Readable turns the implementation specific set of fit parameters into a human readable dictionary.
-
title(params)¶ Give the title of the fit.
Parameters: params – The list of fit method parameters
-
-
general.scans.fit.Gaussian= <general.scans.fit.GaussianFit object>¶ A gaussian fit
-
class
general.scans.fit.GaussianFit¶ A fitting class for handling gaussian peaks
-
readable(fit)¶ Readable turns the implementation specific set of fit parameters into a human readable dictionary.
-
title(params)¶ Give the title of the fit.
Parameters: params – The list of fit method parameters
-
-
general.scans.fit.Linear= <general.scans.fit.PolyFit object>¶ A linear regression
-
class
general.scans.fit.PeakFit(window=None)¶ A simple peak-finding fitter.
This is a simple class that finds the highest point in the data set. It will not find secondary peaks. It also requires a width parameter to give the size of the peak. For example,
>>> scan(TRANSLATION, start=-20, stop=20, step=1).Fit(PeakFit(5), uamps=1)
Will use all of the points within 5 mm of the peak when fitting the quadratic.
-
fit(x, y, err)¶ The fit function takes arrays of independent and depedentend variables. It returns a set of parameters in a format that is convenient for this specific object.
-
fit_quality(x, y, err, params)¶ Find the quality of a fit for a data set
-
get_y(x, fit)¶ get_y takes an array of independent variables and a set of model parameters and returns the expected dependent variables for those parameters
-
readable(fit)¶ Readable turns the implementation specific set of fit parameters into a human readable dictionary.
-
title(center)¶ Give the title of the fit.
Parameters: params – The list of fit method parameters
-
-
class
general.scans.fit.PolyFit(degree, title=None)¶ A fitting class for polynomials
-
fit(x, y, err)¶ The fit function takes arrays of independent and depedentend variables. It returns a set of parameters in a format that is convenient for this specific object.
-
get_y(x, fit)¶ get_y takes an array of independent variables and a set of model parameters and returns the expected dependent variables for those parameters
-
readable(fit)¶ Readable turns the implementation specific set of fit parameters into a human readable dictionary.
-
title(params)¶ Give the title of the fit.
Parameters: params – The list of fit method parameters
-
-
class
general.scans.fit.TopHatFit¶ A simple top hat finder.
y = abs(x-center) < width/2 ? amplitude : background
>>> scan(TRANSLATION, start=-20, stop=20, step=1).Fit(Erf, uamps=1)
-
readable(fit)¶ Readable turns the implementation specific set of fit parameters into a human readable dictionary.
-
title(fit)¶ Give the title of the fit.
Parameters: params – The list of fit method parameters
-
-
general.scans.fit.smart_number_format(x)¶ Turn numbers into strings with a smart number of digits
general.scans.monoid¶
The module defines a series of Monoid classes for handlings measurements. For the unfamiliar, a monoid is just a type that A) has a zero value and B) can be combined with other values of the same type to produce new monoids. For example, Sum is a monoid because Sum(a) + Sum(b) = Sum(a+b) and Sum(a) + Sum(0) = Sum(a).
Putting the incoming data into amonoid makes it easier to get the information out of a combined measuremnts.
-
class
general.scans.monoid.Average(x, count=1)¶ This monoid calculates the average of its values.
-
err()¶ Return the uncertainty of the current value
-
-
class
general.scans.monoid.Exact(x, count=1)¶ A monoid representing an exact measurement.
-
err()¶ Return the uncertainty of the current value
-
-
class
general.scans.monoid.ListOfMonoids(*args)¶ A modified list class with special helpers for handlings lists of Monoids
-
err()¶ Get the uncertainty values from the List
-
max()¶ Find the largest value in the list, including for uncertainty
-
min()¶ Find the smallest value in the list, including for uncertainty
-
plot(axis, xs)¶ Make an errorbar plot of a monoid onto an axis at a given set of x coordinates
-
values()¶ Get the numerical values from the List
-
-
class
general.scans.monoid.Monoid¶ The Monoid base class enforces the two laws: There must be a zero operation and a combining function (add).
-
err()¶ Return the uncertainty of the current value
-
pure(x)¶ Turn a number into a member of this monoid
-
upgrade(x)¶ Ensure that a value is a member of this monoid
-
static
zero()¶ The zero element of the monoid. This element obeys the law that
x + x.zero() == x
-
-
class
general.scans.monoid.MonoidList(values)¶ This class turns a collection of Monoids into its own Monoid.
-
err()¶ Return the uncertainty of the current value
-
max()¶ Return the largest value
-
min()¶ Return the smallest value
-
zero()¶ The zero element of the monoid. This element obeys the law that
x + x.zero() == x
-
general.scans.motion¶
This module contains helper classes for controlling motions on the beamline
There’s three levels of depth to this module. At the simplest level, merely import and call populate(). This create motion object for every block currently registered on the instrument.
The next level down is the BlockMotion class, which allows for creating single objects that correspond to single IBEX blocks.
Finally, at the bottom, BlockMotion derives from the Motion object, which gives a simple framework for all physical parameters that can be controlled by an instrument. Although it is called Motion, it will also handle temperatures, currents, and other physical properties.
-
class
general.scans.motion.BlockMotion(block, unit)¶ A helper class for creating motion objects from Ibex blocks
Parameters: block – A string containing the name of the ibex block to control
-
class
general.scans.motion.Motion(getter, setter, title, low=None, high=None, velocity_getter=None, velocity_setter=None, tolerance_getter=None, unit=None)¶ A Motion object largely acts like a function to control and interrogate a single axis of motion. When called without a parameter, it returns the current position. Being called with a parameter causes the position to update.
We can also define getters and setters for velocity of the motor, and a getter for the tolerance of the motor.
Example: Assume that we have some motion object Foo
>>> Foo() 7 >>> Foo(5) >>> Foo() 5
-
accessible(x)¶ Determines whether a motor can reach the desired position.
Parameters: x – The desired position for the motor Returns: - Tuple (Bool, Str)
- The boolean represents whether the possition can be reached
- The string is an error message explaining why the position is
- unreachable.
-
high¶ The motion’s uppder limit
-
low¶ The motion’s lower limit
-
require(x)¶ Requires that the given position is accessible. If not, an exception is thrown
-
tolerance¶ The tolerance (deadband) of the motor
-
velocity¶ The velocity of the motor
-
-
general.scans.motion.pv_motion(pv_str, name)¶ Create a motion object around a PV string.
general.scans.multiplot¶
general.scans.scans¶
The Scans module holds the base classes for scan objects. These objects reify the steps an instrument takes in a scan and allow us to have single place where all of the various scanning methods can be condensed.
The only export of this module that should ever need to be directly accessed by other modules is SimpleScan. Everything else should be treated as private.
-
class
general.scans.scans.ContinuousMove(start, stop, speed)¶ An object representing a continuous move from start to stop at a constant speed.
-
class
general.scans.scans.ContinuousScan(motion, moves, defaults)¶ A continuous scan that starts motion and then collects while the axis is moving
-
forever¶ Create a scan that will cycle until stopped by the user.
-
map(func)¶ The map function returns a modified scan that performs the given function on all of the original positions to return the new positions.
-
max()¶ Find the largest point in a scan
-
min()¶ Find the smallest point in a scan
-
plot(detector=None, save=None, action=None, update_freq=1.0, **kwargs)¶ Run over a continuous range, plotting every update_freq seconds
-
-
class
general.scans.scans.ForeverContinuousScan(motion, moves, defaults)¶ A special case of a forever scan that can operate with continuous moves.
-
class
general.scans.scans.ForeverScan(scan)¶ ForeverScan repeats the same scan over and over again to improve the statistics until the user manually halts the scan.
-
map(func)¶ The map function returns a modified scan that performs the given function on all of the original positions to return the new positions.
-
max()¶ Find the largest point in a scan
-
min()¶ Find the smallest point in a scan
-
-
class
general.scans.scans.ParallelScan(first, second)¶ ParallelScan runs two scans alongside each other, performing both sets of position adjustments before each step of the scan.
-
map(func)¶ The map function returns a modified scan that performs the given function on all of the original positions to return the new positions.
-
max()¶ Find the largest point in a scan
-
min()¶ Find the smallest point in a scan
-
reverse¶ Creates a new scan that runs in the opposite direction
-
-
class
general.scans.scans.ProductScan(outer, inner)¶ ProductScan performs every possible combination of the positions of its two constituent scans.
-
map(func)¶ The map function returns a modified scan that performs the given function on all of the original positions to return the new positions.
-
max()¶ Find the largest point in a scan
-
min()¶ Find the smallest point in a scan
-
plot(detector=None, save=None, action=None, **kwargs)¶ An overloading of Scan.plot to handle multidimensional scans.
-
reverse¶ Creates a new scan that runs in the opposite direction
-
-
class
general.scans.scans.ReplayScan(xs, ys, axis, result)¶ A Scan that merely repeated the output of a previous scan
-
map(func)¶ The map function returns a modified scan that performs the given function on all of the original positions to return the new positions.
-
max()¶ Find the largest point in a scan
-
min()¶ Find the smallest point in a scan
-
plot(detector=None, save=None, action=None, **kwargs)¶ Overload the scan method for the replay scan. Since we aren’t actually detecting anything, we can run the code much simpler instead of trying to fake a detector.
-
-
class
general.scans.scans.Scan¶ The virtual class that represents all controlled scans. This class should never be instantiated directly, but rather by one of its subclasses.
-
and_back¶ Run then scan both forwards and in reverse. This can help minimise motor movement.
-
calculate(time=False, pad=0, **kwargs)¶ Calculate the expected time needed to perform a scan. Additionally, print the expected time of completion.
Beyond accepting the default arguments for setting a measurement time (e.g uamps, minutes, frames), this method accept two other keywords. The pad argument is an extra time, in seconds, to add to each measurement to account for motor movements, file saving, and other such effects. The quiet keyword, if set to true, prevents the printing of the expected time of completion.
-
fit(fit, **kwargs)¶ The fit method performs the scan, plotting the points as they are taken. Once the scan is completed, a fit is then plotted over the scan and the fitting parameters are returned.
-
forever¶ Create a scan that will cycle until stopped by the user.
-
map(func)¶ The map function returns a modified scan that performs the given function on all of the original positions to return the new positions.
-
max()¶ Find the largest point in a scan
-
measure(title, measure=None, **kwargs)¶ Perform a full measurement at each position indicated by the scan. The title parameter gives the run’s title and allows for values to be interpolated into it. For instance, the string “{theta}” will include the current value of the theta motor if it is being iterated over.
WARNING: This function is deprecated and will be removed in the next release.
-
min()¶ Find the smallest point in a scan
-
plot(detector=None, save=None, action=None, **kwargs)¶ Run over the scan an perform a simple measurement at each position. The measurement parameter can be used to set what type of measurement is to be taken. If the save parameter is set to a file name, then the plot will be saved in that file.
-
reverse¶ Create a new scan that runs in the opposite direction
-
-
class
general.scans.scans.SimpleScan(action, values, defaults)¶ SimpleScan is a scan along a single axis for a fixed set of values
-
map(func)¶ The map function returns a modified scan that performs the given function on all of the original positions to return the new positions.
-
max()¶ Find the largest point in a scan
-
min()¶ Find the smallest point in a scan
-
reverse¶ Create a new scan that runs in the opposite direction
-
-
class
general.scans.scans.SumScan(first, second)¶ The SumScan performs two separate scans sequentially
-
map(func)¶ The map function returns a modified scan that performs the given function on all of the original positions to return the new positions.
-
max()¶ Find the largest point in a scan
-
min()¶ Find the smallest point in a scan
-
reverse¶ Creates a new scan that runs in the opposite direction
-
-
general.scans.scans.estimate(seconds=None, minutes=None, hours=None, uamps=None, frames=None, **_)¶ Estimate takes a measurement specification and predicts how long the measurement will take in seconds.
-
general.scans.scans.just_times(kwargs)¶ Filter a dict down to just the waitfor members
-
general.scans.scans.last_scan(path=None, axis='replay')¶ Load the last run scan and replay that scan
Parameters: - path – The log file to replay. If None, replay the most recent scan
- axis – The label for the x axis
-
general.scans.scans.merge_dicts(x, y)¶ Given two dicts, merge them into a new dict as a shallow copy.
-
general.scans.scans.temporarily_change_motor_speed(*args, **kwds)¶ Context manager to temporarily change motor velocity, and put it back on exit.
Parameters: - motion – the motion object
- temporary_speed – the temporary speed to set within this context manager
general.scans.util¶
The Util module contains functions which are useful for the instrument scientist in defining their beamline. Nothing in this module should ever need to be called by the end user.
-
general.scans.util.get_points(current, start=None, stop=None, step=None, stride=None, count=None, gaps=None, before=None, after=None, **_)¶ This function takes a dictionary of keyword arguments for a scan and returns the points at which the scan should be measured.
This function provides many ways to define a scan
- start point, stop point, and number of points
- start point, stop point, and spacing
- start point, spacing, and number of points
Parameters: - current (float) – The present position of the motor. This is needed to relative scans.
- start (float) – The absolute first position in the scan. This is a valid start point.
- stop (float) – The absolute final position in the scan. This is a valid stop point.
- before (float) – The relative first position in the scan. If the motor is currently
at 3 and
beforeis set to -5, then the first scan point will be -2. This is a valid start point. - after (float) – The relative final position in the scan. If the motor is currently
at 3 and
beforeis set to 5, then the last scan point will be 8. This is a valid stop point. - step (float) – The fixed distance between points. If the distance between the beginning and end aren’t an exact multiple of this step size, then the end point will not be included. This is a valid spacing.
- stride (float) – The approximate distance between points. In order to ensure that
the
startandstoppoints are included in the scan, a finer resolution scan will be called for if the stride is not an exact multiple of the distance. This is a valid spacing. - count (float) – The number of measurements to perform. A scan with a
countof 2 would measure at only the beginning and the end. This is a valid number of points. - gaps (float) – The number of steps that the motor will take. A scan with a
gapsof 1 would measure at only the beginning and the end. This is a valid number of points.
Returns: The positions for the scan.
Return type: Array of Floats
Raises: RuntimeError– If the supplied parameters cannot be combined into a coherent scan.
-
general.scans.util.local_wrapper(obj, method)¶ Get a function that calls a METHOD on object OBJect
technique.sans¶
technique.sans.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
technique.sans.instrument.ScanningInstrument¶ The base class for scanning measurement instruments.
-
TIMINGS¶ The list of valid waitfor keywords.
-
changer_pos¶ Get the current sample changer position
-
check_move_pos(pos)¶ Check whether the position is valid and return True or False
Parameters: pos (str) – The sample changer position
-
static
convert_file(file_path)¶ 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)¶ 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)¶ 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, aperture='', **kwargs)¶ A wrapper around
measurewhich ensures that the instrument is not in transmission modeLook at the documentation for
measureto see the full set of parameters accepted.
-
do_trans(title, pos=None, thickness=1.0, dae=None, blank=False, aperture='', **kwargs)¶ A wrapper around
measurewhich ensures that the instrument is not in transmission mode.Look at the documentation for
measureto see the full set of parameters accepted.
-
enumerate_dae()¶ List the supported DAE modes on this beamline.
-
get_pv(name)¶ Get the given PV within the sub heirarchy of the instrument.
For example, on Larmor, get_pv(“DAE:WIRING_FILE”) would return the value of the PV for “IN:LARMOR:DAE:WIRING_FILE”
-
measure(title, pos=None, thickness=1.0, trans=False, dae=None, blank=False, aperture='', **kwargs)¶ 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()
- aperture (str) – The aperture size. e.g. “Small” or “Medium” A blank string (the default value) results in the aperture 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)¶ 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
titleparameter 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.
-
measurement_id¶ Get the measurement id from the journal
-
measurement_label¶ Get the measurement label from the journal
-
measurement_type¶ Get the measurement type form the journal.
-
method_iterator()¶ Iterate through the class’s public functions
-
static
printsamplepars()¶ Display the basic sample parameters on the console.
-
sanitised_timings(kwargs)¶ Include only the keyword arguments for run timings.
Parameters: - kwargs (dict) –
- dictionary of keyword arguments (A) –
Returns: - dict
- Keyword arguments accepted by gen.waitfor
-
send_pv(name, value)¶ Set the given PV within the sub heirarchy of the instrument.
For example, on Larmor, send_pv(“DAE:WIRING_FILE”, f) would change the value of the PV for “IN:LARMOR:DAE:WIRING_FILE” to the value in f.
-
static
set_aperture(size)¶ Set the beam aperture to the desired size
Parameters: size (str) – The aperture size. e.g. “Small” or “Medium” A blank string (the default value) results in the aperture not being changed.
-
set_default_dae(mode=None, trans=False)¶ 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.
-
setup_dae_bsalignment()¶ Configure wiring tables for beamstop alignment.
-
setup_dae_event()¶ Set the wiring tables for event mode
-
setup_dae_histogram()¶ Set the wiring tables for histogram mode
-
setup_dae_nr()¶ Set the wiring tables for a neutron reflectivity measurement
-
setup_dae_nrscanning()¶ Set the wiring tables for performing scans during neutron reflectivity
-
setup_dae_scanning()¶ Set the wiring tables for a scan
-
setup_dae_transmission()¶ Set the wiring tables for a transmission measurement
-
technique.sans.reduction¶
technique.sans.util¶
Useful utilities for scriping
-
technique.sans.util.dae_setter(suffix, measurement_type)¶ 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.ScanningInstrumentclass. 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.
-
technique.sans.util.pretty_print_time(seconds)¶ 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
-
technique.sans.util.user_script(script)¶ A decorator to perform some sanity checking on a user script before it is run
-
technique.sans.util.wait_time(call)¶ 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