The instrument module
Software representation of a physical instrument.
An Instrument is an object-oriented representation of an instrument—that is,
an object which can accept or return data or do things. Most instruments will be
physical devices like voltmeters or cryostats, but they may also be purely
computational.
This module provides the following class.
- Instrument:
- An abstract base class which should be extended by real instruments, each
of which should define their own capabilities.
Classes
Instrument
-
class src.core.instrument.Instrument(experiment, name='Abstract instrument', spec=None)[source]
An Instrument is an object-oriented software representation of a
physical instrument.
The Instrument class essentially provides an interface (in the
technical, computer science sense) which all instruments should implement.
It defines the methods and properties which all Instrument subclasses
are expected to provide, and it should be overridden for each instrument
model.
Since an instrument generally defines what operations it is able to carry
out, subclasses of Instrument should implement the getActions method.
Parameters : | experiment : Experiment
The Experiment object which owns this instrument.
name : str
The name of the instrument.
spec : list of InstrumentParameter
A list of instances of InstrumentParameter specifying the information
necessary for the instrument to be used and referenced. This should
include, for example, the VISA address of the instrument, if
applicable. If None, the default values will be used.
|
Methods
-
finalize()[source]
Release control of the instrument.
-
getAction(name, instantiate=True)[source]
Return either the action tuple or object with the given name.
Scan through the list of actions implemented by the instrument to find
one which has the specified name, and return either the ActionSpec
or an Action instance associated with it.
Parameters : | name : str
A string specifying the name which identifies the desired action.
instantiate : bool
Whether to create an instance of the action. If False, the
ActionSpec tuple will be returned instead of an Action object.
|
Returns : | ActionSpec or Action :
The ActionSpec (if instantiate is False) or Action (if
instantiate is True) specified by `name, or None if name
cannot be found.
|
-
getActions()[source]
Return a list of Action tuples implemented by the instrument.
-
classmethod getDefaultName()[source]
Return a default name for the instrument.
-
getEqualEnoughAction(compAction)[source]
Return an Action which is ‘the same as’ compAction.
Two actions are “the same” if they have the same description and the
same parameters. Parameters are “the same” if they have the same
name, description, and format string.
-
getExperiment()[source]
Return the experiment which owns this instrument.
Returns : | Experiment :
The Experiment object of which this instrument is part.
|
-
getInformation()[source]
Return the information string describing this instrument.
Returns : | str :
The information string for this instrument.
|
-
getName()[source]
Return the user-specified name of this instrument.
Returns : | str :
The name of the instrument.
|
-
classmethod getRequiredParameters()[source]
Return a template for the specification of the instrument.
The specification indicates which parameters must be defined for the
instrument to work. This should be overridden to indicate the
parameters required for specific instruments.
Returns : | list of InstrumentParameter :
A list of InstrumentParameter objects indicating what
information must be supplied to configure the instrument.
|
-
getSpecification()[source]
Return the specification of the instrument.
Returns : | list of InstrumentParameter :
A list of InstrumentParameters indicating the information
characterizing the instrument.
|
-
getStatusMonitor()[source]
Return the status monitor.
Returns : | StatusMonitor :
The StatusMonitor object for this instrument.
|
-
getXML(indent=0)[source]
Return an XML string representing the instrument.
Returns : | str :
A string containing XML data representing all of the data related
to the instrument, possibly useful as an alternative to pickle.
|
-
initialize()[source]
Prepare the instrument for use.
-
classmethod isSingleton()[source]
Return whether at most one instance of the instrument may exist.
Returns : | bool :
Whether only zero or one instance of the instrument may exist.
|
-
setExperiment(experiment)[source]
Set the experiment which owns this instrument.
Parameters : | experiment : Experiment
The Experiment object of which this instrument is part.
|
-
setName(name)[source]
Set the name of the instrument.
Parameters : | name : str
The name of the instrument.
|
-
setSpecification(newSpec)[source]
Set the specification of the instrument.
Parameters : | newSpec : list of InstrumentParameter
A list of InstrumentParameters indicating the information
characterizing the instrument.
|
-
setStatusMonitor(statusMonitor)[source]
Set the status monitor.
Parameters : | statusMonitor : StatusMonitor
The new StatusMonitor object for this instrument.
|
-
waitWhilePaused(obeyPause=True)[source]
Wait until the experiment is no longer paused.
InstrumentParameter
-
class src.core.instrument.InstrumentParameter(description, value='', allowed=None, formatString='%s')[source]
A parameter for characterizing an instrument.
Each Instrument object must specify what information is necessary to
initially configure itself. For example, in order to communicate with the
computer, an Instrument representing any GPIB instrument must have
a VISA address, so that Instrument should require a Parameter object
corresponding to said address.
Parameters : | description : str
A string indicating what the parameter is, so that the software can
prompt the user for a value in an understandable way.
value : str or int or float
The value of the parameter. Since parameters are initially defined
at compile time, they are defined with a default value. This can
later be changed.
allowed : list or function or None
Information to indicate what values are permitted for the parameter.
If allowed is None, any value will be accepted (assuming, of
course, that it can be typecast into the form indicated by
formatString). If it is a function (or a method), the function
will be evaluated and returned every time the allowed property is
queried. Using a function would be useful for getting a list of
VISA addresses seen by the computer; a simple list would not be
good, since instruments can be connected or disconnected, which would
change the values.
formatString : str
A string indicating how the value should be formatted. An example
could be ‘%.6e’ for an exponential value with six digits after the
decimal. Note that ‘%s’ (a simple string) is the only value which
makes sense if allowed is not None.
|
Methods
-
allowed[source]
Get the allowed values for the parameter.
Returns : | list of str or None :
The allowed values for the parameter. If any value is accepted,
then None is returned. Otherwise, the returned value will be
a list of strings.
|
-
description[source]
Get the description of the instrument parameter.
Returns : | str :
The description of the instrument parameter.
|
-
getXML(indent=0)[source]
Return an XML string representing the parameter.
-
value[source]
Get the value of the instrument parameter.
Returns : | str or int or float :
The value of the instrument parameter. The value will be of the
proper type. For example, if the parameter represents a lock-in’s
frequency, the value will be a float.
|
Controller
-
class src.core.instrument.Controller(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)[source]
A base class for instrument controllers.
Every subclass must implement the getInstrumentClassName class method,
which should return a string indicating the name of the class of the
instrument controlled by the Controller subclass.
Methods
-
classmethod getInstrumentClassName()[source]
Return the class name of the instrument managed by this controller.
Returns : | str :
The name of the class of the instrument controlled by this object.
|
-
classmethod isSingleton()[source]
Return whether at most one instance of the controller may exist.
Returns : | bool :
Whether only zero or one instance of the controller may exist.
|
System
-
class src.core.instrument.System(experiment)[source]
A software representation of the computer.
The System instrument carries out a host of general-purpose operations
including inserting time delays, setting filenames, and performing
calculations.
It also provides access to a series of loop types for performing a
single action, or a set of actions, multiple times.
Methods
-
calculate(expr)[source]
Numerically evaluate an expression.
Parameters : | expr : str
A string which, when constants, parameters, column data, and
standard mathematical functions have been substituted into it,
represents a mathematical expression that can be evaluated to
yield a floating-point number.
|
Returns : | float :
The result of evaluating the input expression.
|
-
finalize()[source]
Finalize the instrument
-
getActions()[source]
Return a list of supported actions.
-
initialize()[source]
Initialize the instrument.
-
setFile(folder, filebase, scan)[source]
Set the files to which the data will be stored.
Parameters : | folder : str
The folder into which the file will be saved. The folder must
exist.
filebase : str
The base name of the file, which is the filename without any
leading directories or following extensions.
scan : int
A scan number to prepend to the filename. If it is a positive
number, it will be used as-is. If it is negative, the scan
will be chosen to be the first integer larger than all other
scan numbers in the data folder. If it is None, no scan number
will be prepended.
|
-
setNumber(number)[source]
Set the value of an internal number.
-
setStoredString(string)[source]
Set the value of an internal string.
-
waitLong(delay)[source]
Pause for a specified time, updating while waiting.
Parameters : | delay : float
The time to wait, in seconds.
|
-
waitShort(delay)[source]
Pause for a specified time.
Parameters : | time : float
The time to wait, in seconds.
|
Postprocessor
-
class src.core.instrument.Postprocessor(experiment)[source]
An instrument for performing post-experiment actions and calculations.
Methods
-
loadPostprocessors()[source]
Search in the default locations to find postprocessor methods.
-
splitFile()[source]
split files
Functions
-
src.core.instrument.getVisaAddresses()[source]
Return a list of available VISA addresses.
Returns : | list of str :
A list of strings representing the VISA addresses which the
VISA controller recognizes as having an associated instrument
attached.
|
-
src.core.instrument.generateFilenameA(folder, baseName, scan=-1, noOverwrite=True)[source]
Generate a filename, applying the desired modifications.
Parameters : | folder : str
The path to the folder into which data will be saved.
baseName : str
The name, relative to folder, which should be used for the data
files. If it does not include an extension, ”.xdat” will be used.
scan : int
If positive, scan will be interpreted as the scan number for the
files. If it is negative, the next scan number will be chosen
automatically. If it is None, no scan number will be prepended
to the filenames. (default = -1)
noOverwrite : bool
Whether to append numbers to the end of the name to prevent over-
writing data. (default = True)
|