PYME.Acquire.ActionManager module

Created on Sat May 28 23:12:24 2016

@author: david

class PYME.Acquire.ActionManager.ActionManager(scope)

Bases: object

This implements a queue for actions which should be called sequentially.

The main purpose of the ActionManager is to facilitate automated imaging by allowing multiple operations to be queued. Rather than being strictly FIFO, different tasks can be asigned different priorities, with higher priority tasks bubbling up and and being executed before lower priority tasks. This allows high priority “imaging” tasks to be inserted into a stream of lower priority “monitoring” tasks if something interesting is detected during monitoring.

An individual action is a function which can be found within the scope of our microscope object (for more details see the QueueAction method).

To function correctly the Tick() method should be called regularly - e.g. from a GUI timer.

Initialise our action manager

Parameters
scopePYME.Acquire.microscope.microscope object

The microscope. The function object to call for an action should be accessible within the scope namespace, and will be resolved by calling eval(‘scope.functionName’)

QueueAction(functionName, args, nice=10, timeout=1000000.0, max_duration=1.7976931348623157e+308)

Add an action to the queue. Legacy version for string based actions. Most applications should use queue_actions() below instead

Parameters
functionNamestring

The name of a function relative to the microscope object. e.g. to call scope.spoolController.start_spooling(), you would use a functionName of ‘spoolController.start_spooling’.

The function should either return None if the operation has already completed, or function which evaluates to True once the operation has completed. See scope.spoolController.start_spooling() for an example.

argsdict

a dictionary of arguments to pass the function

niceint (or float)

The priority with which to execute the function. Functions with a lower nice value execute first. Nice should have a value between 0 and 20. nice=20 is reserved by convention for tidy-up tasks which should run after all other tasks and put the microscope in a ‘safe’ state.

timeoutfloat

A timeout in seconds from the current time at which the action becomes irrelevant and should be ignored.

max_durationfloat

A generous estimate, in seconds, of how long the task might take, after which the lasers will be automatically turned off and the action queue paused. This will not interrupt the current task, though it has presumably already failed at that point. Intended as a safety feature for automated acquisitions, the check is every 3 s rather than fine-grained.

Tick(**kwargs)

Polling function to check if the current action is finished and, if so, start the next action if available.

Should be called regularly for a timer or event loop.

queue_actions(actions, nice=10, timeout=1000000.0, max_duration=1.7976931348623157e+308)

Queue a number of actions for subsequent execution

Parameters
actionslist

A list of Action instances

niceint (or float)

The priority with which to execute the function. Functions with a lower nice value execute first. Nice should have a value between 0 and 20.

timeoutfloat

A timeout in seconds from the current time at which the action becomes irrelevant and should be ignored.

max_durationfloat

A generous estimate, in seconds, of how long the task might take, after which the lasers will be automatically turned off and the action queue paused. This will not interrupt the current task, though it has presumably already failed at that point. Intended as a safety feature for automated acquisitions, the check is every 3 s rather than fine-grained.

Returns

Examples

>>> my_actions = [UpdateState(state={'Camera.ROI' : [50, 50, 200, 200]}),
>>>      SpoolSeries(maxFrames=500, stack=False),
>>>      UpdateState(state={'Camera.ROI' : [100, 100, 250, 250]}).then(SpoolSeries(maxFrames=500, stack=False)),
>>>      ]
>>>
>>>ActionManager.queue_actions(my_actions)

Note that the first two tasks are independant -

class PYME.Acquire.ActionManager.ActionManagerServer(action_manager, port, bind_address='')

Bases: APIHTTPServer, ActionManagerWebWrapper

Server process to expose queue_action functionality to everything on the cluster network.

NOTE - this will likely not be around long, as it would be preferable to add the ActionManagerWebWrapper to PYME.acquire_server.AcquireHTTPServer and run a single server process on the microscope computer.

Parameters
action_managerActionManager

already initialized

portint

port to listen on

bind_addressstr, optional

specifies ip address to listen on, by default ‘’ will bind to local host.

class PYME.Acquire.ActionManager.ActionManagerWebWrapper(action_manager)

Bases: object

Wraps an action manager instance with server endpoints

Parameters
action_managerActionManager

action manager instance to wrap

queue_action(body)

adds an action to the queue

Parameters
body: str
json.dumps(dict) with the following keys:
function_namestr

The name of a function relative to the microscope object. e.g. to call scope.spoolController.start_spooling(), you would use a functionName of ‘spoolController.start_spooling’.

The function should either return None if the operation has already completed, or function which evaluates to True once the operation has completed. See scope.spoolController.start_spooling() for an example.

argsdict, optional

a dictionary of arguments to pass to function_name

niceint, optional

priority with which to execute the function, by default 10. Functions with a lower nice value execute first.

timeoutfloat, optional

A timeout in seconds from the current time at which the action becomes irrelevant and should be ignored. By default 1e6.

max_durationfloat

A generous estimate, in seconds, of how long the task might take, after which the lasers will be automatically turned off and the action queue paused.

queue_actions(body, nice=10, timeout=1000000.0, max_duration=1.7976931348623157e+308)

Add a list of actions to the queue

Parameters
body - json formatted list of serialised actions (see example below)
nice
timeout
max_duration
Returns

Examples

Body json

[{'UpdateState':{'foo':'bar', 'then': {'SpoolSeries' : {...}}}]