MeasAPI
Super class for measurement algorithms for LabExT.
Aside from being an "interface" for measurement algorithm code, this class offers some basic functionality for executing measurements. It holds the currently set measurement parameters and the selected instruments (description and pointers to driver instances).
To get a running measurement, change the properties: name and settings_path. You need to specify the requested
instrument types in get_wanted_instrument and a set of default parameters in get_default_parameter.
The measurement algorithm needs to be implemented in the algorithm method. See their respective reference below.
For a How-To on implementing a new measurement algorithm, see
the New Measurement Algorithm page.
Attributes:
| Name | Type | Description |
|---|---|---|
check_param |
str
|
Class attribute. Will affect what the measure function does on missing
parameters: |
check_instr |
str
|
Class attribute. Will affect what the measure function does on missing instruments:
|
name |
str
|
Name of the measurement, typically similar of equal to the class name. |
settings_path |
str
|
File name of the settings file of this measurement, can be anything and should end in '.json'. |
selected_instruments |
dict
|
Set by the LabExT GUI after instrument selection stage. Keys is an instrument type, values is one instrument description dictionary from instruments.config (i.e. a VISA address, a driver class name, channel information and optionally some more constructor arguments for the driver). |
Source code in LabExT/Measurements/MeasAPI/Measurement.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
id: uuid.UUID
property
Returns a unique ID for this measurement based on its name and its parameters.
Measurements with the same name and parameters will have the same id.
instruments: Dict[Tuple[str, str], Instrument]
property
writable
dict of Instrument: Holds the instances of the instrument drivers after calling init_instruments(),
otherwise returns an empty dict. Keys are a 2-tuple of strings: (type, driver name): type is the type
requested in get_wanted_instrument() and the driver name is the class name of the instruments driver. The
values are pointers to initialized instrument drivers.
logger = logging.getLogger()
instance-attribute
Logger object, use this to log to console and log file
parameters: Dict[str, MeasParam]
property
writable
dict of MeasParam: access the currently set parameters for this measurement. If no parameters were set,
the default parameters are taken. Key is the parameters name and the Value is a MeasParam instance.
selected_instruments: Dict[str, Dict] = {}
instance-attribute
Dict of strings of instrument roles as defined in instruments.config
settings_path = 'example_meas_save_file_name.json'
instance-attribute
Measurement class internal use
wanted_instruments: List[str] = []
instance-attribute
List of strings of instrument types as defined in instruments.config
__init__(experiment=None, experiment_manager=None)
Constructor of a measurement.
The arguments are automatically filled when using the measurement with the LabExT GUI. For standalone use, the arguments do not need to be provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment |
StandardExperiment
|
Reference to the experiment instance. Optional, but can be used to enable live-plotting during measurements. |
None
|
experiment_manager |
ExperimentManager
|
Ref to the main experiment manager of LabExT, the root object which interconnects all parts of LabExT. Used to access all loaded instruments. Optional for stand-alone usage outside the LabExT GUI. |
None
|
Source code in LabExT/Measurements/MeasAPI/Measurement.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
algorithm(device, data, instruments, parameters)
The main body of the measurement algorithm to be performed.
Generally includes the following steps
- read all parameters to variables
- read all instrument driver instances to local variables
- do preliminary checks, e.g. if the desired parameters are possible with the selected instruments
- save the used parameters in the
data['measurement settings']dictionary - set instrument settings according to chosen parameters
- execute the measurement routine
- read back data from the instruments and store it in the
data['values']dictionary - (recommended) check if you have populated all fields in the
datadictionary by usingself._check_data(data)
This method must be overriden for any working measurement implementation. See the New Measurement Algorithm page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device |
Device
|
Device instance on which the measurement is performed. Allows to adapt measurement algorithm according to some device property. |
required |
data |
dict
|
Dictionary in which we store the result of the measurement. |
required |
instruments |
dict
|
Dictionary with the instr. types as keys and the instrument driver instances as values. |
required |
parameters |
dict
|
Dictionary of all parameters. Keys are parameters names, values are |
required |
Source code in LabExT/Measurements/MeasAPI/Measurement.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
get_default_parameter()
staticmethod
The dictionary of all parameters required in this measurement at their default value.
Inside the algorithm, you can access all parameters via the parameters argument which is the same
structured dictionary as specified here but with the parameter values as chosen in the GUI.
This method must be overriden for any working measurement implementation. See the New Measurement Algorithm page.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, MeasParam]
|
keys are parameter names (strings), its values are instances of |
Source code in LabExT/Measurements/MeasAPI/Measurement.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
get_instrument(instrument_type)
Returns the pointer to the initialized instrument for the given instrument type.
Use this function within self.algorithm() to get the pointer to the instrument driver you can use for instrument interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument_type |
str
|
The type string of the instrument requested.
Must be in the list specified in |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the instrument with the given type cannot be found in the dict of the initialized instruments. |
RuntimeError
|
If the instrument with the given type is not initialized yet. |
Returns:
| Name | Type | Description |
|---|---|---|
Instrument |
Instrument
|
Initialised instrument driver. |
Source code in LabExT/Measurements/MeasAPI/Measurement.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
get_name_with_id()
Returns the measurements name property and the unique id for this measurement's instance.
Source code in LabExT/Measurements/MeasAPI/Measurement.py
145 146 147 148 | |
get_non_sweepable_parameters()
staticmethod
A dict mapping names of the parameters that are explicitly non-sweepable to the corresponding MeasParam.
If all parameters are sweepable this method should return an empty dict.
The default implementation also returns an empty dict.
Returns:
| Type | Description |
|---|---|
Dict[str, MeasParam]
|
dict[str, MeasParam]: names of the parameters that aren't sweepable mapped to the corresponding parameters |
Source code in LabExT/Measurements/MeasAPI/Measurement.py
223 224 225 226 227 228 229 230 231 232 233 | |
get_wanted_instrument()
staticmethod
The list of all instrument types (strings) required in this measurement.
Inside the algorithm, you can access the instantiated instrument driver classes by accessing the
instruments argument which is a dict. The list you return in this method will be the keys of said dict.
If you want to use more than one instrument of the same type, you can add a number after the instrument type.
So to include two lasers and one power meter, I would return: ['Laser 1', 'Laser 2', 'PowerMeter'].
This method must be overriden for any working measurement implementation. See the New Measurement Algorithm page.
Returns:
| Name | Type | Description |
|---|---|---|
list |
List[str]
|
the elements are strings of instrument types as available in instruments.config |
Source code in LabExT/Measurements/MeasAPI/Measurement.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
init_instruments()
Instantiates instrument drivers according to self.selected_instruments and saves them in self.instruments
This method gets called from the LabExT GUI and does not need to be invoked by the user.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
In case any instrument could not be initilized. Sometimes initialization fails silently... |
Source code in LabExT/Measurements/MeasAPI/Measurement.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
measure(device, data, **kwargs)
Gathers the parameters and instruments set via GUI and executes self.algorithm() with correct arguments.
First checks whether all the needed contents are present, and if so starts execution of the algorithm. This function can take some optional arguments, namely parameters and instruments, to override the already saved ones.
Furthermore, there are modes in place to fill missing parameters automatically. The flags check_instr and check_param can take various (static) values, that will dictate how measurement will handle missing parameters and instruments.
There should be no need for a sub-class to overwrite this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device |
Device
|
Device instance on which the measurement is performed. Allows to adapt measurement algorithm according to some device property. |
required |
data |
dict
|
Dictionary in which we store the result of the measurement. |
required |
**kwargs |
|
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If some instrument or parameter is missing and the check_ flags are set to |
Source code in LabExT/Measurements/MeasAPI/Measurement.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
open_side_windows()
Include any code you want to be executed on the "open side windows" button for the measurement.
Source code in LabExT/Measurements/MeasAPI/Measurement.py
392 393 394 395 | |
setup_return_dict()
classmethod
Gives the absolute bare minimum of keys which need to be filled in data dictionary in an algorithm() run.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Dict]
|
The minimum set of keys for a |
Source code in LabExT/Measurements/MeasAPI/Measurement.py
343 344 345 346 347 348 349 350 351 | |
store_new_param(new_params)
Used as callback function for the GUI to set parameters of the measurement.
Source code in LabExT/Measurements/MeasAPI/Measurement.py
397 398 399 400 | |
LabExT Copyright (C) 2021 ETH Zurich and Polariton Technologies AG This program is free software and comes with ABSOLUTELY NO WARRANTY; for details see LICENSE file.
MeasParam
Implementation of a single measurement parameter.
Should never be used directly, only the subclasses in this file should be used.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
Union[str, float, int, bool, list]
|
The value which the parameter represents |
unit |
str
|
What unit the parameter has. Purely visual as a help for the user, does not influence calculations. |
extra_type |
Extra type, should be removed in future versions. |
Source code in LabExT/Measurements/MeasAPI/Measparam.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
sweep_type: Union[None, Literal['binary', 'range', 'list']]
property
Returns the type of sweep this parameter supports.
__init__(value=None, unit=None, extra_type=None)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Optional[Union[str, float, int, bool, list]]
|
The value which the parameter represents |
None
|
unit |
str
|
What unit the parameter has. Purely visual as a help for the user, does not influence calculations. |
None
|
extra_type |
Extra type, should be removed in future versions. |
None
|
Source code in LabExT/Measurements/MeasAPI/Measparam.py
21 22 23 24 25 26 27 28 29 30 31 32 | |
__str__()
Converts this parameter to a string.
Source code in LabExT/Measurements/MeasAPI/Measparam.py
54 55 56 57 | |
as_dict()
Returns the stored value as part of a dict.
Source code in LabExT/Measurements/MeasAPI/Measparam.py
40 41 42 43 44 45 46 | |
copy()
Creates and returns a shallow copy of this MeasParam.
Source code in LabExT/Measurements/MeasAPI/Measparam.py
34 35 36 37 38 | |
MeasParamBool
Bases: MeasParam
Implements a MeasParam that represents a boolean.
Gets rendered as a check-box.
Source code in LabExT/Measurements/MeasAPI/Measparam.py
119 120 121 122 123 124 125 126 127 128 129 130 | |
MeasParamFloat
Bases: MeasParam
Implements a MeasParam that represents a floating-point number.
Source code in LabExT/Measurements/MeasAPI/Measparam.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
MeasParamInt
Bases: MeasParam
Implements a MeasParam that represents an integer number.
Source code in LabExT/Measurements/MeasAPI/Measparam.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
MeasParamList
Bases: MeasParam
Implements a MeasParam that represents a selection as part of a list.
Aside from the MeasParam arguments, needs the options argument, a list of all possible selections. Gets rendered
as a drop-down menu in LabExT GUI.
Source code in LabExT/Measurements/MeasAPI/Measparam.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
__init__(options, value=None, unit=None, extra_type=None)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options |
list
|
all the options this MeasParam can take |
required |
Source code in LabExT/Measurements/MeasAPI/Measparam.py
144 145 146 147 148 149 150 151 | |
MeasParamString
Bases: MeasParam
Implements a MeasParam that represents a string.
Source code in LabExT/Measurements/MeasAPI/Measparam.py
111 112 113 114 115 116 | |
MeasParamAuto(value=None, unit=None, extra_type=None, selected=None)
Automatically chooses the correct type of MeasParam based on the type of the value argument.
Source code in LabExT/Measurements/MeasAPI/Measparam.py
160 161 162 163 164 165 166 167 168 169 170 171 172 | |