lightlab.util.sweep module¶
Generalized sweep classes
Summary¶
Classes:
Actuation |
|
CommandControlSweeper |
Generic command-control sweep for evaluating a controller. |
NdSweeper |
Generic sweeper. |
Sweeper |
Functions:
assertValidPlotType |
|
availablePlots |
Filter by dims and swpType |
loadPickle |
|
plotCmdCtrl |
sweepData should have ALL the command weights specified |
savePickle |
|
simpleSweep |
Basic sweep in one dimension, without function keys, parsing, or plotting. |
Data:
hArrow |
|
hCurves |
|
hEllipse |
|
interAx |
|
pTypes |
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list.For example: dict(one=1, two=2). |
Reference¶
-
class
Sweeper[source]¶ Bases:
object-
plotOptions= None¶
-
monitorOptions= None¶
-
load(savefile=None)[source]¶ This is basically make it so that gather() and load() have the same effect.
It does not keep actuation or measurement members, only whatever was put in self.data
Parameters: savefile (str/Path) – file to load
-
setPlotOptions(**kwargs)[source]¶ - Valid options for NdSweeper
- plType
- xKey
- yKey
- axArr
- cmap-surf
- cmap-curves
- Valid options for CommandControlSweeper
- plType
-
-
class
Actuation(function=None, domain=None, doOnEveryPoint=False)[source]¶ Bases:
object-
function= None¶
-
domain= None¶
-
doOnEveryPoint= None¶
-
-
class
NdSweeper[source]¶ Bases:
lightlab.util.sweep.SweeperGeneric sweeper.
- Here’s the difference between measure and parse:
- measure is a call to something, usually an instrument and some simpe post processing, like peak finding.
- It is stored in data
- When subsuming, only unique measurements are kept
- parse gets this in a form to visualize interactively, perhaps save and/or score along the way
- When subsuming, all parse functions are maintained
Make sure that measure is bound if it is a method
Specify the hard domain and actuate dimensions
- The sweep dimension order is major first, so put your slow actuations (e.g. tuning lasers)
- before the fast actuations (e.g. tuning current source)
Parameters: - domain (tuple, iterable) – the sweep values, or a tuple of sweep values for different dimensions
- actuate (tuple, procedure-like) – procedure, one argument per, that is called for each line of the sweep. Return is optional
- actuNames (tuple, str, None) – Names of actuator return values. These are stored as data if present, under the key ‘’actuName-return’‘
- measure (dict) – dict of functions, no arguments, called at every point. Use descriptive keys please.
- parse (dict) – dict of functions, operate on measurements, produce scalars Use descriptive keys please.
-
measure= None¶
-
actuate= None¶
-
parse= None¶
-
static= None¶
-
gather(soakTime=None, autoSave=False, returnToStart=False)[source]¶ Perform the sweep
Parameters: Returns: None
-
addActuation(name, function, domain, doOnEveryPoint=False)[source]¶ Specify an actuation dimension: what is called, the domain values to use as arguments.
Parameters: - name (str) – key for accessing this actuator’s value data
- function (func) – actuation function, usually linked to hardware. One argument.
- domain (ndarray, None) – 1D array of arguments that will be passed to the function. If None, the function is called with a None argument every point (if doOnEveryPoint is True).
- doOnEveryPoint (bool) – call this function in the inner loop (True) or once before the corresponding rows(False)
-
addMeasurement(name, function)[source]¶ Specify a measurement to be taken at every sweep point.
Parameters: - name (str) – key for accessing this measurement’s value data
- function (func) – measurement function, usually linked to hardware. No arguments.
-
addParser(name, function)[source]¶ Adds additional parsing formulas to data, and reparses, if data has been taken
Parameters: - name (str) – key for accessing this parser’s value data
- function (func) – parsing function, not linked to hardware. One dictionary argument.
-
addStaticData(name, contents)[source]¶ Add a ndarray or scalar that can be referenced by parsers
The array’s shape must match that of the currently loaded actuation grid.
If you then
addActuation(), the static data automatically expands in dimension to accomodate. Values are filled by tiling in the new dimension.Add static data after the actuations that have different static data, but before the actuations for which you want that data to be constant.
Parameters: - name (str) – key for accessing this data
- contents (scalar, ndarray) – data contents
-
subsume(other, useMinorOptions=False)[source]¶ Makes the argument sweep a minor sweep within this one
- The new measurement dictionary will contain all measurements of both.
- If there is a duplicate key, the self measurement will take precedence
Existing data is discarded.
Parameters:
-
copy(includeData=True)[source]¶ Shallow copy, which means function pointers are maintained
If includeData, it does a deep copy of data
-
plot(slicer=None, tempData=None, index=None, axArr=None, pltKwargs=None)[source]¶ Plots
Much of the behavior to figure out labels and numbers for axes comes from the plotOptions attribute.
- The xKeys and yKeys are keys within this objects data dictionary (actuation, measurement, and parsers)
- The total number of plots will be the product of len(‘xKey’) and len(‘yKey’). xKeys can be anything, including parsed data members. By default it is the minor actuation variable yKeys can also be anything that has scalar elements. By default it is everything that is currently present, except xKeys and non-scalars
- When doing line plots in 2D sweeps, the legend does automatic labelling.
- Each line must correspond to an actuation dimension, otherwise it doesn’t make sense.
- This is despite the fact that the xKeys can still be anything.
- Usually, each line corresponds to a particular domain value of the major sweep axis;
- however, if that is specified as an xKey, the lines will correspond to the minor axis.
- Surface plotting:
- Ignores whatever is in xKeys. The plotting domain is locked to the actuation domain in order to keep a rectangular grid. The values indicated in yKeys will become color data.
Parameters: Todo
- Graphics caching for 2D line plots
-
saveObj(savefile=None)[source]¶ Also saves what are the actuation keys. This is important for plotting when you reload
-
classmethod
loadObj(savefile, functionSource=None)[source]¶ savefile must have been saved with saveObj. It restores actuation names and domains to help with plotting.
Functions referring to actuation and measurement cannot be saved.
- functionSource: an instantiated object of class cls
- If you give it a functionSource, then those can be restored as well. This is very useful if you have a parser such as live plot spectra, or move stuff here or there. Also useful if you want to re-gather for some reason.
-
simpleSweep(actuate, domain, measure=None)[source]¶ Basic sweep in one dimension, without function keys, parsing, or plotting.
Parameters: - actuate (function) – a procedure or function of one argument called at every point
- domain (ndarray) – elements passed as an argument to actuate for each point
- measure (function, None) – a function of no arguments called at every point. None means the return of actuate will act as the measurement
Returns: what is measured. Same length as domain
Return type: (ndarray)
-
class
CommandControlSweeper(evaluate, defaultArg, swpInds, domain, nTrials=1)[source]¶ Bases:
lightlab.util.sweep.SweeperGeneric command-control sweep for evaluating a controller.
The command function called at each point takes one argument that is an array (length M) and returns an array of equal length.
- The sweep is N (<= M) dimensional.
- The user specifies the mapping between the sweep domain and the argument/return array indeces
- The user specifies defaults for the other (M-N) arguments
- Some of the uncontrolled arguments can be monitored
Todo
How can we get this subsumed by a NdSweeper for trial repetition. CommandControlSweeper shouldn’t be able to subsume as major
Parameters: -
saveObj(savefile=None)[source]¶ Instead of just saving data, save the whole damn thing.
Cannot save evaluate function because it is unbound.
-
classmethod
loadObj(savefile)[source]¶ This is basically make it so that gather() and load() have the same effect.
It does not keep actuation or measurement members, only whatever was put in self.data
-
gather(autoSave=False, randomize=False)[source]¶ Executes the sweep
Todo
Store all outputs, but provide a way just to get the controlled ones
-
plotCmdCtrl(sweepData, index=None, ax=None, interactive=False)[source]¶ sweepData should have ALL the command weights specified
Parameters: - sweepData (tuple) – cmdWeights, measWeights, monitWeights (optional) measWeights has shape (nTrials, len(swp1), len(sp2) or 1, len(sweepingChannels))
- index (tuple) – tells which parts of measured weights are valid. If None, assumes sweepData is complete
- interactive (bool) – show plot immediately after call, even with incomplete data (index must be specified)
Todo
Fix the global hack for persistent plots – actually, this is fine