User Commands

Getting help

help(obj=None)

Show help for a command, for a device or for any other object.

For commands, the command help and usage will be shown. For devices, the device help, parameters and special commands will be shown.

listcommands()

List all available commands.

listdevices()

List all currently created devices.

listparams(dev)

List all parameters of the device.

listmethods(dev)

List user-callable methods for the device.

listallparams(*names)

List the given parameters for all existing devices that have them.

Example:

listallparams('offset')

lists the offset for all devices with an “offset” parameter.

version(*devlist)

List version info of the device(s).

Output commands

These commands can be used from user scripts to print information to the output and the logfile.

printinfo(*msgs, **kwds)

Print a message.

printdebug(*msgs, **kwds)

Print a debug message.

printwarning(*msgs, **kwds)

Print a warning message.

printerror(*msgs)

Print an error message.

printexception(*msgs)

Print an error message, and add info about the last exception.

Setup-related commands

NewSetup(*setupnames)

Load the given setups instead of the current one. Without arguments, the current setups are reloaded.

Example:

NewSetup('tas', 'psd')

will clear the current setup and load the “tas” and “psd” setups at the same time.

AddSetup(*setupnames)

Load the given setups additional to the current one.

Example:

AddSetup('gaussmeter')

will load the “gaussmeter” setup in addition to the current setups.

RemoveSetup(*setupnames)

Remove the given setups from the currently loaded ones.

Example:

RemoveSetup('gaussmeter')

will re-load all current setups except for “gaussmeter”.

ListSetups()

Print a list of all known setups.

CreateDevice(*devnames)

Create all given devices.

Example:

CreateDevice('stx', 'sty', 'stz')
CreateAllDevices()

Create all devices in the current setup that are not marked as lowlevel devices.

This is useful when a setup failed to load many devices, and another attempt should be made.

DestroyDevice(*devnames)

Destroy all given devices.

Example:

DestroyDevice('stx', 'sty', 'stz')
SetMode(mode)

Set the execution mode.

Valid modes are: master, slave, simulation, maintenance

Notification commands

Notify(*args)

Send a message via email and/or SMS to the receivers selected by SetMailReceivers() and SetSMSReceivers(). Usage is one of these two:

Notify('some text')
Notify('subject', 'some text')
SetMailReceivers(*emails)

Set a list of email addresses that will be notified on unhandled errors, and when the Notify() command is used.

SetSMSReceivers(*numbers)

Set a list of mobile phone numbers that will be notified on unhandled errors, and when the Notify() command is used.

Note that all those phone numbers have to be registered with the IT department before they can be used.

Miscellaneous commands

sleep(secs)

Sleep for a given number of seconds.

This is different from Python’s time.sleep() in that it allows breaking and stopping the sleep, and supports simulation mode.

Keep(name, obj)

Export the given obj into the NICOS namespace under the name.

This makes the given name read-only, so that the object cannot be overwritten by accident.

ClearCache(*devnames)

Clear all cached information for the given device(s).

This can be used when a device has been reconfigured in the setup and all parameters should be read from the setup file on the next loading of the setup. Example:

ClearCache('om', 'phi')
NewSetup()

will clear cache information for devices “om” and “phi” and then reload the current setup.

UserInfo(name)

Return an object for use in “with” that adds status information. It can be used like this:

with UserInfo('Qscan around (1,1,0)'):
    qscan(...)
SaveSimulationSetup(filename, name=None)

Save the whole current setup as a file usable in simulation mode.

Device commands

read(*devlist)

Read the position (or value) of one or more devices.

If no device is given, read all readable devices.

status(*devlist)

Read the status of one or more devices.

If no device is given, read the status of all readable devices.

move(*dev_pos_list)

Move one or more devices to a new position.

This can be used with multiple devices like this:

move(dev1, pos1, dev2, pos2, ...)
wait(*devlist)

Wait until motion of one or more devices is complete, or device is out of “busy” status. A time in seconds can also be used to wait the given number of seconds.

Example:

wait(T, 60)

waits for the T device, and then another 60 seconds.

maw(*dev_pos_list)

Move one or more devices to a new position and wait until motion of all devices is completed.

This can be used with multiple devices like this:

maw(dev1, pos1, dev2, pos2, ...)
stop(*devlist)

Stop one or more devices.

If no device is given, stop all stoppable devices in parallel.

reset(*devlist)

Reset the given device(s).

limits(*devlist)

Print the limits of the device(s).

resetlimits(*devlist)

Reset the user limits for the device(s) to the absolute limits.

fix(dev, reason='')

Fix a device, i.e. prevent movement until release() is called.

You can give a reason that is displayed when movement is attempted. Example:

fix(phi, 'will drive into the wall')
release(*devlist)

Release one or more devices, i.e. undo the effect of fix().

adjust(dev, value, newvalue=None)

Adjust the offset of the device.

There are two ways to call this function:

  • with one value: the offset is adjusted so that read() then returns the given value.
  • with two values: the offset is adjusted so that the position that previously had the value of the first parameter now has the value of the second parameter.

Examples:

>>> adjust(om, 100)     # om's current value is now 100
>>> adjust(om, 99, 100) # what was om = 99 before is now om = 100

“dev” must be a device that supports the “offset” parameter.

history(dev, key='value', fromtime=None, totime=None)

Print history of a device parameter.

The optional argument key selects a parameter of the device. “value” is the main value, and “status” is the device status.

fromtime and totime are UNIX timestamps, or negative numbers giving hours in the past. The default is to list history of the last hour for “value” and “status”, or from the last day for other parameters. For example:

>>> history(mth)              # show value of mth in the last hour
>>> history(mth, -48)         # show value of mth in the last two days
>>> history(mtt, 'offset')    # show offset of mth in the last day

Measuring commands

count(*detlist, **preset)

Perform a single counting.

With preset arguments, this preset is used instead of the default preset.

With detector devices as arguments, these detectors are used instead of the default detectors set with SetDetectors().

Within a manual scan, perform the count as one step of the manual scan.

Examples:

count()             # count once with the default preset and detectors
count(t=10)         # count once with time preset of 10 seconds
count(psd, t=10)    # count 10 seconds with the psd detector
preset(**preset)

Set a new default preset for the currently selected detectors.

The arguments that are accepted depend on the detectors.

Examples:

preset(t=10)      # sets a time preset of 5 seconds
preset(m1=5000)   # sets a monitor preset of 5000 counts, for detectors
                  # that support monitor presets
SetDetectors(*detlist)

Select the detector device(s) to read out when calling scan() or count().

Examples:

SetDetectors(det)       # to use the "det" detector
SetDetectors(det, psd)  # to use both the "det" and "psd" detectors
SetEnvironment(*devlist)

Select the device(s) to read out as “experiment environment” at every step of a scan.

Examples:

SetEnvironment(T, B)   # to read out T and B devices
SetEnvironment()       # to read out no additional devices
AddDetector(*detlist)

Add the specified detector device(s) to the standard detectors.

AddEnvironment(*devlist)

Add the specified environment device(s) to the standard environment.

ListDetectors()

List the standard detectors.

ListEnvironment()

List the standard environment devices.

Scanning commands

scan(dev, *args, **kwargs)

Scan over device(s) and count detector(s).

The general syntax is either to give start, step and number of steps:

scan(dev, 0, 1, 11)   # scans from 0 to 10 in steps of 1.

or a list of positions to scan:

scan(dev, [0, 1, 2, 3, 7, 8, 9])  # scans at the given positions.

The device can also be a list of devices that should be moved for each step. In this case, the start and stepwidth also have to be lists:

scan([dev1, dev2], [0, 0], [0.5, 1], 10)

This also works for the second basic syntax:

scan([dev1, dev2], [[0, 1, 2, 3], [0, 2, 4, 6]])

Presets can be given using keyword arguments:

scan(dev, ..., t=5)
scan(dev, ..., mon1=1000)

An info string describing the scan can be given as a string argument:

scan(dev, ..., 'peak search', ...)

By default, the detectors are those selected by SetDetectors(). They can be replaced by a custom set of detectors by giving them as arguments:

scan(dev, ..., det1, det2)

Other devices that should be recorded at every point (so-called environment devices) are by default those selected by SetEnvironment(). They can also be overridden by giving them as arguments:

scan(dev, ..., T1, T2)

Any devices can be moved to different positions before the scan starts. This is done by giving them as keyword arguments:

scan(dev, ..., ki=1.55)

A similar syntax can be used to count multiple times per scan point, with one or more devices at different positions:

scan(dev, ..., pol=['up', 'down'])

will measure twice at every point: once with pol moved to ‘up’, once with pol moved to ‘down’.

cscan(dev, *args, **kwargs)

Scan around center.

The general syntax is to give center, step and number of steps per side:

cscan(dev, 0, 1, 5)   # scans from -5 to 5 in steps of 1.

The total number of steps is (2 * numperside) + 1.

The device can also be a list of devices that should be moved for each step. In this case, the start and stepwidth also have to be lists:

cscan([dev1, dev2], [0, 0], [0.5, 1], 10)

This also works for the second basic syntax:

cscan([dev1, dev2], [[0, 1, 2, 3], [0, 2, 4, 6]])

Presets can be given using keyword arguments:

cscan(dev, ..., t=5)
cscan(dev, ..., mon1=1000)

An info string describing the scan can be given as a string argument:

cscan(dev, ..., 'peak search', ...)

By default, the detectors are those selected by SetDetectors(). They can be replaced by a custom set of detectors by giving them as arguments:

cscan(dev, ..., det1, det2)

Other devices that should be recorded at every point (so-called environment devices) are by default those selected by SetEnvironment(). They can also be overridden by giving them as arguments:

cscan(dev, ..., T1, T2)

Any devices can be moved to different positions before the scan starts. This is done by giving them as keyword arguments:

cscan(dev, ..., ki=1.55)

A similar syntax can be used to count multiple times per scan point, with one or more devices at different positions:

cscan(dev, ..., pol=['up', 'down'])

will measure twice at every point: once with pol moved to ‘up’, once with pol moved to ‘down’.

timescan(numsteps, *args, **kwargs)

Count a number of times without moving devices.

“numsteps” can be -1 to scan for unlimited steps (break to quit).

By default, the detectors are those selected by SetDetectors(). They can be replaced by a custom set of detectors by giving them as arguments:

timescan(5, ..., det1, det2)

Other devices that should be recorded at every point (so-called environment devices) are by default those selected by SetEnvironment(). They can also be overridden by giving them as arguments:

timescan(5, ..., T1, T2)

Any devices can be moved to different positions before the scan starts. This is done by giving them as keyword arguments:

timescan(5, ..., ki=1.55)

A similar syntax can be used to count multiple times per scan point, with one or more devices at different positions:

timescan(5, ..., pol=['up', 'down'])

will measure twice at every point: once with pol moved to ‘up’, once with pol moved to ‘down’.

contscan(dev, start, end, speed=None, *args, **kwargs)

Scan a device continuously with low speed.

If the “speed” is not explicitly given, it is set to 1/5 of the normal speed of the device.

By default, the detectors are those selected by SetDetectors(). They can be replaced by a custom set of detectors by giving them as arguments:

contscan(dev, ..., det1, det2)
manualscan(*args, **kwargs)

“Manual” scan where no devices are moved automatically.

An example usage:

with manualscan(device, otherdevice):
    for i in range(10):
        if otherdevice.read() < 15:
            raise NicosError('cannot continue')
        maw(device, i+1)
        count(t=600)

This example mimicks a regular scan(), with the exception that before every point the value of another device is checked for validity.

The arguments to manualscan() can be are:

  • detector devices, to use these for counting
  • other devices, to read them at every scan point
  • presets, in the form accepted by the other scan commands

Within the with manualscan block, call count() (using the default preset) or count(presets...) whenever you want to measure a point.

On-line analysis commands

center_of_mass(*columns)

Calculate the center of mass x-coordinate of the last scan. The data columns to use can be given by the arguments: either only the Y column, or both X and Y columns. If they are not given, then the default X column is the first, and the default Y column is the first column of type “counter”. Examples:

center_of_mass()     # use first X column and first counter Y column
center_of_mass(2)    # use first X column and second Y column
center_of_mass(2, 3) # use second X column and third Y column

It is also possible to give columns by name, for example:

center_of_mass('om', 'ctr1')
root_mean_square(col=None)

Calculate the root-mean-square of the last scan.

The data column to use can be given by an argument (by name or number); the default is the first Y column of type “counter”.

fwhm(*columns)

Calculate an estimate of full width at half maximum.

The search starts a the ‘left’ end of the data.

Returns a tuple (fwhm, xpeak, ymax, ymin):

  • fwhm - full width half maximum
  • xpeak - x value at y = ymax
  • ymax - maximum y-value
  • ymin - minimum y-value

The data columns to use can be given by the arguments: either only the Y column, or both X and Y columns. If they are not given, then the default X column is the first, and the default Y column is the first column of type “counter”. Examples:

fwhm()     # use first X column and first counter Y column
fwhm(2)    # use first X column and second Y column
fwhm(2, 3) # use second X column and third Y column

It is also possible to give columns by name, for example:

fwhm('om', 'ctr1')
poly(n, *columns)

Fit a polynomial of degree n through the last scan.

The return value is a pair of tuples:

(coefficients, coeff_errors)

where both coefficients and coeff_errors are tuples of n+1 elements.

The data columns to use can be given by the arguments: either only the Y column, or both X and Y columns. If they are not given, then the default X column is the first, and the default Y column is the first column of type “counter”. Examples:

poly(2, )     # use first X column and first counter Y column
poly(2, 2)    # use first X column and second Y column
poly(2, 2, 3) # use second X column and third Y column

It is also possible to give columns by name, for example:

poly(2, 'om', 'ctr1')
gauss(*columns)

Fit a Gaussian through the data of the last scan.

The return value is a pair of tuples:

((x0, ampl, sigma, background), (d_x0, d_ampl, d_sigma, d_back))

where the elements of the second tuple are the estimated standard errors of the fit parameters. The fit parameters are:

  • x0 - center of the Gaussian
  • ampl - amplitude
  • sigma - FWHM
  • background

The data columns to use can be given by the arguments: either only the Y column, or both X and Y columns. If they are not given, then the default X column is the first, and the default Y column is the first column of type “counter”. Examples:

gauss()     # use first X column and first counter Y column
gauss(2)    # use first X column and second Y column
gauss(2, 3) # use second X column and third Y column

It is also possible to give columns by name, for example:

gauss('om', 'ctr1')
center(dev, center, step, numsteps, *args, **kwargs)

Move the given device to the maximum of a Gaussian fit through a scan around center with the given parameters.

This supports all arguments and keyword arguments that cscan() supports, and additionally a keyword “ycol” that gives the Y column of the dataset to use for the Gaussian fit (see the help for gauss() for the meaning of this parameter).

checkoffset(dev, center, step, numsteps, *args, **kwargs)

Readjust offset of the given device, so that the center of the given scan coincides with the center of a Gaussian fit.

This supports all arguments and keyword arguments that cscan() supports, and additionally a keyword “ycol” that gives the Y column of the dataset to use for the Gaussian fit (see the help for gauss() for the meaning of this parameter).

Triple-axis commands

To use these commands, add 'nicos.commands.tas' to the modules list of one of your loaded setups.

Q(*args, **kwds)

Create a Q-E vector that can be used for calculations. Use:

To create a Q vector (1, 0, 0) with energy transfer 0 or 5:

q = Q(1)
q = Q(1, 0, 0)
q = Q(1, 0, 0, 5)
q = Q(h=1, E=5)

To create a Q vector from another Q vector, adjusting one or more entries:

q2 = Q(q, h=2, k=1)
q2 = Q(q, E=0)

You can then use the Q-E vectors in scanning commands:

qscan(q, q2, 5, t=10)
qscan(Q, dQ, numsteps, *args, **kwargs)

Single-sided Q scan.

The Q and dQ arguments can be lists of 3 or 4 components, or a Q object.

By default, the detectors are those selected by SetDetectors(). They can be replaced by a custom set of detectors by giving them as arguments:

qscan(Q, dQ, ..., det1, det2)

Other devices that should be recorded at every point (so-called environment devices) are by default those selected by SetEnvironment(). They can also be overridden by giving them as arguments:

qscan(Q, dQ, ..., T1, T2)

Any devices can be moved to different positions before the scan starts. This is done by giving them as keyword arguments:

qscan(Q, dQ, ..., ki=1.55)

A similar syntax can be used to count multiple times per scan point, with one or more devices at different positions:

qscan(Q, dQ, ..., pol=['up', 'down'])

will measure twice at every point: once with pol moved to ‘up’, once with pol moved to ‘down’.

qcscan(Q, dQ, numperside, *args, **kwargs)

Centered Q scan.

The Q and dQ arguments can be lists of 3 or 4 components, or a Q object.

By default, the detectors are those selected by SetDetectors(). They can be replaced by a custom set of detectors by giving them as arguments:

qcscan(Q, dQ, ..., det1, det2)

Other devices that should be recorded at every point (so-called environment devices) are by default those selected by SetEnvironment(). They can also be overridden by giving them as arguments:

qcscan(Q, dQ, ..., T1, T2)

Any devices can be moved to different positions before the scan starts. This is done by giving them as keyword arguments:

qcscan(Q, dQ, ..., ki=1.55)

A similar syntax can be used to count multiple times per scan point, with one or more devices at different positions:

qcscan(Q, dQ, ..., pol=['up', 'down'])

will measure twice at every point: once with pol moved to ‘up’, once with pol moved to ‘down’.

calpos(*args)

Calculate instrument position for a given (Q, E) position.

Can be called with 3 to 5 arguments:

>>> calpos(1, 0, 0)             # H, K, L
>>> calpos(1, 0, 0, -4)         # H, K, L, E
>>> calpos(1, 0, 0, -4, 2.662)  # H, K, L, E, scanconstant

or with a Q-E vector:

>>> calpos(Q(1, 0, 0, -4))         # Q-E vector
>>> calpos(Q(1, 0, 0, -4), 2.662)  # Q-E vector and scanconstant
pos(*args)

Move the instrument to a given (Q, E) position, or without arguments to the last position calculated with calpos(). Examples:

>>> pos()                       # last calpos() position
>>> pos(1, 0, 0)                # H, K, L
>>> pos(1, 0, 0, -4)            # H, K, L, E
>>> pos(1, 0, 0, -4, 2.662)     # H, K, L, E, scanconstant
>>> pos(Q(1, 0, 0, -4))         # Q-E vector
>>> pos(Q(1, 0, 0, -4), 2.662)  # Q-E vector and scanconstant
rp()

Read the current (Q, E) position.

alu(ki=None, phi=None)

Print powder ray positions of Al.

copper(ki=None, phi=None)

Print powder ray positions of Cu.

ho_spurions(kf=None, dEmin=0, dEmax=20)

Calculation of elastic spurions due to higher order neutrons.

kf is the final wavevector to use for calculation. dEmin and dEmax are the minimum and maximum energy transfer to list.

acc_bragg(h, k, l, ny, sc=None)

Check accidental Bragg scattering conditions for type A or type M at the given spectrometer position.