API

asgard_alignment.ESOdevice Module

Scaffolds for devices to run with ESO command sets

class asgard_alignment.ESOdevice.ESOdevice(name)

Bases: ABC

class asgard_alignment.ESOdevice.Lamp(name)

Bases: ESOdevice

abstract is_off()
abstract is_on()
abstract turn_off()
abstract turn_on()
class asgard_alignment.ESOdevice.Motor(name, semaphore_id, named_positions={})

Bases: ESOdevice

that in IC0FB, all motors are considered as “discrete”. A discrete motor can be set to any given encoder position, so continuous motors are actually discrete motors with no named positions defined.

This class covers both continuous and discrete motors.

abstract disable()

The DISABLE command can be used to request the MCU to power off devices.

abstract enable()

The ENABLE command can be used to request the MCU to power on devices.

abstract move_abs(position: float)
abstract move_relative(position: float)
abstract online()

Upon reception, the ICS back-end server of the MCU shall power on all the controlled devices and have them ready to accept SETUP commands.

abstract ping()

The PING command is used to check the status of the controller, sending a dummy command such as *IDN? and making sure there is a reply

abstract read_state()
abstract setup(value: str | float)

Command to move a device to a given position. The position is given in the value field.

abstract standby()

Upon reception, the ICS back-end server of the MCU shall move some of the controlled devices to a safe “parking” position (if required) and power off all the controlled devices.

abstract stop()

The STOP command is issued by the ICS on wag to immediately stop the motion (initiated by a SETUP command) of devices.

class asgard_alignment.ESOdevice.SemaphoreState(value)

Bases: Enum

An enumeration.

RELEASED = 0
TAKEN = 1
class asgard_alignment.ESOdevice.SetupCommand(device_name, m_type, value)

Bases: object

Classes

ESOdevice(name)

Enum(value)

Generic enumeration.

Lamp(name)

Motor(name, semaphore_id[, named_positions])

that in IC0FB, all motors are considered as “discrete”.

SemaphoreState(value)

An enumeration.

SetupCommand(device_name, m_type, value)

datetime(year, month, day[, hour[, minute[, ...)

The year, month and day arguments are required.

asgard_alignment.Engineering Module

A script with functions for engineering Includes functions for: - move_image : move an image to a new location - move_pupil : move the pupil (on N1) to a new location

asgard_alignment.Engineering.get_matricies(config)

Get the matricies for moving the pupil and imagem, depending on the configuration

Parameters:

config (str) – The configuration to use - either “c_red_one_focus” or “intermediate_focus”

Returns:

  • pupil_move_matricies (dict) – A dictionary of matricies for moving the pupil

  • image_move_matricies (dict) – A dictionary of matricies for moving the image

asgard_alignment.Engineering.move_image(beam_number, x, y, send_command, config)

Move image to a new location (relative motion) x,y are in pixels

Parameters:
  • beam_number (int) – The beam number to move

  • x (float) – The x coordinate to move to, in pixels

  • y (float) – The y coordinate to move to, in pixels

  • send_command (function) – A function to send commands to the motors

  • config (str) – The configuration to use - either “c_red_one_focus” or “intermediate_focus”

Returns:

  • uv_commands (np.array) – The u,v commands sent to the motors

  • axis_list (list) – The list of axis names

asgard_alignment.Engineering.move_pupil(beam_number, x, y, send_command, config)

Move the pupil to a new location x,y are in mm

Parameters:
  • beam_number (int) – The beam number to move

  • x (float) – The x coordinate to move to

  • y (float) – The y coordinate to move to

  • send_command (function) – A function to send commands to the motors

  • config (str) – The configuration to use - either “c_red_one_focus” or “intermediate_focus”

Returns:

  • uv_commands (np.array) – The u,v commands sent to the motors

  • axis_list (list) – The list of axis names

Functions

get_matricies(config)

Get the matricies for moving the pupil and imagem, depending on the configuration

move_image(beam_number, x, y, send_command, ...)

Move image to a new location (relative motion) x,y are in pixels

move_pupil(beam_number, x, y, send_command, ...)

Move the pupil to a new location x,y are in mm

asgard_alignment.Instrument Module

class asgard_alignment.Instrument.Instrument(config_pth)

Bases: object

A class that creates connections to controllers, ESOdevice instances, and provides a means for the MDS to communicate with the Instrument. Open an instrument with a configuration file. The configuration file must be a JSON file with the following format:

[
    {
        "name": "HTPP1",
        "serial_number": "123456",
        "motor_type": "M100D",
        "motor_config": {}
    },
]

The Instrument will attempt to connect to each device in the config file, opening and saving connections to the controllers and devices.

Parameters:

config_pth (str) – The path to the configuration file for the instrument

Return type:

None

static compute_serial_to_port_map()

By inspecting the list of usb devices, find the serial number of the motor and the corresponding port (e.g. /dev/ttyUSB0)

Returns:

mapping – A dictionary that maps the serial number of the motor to the port

Return type:

dict

property devices

A dictionary of devices with the device name as the key

static find_zaber_usb_port()

Find the COM port for the Zaber motor

Returns:

str

The COM port for the Zaber motor

health()

Summarise the health of the instrument in a json format with the following - axis name - motor type - is connected - state

ping_connection(axis)

Ping the connection to the motor

Parameters:

axis (str) – The name of the motor to ping

Returns:

True if the connection is successful, False otherwise

Return type:

bool

Classes

Connection(interface_id)

Class representing access to particular connection (serial port, TCP connection).

Instrument(config_pth)

A class that creates connections to controllers, ESOdevice instances, and provides a means for the MDS to communicate with the Instrument.

Path(*args, **kwargs)

PurePath subclass that can make system calls.

asgard_alignment.Lamps Module

class asgard_alignment.Lamps.LightSource(name, controllino_connection, nCooldown, nWarmup, nMaxOn)

Bases: Lamp

All light sources in H/B/S use this framework

init()

Initialise the laser

is_off()

Check if the light source is off

is_on()

Check if the light source is on

turn_off()

Turn the thermal source off

turn_on()

Turn the thermal source on

Classes

LightSource(name, controllino_connection, ...)

All light sources in H/B/S use this framework

asgard_alignment.MultiDeviceServer Module

class asgard_alignment.MultiDeviceServer.MockMDS

Bases: object

handle_zmq(message)
class asgard_alignment.MultiDeviceServer.MultiDeviceServer(port, host, config_file)

Bases: object

A class to run the Instrument MDS.

DATABASE_MSG_TEMPLATE = {'command': {'name': 'write', 'parameters': [], 'time': 'YYYY-MM-DDThh:mm:ss'}}
static get_time_stamp()
handle_message(message)

Handles a recieved message. Custom messages are indicated by lowercase commands

log(message)
run()
socket_funct(s)

Classes

MockMDS()

MultiDeviceServer(port, host, config_file)

A class to run the Instrument MDS.

asgard_alignment.NewportMotor Module

Module for the newport motors.

class asgard_alignment.NewportMotor.LS16PAxis(connection, semaphore_id, name)

Bases: Motor

CONTROLLER_STATES = {'0A': 'READY OPEN LOOP: after reset', '0B': 'READY OPEN LOOP: after HOMING state', '0C': 'READY OPEN LOOP: after STEPPING state', '0D': 'READY OPEN LOOP: after CONFIGURATION state', '0E': 'READY OPEN LOOP: after with no parameters', '0F': 'READY OPEN LOOP: after JOGGING state', '10': 'READY OPEN LOOP: after SCANNING state', '11': 'READY OPEN LOOP: after READY CLOSED LOOP state', '14': 'CONFIGURATION', '1E': 'HOMING', '1F': 'REFERENCING', '28': 'MOVING OPEN LOOP (OL)', '29': 'MOVING CLOSED LOOP (CL)', '32': 'READY CLOSED LOOP: after HOMING state', '33': 'READY CLOSED LOOP: after MOVING CL state', '34': 'READY CLOSED LOOP: after DISABLE state', '35': 'READY CLOSED LOOP: after REFERENCING state', '36': 'READY CLOSED LOOP: after HOLDING state', '3C': 'DISABLE: after READY CLOSED LOOP state', '3D': 'DISABLE: after MOVING CL state', '46': 'JOGGING', '50': 'SCANNING', '5A': 'HOLDING'}
ERROR_BITS = {'0000': 'No error', '0010': 'Bit motor stall timeout', '0020': 'Bit time out motion', '0040': 'Bit time out homing', '0080': 'Bit bad memory parameters', '0100': 'Bit supply voltage too low', '0200': 'Bit internal error', '0400': 'Bit memory problem', '0800': 'Bit over temperature'}
LOWER_LIMIT = 0.0
MIDDLE = 8.0
UPPER_LIMIT = 16.0
disable()

The DISABLE command can be used to request the MCU to power off devices.

enable()

The ENABLE command can be used to request the MCU to power on devices.

init()
is_at_limit()
is_init_success()
is_motion_done()
is_moving()
is_reset_success()
is_stop_success()
move_abs(position: float)
move_relative(position)
online()

Upon reception, the ICS back-end server of the MCU shall power on all the controlled devices and have them ready to accept SETUP commands.

ping()

The PING command is used to check the status of the controller, sending a dummy command such as *IDN? and making sure there is a reply

read_position()
read_state(echo=False)

Read the state of the motor

setup(value)

Command to move a device to a given position. The position is given in the value field.

standby()

Upon reception, the ICS back-end server of the MCU shall move some of the controlled devices to a safe “parking” position (if required) and power off all the controlled devices.

stop()

The STOP command is issued by the ICS on wag to immediately stop the motion (initiated by a SETUP command) of devices.

class asgard_alignment.NewportMotor.M100DAxis(connection: NewportConnection, semaphore_id: int, axis: Literal['U', 'V'], name: str)

Bases: Motor

A class for the tip or tilt M100D motors https://www.newport.com.cn/p/CONEX-AG-M100D

CONTROLLER_STATES = {'14': 'CONFIGURATION', '28': 'MOVING CL', '29': 'STEPPING OL', '32': 'READY from Reset', '33': 'READY from MOVING CL', '34': 'READY from DISABLE', '35': 'READY from JOGGING OL', '36': 'READY from STEPPING OL', '3C': 'DISABLE from READY OL', '3D': 'DISABLE from MOVING CL', '46': 'JOGGING OL'}
LOWER_LIMIT = -0.75
UPPER_LIMIT = 0.75
property axis
disable()

The DISABLE command can be used to request the MCU to power off devices.

enable()

The ENABLE command can be used to request the MCU to power on devices.

init()
is_at_limit()

Check if the motor is at the limit

Returns:

bool

True if the motor is at the limit, False otherwise

is_init_success()

Check if the initialisation was successful

Returns:

bool

True if the initialisation was successful, False otherwise

is_motion_done()

Check if the motion is done

Returns:

bool

True if the motion is done, False otherwise

is_moving()

Check if the motor is moving

Returns:

is_moving: bool

True if the motor is moving, False otherwise

is_reset_success()

Check if the reset was successful

Returns:

bool

True if the reset was successful, False otherwise

is_stop_success()

Check if the stop was successful

Returns:

bool

True if the stop was successful, False otherwise

move_abs(position: float)

Move the motor to an absolute position

Parameters:

position: float

The position to move to

move_relative(position: float)

Move the motor to a relative position

Parameters:

position: float

The position to move to

online()

Upon reception, the ICS back-end server of the MCU shall power on all the controlled devices and have them ready to accept SETUP commands.

ping()

The PING command is used to check the status of the controller, sending a dummy command such as *IDN? and making sure there is a reply

read_position()

Read the position of the motor

Returns:

position: float

The position of the motor

read_state(echo=False)

Read the state of the motor

setup(value)

Command to move a device to a given position. The position is given in the value field.

standby()

Upon reception, the ICS back-end server of the MCU shall move some of the controlled devices to a safe “parking” position (if required) and power off all the controlled devices.

stop()

The STOP command is issued by the ICS on wag to immediately stop the motion (initiated by a SETUP command) of devices.

class asgard_alignment.NewportMotor.NewportConnection(serial_port: str, resource_manager: ResourceManager)

Bases: object

A class to handle the connection to the newport motors One per controller

SERIAL_BAUD = 921600
SERIAL_TERMIN = '\r\n'
close_connection()

Close the connection to the motor

open_connection(resource_manager: ResourceManager)

resource_manager : pyvisa.ResourceManager object (to avoid constructing it many times)

query_str(str_to_write)

Send a query through serial and return the response

Parameters:

str_to_write: str

The string to write to the serial port

Returns:

return_str: str

The string returned from the serial port

write_str(str_to_write)

Write a string through serial and do not expect anything to be returned

Parameters:

str_to_write: str

The string to write to the serial port

Classes

LS16PAxis(connection, semaphore_id, name)

M100DAxis(connection, semaphore_id, axis, name)

A class for the tip or tilt M100D motors https://www.newport.com.cn/p/CONEX-AG-M100D

NewportConnection(serial_port, resource_manager)

A class to handle the connection to the newport motors One per controller

asgard_alignment.ZaberMotor Module

A module for controlling the Zaber motors: LAC10A-T4A (through a X-MCC), X-LSM and X-LHM

Need to come up with a way to be able to name an axis/optic and move the right controller Ideas: - XMCC class with usage like XMCC[<axis number>].move_absolute(1000), + a dictionary that maps the name of the optic to both the axis number and controller

class asgard_alignment.ZaberMotor.ZaberLinearActuator(name, semaphore_id, axis)

Bases: Motor

IS_BLOCKING = False
LOWER_LIMIT = 0
UPPER_LIMIT = 10000
disable()

The DISABLE command can be used to request the MCU to power off devices.

enable()

The ENABLE command can be used to request the MCU to power on devices.

init()

Don’t do anything, the motor is already initialised by the constructor Might need to home after power cycle

is_at_limit()

Check if the motor is at the limit

Returns:

bool

True if the motor is at the limit, False otherwise

is_init_success()

Check if the initialisation was successful

Returns:

bool

True if the initialisation was successful, False otherwise

is_motion_done()

Check if the motion is done

Returns:

bool

True if the motion is done, False otherwise

is_reset_success()

Check if the reset was successful

Returns:

bool

True if the reset was successful, False otherwise

is_stop_success()

Check if the stop was successful

Returns:

bool

True if the stop was successful, False otherwise

move_abs(position)

Move the motor to the absolute position

Parameters:

position: float

The position to move to

Returns:

None

move_absolute(new_pos, units=Units.LENGTH_MICROMETRES)

Move the motor to the absolute position

Parameters:

new_pos: float

The position to move to

units: zaber_motion.Units

The units of the position, default is micrometres

Returns:

None

move_relative(new_pos, units=Units.LENGTH_MICROMETRES)

Move the motor to the relative position

Parameters:

new_pos: float

The position to move to, relative to the current position

units: zaber_motion.Units

The units of the position, default is micrometres

Returns:

None

online()

Upon reception, the ICS back-end server of the MCU shall power on all the controlled devices and have them ready to accept SETUP commands.

ping()

The PING command is used to check the status of the controller, sending a dummy command such as *IDN? and making sure there is a reply

read_position(units=Units.LENGTH_MICROMETRES)
read_state()

Read the state of the motor

Returns:

str

The state of the motor

setup(value)

Command to move a device to a given position. The position is given in the value field.

standby()

Upon reception, the ICS back-end server of the MCU shall move some of the controlled devices to a safe “parking” position (if required) and power off all the controlled devices.

stop()

The STOP command is issued by the ICS on wag to immediately stop the motion (initiated by a SETUP command) of devices.

stop_now()

Stop the motor immediately

Returns:

None

class asgard_alignment.ZaberMotor.ZaberLinearStage(name, semaphore_id, device)

Bases: Motor

A linear stage, e.g. the X-LHM100A-SE03, or the X-LSM150A-SE03 Default units are milimetres

IS_BLOCKING = False
disable()

The DISABLE command can be used to request the MCU to power off devices.

enable()

The ENABLE command can be used to request the MCU to power on devices.

init()

Don’t do anything, the motor is already initialised by the constructor Might need to home after power cycle

is_at_limit()

Check if the motor is at the limit

Returns:

bool

True if the motor is at the limit, False otherwise

is_init_success()

Check if the initialisation was successful

Returns:

bool

True if the initialisation was successful, False otherwise

is_motion_done()

Check if the motion is done

Returns:

bool

True if the motion is done, False otherwise

is_reset_success()

Check if the reset was successful

Returns:

bool

True if the reset was successful, False otherwise

is_stop_success()

Check if the stop was successful

Returns:

bool

True if the stop was successful, False otherwise

move_abs(position)

Move the motor to the absolute position

Parameters:

position: float

The position to move to

Returns:

None

move_absolute(new_pos, units=Units.LENGTH_MILLIMETRES)

Move the motor to the absolute position

Parameters:

new_pos: float

The position to move to

units: zaber_motion.Units

The units of the position, default is milimetres

Returns:

None

move_relative(new_pos, units=Units.LENGTH_MILLIMETRES)

Move the motor to the relative position

Parameters:

new_pos: float

The position to move to, relative to the current position

units: zaber_motion.Units

The units of the position, default is milimetres

Returns:

None

online()

Upon reception, the ICS back-end server of the MCU shall power on all the controlled devices and have them ready to accept SETUP commands.

ping()

The PING command is used to check the status of the controller, sending a dummy command such as *IDN? and making sure there is a reply

read_position(units=Units.LENGTH_MILLIMETRES)
read_state()

Read the state of the motor

Returns:

str

The state of the motor

setup(value)

Command to move a device to a given position. The position is given in the value field.

standby()

Upon reception, the ICS back-end server of the MCU shall move some of the controlled devices to a safe “parking” position (if required) and power off all the controlled devices.

stop()

The STOP command is issued by the ICS on wag to immediately stop the motion (initiated by a SETUP command) of devices.

stop_now()

Stop the motor immediately

Returns:

None

Classes

Connection(interface_id)

Class representing access to particular connection (serial port, TCP connection).

ZaberLinearActuator(name, semaphore_id, axis)

ZaberLinearStage(name, semaphore_id, device)

A linear stage, e.g. the X-LHM100A-SE03, or the X-LSM150A-SE03 Default units are milimetres.

asgard_alignment.Cameras Module

class asgard_alignment.Cameras.MockPointGrey(image_path, n_samples, shift_type='random', noise_level=0.01)

Bases: object

EDITABLE_PARAMS = ['OffsetX', 'OffsetY', 'Height', 'Width', 'ExposureTime', 'Gain']
__getitem__(key)

Get the value of a mock camera parameter.

Parameters:

key (str) – The name of the parameter to get.

Returns:

The value of the parameter.

Return type:

Any

Raises:

KeyError – If the key is not a valid parameter.

__setattr__(name, value)

Set the attribute of the mock camera.

Parameters:
  • name (str) – The name of the attribute to set.

  • value (Any) – The value to set the attribute to.

__setitem__(key, value)

Set the value of a mock camera parameter.

Parameters:
  • key (str) – The name of the parameter to set.

  • value (Any) – The value to set the parameter to.

Raises:

KeyError – If the key is not a valid parameter.

get_frame()

Get the next image frame from the mock camera.

Returns:

The next image frame as a numpy array.

Return type:

numpy.ndarray

property img_size

Get the image size.

Returns:

The height and width of the image.

Return type:

tuple

release()

Mock release resources (no operation).

start_stream()

Mock start stream (no operation).

stop_stream()

Mock stop stream (no operation).

class asgard_alignment.Cameras.PointGrey(cam_index=0)

Bases: object

No-index:

EDITABLE_PARAMS = ['AcquisitionFrameRate', 'ExposureTime', 'Gain', 'Height', 'Width', 'PixelFormat', 'ExposureAuto', 'GainAuto', 'AcquisitionMode', 'ExposureMode', 'OffsetX', 'OffsetY']
__getitem__(key)

Get the value of a camera parameter.

Parameters:

key (str) – The name of the parameter to get.

Returns:

The value of the parameter.

Return type:

Any

Raises:

KeyError – If the key is not a valid parameter.

__setattr__(name, value)

Set the attribute of the camera.

Parameters:
  • name (str) – The name of the attribute to set.

  • value (Any) – The value to set the attribute to.

__setitem__(key, value)

Set the value of a camera parameter.

Parameters:
  • key (str) – The name of the parameter to set.

  • value (Any) – The value to set the parameter to.

Raises:

KeyError – If the key is not a valid parameter.

property camera

Get the camera instance.

Returns:

The camera instance.

Return type:

PySpin.Camera

get_frame()

Get the next image frame from the camera.

Returns:

The next image frame as a numpy array.

Return type:

numpy.ndarray

property img_size

Get the image size.

Returns:

The height and width of the image.

Return type:

tuple

release()

Release the camera resources.

set_region_from_corners(x1, y1, x2, y2)

Set the region of interest from the top left and bottom right corners.

Parameters:
  • x1 (int) – The x coordinate of the top left corner.

  • y1 (int) – The y coordinate of the top left corner.

  • x2 (int) – The x coordinate of the bottom right corner.

  • y2 (int) – The y coordinate of the bottom right corner.

start_stream()

Start the camera acquisition stream.

stop_stream()

Stop the camera acquisition stream.

Classes

MockPointGrey(image_path, n_samples[, ...])

PointGrey([cam_index])