camacq package¶
Control microscope through client server program.
Subpackages¶
Submodules¶
camacq.bootstrap module¶
Configure and set up control center.
- async camacq.bootstrap.setup_dict(center: Center, config: dict[str, Any]) None[source]¶
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: Path, cmd_args: dict[str, Any]) Center[source]¶
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: Path) Path | None[source]¶
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: Path) Path | None[source]¶
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: Path) Path | None[source]¶
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.const module¶
Store common constants.
camacq.control module¶
Control the microscope.
- class camacq.control.Action(action_type: str, action_id: str, func: Callable[[...], Awaitable[None]], schema: Schema | Any)[source]¶
Bases:
objectRepresent an action.
- class camacq.control.ActionsRegistry(center: Center)[source]¶
Bases:
objectManage all registered actions.
- property actions: dict[str, ActionType]¶
dict: Return dict of ActionTypes with all registered actions.
- async call(action_type: str, action_id: str, **kwargs: Any) None[source]¶
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: str, action_id: str, action_func: Callable[[...], Awaitable[None]], schema: Schema | Any) None[source]¶
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: dict[str, Any] | None = None)[source]¶
Bases:
EventAn event fired when camacq has started.
- event_type: ClassVar[str] = 'camacq_start_event'¶
- class camacq.control.CamAcqStopEvent(data: dict[str, Any] | None = None)[source]¶
Bases:
EventAn event fired when camacq is about to stop.
- event_type: ClassVar[str] = 'camacq_stop_event'¶
- property exit_code: int | None¶
int: Return the plate instance of the event.
- class camacq.control.Center(loop: AbstractEventLoop | None = None)[source]¶
Bases:
objectRepresent 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
- actions: ActionsRegistry¶
- add_executor_job(func: ~collections.abc.Callable[[~_P], ~camacq.control._T], *args: ~typing.~_P, **kwargs: ~typing.~_P) Future[_T][source]¶
Schedule a function to be run in the thread pool.
Return a task.
- create_task(coro: Coroutine[Any, Any, _T]) Task[_T][source]¶
Schedule a coroutine on the event loop.
Return a task.
- data: dict[str, Any]¶
- async end(code: int) None[source]¶
Prepare app for exit.
- Parameters:
code (int) – Exit code to return when the app exits.
- loop: AbstractEventLoop¶
camacq.event module¶
Hold events.
- class camacq.event.Event(data: dict[str, Any] | None = None)[source]¶
Bases:
objectA base event.
- Parameters:
data (dict, optional) – The data of the event.
- data: dict[str, Any]¶
Return the data of the event.
- event_type: ClassVar[str] = 'base_event'¶
- class camacq.event.EventBus(center: Center)[source]¶
Bases:
objectRepresentation of an eventbus.
- Parameters:
center (Center instance) – The Center instance.
- property event_types: list[str]¶
list: Return all registered event types.
- async notify(event: Event) None[source]¶
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: str, handler: EventHandler) Callable[[], None][source]¶
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.exceptions module¶
Provide exceptions.
- exception camacq.exceptions.CamAcqError[source]¶
Bases:
ExceptionRepresent the base camacq exception.
- exception camacq.exceptions.MissingActionError(action_id: str)[source]¶
Bases:
CamAcqErrorRepresent a missing action error.
- exception camacq.exceptions.MissingActionTypeError(action_type: str)[source]¶
Bases:
CamAcqErrorRepresent a missing action type error.
- exception camacq.exceptions.SampleError[source]¶
Bases:
CamAcqErrorRepresent a sample error.
- exception camacq.exceptions.TemplateError(exc: Exception)[source]¶
Bases:
CamAcqErrorRepresent a template error.
camacq.image module¶
Handle images.
- class camacq.image.ImageData(path: str | None = None, data: ndarray[tuple[Any, ...], dtype[Any]] | None = None, metadata: dict[str, Any] | None = None)[source]¶
Bases:
objectRepresent 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: ndarray[tuple[Any, ...], dtype[Any]]¶
numpy array: Return the data of the image.
- Setter:
Set the data of the image.
- property histogram: tuple[ndarray[tuple[Any, ...], dtype[Any]], ndarray[tuple[Any, ...], dtype[Any]]]¶
numpy array: Calculate and return image histogram.
- property metadata: dict[str, Any]¶
str: Return metadata of image.
- Setter:
Set the meta data of the image.
- save(path: str | None = None, data: ndarray[tuple[Any, ...], dtype[Any]] | None = None, metadata: dict[str, Any] | None = None) None[source]¶
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: dict[str, int]) dict[int, ImageData][source]¶
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: str) ndarray[tuple[Any, ...], dtype[Any]] | None[source]¶
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: str, data: ndarray[tuple[Any, ...], dtype[Any]], description: str | None = None) None[source]¶
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.util module¶
Host utils that are not aware of the implementation of camacq.