SPEC Simulation: Macros module

Module macros: Additional SPEC-like emulation

Python functions listed below are designed to implement functionality for data collection similar to that available in spec. Routines are divided into sections, General Purpose Routines, Logging, Plotting, Monitoring and Macros specific to 1-ID

General Purpose Routines

Note that the ascan() and dscan() are affected by what is used in SetDet() and possibly spec.SetMon() as well as the Logging configuration.

General routines Description
specdate() Returns the date/time formated like Spec
SetScanFile() Open a file for scan output
ascan() Scan a single motor on a fixed range
dscan() Scan a single motor on a range relative to current position
RefitLastScan() Fit a user-supplied function to a user-supplied function
SendTextEmail() Sends an e-mail message to one or more addresses
UserIn() Prompts a user for input

Logging

An important set of configuration parameters is that which determine what values are recorded. During data collection, for example, after each ascan() or dscan() data point. Also, for use in defining macros, the values can also be saved to a log file using write_logging_parameters().

Logging routines Description
init_logging() Initializes the list of items to be reported
show_logging() Displays a list of the items that will be logged
make_log_obj_PV() Define Logging Object that records a PV value
make_log_obj_Global() Define Logging Object that records a global variable
make_log_obj_PVobj() Define Logging Object that records a value from a PVobj object
make_log_obj_motor() Define Logging Object that records a motor position.
make_log_obj_scaler() Define Logging Object that records a scaler channel value.
log_it() Adds a Logging Object to the list of items to be reported
add_logging_PV() Adds a PV to the list of items to be reported
add_logging_Global() Adds a Global variable to the list of items to be reported
add_logging_PVobj() Adds a PV object to the list of items to be reported
add_logging_motor() Adds a motor reference to the list of items to be reported
add_logging_scaler() Adds a scaler channel to the list of items to be reported
write_logging_header() Writes a header line with labels for each logged item
write_logging_parameters() Write the current value of each logged variable

Two examples for setting up logging (new method):

>>> import macros
>>> macros.init_logging()
>>> GE_prefix = 'GE2:cam1:'
>>> macros.log_it(macros.make_log_obj_PV('GE_fname',GE_prefix+"FileName",as_string=True))
>>> macros.log_it(macros.make_log_obj_PV('GE_fnum',GE_prefix+"FileNumber"))
>>> macros.log_it(macros.make_log_obj_motor(spec.samX))
>>> macros.log_it(macros.make_log_obj_scaler(9))
>>> macros.log_it(macros.make_log_obj_Global('var S9','spec.S[9]'))
>>> macros.log_it(macros.make_log_obj_PV('p1Vs',"1idc:m64.RBV"))

Note that the make_log_obj_scaler and make_log_obj_Global calls above will record the same value (though with different headings), but the make_log_obj_scaler is a better choice as the second option could produce the wrong value if use of a second scaler is later added to a script.

Old method (does the same as the previous) is:

>>> import macros
>>> macros.init_logging()
>>> GE_prefix = 'GE2:cam1:'
>>> macros.add_logging_PV('GE_fname',GE_prefix+"FileName",as_string=True)
>>> macros.add_logging_PV('GE_fnum',GE_prefix+"FileNumber")
>>> macros.add_logging_motor(spec.samX)
>>> macros.add_logging_scaler(9)
>>> macros.add_logging_Global('var S9','spec.S[9]')
>>> macros.add_logging_PV('p1Vs',"1idc:m64.RBV")

Example for use of logging in a script:

>>> mac.write_logging_header(logname)
>>> spec.umv(spec.mts_y,stY) 
>>> for iLoop in range(nLoop):
>>>     spec.umvr(spec.mts_y,dY) 
>>>     count_em(Nframe*tframe)
>>>     GE_expose(fname, Nframe, tframe)
>>>     wait_count()
>>>     get_counts()
>>>     mac.write_logging_parameters(logname)
>>> mac.beep_dac()

This code step-scans motor mts_y. It writes a header to the log file at the beginning of the operation and then logs parameters after each measurement. Measurements are done in GE_expose() and the default scaler, which are run at the same time.

Note that it can be useful to put differing sets of logging configurations into files where they can be invoked as needed using execfile(xxx.py) [where xxx.py is the name of the file to be read]. Do not use import for this task because import will process the file when it is referenced first, but will not do anything if one attempts to import the file again (to reset values back after a different setting has been used). One must use reload to force that.

Plotting

Similar to logging, it is also possible to designate that values can be plotted as part of a script. A Logging Object (from the make_log_obj_... routines) is needed for each item that will be plotted.

Plotting routines Description
make_log_obj_PV() Define Logging Object that records a PV value
make_log_obj_Global() Define Logging Object that records a global variable
make_log_obj_PVobj() Define Logging Object that records a value from a PVobj object
make_log_obj_motor() Define Logging Object that records a motor position.
make_log_obj_scaler() Define Logging Object that records a scaler channel value.
DefineLoggingPlot()
Creates a plot (if needed) or tab on tab to display values
and register items to be plotted.
UpdateLoggingPlots()
Read and display all parameters added to plot in
DefineLoggingPlot().
InitLoggingPlot()
Clear out plotting definitions from previous calls to
DefineLoggingPlot().

Examples:

>>> macros.DefineLoggingPlot(
...     'I vs pos',
...     macros.make_log_obj_motor(spec.samX),
...     macros.make_log_obj_scaler(2),
...     )
>>> spec.umv(spec.samX,2) 
>>> for iLoop in range(30):
...    spec.umvr(spec.samX,0.05)
...    spec.ct(1)
...    macros.UpdateLoggingPlots()

In the above example, a scaler channel is read and plotted against a motor position.

>>> macros.DefineLoggingPlot(
...     'I vs time',
...     macros.make_log_obj_Global('time (sec)','spec.ELAPSED'),
...     macros.make_log_obj_scaler(2),
...     macros.make_log_obj_scaler(3),
...     )
>>> spec.initElapsed()
>>> for iLoop in range(30):
...    spec.ct(1)
...    macros.UpdateLoggingPlots()

In the above example, two scaler channels are plotted against elapsed time.

Monitoring

Monitoring of PVs is used to record values of selected PVs when any designated PV changes. Optionally, only when that PV changes to a specific value or the recording can be limited to not occur more than a maximum frequency. It may be best to perform monitoring in a process separate from the one making changes to EPICS PVs.

Monitoring routines Description
DefMonitor() Set up a PV to be monitored
StartAllMonitors() Start the monitoring operation

Monitor definition examples:

>>> spec.EnableEPICS()
>>> macros.DefMonitor('/tmp/tst','1ide1:m1.VAL',
...               ('1id:scaler1.S2','1id:scaler1.S3','1ide1:m1.RBV','1ide1:m1.VAL')
...               )
>>> macros.StartAllMonitors()

This will report the values of four PVs every time that PV 1ide1:m1.VAL is changed.

>>> macros.DefMonitor('/tmp/tst','1ide1:m1.RBV',
...               ('1id:scaler1.S3','1ide1:m1.RBV','1ide1:m1.VAL'),
...               pvvalue=0.0)
>>> macros.StartAllMonitors()

This will report three PVs, but only when PV 1ide1:m1.RBV is changed to 0.0 (within 0.00001)

>>> macros.DefMonitor('/tmp/tst','1ide1:m1.RBV',
...              ('1id:scaler1.S2','1id:scaler1.S3','1ide1:m1.RBV','1ide1:m1.VAL'),
...               delay=1.0)
>>> macros.StartAllMonitors()

This will report three PVs, every time that PV 1ide1:m1.RBV is changed, but only a maximum of one change will be reported each second.

Macros specific to 1-ID

These macros reference 1-ID PV’s or are customized for 1-ID in some other manner.

1-ID specific routines Description
beep_dac() Causes a beep to sound
Cclose() Close 1-ID fast shutter in B hutch
Copen() Open 1-ID fast shutter in B hutch
shutter_sweep() Set 1-ID fast shutter to external control
shutter_manual() Set 1-ID fast shutter to manually control
check_beam_shutterA() Open 1-ID Safety shutter to bring beam into 1-ID-A
check_beam_shutterC() Open 1-ID Safety shutter to bring beam into 1-ID-C
Sopen() Same as check_beam_shutterC(), bring beam into 1-ID-C
MakeMtrDefaults() Create a file with default motor assignments
SaveMotorLimits() Create a file with soft limits for off-line simulations

Complete Function Descriptions

The functions available in this module are listed below.

APSpy.macros.Cclose()[source]

Close 1-ID fast shutter in B hutch

APSpy.macros.Copen()[source]

Open 1-ID fast shutter in B hutch

APSpy.macros.DefMonitor(fileprefix, pv, monitorlist, pvvalue=None, delay=None)[source]

Write values of PVs in monitorlist each time that PV pv changes, values are written to a file named by fileprefix + timestamp optionally, values are written only if the PV is set to value pvvalue (if not None) and optionally only recording the first change in a period of delay seconds (if not None):

Monitoring starts when StartAllMonitors() is called.

Parameters:
  • fileprefix (str) – defines name of file to use
  • pv (str) – PV to monitor
  • monitorlist (list) – list of PVs to report
  • pvvalue (?) – report monitored PV only if this value is obtained
  • delay (float) – do not log changes more frequently than this frequency in seconds

see Monitoring for an example of use.

APSpy.macros.DefineLoggingPlot(tablbl, Xvar, *args)[source]

Creates a plot window (if needed) or tab on plot to display values. Parameters include a label for the tab, a Logging Object that will be used as an x-value and as many Logging Object as desired (minimum 1) that will be define y-values. Each time this routine is called, a new plot tab is called. As many plot tabs can be created and populated as desired.

see Plotting for an example of use.

Parameters:
class APSpy.macros.FitClass(x, y)[source]

Defines a prototype class for deriving fitting class implementations. A fitting class should define at least two method: __init__ and Eval.

__init__(x,y) computes a list of very approximate values for the fit parameters,
good enough to be used as the starting values in the fit. The number of terms computed determines the number of parameter values that will be fit.

Eval(parms,x) provides the function to be fit.

optionally, Format(parms) is used to return a nicely-formatted text string with
the fitted parameters.
Eval(parm, x)[source]

Evaluate the fitting function and return a “y” value computed for each value in x. Ideally this expression computes all values in a single NumPy expression, but looping is allowed. Both parameters should be lists, tuples or numpy arrays.

Parameters:
  • parm (list,tuple,etc.) – parameters in the same order as returned by StartParms()
  • x (list,tuple,etc.) – values of the independent parameter (scanned variable) for evaluation of the function.
Format(parm)[source]

This prints the parameters, potentially in a way that explains what they mean. If not overridden, one gets “Parameter values = <list>”

Parameters:parm (list,tuple,etc.) – parameters in the same order as returned by StartParms()
StartParms()[source]

Return the starting parameter values determined in __init__()

class APSpy.macros.FitGauss(x, y)[source]

Define a function for fitting with a Gaussian.

Parameters are defined as:

index value
[0] location of peak
[1] function value at maximum, less parm[3]
[2] width as FWHM
[3] added to all points
Eval(parm, x)[source]

Evaluate the Gaussian

Format(parm)[source]

Prints the parameters

class APSpy.macros.FitSawtooth(x, y, Symmetric=True)[source]

Define a function for fitting with a symmetric or asymmetric saw-tooth function.

Parameters are defined as:

index value
[0] location of peak
[1] function value at maximum
[2] added to all points
[3] asymmetric: slope on leading side of peak (+ is rising) symmetric: slope on both sides of peak
[4] asymmetric: slope on trailing side of peak (+ is falling)
Parameters:Symmetric (bool) – determines if the SawTooth is symmetric (True) or asymmetric (False), meaning that the leading side and the trailing side of the peak can have different slopes.
Eval(parm, x)[source]

Evaluate the sawtooth function

APSpy.macros.InitLoggingPlot()[source]

Clear out plot definitions from previous calls to DefineLoggingPlot(). Prevents updates from occuring in UpdateLoggingPlot(), but does not delete any tabs or the window.

APSpy.macros.MakeMtrDefaults(fil=None, out=None)[source]

Routine in Development: Creates an initialization file from a spreadsheet describing the 1-ID beamline motor assignments

Parameters:
  • fil (str) – input file to read. By default opens file ../1ID/1ID_stages.csv relative to the location of the current file.
  • out (str) – output file to write. By default writes file ../1ID/mtrsetup.py.new Note that if the default file name is used, the output file must be renamed before use to mtrsetup.py
APSpy.macros.RefitLastScan(FitClass, **kwargs)[source]

Fit and plot an arbitrary equation to data from the last ascan

Parameters:FitClass (class) – a class that defines a minumum of two methods, one to define a fitting function and the other to determine rough starting values for the fitting function. See FitGauss or FitSawtooth for examples of Fitting classes.

Optional: additional keyword parameters will be passed for the creation of a FitClass object.

Returns:an optimized list of parameters or None if the fit fails
Example:
>>> macros.RefitLastScan(macros.FitSawtooth)
Parameter values =1.45, 28.5, 1.5, 2.1053
array([  1.44999999,  28.50005241,   1.4999749 ,   2.10525894])
or
>>> macros.RefitLastScan(macros.FitSawtooth, Symmetric=False)
Parameter values =1.45, 28.5, 1.5, 2.1053, 2.1053
array([  1.44999999,  28.5000524 ,   1.49997491,   2.10525896,   2.10525891])
APSpy.macros.SaveMotorLimits(out=None)[source]

Routine in Development: Creates an initialization file for simulation use with the limits for every motor PV that is found in the current 1-ID beamline motor assignments. import mtrsetup.py or equivalent first. Scans each PV from 1 to the max number defined.

Parameters:out (str) – output file to write, writes file motorlimits.dat.new in the same directory as this file by default. Note that if the default file name is used, the output file must be renamed before use to motorlimits.dat
APSpy.macros.SendTextEmail(recipientlist, msgtext, subject='APSpy auto msg', recipientname=None, senderemail='1ID@aps.anl.gov')[source]

Send a short text string as an e-mail message. Uses the APS outgoing email server (apsmail.aps.anl.gov) to send the message via SMTP.

Parameters:
  • recipientlist (str) – A string containing a single e-mail address or a list or tuple (etc.) containing a list of strings with e-mail addresses.
  • msgtext (str) – a string containing the contents of the message to be sent.
  • subject (str) – a subject to be included in the e-mail message; defaults to “APSpy auto msg”.
  • recipientname (str) – a string to be used for the recipient(s) of the message. If not specified, no “To:” header shows up in the e-mail. This should be an e-mail address or @aps.anl.gov is appended.
  • senderemail (str) – a string with the e-mail address identified as the sender of the e-mail; defaults to “1ID@aps.anl.gov”. This should be an e-mail address or @aps.anl.gov is appended.
Examples:
>>> msg = 'This is a very short e-mail'
>>> macros.SendTextEmail(['toby@sigmaxi.net','brian.h.toby@gmail.com'],msg, subject='test')
or with a single address:
>>> msg = """Dear Brian,
...   How about a longer message?
... Thanks, Brian
... """
>>> to = "toby@anl.gov"
>>> macros.SendTextEmail(to,msg,recipientname='spamee@anl.gov',senderemail='spammer@anl.gov')
A good way to use this routine is in a try/except block:
>>> userlist = ['user@univ.edu','contact@anl.gov']
>>> try:
>>>     macros.write_logging_header(logname)
>>>     spec.umv(spec.mts_y,stY) 
>>>     for iLoop in range(nLoop):
>>>         spec.umv(spec.mts_x2,stX) 
>>>         for xLoop in range(nX): 
>>>             GE_expose(fname, Nframe, tframe)
>>>             macros.write_logging_parameters(logname)
>>>             spec.umvr(spec.mts_x2,dX) 
>>>         spec.umvr(spec.mts_y,dY) 
>>>     macros.beep_dac()
>>> except Exception:
>>>     import traceback
>>>     msg = "An error occurred at " + macros.specdate()
>>>     msg += " in file " + __file__ + "\n\n"
>>>     msg += str(traceback.format_exc())
>>>     macros.SendTextEmail(userlist, msg, 'Beamline Abort')
APSpy.macros.SetScanFile(outfile=None)[source]

Set a file for output from ascan, etc. The output is intended to closely mimic what spec produces in ascan and dscan.

Parameters:outfile (str) – the file name to be opened. If not specified, output is sent to the terminal. If the file is new (or is the not specified) a header listing all motors, etc. is printed
APSpy.macros.ShowPlots()[source]

Pause to show plot screens. Call this at the end of a script, if needed.

APSpy.macros.Sopen()

If not already open, open 1-ID-C Safety shutter to bring beam into 1-ID-C. Keep trying in an infinite loop until the shutter opens.

APSpy.macros.StartAllMonitors(sleep=True)[source]

Start the monitoring defined in DefMonitor. Optionally delay until control-C is pressed. The control-C operation closes all files and clears the monitoring information.

Parameters:sleep (bool) – if True (default) start an infinite loop of one second delays

see Monitoring for an example of use.

APSpy.macros.UpdateLoggingPlots()[source]

Read all current values in plot and display in plots

see Plotting for an example of use.

APSpy.macros.UserIn(parname, default, typ)[source]

Prompt a user for input.

For reasons unclear, this is not raising an Exception on Control-C on Linux, but Control D does raise an exception, so use that.

Parameters:
  • parname (str) – a string to be given to the user to tell them what to input
  • default ((any)) – a default value, if no input is provided, use None to force user input
  • typ (type) – a data type, such as int, float, or str
Returns:

the value provided by the user in the selected type

Examples:

>>> UserIn('test',2.0,float)
test (2.0): x
Invalid, try again
test (2.0): 3.1
3.1
>>> UserIn('test',None,float)
test (None): 
Invalid, try again
test (None): 4
4.0
>>> UserIn('test',2,int)
test (2): 2.0
Invalid, try again
test (2): 2
2
APSpy.macros.add_logging_Global(txt, var)[source]

Define a global variable to be recorded when write_logging_parameters() is called.

Parameters:
  • txt (str) – defines a text string, preferably short, to be used when write_logging_header() is called as a header for the item to be logged.
  • var (str) – defines a Python variable that will be logged each time write_logging_parameters() is called. Note that this is read inside the macros module so the variable must be defined inside that module or must be prefixed by a reference to a module referenced in that module, e.g. spec.S[0]

see Logging for an example of use.

APSpy.macros.add_logging_PV(txt, PV, as_string=False)[source]

Define a PV to be recorded when write_logging_parameters() is called.

Parameters:
  • txt (str) – defines a text string, preferably short, to be used when write_logging_header() is called as a header for the item to be logged.
  • PV (str) – defines an EPICS Process Variable that will be read and logged each time write_logging_parameters() is called.
  • as_string (bool) – if True, the PV will be translated to a string. When False (default) the native data type will be used. Use of True is of greatest for waveform records that are used to store character strings as a series of integers.

see Logging for an example of use.

APSpy.macros.add_logging_PVobj(txt, PVobj, as_string=False)[source]

Define a PVobj to be recorded when write_logging_parameters() is called.

Parameters:
  • txt (str) – defines a text string, preferably short, to be used when write_logging_header() is called as a header for the item to be logged.
  • PV (epics.PV) – defines a PyEpics PV object that is connected to an EPICS Process Variable. The PV method .get() will be used to read that PV to log it each time write_logging_parameters() is called.
  • as_string (bool) – if True, the PV value will be translated to a string. When False (default) the native data type will be used. Use of True is of greatest for waveform records that are used to store character strings as a series of integers.

see Logging for an example of use.

APSpy.macros.add_logging_motor(mtr)[source]

Define a motor object to be recorded when write_logging_parameters() is called. Note that the heading text string is defined as the motor’s symbol (see spec.DefineMtr()).

Parameters:mtr (str) – a reference to a motor object, returned by spec.DefineMtr() or defined in the motor symbol. The position of the motor will be read and logged each time write_logging_parameters() is called.

see Logging for an example of use.

APSpy.macros.add_logging_scaler(channel, index=0)[source]

Define a scaler channel to be recorded when write_logging_parameters() is called. Note that the heading text string is defined as the scaler’s label (which is read from the scaler when spec.DefineScaler() is run).

Parameters:
  • channel (str) – a channel number for a scaler, which can be any value between 0 and one less than the number of channels. The last-read value of that scaler logged each time write_logging_parameters() is called.
  • index (int) – an index for the scaler, if more than one is be defined (see DefineScaler()). The default (0) is used if not specified.

see Logging for an example of use.

APSpy.macros.ascan(mtr, start, finish, npts, count, index=0, settle=0.0, _func='ascan')[source]

Scan one motor and record parameters set with logging to the scanfile (see func:SetScanFile).

Parameters:
  • mtr (str) – a reference to a motor object, returned by spec.DefineMtr() or defined in the motor symbol.
  • start (float) – starting position for scan
  • finish (float) – ending position for scan
  • npts (int) – number of points for scan
  • count (float) – count time. Counting is on time (sec) if count is 0 or positive; Counting is on monitor if count < 0
  • index (int) – an index for the scaler, if more than one will be defined (see DefineScaler()). The default (0) is used if not specified.
  • settle (float) – a time to wait (sec) after the motor has been moved before counting is starting. Default is 0.0 which means no delay
Example:
>>> spec.SetDet(2)
>>> macros.ascan(spec.samX,1,2,21,1,settle=.1)
It is recommended that if ascan will be run in command line, where python commands are
typed into a console window, that ipython be used in pylab mode (ipython --pylab).
APSpy.macros.beep_dac(beeptime=1.0)[source]

Set the 1-ID beeper on for a fixed period, which defaults to 1 second uses PV object beeper (defined as 1id:DAC1_8.VAL) makes sure that the beeper is actually turned on and off throws exception if beeper fails

Parameters:beeptime (float) – time to sound the beeper (sec), defaults to 1.0
APSpy.macros.check_beam_shutterA()[source]

If not already open, open 1-ID-A Safety shutter to bring beam into 1-ID-A. Keep trying in an infinite loop until the shutter opens.

APSpy.macros.check_beam_shutterC()[source]

If not already open, open 1-ID-C Safety shutter to bring beam into 1-ID-C. Keep trying in an infinite loop until the shutter opens.

APSpy.macros.dscan(mtr, start, finish, npts, count, index=0, settle=0.0)[source]

Relative scan of motor, see func:ascan,

Parameters:
  • mtr (str) – a reference to a motor object, returned by spec.DefineMtr() or defined in the motor symbol.
  • start (float) – starting position for scan, relative to current motor position
  • finish (float) – ending position for scan, relative to current motor position
  • npts (int) – number of points for scan
  • count (float) – count time. Counting is on time (sec) if count is 0 or positive; Counting is on monitor if count < 0
  • index (int) – an index for the scaler, if more than one will be defined (see DefineScaler()). The default (0) is used if not specified.
  • settle (float) – a time to wait (sec) after the motor has been moved before counting is starting. Default is 0.0 which means no delay
Example:
>>> spec.SetDet(2)
>>> macros.dscan(spec.samX,-1,1,21,1,settle=.1)
It is recommended that if dscan will be run in command line, where python commands are
typed into a console window, that ipython be used in pylab mode (ipython --pylab).
APSpy.macros.init_logging()[source]

Initialize the list of data items to be logged

see Logging for an example of use.

APSpy.macros.log_it(LogObj)[source]

Add a Logging Object into list to be recorded when write_logging_parameters() is called.

Parameters:LogObj (object) – a reference to a Logging Object created by make_log_obj_PV(), make_log_obj_Global(), make_log_obj_PVobj(), make_log_obj_motor() or make_log_obj_scaler()
APSpy.macros.make_log_obj_Global(txt, var)[source]

Define Logging Object that records a global variable

Parameters:
  • txt (str) – defines a text string, preferably short, to be used when write_logging_header() is called as a header for the item to be logged.
  • var (str) – defines a Python variable that will be logged each time write_logging_parameters() is called. Note that this is read inside the macros module so the variable must be defined inside that module or must be prefixed by a reference to a module referenced in that module, e.g. spec.S[0]

see Logging for an example of use.

APSpy.macros.make_log_obj_PV(txt, PV, as_string=False)[source]

Define Logging Object that records a PV value

Parameters:
  • txt (str) – defines a text string, preferably short, to be used when write_logging_header() is called as a header for the item to be logged.
  • PV (str) – defines an EPICS Process Variable that will be read and logged each time write_logging_parameters() is called.
  • as_string (bool) – if True, the PV will be translated to a string. When False (default) the native data type will be used. Use of True is of greatest for waveform records that are used to store character strings as a series of integers.

see Logging for an example of use.

APSpy.macros.make_log_obj_PVobj(txt, PVobj, as_string=False)[source]

Define Logging Object that records a value from a PVobj object

Parameters:
  • txt (str) – defines a text string, preferably short, to be used when write_logging_header() is called as a header for the item to be logged.
  • PV (epics.PV) – defines a PyEpics PV object that is connected to an EPICS Process Variable. The PV method .get() will be used to read that PV to log it each time write_logging_parameters() is called.
  • as_string (bool) – if True, the PV value will be translated to a string. When False (default) the native data type will be used. Use of True is of greatest for waveform records that are used to store character strings as a series of integers.

see Logging for an example of use.

APSpy.macros.make_log_obj_motor(mtr)[source]

Define Logging Object that records a motor position. Note that the heading text string is defined as the motor’s symbol (see spec.DefineMtr()).

Parameters:mtr (str) – a reference to a motor object, returned by spec.DefineMtr() or defined in the motor symbol. The position of the motor will be read and logged each time write_logging_parameters() is called.

see Logging for an example of use.

APSpy.macros.make_log_obj_scaler(channel, index=0)[source]

Define Logging Object that records a scaler channel value. Note that the heading text string is defined as the scaler’s label (which is read from the scaler when spec.DefineScaler() is run).

Parameters:
  • channel (str) – a channel number for a scaler, which can be any value between 0 and one less than the number of channels. The last-read value of that scaler logged each time write_logging_parameters() is called.
  • index (int) – an index for the scaler, if more than one is be defined (see DefineScaler()). The default (0) is used if not specified.

see Logging for an example of use.

APSpy.macros.show_logging()[source]

Show the user the current logged items

APSpy.macros.shutter_manual()[source]

Set 1-ID fast shutter so that it will not be controlled by the GE TTL signal and can be manually opened and closed with Copen() and Cclose()

APSpy.macros.shutter_sweep()[source]

Set 1-ID fast shutter so that it will be controlled by an external electronic control (usually the GE TTL signal)

APSpy.macros.specdate()[source]

format current date/time as produced in Spec

Returns:the current date/time as a string, formatted like “Thu Oct 04 18:24:14 2012”
Example:
>>> macros.specdate()
'Thu Oct 11 16:16:39 2012'
APSpy.macros.write_logging_header(filename='')[source]

Write a header for parameters recorded when write_logging_parameters() is called.

Parameters:filename (str) – a filename to be be used for output. If not specified, the output is sent to the terminal window.

see Logging for an example of use.

APSpy.macros.write_logging_parameters(filename='')[source]

Record the current value of all items tagged to be recorded in add_logging_PV(), add_logging_Global(), add_logging_PVobj(), add_logging_motor() or add_logging_scaler().

Parameters:filename (str) – a filename to be be used for output. If not specified, the output is sent to the terminal window.

see Logging for an example of use.