SPEC Simulation module

Module spec: SPEC-like emulation

The Python functions in this module are designed to emulate similar commands/macros in SPEC or provide similar functionality. They require the PyEpics [1] package.

[1]PyEpics: http://cars9.uchicago.edu/software/python/pyepics3/

Motor interface routines

Description Relative Absolute
move motor mvr() mv()
move motor with wait umvr() umv()
move multiple motors [2] mmv()
move multiple w/wait [2] ummv()
where is this motor? wm()
where are all motors? wa()
[2](1, 2) These commands implement capabilities not present in SPEC.

Scaler routines

description command
start and readout scaler after completion ct()
start scaler and return count_em()
wait for scaler to complete wait_count()
read scaler get_counts()

More spec-like capabilities

description command
Turn simulation mode on onsim()
Turn simulation mode off offsim()
array of motor positions A[]
array of last count values S[]

Routines not in spec

Routine Description
sleep() Delay for a specified amount of time
EnableEPICS() Turns simulation mode on or off
UseEPICS() Show if EPICS should be accessed
DefineMtr() Define a motor to be accessed
DefinePseudoMtr() Define pseudo motors from previously defined motors
GetMtrInfo() Retrieves all motor info from a key
DefineMotorSymbols() Used to define motor symbols in caller’s namespace
DefineScaler() Define a scaler to be accessed
GetScalerInfo() Retrieves all scaler info from an index
ListMtrs() Returns a list of motor symbols
Sym2MtrVal() Retrieves the motor entry key from a symbol
ExplainMtr() Retrieves the motor description from a key or symbol
ReadMtr() Returns the motor position from a key
PositionMtr() Moves a motor
MoveMultipleMtr() Move several motors together
GetScalerLastCount() Returns the last set of counts that have been read for a scaler
GetScalerLastTime() Returns the counting time for the last use of a scaler
GetScalerLabels() Returns the labels that have been retrieved for a scaler
SetMon() Set the monitor channel for the scaler
GetMon() Return the monitor channel for the scaler
SetDet() Set the main detector channel for the scaler
GetDet() Return the main detector channel for the scaler
setCOUNT() Sets the default counting time
initElapsed() Initialize the elapsed time counter
setElapsed() Update the elapsed time counter
setRETRIES() Sets the maximum number of EPICS retries
setDEBUG() Sets debugging mode (printing lots of stuff) on or off

Global variables

As described below, these variables can be read from outside of the package, but should be set with care.

COUNT:

defines the default counting time (sec) when ct is called without an argument. Defaults to 1 sec. Use setCOUNT() to set this when using from APSpy.spec import *, as setting the variable directly has problems:

This will sort-of work:
>>>  from APSpy.spec import *
>>>  import APSpy.spec
>>>  APSpy.spec.COUNT=3

however, COUNT in the local namespace will still have the old value.

but this will not work:
>>>  from APSpy.spec import *
>>>  COUNT=3

This fails because the local copy of COUNT gets replaced, but the copy of COUNT actually in the spec module is left unchanged.


MAX_RETRIES:Number of times to retry an EPICS operation (that are nominally expected to work on the first try) before generating an exception. Use setRETRIES() to set this or care when changing this (see comment on COUNT, in this section.)

DEBUG:When set to True lots of print statements to be executed. Use for code development/testing. Use setDEBUG() to set this or care when changing this (see comment on COUNT, above in this section.)
ELAPSED:Contains the time that has elapsed between when the spec module was loaded (or initElapsed() was called) and when setElapsed() was last called, which happens when motors are moved or counting is done or sleep() is called.
SIMSPEED:When in simulation mode, scripts are sped up by decreasing delays (calls to spec.sleep()) by a factor of SIMSPEED. Be sure to change spec.SIMSPEED if you want to change this.

A[]

A:As in spec, A[mtr1] provides the current position of mtr1. A is not actually implemented as a global array, but can be indexed as one.

S[]

S:As in spec, S[i] provides the last read intensity from scaler channel i. This is a python list and is thus indexed starting at 0. The first channel, S[0], is expected to be configured as the count-time reference channel.

Complete Function Descriptions

The functions available in this module are listed below.

exception APSpy.spec.APSpyException[source]

any exception from this module

exception APSpy.spec.APSpyMotorException[source]

any motor exception

exception APSpy.spec.APSpyScalerException[source]

any scaler exception

exception APSpy.spec.APSpyUndefinedMotorException[source]

requested a mne or mtrsym that was not defined

exception APSpy.spec.APSpyUndefinedScalerException[source]

(one instance occurs) - needs work to demonstrate usage

APSpy.spec.DefineMotorSymbols(db={}, make_global=False)[source]

make definitions of the motor symbolic names

Returns a string listing the motor symbols and values. This string can be executed in the local namespace (by exec()) to define (or redefine) these names locally for convenience. This is recommended for interactive (command-line session) use only.

>>> from spec import *
>>> DefineMtr('samX', 'como:m1',  'sample X position (mm) + outboard')
>>> DefineMtr('samZ', 'como:m2',  'sample Z position (mm) + up')
>>> samX
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'samX' is not defined
>>> exec( DefineMotorSymbols(mtrDB) )
>>> samX
'mtr1000'
>>>

Note

Using exec() is the only known and reliable way to import the motor symbol definitions into the local namespace.

To import the motor symbols into a module’s global namespace, (non-interactive, as used in a script or macro file) one way would be to include the following function in the module:

import spec
# ...
def ImportMotorSymbols():
    exec( spec.DefineMotorSymbols(spec.mtrDB, make_global=True) )
# ...
ImportMotorSymbols()
APSpy.spec.DefineMtr(symbol, prefix, comment='')[source]

Define a motor for use in this module. Adds a motor to the motor table.

Parameters:
  • symbol (string) – a symbolic name for the motor. A global variable is defined in this module’s name space with this name, This must be unique; Exception APSpyException is raised if a name is reused.
  • prefix (string) – the prefix for the motor PV (ioc:mnnn). Omit the motor record field name (.VAL, etc.).
  • comment (string) – a human-readable text field that describes the motor. Suggestion: include units and define the motion direction.
Returns:

key of entry created in motor table (str).

If you will use the `` from APSpy.spec import * `` python command to import these routines into the current module’s name space, it is necessary to repeat this command after DefineMtr() to import the globals defined within in the top namespace:

Example (recommended for interactive use):
>>>  from spec import *
>>>  EnableEPICS()
>>>  DefineMtr('mtrXX1','ioc1:mtr98','Example motor #1')
>>>  DefineMtr('mtrXX2','ioc1:mtr99','Example motor #2')
>>>  from spec import *
>>>  mv(mtrXX1, 0.123)

Note that if the second from ... import * command is not used, the variables *mtrXX1* and *mtrXX2* cannot be accessed and the final command will fail.

Alternate example (this is a cleaner way to code scripts, since namespaces are not mixed):
>>>  import APSpy.spec
>>>  APSpy.spec.EnableEPICS()
>>>  APSpy.spec.DefineMtr('mtrXX1','ioc1:mtr98','Example motor #1')
>>>  APSpy.spec.DefineMtr('mtrXX2','ioc1:mtr99','Example motor #2')
>>>  APSpy.spec.mv(spec.mtrXX1, 0.123)
It is also possible to mix the two styles:
>>>  import APSpy.spec
>>>  APSpy.spec.EnableEPICS()
>>>  APSpy.spec.DefineMtr('mtrXX1','ioc1:mtr98','Example motor #1')
>>>  APSpy.spec.DefineMtr('mtrXX2','ioc1:mtr99','Example motor #2')
>>>  from APSpy.spec import *
>>>  mv(mtrXX1, 0.123)
APSpy.spec.DefinePseudoMtr(inpdict, comment='')[source]

Define one or more pseudo motors in terms of previously defined motors. Adds the new pseudo motor definition(s) to the motor table.

Parameters:
  • inpdict (dict) – defines a dictionary that defines pseudo motor postions in terms of real motor positions and maps pseudo-motor target positions into real motor target positions. Dictionary entries that do not correspond to previously defined motors are used to define new pseudo-motors.
  • comment (string) – a human-readable text field that describes the motor. Suggestion: include units and define the motion direction.
Returns:

key of entry created in motor table (str).

For computations in the dictionary, motor positions may be referenced in one of two ways, A[mtr] or T[mtr]. A[mtr] provides the actual position of the motor while T[mtr] provides the target position for the move, i.e., the value of the motor or pseudo-motor after the move, if it will be changed. For definitions of pseudo motors, use of A[] is usually correct, but for entries that compute target positions of real motors, one almost always wishes to use T[] to compute from target positions (this is most important for use with MoveMultipleMtr(), where multiple target positions are updated prior to any motor movement.). See the examples, below. Note also that these expressions are computed in the spec namespace, so the prefix ‘spec.’ on motor names (etc.) is not needed.

Note that all the routines in math and numpy are available for use in these calculations (but must be prefixed by math or numpy or np (such as math.log10() or np.exp2() or numpy.exp2() or constant math.pi). In addition, for convenience the following functions are also defined without a prefix: sind() (sine of angle in degrees), cosd() (cosine of angle in degrees), tand() (tangent of angle in degrees), asind() (inverse sine, returns angle in degrees), acosd() (inverse cosine, returns angle in degrees), atand() (inverse tangent, returns angle in degrees), abs(), sqrt() and exp().

Examples:

>>>  DefineMtr('j1','1idc:j1','sample table N jack')
>>>  DefineMtr('j2','1idc:j2','sample table SE jack')
>>>  DefineMtr('j3','1idc:j3','sample table SW jack')
>>>  APSpy.spec.DefinePseudoMtr({
...      # define pseudo motor position
...      'jack': '(A[j1] + A[j2] + A[j3])/3.',
...      # map motor movements in terms of pseudo motor target position
...      'j1': 'A[j1] + T[jack] - A[jack]',
...      'j2': 'A[j2] + T[jack] - A[jack]',
...      'j3': 'A[j3] + T[jack] - ((A[j1] + A[j2] + A[j3])/3)',
...      })

The above definition a new pseudo motor, jack is defined in terms of three motors that are already defined, j1, j2, and j3. Note that ‘T[jack] - A[jack]’ (or equivalently ‘T[jack] - ((A[j1] + A[j2] + A[j3])/3)’, both are used here as a pedagogical example) computes the difference between the target position for jack and its current position and then adds that difference to the positions for j1, j2, and j3, thus, the motors move relative to their initial positions. Note that the comments placed in the input are only a guide to the reader, the fact that ‘jack’ is new and j1, j2, and j3 are defined indicates that jack is to be defined.

>>>  DefineMtr('samX','1idc:m77','sample X position (mm) + outboard')
>>>  DefineMtr('samZ','1idc:m78','sample Z position (mm) + up')
>>>  DefineMtr('phi','1idc:mphi','sample rotation (deg)')
>>>  APSpy.spec.DefinePseudoMtr({
...      # define pseudo motor positions
...      'samLX': 'cosd(A[phi])*A[samX] + sind(A[phi])*A[samZ]',
...      'samLZ': '-sind(A[phi])*A[samX] + cosd(A[phi])*A[samZ]',
...      # define motor movements in terms of pseudo motor target position
...      'samX' : 'cosd(T[phi])*T[samLX] - sind(T[phi]) * T[samLZ]',
...      'samZ' : 'sind(T[phi])*T[samLX] + cosd(T[phi]) * T[samLZ]',
...      })

In the above definition two new pseudo motors, samLX and samLZ are defined in terms of three motors that are already defined, samX, samZ, and phi. This maps the axes defined by the sample translations samX, samZ which are rotated by motor phi relative to the diffractometer coordinate system into a static frame of reference. Note that use of T[samLX] and T[samLY] is necessary in the latter expressions, but A[phi] could be used in place of T[phi] as long as one does not try to move phi along with samLX and/or samLY in a single call to MoveMultipleMtr().

As described for DefineMtr(), if you will use the `` from APSpy.spec import * `` python command to import these routines into the current module’s name space, it is necessary to repeat this import command after defining all motors and pseudo motors to import the newly defined global symbols into the top namespace.

APSpy.spec.DefineScaler(prefix, channels=8, index=0)[source]

Defines a scaler to be used for this module

Parameters:
  • prefix (string) – the prefix for the scaler PV (ioc:mnnn). Omit the scaler record field name (.CNT, etc.)
  • channels (int) – the number of channels associated with the scaler. Defaults to 8.
  • index (int) – an index for the scaler, if more than one will be defined. The default (0) is used to define the scaler that will be used when ct() is called with one or no arguments.
Example (recommended for interactive use):
>>>  from APSpy.spec import *
>>>  EnableEPICS()
>>>  DefineScaler('id1:scaler1',16)
>>>  DefineScaler('id1:scaler2',index=1)
>>>  ct()
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
Alternate example (preferred for use in code):
>>>  import APSpy.spec as s
>>>  s.EnableEPICS()
>>>  s.DefineScaler('ioc1:3820:scaler1',16)
>>>  s.DefineScaler('ioc1:3820:scaler2',index=1)
>>>  s.ct()
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
>>>  s.ct(index=1)
[1, 2, 3, 4, 5, 6, 7, 8]
APSpy.spec.EnableEPICS(state=True)[source]

Call to enable communication with EPICS.

This must be called to enable communication with EPICS before initializing motors. If not called then APSpy will function in simulation mode only. If the PyEpics module cannot be loaded, then this function has no effect.

Parameters:state (bool) – if False is specified, then EPICS communication is disabled (default value, True).
APSpy.spec.ExplainMtr(mtr)[source]

Show the description for a motor, as defined in DefineMtr()

Parameters:mtr (various) – symbolic name for the motor, can take two forms: a motor key or a motor symbol.
Returns:motor description (str) or ‘?’ if not defined
APSpy.spec.GetDet(index=0)[source]

Return the main detector channel for the scaler or none if not defined. (See SetDet()) This is used for ASCAN, etc.

Parameters:index (int) – an index for the scaler, if more than one will be defined (see DefineScaler()). The default (0) is used if not specified.
Returns:the channel number of the Detector
APSpy.spec.GetMon(index=0)[source]

Return the monitor channel for the scaler or none if not defined. (See SetMon()) This is used for counting on the Monitor.

Parameters:index (int) – an index for the scaler, if more than one will be defined (see DefineScaler()). The default (0) is used if not specified.
Returns:the channel number of the Monitor
APSpy.spec.GetMtrInfo(mtr)[source]

Return a dictionary with motor information.

Parameters:mtr (str) – a key corresponding to an entry in the motor table. If the value does not correspond to a motor entry, an exception is raised.
Returns:dictionary with motor information
APSpy.spec.GetScalerInfo(index=0)[source]

returns information about a scaler based on the index

Parameters:index (int) – an index for the scaler, if more than one is be defined (see DefineScaler()). The default (0) is used if not specified.
Returns:a dictionary with information on the scaler
APSpy.spec.GetScalerLabels(index=0)[source]

returns the labels that have been retrieved for a scaler

Parameters:index (int) – an index for the scaler, if more than one is be defined (see DefineScaler()). The default (0) is used if not specified.
Returns:a list of labels
APSpy.spec.GetScalerLastCount(index=0)[source]

returns the last set of counts that have been read for a scaler

Parameters:index (int) – an index for the scaler, if more than one is be defined (see DefineScaler()). The default (0) is used if not specified.
Returns:a list of the last counts
APSpy.spec.GetScalerLastTime(index=0)[source]

returns the count time for the last read from a scaler

Parameters:index (int) – an index for the scaler, if more than one is be defined (see DefineScaler()). The default (0) is used if not specified.
Returns:a single float with the last elapsed time for that scaler (initialized at 0) of the last counts
APSpy.spec.ListMtrs()[source]

Returns a list of the variables defined as motor symbols.

Returns:a python list of defined motor symbols (list of str values).
APSpy.spec.MoveMultipleMtr(mtrposlist, nsteps=1, wait=True)[source]

Launch movement of several motors together. If a motor would be moved more than one time (for example because it is referenced in more than on pseudo-motor), only the last move is actually performed. The target for each motor is included in subsequent computations, so that when motor positions are computed from postions of more than one pseudo-motor, the performed move will represent the positions from the cummulative move of all previous motors. To deal with the case where motor speeds or movements are unequal, the requested moves can be broken down into a series of nsteps steps, where each motor will be moved an increment of 1/nsteps times the total requested change in position. This will not keep the movement on exactly the requested trajectory, but it will stay close.

Parameters:
  • mtrposlist (list) – A list of motor keys and target positions, for example [(samLX,1.1),(samLZ,0.25)]
  • nsteps (int) – the number of steps to be used to break down the requested move. The default, 1, means that all motors are launched at the same time for the entire requested movement range, but a value of 2 indicates that all motors will launched to the mid-point of the requested movement range and only after all motors have reached that point, will the subsequent set of moves be started.
  • wait (bool) – When wait is False, moves are started, but the routine returns immediately, but wait is True (default), the routine returns after all motors have stopped moving. If :nsteps is greater than 1, this parameter is ignored and the routine returns only after all requested moves are completed.

Example:

>>>  MoveMultipleMtr([(samLX,1.1),(samLZ,0.25)],5,wait=True)
APSpy.spec.PositionMtr(mtr, pos, wait=True)[source]

Move a motor

Position a motor associated with mtr to position pos, wait for the move to complete if wait is True, or else return immediately. The function attempts to verify the move command has been acted upon.

Parameters:
  • mtr (int) – a value corresponding to an entry in the motor table, as defined in DefineMtr(). If the value does not correspond to a motor entry, an exception is raised.
  • pos (float) – a value to position the motor. If the value is invalid or outside the limits an exception occurs (are hard limits checked?).
  • wait (bool) – a flag that specifies if the move should be completed before the function returns. If False, the function returns immediately.
APSpy.spec.ReadMtr(mtr)[source]

Return the motor position associated with the passed motor value.

Parameters:mtr (int) – a key corresponding to an entry in the motor table. If the value does not correspond to a motor entry, an exception is raised.
Returns:motor position (float).
APSpy.spec.SetDet(Detector=None, index=0)[source]

Set the main detector channel for the scaler.

The default is to restore this to the initial setting, where this is undefined. This is used for ASCAN, etc.

Parameters:
  • Detector (int) – channel number. If omitted the Detector is set as undefined. The valid range for this parameter is 0 through one less than the number of channels.
  • index (int) – an index for the scaler, if more than one will be defined (see DefineScaler()). The default (0) is used if not specified.
APSpy.spec.SetMon(Monitor=None, index=0)[source]

Set the monitor channel for the scaler. The default is to restore this to the initial setting, where this is undefined. This is needed for counting on the Monitor.

Parameters:
  • Monitor (int) – channel number. If omitted the Monitor is set as undefined. The valid range for this parameter is 0 through one less than the number of channels.
  • index (int) – an index for the scaler, if more than one will be defined (see DefineScaler()). The default (0) is used if not specified.
APSpy.spec.Sym2MtrVal(mtrsym)[source]

Converts a motor symbol (as a string) to the motor value (key) as assigned in DefineMtr()

Parameters:mtrsym (str) – a motor symbol (such as ‘phi’)
Returns str:motor value (such as mtr1002)
Raises :APSpyException if the value does not correspond to a motor entry.
APSpy.spec.UseEPICS()[source]

Show if use of EPICS is allowed or disabled, see EnableEPICS(), onsim() and offsim().

Returns:True if PyEpics has been loaded and enabled (see EnableEPICS()) and simulate mode is False (see onsim() and offsim()), False otherwise.
APSpy.spec.count_em(count=None, index=0)[source]

Cause scaler to start counting for specified period, but return immediately. On the first use, this will take the scaler out of autocount mode and put it into one-shot mode (this is because if one does not read the scaler shortly after a count when in autocount mode, the scaler returns to autocount and the values are lost.) If put in one-shot mode, then autocount will be restored when the python interpreter is exited.

Counting is on time if count is 0 or positive; Counting is on monitor if count < 0

Parameters:
  • count (float) – time (sec) to count, if omitted COUNT is used (see Global variables section)
  • index (int) – an index for the scaler, if more than one will be defined (see DefineScaler()). The default (0) is used if not specified.
Returns:

None

Example:
>>>  count_em()
>>>  # do other commands
>>>  wait_count()
>>>  get_counts()
APSpy.spec.ct(count=None, index=0, label=False)[source]

Cause scaler to count for specified period or to a specified number of counts on a prespecified channel (see SetMon())

Counting is on time if count is 0 or positive; Counting is on monitor if count < 0

Global variable S is set to the count values for the n channels (set in DefineScaler()) to provide functionality similar to SPEC.

Parameters:
  • count (float) – time (sec) to count, if omitted COUNT is used (see Global variables section)
  • index (int) – an index for the scaler, if more than one is defined (see DefineScaler()). The default (0) is used if not specified.
  • label (bool) – indicates if counts should be printed along with their labels The default (False) is to not print counts
Returns:

count values for the channels (see DefineScaler())

Example:

>>>  ct()
[10000000.0, 505219.0, 359.0, 499.0, 389.0, 356.0, 114.0, 53.0]
>>>  SetMon(3)
>>>  ct(-1000)
[20085739.0, 1011505.0, 719.0, 1000.0, 781.0, 715.0, 226.0, 105.0]
APSpy.spec.get_counts(wait=False)[source]

Read scaler with optional delay, must follow count_em

reads count values for the channels (see DefineScaler())

Parameters:wait (bool) – True causes the routine to wait for the scaler to complete; False (default) will read the scaler instananeously
Returns:a list of channels values
Example:
>>>  get_counts()
[1, 2, 3, 4, 5, 6, 7, 8]
APSpy.spec.get_mtrsym(key)[source]

return motor mtrsym given either mtrsym or mne

mne: motor menmonic symbol, such as phi

mtrsym: motor symbol, such as mtr1002. mtrsym is the key used to index mtrDB

Parameters:key (str) – either a motor mne or a mtrsym
Returns str:a motor key
Raises :APSpyUndefinedMotorException if mtrsym is not found
APSpy.spec.initElapsed()[source]

Initialize the elapsed time counter

APSpy.spec.mmv(mtrposlist, nsteps=1, wait=False)[source]

Launch movement of several motors together. By default, does not wait for all motion to complete. See the equivalent function, MoveMultipleMtr(), for a complete description.

Parameters:
  • mtrposlist (list) – A list of pairs of motor keys and target positions
  • nsteps (int) – the number of steps to be used to break down the requested move. The default, 1, means that all motors are launched at the same time for the entire requested movement range, but a value of 2 indicates that all motors will launched to the mid-point of the requested movement range and only after all motors have reached that point, will the subsequent set of moves be started.
  • wait (bool) – When wait is False, moves are started, but the routine returns immediately, but wait is True, the routine returns after all motors have stopped moving. the default is to not wait. Note that if nsteps is greater than 1, this parameter is ignored and the routine returns only after all requested moves are completed.

Example:

>>>  mmv([(samLX,1.1),(samLZ,0.25)])
APSpy.spec.mv(mtr, pos)[source]

Move motor without wait

If the move cannot be made, an exception is raised.

Parameters:
  • mtr (int) – a value corresponding to an entry in the motor table, as defined in DefineMtr(). If the value does not correspond to a motor entry, an exception is raised.
  • pos (float) – a value to position the motor. If the value is invalid or outside the limits, an exception occurs.
Example:
>>> mv(samX,0.1)
APSpy.spec.mvr(mtr, delta)[source]

Move motor relative to current position without wait.

If the move cannot be made, an exception is raised.

Parameters:
  • mtr (int) – a value corresponding to an entry in the motor table, as defined in DefineMtr(). If the value does not correspond to a motor entry, an exception is raised.
  • delta (float) – a value to offset the motor. If the resulting value is invalid or outside the limits, an exception occurs.
Example:
>>> mvr(samX,0.1)
APSpy.spec.offsim()[source]

Turns simulation mode off. Note that unlike EnableEPICS(), onsim() and offsim() can be used at any time.

APSpy.spec.onsim()[source]

Turns simulation mode on. Note that unlike EnableEPICS(), onsim() and offsim() can be used at any time.

APSpy.spec.setCOUNT(count)[source]

Sets the default counting time, see global variable COUNT (see Global variables section). Used in ct().

Parameters:count (float) – default time (sec) to count.
APSpy.spec.setDEBUG(state=True)[source]

Sets the debug state on or off, see global variable DEBUG (see Global variables section)

Parameters:state (bool) – DEBUG is initialized as False, but the default effect of setDEBUG, if no parameter is specified is to turn the debug state on.
APSpy.spec.setElapsed()[source]

Measure time from the last call to initElapsed().

Global variable ELAPSED is set to this value. This is called after motors are moved and when counting is done with scalers or sleep() is called.

Returns:the elapsed time in sec (float)
APSpy.spec.setRETRIES(count=20)[source]

Sets the maximum number of times to retry an EPICS operation (that would nominally be expected to work on the first try) before generating an exception. See global variable MAX_RETRIES (in Global variables section)

Parameters:count (float) – maximum number of times to retry an EPICS operation. Defaults to 20.
APSpy.spec.sleep(sec)[source]

Causes the script to delay for sec seconds.

This method is replaced when plotting is loaded by an alternate method (see sleepWithYield() in macros._makePlotWin()).

Parameters:sec (float) – time to delay in seconds
APSpy.spec.ummv(mtrposlist, nsteps=1, wait=True)[source]

Launch movement of several motors together. By default, waits for all motion to complete. See the equivalent function, MoveMultipleMtr(), for a complete description.

Parameters:
  • mtrposlist (list) – A list of pairs of motor keys and target positions
  • nsteps (int) – the number of steps to be used to break down the requested move. The default, 1, means that all motors are launched at the same time for the entire requested movement range, but a value of 2 indicates that all motors will launched to the mid-point of the requested movement range and only after all motors have reached that point, will the subsequent set of moves be started.
  • wait (bool) – When wait is False, moves are started, but the routine returns immediately, but wait is True (default), the routine returns after all motors have stopped moving. If nsteps is greater than 1, this parameter is ignored and the routine returns only after all requested moves are completed.

Example:

>>>  ummv([(samLX,1.1),(samLZ,0.25)])
APSpy.spec.umv(mtr, pos)[source]

Move motor with wait.

If the move cannot be completed, an exception is raised.

Parameters:
  • mtr (int) – a value corresponding to an entry in the motor table, as defined in DefineMtr(). If the value does not correspond to a motor entry, an exception is raised.
  • pos (float) – a value to position the motor. If the value is invalid or outside the limits, an exception occurs.
Example:
>>> umv(samX,0.1)
APSpy.spec.umvr(mtr, delta)[source]

Move motor relative to current position with wait.

If the move cannot be completed, an exception is raised.

Parameters:
  • mtr (int) – a value corresponding to an entry in the motor table, as defined in DefineMtr(). If the value does not correspond to a motor entry, an exception is raised.
  • delta (float) – a value to offset the motor. If the resulting value is invalid or outside the limits, an exception occurs.
Example:
>>> umvr(samX,0.1)
APSpy.spec.wa(label=False)[source]

Print positions of all motors defined using DefineMtr().

Parameters:label (bool) – a flag that specifies if the list should include the motor descriptions. If omitted or False, the descriptions are not included.
Example:
>>> wa()
===== ========
motor position
===== ========
samX  1.0     
samZ  0.5  
===== ========   
>>> wa(True)
===== ======== =================================
motor position description                      
===== ======== =================================
samX  1.0      sample X position (mm) + outboard
samZ  0.5      sample Z position (mm) + up      
===== ======== =================================
APSpy.spec.wait_count()[source]

Wait for scaler to finish, must follow count_em

Returns:None
Example:
>>>  wait_count()
APSpy.spec.wm(*mtrs)[source]

Read out specified motor(s).

Arguments :one or more motor table entries that are defined in DefineMtr().
Returns:a single float if a single argument is passed to wm. Returns a list of floats if more than one argument is passed.
Example:
>>> wm(samX,samZ)
[1.0, 0.0]