microscope_automation.connectors package¶
Submodules¶
microscope_automation.connectors.connect_slidebook module¶
Communication layer for 3i Slidebook This layer sends http commands to a command and data servers. Slidebook calls a MatLab library that pulls the commands from the server queue
Date Created: January 26, 2020
-
class
microscope_automation.connectors.connect_slidebook.
ConnectMicroscope
(cmd_url='http://127.0.0.1:5000', data_url='http://127.0.0.1:5100', microscope='3iW1-0', dummy=False)[source]¶ Bases:
object
-
create_experiment_path
(experiment, experiment_folder)[source]¶ Creates complete path to capture settings. Raises exception if experiment does not exist.
- Input:
experiment: string with name of capture settings (with or w/o extension .exp.prefs)
experiment_folder: folder for capture settings
- Output:
experiment_path: path to experiment
-
execute_experiment
(capture_settings, locations, objective='')[source]¶ Execute experiments with parameters defined in experiment on multiple positions.
- Input:
capture_settings: string with name of experiment as defined within Microscope software
objective: objective used to acquire image. If none keep objective.
locations: list with (x,y,z) stage locations
- Output:
success: True when experiment was successfully posted on command server
-
get_focus_pos
()[source]¶ Return current position of focus drive.
- Input:
none
- Output:
zPos: position of focus drive in micrometer
-
get_focus_settings
(experiment_path=None, experiment_name=None)[source]¶ Get focus settings. Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
- Output:
none
-
get_microscope_name
()[source]¶ Returns name of the microscope from hardware that is controlled by this class
- Input:
none
- Output:
Microscope: name of Microscope
-
get_objective_position_from_experiment_file
(experiment_path=None, experiment_name=None)[source]¶ Function to get the position of the objective used in the experiment Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
- Output:
none
-
get_stage_pos
(repetitions=5, wait=1)[source]¶ Return most recent position of Microscope stage.
- Input:
repetitions: number of times to try to get a response
wait: wait time per repetition in sec
- Output:
xPos, yPos, zPos: x and y position of stage in micrometer
-
is_tile_scan
(experiment_path=None, experiment_name=None)[source]¶ Function to check if the experiment is a tile scan. Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
- Output:
none
-
is_z_stack
(experiment_path=None, experiment_name=None)[source]¶ Function to check if the experiment contains z-stack acquisition. Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
- Output:
none
-
live_mode_start
(experiment)[source]¶ Start live mode. Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
experiment: name of experiment
- Output:
none
-
live_mode_stop
(experiment)[source]¶ Stop live mode. Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
experiment: name of experiment
- Output:
none
-
load_image
(image, get_meta_data=False)[source]¶ Load most recent image from data service and return it a class ImageAICS
- Input:
image: image object of class ImageAICS.
get_meta: if true, retrieve meta data from file. Default is False
- Output:
image: image with data and meta data as ImageAICS class
-
move_focus_to
(zPos)[source]¶ Move focus to new position. Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
zPos, yPos: new focus position in micrometers.
- Output:
zFocus: new position of focus drive
-
move_focus_to_load
()[source]¶ Move focus to load position if defined.
- Input:
zPos, yPos: new focus position in micrometers.
- Output:
zFocus: new position of focus drive
-
move_focus_to_work
()[source]¶ Move focus to work position if defined.
- Input:
zPos, yPos: new focus position in micrometers.
- Output:
zFocus: new position of focus drive
-
move_stage_to
(xPos, yPos, zPos, capture_settings=None, test=False)[source]¶ Move stage to new position.
- Input:
xPos, yPos, zPos: new stage and objective position in micrometers.
capture_settings: capture settings in Slidebook Capture dialog to move stage
test: not used but included for consistency with ZEN Blue API
- Output:
xPos, yPos, zPos: new stage and objective position in micrometers
-
not_implemented
(method_name)[source]¶ Raise exception if method is not implemented.
- Input:
method_name: method that calls this method
- Output:
none
-
post_experiment
(experiment)[source]¶ Post experiment as last entry on queue and return updated experiment
-
save_image
(fileName)[source]¶ Save last acquired ImageAICS in original file format using microscope software
Raises HardwareCommandNotDefinedError
- Input:
file: file name and path for ImageAICS save
- Output:
none
-
set_focus_load_position
()[source]¶ Retrieve current position and set as load position.
- Input:
none
- Output:
zLoad: current focus position in mum
-
set_focus_work_position
()[source]¶ Retrieve current position and set as work position.
- Input:
none
- Output:
z_work: current focus position in mum
-
snap_image
(capture_settings, objective='')[source]¶ Snap image with parameters defined in experiment at current location. Raise exception if request was not successful
- Input:
capture_settings: string with name of capture_settings as defined within Microscope software
objective: objective used to acquire image. If none keep objective.
- Return:
response: Return dictionary with response from commands microservice
-
trigger_pump
(seconds, port='COM1', baudrate=19200)[source]¶ Trigger pump
- Input:
seconds: the number of seconds pump is activated
port: com port, default = ‘COM1’
baudrate: baudrate for connection, can be set on pump, typically = 19200
- Output:
none
-
update_tile_positions
(experiment_path, experiment_name, x_value, y_value, z_value)[source]¶ Function to define the position of the tile. Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
x_value: float (x - coordinate)
y_value: float (y - coordinate)
z_value: float (z - coordinate)
- Output:
none
-
validate_experiment
(experiment_path=None, experiment_name=None)[source]¶ Function to check if the experiment is defined in the Slidebook software
- Input:
experiment_path: path of the experiment file - does not matter for Zen Black
experiment_name: name of the experiment
- Output:
valid_experiment: bool describing if the experiment is valid
-
z_down_relative
(delta)[source]¶ Move focus relative to current position away from sample. Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
delta: absolute distance in mum
- Output:
z: new position of focus drive
-
z_relative_move
(delta)[source]¶ Move focus relative to current position. Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
delta: distance in mum
- Output:
z: new position of focus drive
-
z_stack_range
(experiment_path=None, experiment_name=None)[source]¶ Function to get the range of first z-stack in experiment. Included for parity between Microscope connections.
Raises HardwareCommandNotDefinedError.
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
- Output:
none
-
microscope_automation.connectors.connect_zen_black module¶
microscope_automation.connectors.connect_zen_blue module¶
Communication layer for Zen Blue API Date Created: June 09, 2016
-
class
microscope_automation.connectors.connect_zen_blue.
ConnectMicroscope
(connect_dll=True)[source]¶ Bases:
object
Simulation: Connect to Carl Zeiss ZEN blue Python API.
To be able to use ZEN services in a COM environment, the ZEN functionality must be registered as follows as administrator (right click when opening command prompt to run as administrator) (you might have to update versions):
pushd “C:WindowsMicrosoft.NETFramework64v4.0.30319” SET dll-1=”C:Program FilesCarl ZeissZEN 2ZEN 2 (blue edition)Zeiss.Micro.Scripting.dll” regasm /u /codebase /tlb %dll-1% regasm /codebase /tlb %dll-1%
SET dll-2=”C:Program FilesCarl ZeissZEN 2ZEN 2 (blue edition)Zeiss.Micro.LM.Scripting.dll” regasm /u /codebase /tlb %dll-2% regasm /codebase /tlb %dll-2% popd
-
close_experiment
(experiment=None)[source]¶ Closes experiment and forces reload.
- Input:
experiment: string with name of experiment defined within Microscope software
- Output:
none
-
create_experiment_path
(experiment, experiment_folder)[source]¶ Creates complete path to experiment. Raises exception if experiment does not exist
- Input:
experiment: string with name of experiment (with or w/o extension .czexp)
experiment_folder: folder for capture settings
- Output:
experiment_path: path to experiment
-
execute_experiment
(experiment=None, pos_list=None)[source]¶ Execute experiments with parameters defined in experiment. Image object is stored in self.image. Takes all images that are part of experiment (e.g. all slices).
- Input:
experiment: string with name of experiment defined within Microscope software. If None use actual experiment.
pos_list: if experiment has tiles enabled execute experiment at positions [(x1, y1, z1), (x2 …]. Supports only one block experiments.
- Output:
none
-
find_autofocus
(experiment)[source]¶ Focus with ZEN software autofocus.
- Input:
experiment: string with name for experiment defined in ZEN
- Output:
zPos: position of focus drive after autofocus
-
find_surface
()[source]¶ Find cover slip using Definite Focus 2.
- Input:
none
- Output:
z: position of focus drive after find surface
-
get_all_objectives
(n_positions)[source]¶ Retrieve name and magnification of all objectives. Warning! The objectives will move.
- Input:
n_positions: number of objective positions
- Output:
objectives_dict: dictionary of all objectives mounted at microscope in form {‘magnification’: {‘Position’: position, ‘Name’: name}
-
get_autofocus_ready
()[source]¶ Check if auto focus position for DF2 was stored and recall_focus should work.
Raises AutofocusNotSetError if not ready. Raises AutofocusObjectiveChangedError if there is an issue with objective_name
- Input:
none
- Output:
ready: True if DF2 was initialized and recall_focus should work.
-
get_experiment_folder
()[source]¶ Return path to user specific experiment file.
- Input:
none
- Output:
experiment_path: path to experiment file
-
get_focus_pos
()[source]¶ Return current position of focus drive.
- Input:
none
- Output:
zPos: position of focus drive in micrometer
-
get_focus_settings
(experiment_path, experiment_name)[source]¶ Function to get the focus settings used in the experiment
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
- Output:
focus_settings: All instances of focus settings in experiment file
-
get_last_known_focus_position
()[source]¶ Retrieves focus position used for recovery if autofocus fails. Will raise AutofocusNotSetError exception if not defined
- Input:
focusPostion: position in um to be used for autofocus recovery
- Output:
none.
-
get_microscope_name
()[source]¶ Returns name of the microscope from hardware that is controlled by this class.
- Input:
none
- Output:
Microscope: name of Microscope
-
get_objective_magnification
()[source]¶ Get magnification of actual objective.
- Input:
none
- Output:
magnification: magnification of actual objective, objective in imaging position
-
get_objective_name
()[source]¶ Get name of actual objective.
- Input:
none
- Output:
name: name of actual objective, objective in imaging position
-
get_objective_position
()[source]¶ Get position of actual objective.
- Input:
none
- Output:
position: position of actual objective, objective in imaging position
-
get_objective_position_from_experiment_file
(experiment_path, experiment_name)[source]¶ Function to get the position of the objective used in the experiment
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
- Output:
position: the integer position of the objective
-
get_stage_pos
()[source]¶ Return current position of Microscope stage.
- Input:
none
- Output:
xPos, yPos: x and y position of stage in micrometer
-
is_tile_scan
(experiment_path=None, experiment_name=None)[source]¶ Function to check if the experiment is a tile scan
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
- Output:
tile_scan_bool: bool describing if the experiment contains a tile scan
-
is_z_stack
(experiment_path=None, experiment_name=None)[source]¶ Function to check if the experiment is a z-stack experiment
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
- Output:
z_stack_experiment: bool describing if the experiment acquires a z stack
-
live_mode_start
(experiment=None)[source]¶ Start live mode of ZEN software.
- Input:
experiment: name of ZEN experiment (default = None)
- Output:
imgLive: image of type ZenImage
-
live_mode_stop
(experiment=None)[source]¶ Stop live mode of ZEN software.
- Input:
experiment: name of ZEN experiment (default = None)
- Output:
none
-
load_image
(image, get_meta=False)[source]¶ Load image using aicsimage and return it a class ImageAICS
- Input:
image: image object of class ImageAICS. Holds meta data at this moment, no image data.
get_meta: if true, retrieve meta data from file. Default is False
- Output:
image: image with data and meta data as ImageAICS class
-
move_focus_to
(zPos)[source]¶ Move focus to new position.
- Input:
zPos, yPos: new focus position in micrometers.
-
move_focus_to_load
()[source]¶ Move focus to load position if defined.
- Input:
zPos, yPos: new focus position in micrometers.
-
move_focus_to_work
()[source]¶ Move focus to work position if defined.
- Input:
zPos, yPos: new focus position in micrometers.
- Output:
none
-
move_stage_to
(xPos, yPos, zPos=None, experiment=None, test=False)[source]¶ Move stage to new position.
- Input:
xPos, yPos: new stage position in micrometers.
zPos, experiment: not used but included for consistency with Slidebook API
test: if True return travel path and do not move stage
- Output:
xPos, yPos: x and y position of stage in micrometer after stage movement (if test = False)
x_path, y_path: projected travel path (if test = True)
-
recall_focus
(pre_set_focus=True)[source]¶ Find stored focus position as offset from coverslip. Stored focus position is lost when switching objective, even when returning to original objective.
- Input:
pre_set_focus: Move focus to previous auto-focus position. This makes definite focus more robust
- Output:
z: position of focus drive after recall focus
-
run_macro
(macro_name, macro_param=None, trials=3)[source]¶ Function to run a given Zen Blue Macro
- Input:
macro_name: name of the macro
macro_param: parameters to pass into the macro
trials: maximum number of attempts to run the macro. Gives user the option to fix any errors that arise.
- Output:
none
-
save_image
(fileName)[source]¶ Save last acquired ImageAICS in original file format using microscope software.
- Input:
file: file name and path for ImageAICS save
-
set_autofocus_not_ready
()[source]¶ Set flag that auto focus position for DF2 is not ready and recall_focus will not work.
- Input:
none
- Output:
none
-
set_autofocus_ready
()[source]¶ Set flag that auto focus position for DF2 was stored and recall_focus should work.
- Input:
none
- Output:
none
-
set_experiment
(experiment=None, pos_list=None)[source]¶ Sets the experiment with ZEN API
- Input:
experiment: string with name of experiment defined within Microscope software. If None use actual experiment.
pos_list: if experiment has tiles enabled execute experiment at positions [(x1, y1, z1), (x2 …]. Supports only one block experiments.
- Output:
exp_class: the instance of the experiment returned by ZEN API
-
set_focus_load_position
()[source]¶ retrieve current position and set as load position.
- Input:
none
- Output:
zLoad: current focus position in mum
-
set_focus_work_position
()[source]¶ retrieve current position and set as work position.
- Input:
none
- Output:
z_work: current focus position in mum
-
set_last_known_focus_position
(focusPostion)[source]¶ Stores focus position used for recovery if autofocus fails.
- Input:
focusPostion: position in um to be used for autofocus recovery
- Output:
none.
-
snap_image
(experiment=None)[source]¶ Snap image with parameters defined in experiment. Image object is stored in self.image. Acquires single image from experiment (e.g. single slice of stack).
- Input:
experiment: string with name of experiment as defined within Microscope software. If None use active experiment.
- Output:
none
-
store_focus
()[source]¶ Store actual focus position as offset from coverslip. Stored focus position is lost when switching objective, even when returning to original objective.
- Input:
none
- Output:
z: position of focus drive after store focus
-
switch_objective
(targetPosition, load=True)[source]¶ Switches objective.
- Input:
targetPosition: Position of new objective on objective switcher
load: if True, move objective to load position before switching. Default: True
- Output:
objectiveName: name of new objective
-
trigger_pump
(seconds, port='COM1', baudrate=19200)[source]¶ Trigger pump
- Input:
seconds: the number of seconds pump is activated
port: com port, default = ‘COM1’
baudrate: baudrate for connection, can be set on pump, typically = 19200
- Output:
none
-
update_tile_positions
(experiment_path, experiment_name, x_value, y_value, z_value)[source]¶ Function to define the position of the tile
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
x_value: float (x - coordinate)
y_value: float (y - coordinate)
z_value: float (z - coordinate)
- Output:
none
-
validate_experiment
(experiment_path=None, experiment_name=None)[source]¶ Function to check if the experiment is defined in the Zen blue software
- Input:
experiment_path: path of the experiment file
experiment_name: name of the experiment
- Output:
valid_experiment: bool describing if the experiment is valid
-
wait_for_experiment
(experiment)[source]¶ Wait until experimentis active experiment.
- Input:
experiment: string with name of experiment defined within Microscope software.
- Output:
none
-
wait_for_objective
(target_objective)[source]¶ Wait until objective is in place.
- Input:
target_objective: string with name of objective.
- Output:
None
-
z_down_relative
(delta)[source]¶ Move focus relative to current position away from sample.
- Input:
delta: absolute distance in mum
- Output:
z: new position of focus drive
-
z_relative_move
(delta)[source]¶ Move focus relative to current position.
- Input:
delta: distance in mum
- Output:
z: new position of focus drive
-
-
microscope_automation.connectors.connect_zen_blue.
test_connect_zen_blue
(test=['test_definite_focus', 'execute_experiment', 'snap_image', 'get_all_objectives', 'trigger_pump', 'test_focus', 'save_image', 'test_stage'])[source]¶ Test suite to test module with Zeiss SD hardware or test hardware.
- Input:
test: list with tests to perform
- Output:
success: True when test was passed
-
microscope_automation.connectors.connect_zen_blue.
test_definite_focus
(microscope, interactive=False)[source]¶ Test DefiniteFocus 2 with ZEN Blue on spinning disk.
- Input:
microscope: instance of class ConnectMicroscope interactive: if true allow input from microscope
- Output:
success: True when test was passed
microscope_automation.connectors.connect_zen_blue_dummy module¶
Dummy function for ZEN blue conection Created on Sep 23, 2016
@author: winfriedw
-
class
microscope_automation.connectors.connect_zen_blue_dummy.
Acquisition
(microscope_status)[source]¶ Bases:
object
Simulate image acquisition
-
FindAutoFocus
()[source]¶ Use the autofocus of the current experiment to find the sample.
- Input:
none
- Output:
none
-
-
class
microscope_automation.connectors.connect_zen_blue_dummy.
Application
(microscope_status)[source]¶ Bases:
object
-
class
microscope_automation.connectors.connect_zen_blue_dummy.
Devices
(microscope_status)[source]¶ Bases:
object
Simulated device objects
-
class
microscope_automation.connectors.connect_zen_blue_dummy.
Experiments
(microscope_status)[source]¶ Bases:
object
-
class
microscope_automation.connectors.connect_zen_blue_dummy.
Focus
(microscope_status)[source]¶ Bases:
object
-
property
ActualPosition
¶ Get the current z position for focus drive
-
property
-
class
microscope_automation.connectors.connect_zen_blue_dummy.
GetActiveObject
(name)[source]¶ Bases:
object
Simulation for connection to ZEN blue software.
-
class
microscope_automation.connectors.connect_zen_blue_dummy.
MicroscopeStatus
[source]¶ Bases:
object
Create instance of this class to keeps track of microscope status.
- Input:
none
- Output:
none
-
property
objective_name
¶ Get name for actual objective
-
property
objective_position
¶ Get position for objective in objective changer
-
property
xPos
¶ Get absolute x position for stage
-
property
yPos
¶ Get absolute y position for stage
-
property
zPos
¶ Get absolute z position for focus drive
Module contents¶
Connectors package for Microscope Automation.