script
frog.gui.measure_script.script
¤
An interface for using the YAML-formatted measure scripts.
This includes code for parsing and running the scripts.
Attributes¤
CURRENT_SCRIPT_VERSION = 1
module-attribute
¤
The current version of the measure script format.
Classes¤
Measurement(angle, measurements)
dataclass
¤
ParseError(_)
¤
Bases: Exception
An error occurred while parsing a measure script.
Create a new ParseError.
Source code in frog/gui/measure_script/script.py
92 93 94 |
|
Functions¤
Script(path, repeats, sequence)
¤
Represents a measure script, including its file path and data.
Create a new Script.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The file path to this measure script |
required |
repeats
|
int
|
The number of times to repeat the sequence of measurements |
required |
sequence
|
Sequence[dict[str, Any]]
|
Different measurements (i.e. angle + num measurements) to record |
required |
Source code in frog/gui/measure_script/script.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
Functions¤
__iter__()
¤
Get an iterator for the measurements.
Source code in frog/gui/measure_script/script.py
59 60 61 |
|
run(parent=None)
¤
Run this measure script.
Source code in frog/gui/measure_script/script.py
63 64 65 66 67 |
|
try_load(parent, file_path)
classmethod
¤
Try to load a measure script at the specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent
|
QWidget
|
The parent widget (for error messages shown) |
required |
file_path
|
Path
|
The path to the script to be loaded |
required |
Returns: A Script if successful, else None
Source code in frog/gui/measure_script/script.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
ScriptIterator(script)
¤
Allows for iterating through a Script with the required number of repeats.
Create a new ScriptIterator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
script
|
Script
|
The Script from which to create this iterator. |
required |
Source code in frog/gui/measure_script/script.py
147 148 149 150 151 152 153 154 155 |
|
Functions¤
__iter__()
¤
Return self.
Source code in frog/gui/measure_script/script.py
157 158 159 |
|
__next__()
¤
Return the next Measurement in the sequence.
Source code in frog/gui/measure_script/script.py
161 162 163 164 165 166 167 168 169 170 171 |
|
ScriptRunner(script, parent=None)
¤
Bases: StateMachine
A class for running measure scripts.
The ScriptRunner is a finite state machine. Besides the one initial state, the runner can either be in a "moving" state (i.e. the motor is moving) or a "measuring" state (i.e. the motor is stationary and the EM27 is recording a measurement).
The state diagram looks like this:
Create a new ScriptRunner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
script
|
Script
|
The script to run |
required |
parent
|
QWidget | None
|
The parent widget |
None
|
Source code in frog/gui/measure_script/script.py
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 |
|
Attributes¤
cancel_measuring = measuring.to(not_running)
class-attribute
instance-attribute
¤
Cancel the current measurement.
cancel_move = moving.to(not_running)
class-attribute
instance-attribute
¤
Cancel the current movement.
cancel_waiting_to_measure = waiting_to_measure.to(not_running)
class-attribute
instance-attribute
¤
Cancel the script from a waiting to measure state.
cancel_waiting_to_move = waiting_to_move.to(not_running)
class-attribute
instance-attribute
¤
Cancel the script from a waiting to move state.
current_measurement
instance-attribute
¤
The current measurement to acquire.
current_measurement_count
instance-attribute
¤
How many times a measurement has been recorded at the current angle.
finish = moving.to(not_running)
class-attribute
instance-attribute
¤
To be called when all measurements are complete.
finish_moving = moving.to(waiting_to_measure)
class-attribute
instance-attribute
¤
Finish the moving stage.
finish_waiting_for_move = waiting_to_move.to(moving)
class-attribute
instance-attribute
¤
Stop waiting and start the next move.
measurement_iter = iter(self.script)
instance-attribute
¤
An iterator yielding the required sequence of measurements.
measuring = State('Measuring')
class-attribute
instance-attribute
¤
State indicating that a measurement is taking place.
moving = State('Moving')
class-attribute
instance-attribute
¤
State indicating that the motor is moving.
not_running = State('Not running', initial=True)
class-attribute
instance-attribute
¤
State indicating that the script is not yet running or has finished.
parent = parent
instance-attribute
¤
The parent widget.
paused = False
instance-attribute
¤
Whether the script is paused.
repeat_measuring = measuring.to(waiting_to_measure)
class-attribute
instance-attribute
¤
Record another measurement at the same angle.
script = script
instance-attribute
¤
The running script.
start_measuring = waiting_to_measure.to(measuring)
class-attribute
instance-attribute
¤
Start recording for the current measurement.
start_moving = not_running.to(moving)
class-attribute
instance-attribute
¤
Start moving the motor to the required angle for the current measurement.
start_next_move = measuring.to(waiting_to_move)
class-attribute
instance-attribute
¤
Trigger a move to the angle for the next measurement.
waiting_to_measure = State('Waiting to measure')
class-attribute
instance-attribute
¤
State indicating that measurement will start when the script is unpaused.
waiting_to_move = State('Waiting to move')
class-attribute
instance-attribute
¤
State indicating that the motor will move when the script is unpaused.
Functions¤
abort()
¤
Abort the current measure script run.
Source code in frog/gui/measure_script/script.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
before_start_moving()
¤
Send a pubsub message to indicate that the script is running.
Source code in frog/gui/measure_script/script.py
252 253 254 |
|
on_enter_moving()
¤
Try to load the next measurement and start the next movement.
If there are no more measurements, the ScriptRunner will return to a not_running state.
Source code in frog/gui/measure_script/script.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
on_enter_not_running(event)
¤
If finished, unsubscribe from pubsub messages and send message.
Source code in frog/gui/measure_script/script.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
on_enter_state(target, event)
¤
Log the state every time it changes.
Source code in frog/gui/measure_script/script.py
256 257 258 |
|
on_enter_waiting_to_measure()
¤
Move onto the next measurement unless the script is paused.
Source code in frog/gui/measure_script/script.py
337 338 339 340 341 342 343 344 |
|
on_enter_waiting_to_move()
¤
Move onto the next move unless the script is paused.
Source code in frog/gui/measure_script/script.py
332 333 334 335 |
|
on_exit_measuring()
¤
Unsubscribe from pubsub topics.
Source code in frog/gui/measure_script/script.py
325 326 327 328 329 330 |
|
on_exit_not_running()
¤
Subscribe to pubsub messages for the stepper motor and spectrometer.
Source code in frog/gui/measure_script/script.py
283 284 285 286 287 288 289 290 291 292 |
|
on_exit_waiting_to_measure()
¤
Unsubscribe from pubsub topics.
Source code in frog/gui/measure_script/script.py
346 347 348 349 350 |
|
pause()
¤
Pause the current measure script run.
Source code in frog/gui/measure_script/script.py
387 388 389 |
|
unpause()
¤
Unpause the current measure script run.
Source code in frog/gui/measure_script/script.py
391 392 393 394 395 396 397 398 399 400 |
|
Functions¤
parse_script(script)
¤
Parse a measure script.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
script
|
str | TextIOBase
|
The contents of the script as YAML or a stream containing YAML |
required |
Raises: ParseError: The script's contents were invalid
Source code in frog/gui/measure_script/script.py
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 |
|