camacq package¶
Control microscope through client server program.
Subpackages¶
- camacq.data package
- camacq.helper package
- camacq.plugins package
get_plugins()
setup_module()
- Subpackages
- camacq.plugins.api package
- camacq.plugins.automations package
- camacq.plugins.leica package
- camacq.plugins.sample package
- Submodules
- camacq.plugins.rename_image module
Submodules¶
camacq.bootstrap module¶
Configure and set up control center.
- async camacq.bootstrap.setup_dict(center, config)¶
Set up control center from config dict.
- Parameters:
config (dict) – The config dict.
- Returns:
Return the Center instance.
- Return type:
Center instance
- async camacq.bootstrap.setup_file(config_file, cmd_args)¶
Set up control center from config file and command line args.
- Parameters:
config_file (str) – The path to the configuration YAML file.
cmd_args (dict) – The dict with the command line arguments.
- Returns:
Return the Center instance.
- Return type:
Center instance
camacq.config module¶
Handle the config file.
- camacq.config.create_default_config(config_dir)¶
Create a default config file in given configuration directory.
- Parameters:
config_dir (pathlib.Path) – The path to the configuration directory.
- Returns:
Return path to new configuration file if success, None if failed.
- Return type:
pathlib.Path
- camacq.config.ensure_config_exists(config_dir)¶
Ensure configuration file exists in the configuration directory.
Create a default configuration file if needed.
- Parameters:
config_dir (pathlib.Path) – The path to the configuration directory.
- Returns:
Return path to the configuration file.
- Return type:
pathlib.Path
- camacq.config.find_config_file(config_dir)¶
Find the configuration file in the configuration directory.
- Parameters:
config_dir (pathlib.Path) – The path to the configuration directory.
- Returns:
Return path to the configuration file if found, None if not found.
- Return type:
pathlib.Path
- camacq.config.get_default_config_dir()¶
Get the default configuration directory based on OS.
- Returns:
Return the path to the configuration directory.
- Return type:
str
- camacq.config.load_config_file(path)¶
Parse a YAML configuration file.
- Parameters:
path (pathlib.Path) – The path to the configuration YAML file.
- Returns:
Return a dict with the configuration contents.
- Return type:
dict
camacq.const module¶
Store common constants.
camacq.control module¶
Control the microscope.
- class camacq.control.Action(action_type, action_id, func, schema)¶
Bases:
object
Represent an action.
- class camacq.control.ActionType¶
Bases:
dotdict
Represent an action type.
- clear() None. Remove all items from D. ¶
- copy() a shallow copy of D ¶
- fromkeys(value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised
- popitem()¶
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F. ¶
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values ¶
- class camacq.control.ActionsRegistry(center)¶
Bases:
object
Manage all registered actions.
- property actions¶
Return dict of ActionTypes with all registered actions.
- Type:
dict
- async call(action_type, action_id, **kwargs)¶
Call an action with optional kwargs.
- Parameters:
action_type (str) – The name of the module where the action is registered.
action_id (str) – The id of the action to call.
**kwargs – Arbitrary keyword arguments. These will be passed to the action function when an action is called.
- register(action_type, action_id, action_func, schema)¶
Register an action.
Register actions per module.
- Parameters:
action_type (str) – The name of the action_type to register the action under.
action_id (str) – The id of the action to register.
action_func (voluptuous schema) – The function that should be called for the action.
action_func – The voluptuous schema that should validate the parameters of the action call.
- class camacq.control.CamAcqStartEvent(data=None)¶
Bases:
Event
An event fired when camacq has started.
- data¶
- event_type = 'camacq_start_event'¶
- class camacq.control.CamAcqStopEvent(data=None)¶
Bases:
Event
An event fired when camacq is about to stop.
- data¶
- event_type = 'camacq_stop_event'¶
- property exit_code¶
Return the plate instance of the event.
- Type:
int
- class camacq.control.Center(loop=None)¶
Bases:
object
Represent a control center for the microscope.
- Parameters:
loop (asyncio.EventLoop) – The event loop.
- loop¶
Return the event loop.
- Type:
asyncio.EventLoop
- bus¶
Return the EventBus instance.
- Type:
EventBus instance
- samples¶
Return the Samples instance that holds all the Sample instances.
- Type:
Samples instance
- actions¶
Return the ActionsRegistry instance.
- Type:
ActionsRegistry instance
- data¶
Return dict that stores data from other modules than control.
- Type:
dict
- add_executor_job(func, *args)¶
Schedule a function to be run in the thread pool.
Return a task.
- create_task(coro)¶
Schedule a coroutine on the event loop.
Return a task.
- async end(code)¶
Prepare app for exit.
- Parameters:
code (int) – Exit code to return when the app exits.
- async start()¶
Start the app.
- async wait_for()¶
Wait for all pending tasks.
- camacq.control.loop_exception_handler(loop, context)¶
Handle exceptions inside the event loop.
camacq.event module¶
Hold events.
- class camacq.event.Event(data=None)¶
Bases:
object
A base event.
- Parameters:
data (dict) – The data of the event.
- data¶
Return the data of the event.
- Type:
dict
- data¶
- event_type = 'base_event'¶
- class camacq.event.EventBus(center)¶
Bases:
object
Representation of an eventbus.
- Parameters:
center (Center instance) – The Center instance.
- property event_types¶
Return all registered event types.
- Type:
list
- async notify(event)¶
Notify handlers that an event has fired.
- Parameters:
event (Event instance) – An instance of Event or an instance of subclass of Event.
- register(event_type, handler)¶
Register event handler and return a function to remove it.
An event can be a message from the microscope API or an internal event.
- Parameters:
event_type (str) – A string representing the type of event.
handler (callable) – A coroutine function that should accept two parameters, center and event. The first parameter is the Center instance, the second parameter is the Event instance that has fired.
- Returns:
Return a function to remove the registered handler.
- Return type:
callable
- camacq.event.match_event(event, **event_data)¶
Return True if event attributes match event_data.
camacq.exceptions module¶
Provide exceptions.
- exception camacq.exceptions.CamAcqError¶
Bases:
Exception
Represent the base camacq exception.
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception camacq.exceptions.MissingActionError(action_id)¶
Bases:
CamAcqError
Represent a missing action error.
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception camacq.exceptions.MissingActionTypeError(action_type)¶
Bases:
CamAcqError
Represent a missing action type error.
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception camacq.exceptions.SampleError¶
Bases:
CamAcqError
Represent a sample error.
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception camacq.exceptions.TemplateError(exc)¶
Bases:
CamAcqError
Represent a template error.
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
camacq.image module¶
Handle images.
- class camacq.image.ImageData(path=None, data=None, metadata=None)¶
Bases:
object
Represent the data of an image with path, data, metadata and histogram.
- Parameters:
path (str) – Path to the image.
data (numpy array) – A numpy array with the image data.
metadata (dict) – The meta data of the image as a JSON dict.
- path¶
The path to the image.
- Type:
str
- property data¶
Return the data of the image.
- Setter:
Set the data of the image.
- Type:
numpy array
- property histogram¶
Calculate and return image histogram.
- Type:
numpy array
- property metadata¶
Return metadata of image.
- Setter:
Set the meta data of the image.
- Type:
str
- save(path=None, data=None, metadata=None)¶
Save image with image data and optional meta data.
- Parameters:
path (str) – The path to the image.
data (numpy array) – A numpy array with the image data.
metadata (dict) – The meta data of the image as a JSON dict.
- camacq.image.make_proj(images)¶
Make a dict of max projections from a dict of channels and paths.
Each channel will make one max projection.
- Parameters:
images (dict) – Dict of paths and channel ids.
- Returns:
Return a dict of channels that map ImageData objects. Each image object have a max projection as data.
- Return type:
dict
- camacq.image.read_image(path)¶
Read a tif image and return the data.
- Parameters:
path (str) – The path to the image.
- Returns:
Return a numpy array with image data.
- Return type:
numpy array
- camacq.image.save_image(path, data, description=None)¶
Save a tif image with image data and meta data.
- Parameters:
path (str) – The path to the image.
data (numpy array) – A numpy array with the image data.
description (str) – The description string of the image.
camacq.log module¶
Handle logging.
- camacq.log.check_path(path)¶
Check that path to config exists and is writable for logging.
- Parameters:
path (pathlib.Path) – The path to the log file or log directory.
- Returns:
Return True if path exists and is writable.
- Return type:
bool
- camacq.log.enable_log(config)¶
Enable logging.
- Parameters:
config (dict) – The dict with the configuration.
camacq.util module¶
Host utils that are not aware of the implementation of camacq.
- class camacq.util.dotdict¶
Bases:
dict
Access to dictionary attributes with dot notation.
- clear() None. Remove all items from D. ¶
- copy() a shallow copy of D ¶
- fromkeys(value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised
- popitem()¶
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F. ¶
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values ¶