The SpectroControl Class

This is the DESI spectrograph control application.

NOTE- Error raising not yet implemented

This application provides the connection between DOS and the spectrograph controller module (spectro_controller.py) that handles the interface to the spectrograph hardware and mechanisms. For testing and development a matching spectro_simulator.py module can be used to simulate the hardware. The configuration variable controller_type selects between these options.

The following commands are implmented:
  • configure to configure the application and the controller
  • get to read status and configuration information
  • set to update select variables at run time
These commands manipulate the mechanisms of the spectrograph
  • exp_shutter to open/close the shutter (an exposure time can be given but usually the expose command is used)
  • nir_shutter to open/close the NIR shutter
  • illuminator to turn on, off or flash the illuminator
  • prepare_for_illumination to prepare the spectrograph for fiber illumination
  • hartmann_doors to control the Hartmann doors and power up/down the controller
  • wago to interact directly with the WAGO controller
  • power to control power to different mechanisms
These commands are used for exposures:
  • prepare_for_exposure to prepare the spectrograph for an exposure
  • expose to take an exposure (including normal/dark, exposure time, callback and callback arguments)
  • pause_exposure to pause an exposure
  • resume_exposure to resume an exposure that has been paused
  • stop_exposure to end an exposure (can’t be resumed) (no need to distinguish stop/abort since this application doesn’t have to support readout)
  • register_callback to register a PML interface/function to receive a callback at the end of an exposure

Several shared variables published by this application: STATUS reflects the application’s status CONNECTED is True when the controller is connected and alive (ie responds to version command)

Exposures can be paused, resumed and ended (either stopped or aborted). Synchronization among all 10 spectrographs is handled at a higher software level. The application is part of the spectrograph(s) interlock.

Telemetry and status information is polled periodically from the spectrograph controller. At this point no asynchronous link is provided between the controller and the spectrograph application to send alarms or event information (e.g. shutter is closed) but this can be added in the future.

Version History 12/30/2014 v0.2.0 KH Initial framework 01/31/2016 v0.5.0 KH Updated to device framework

class SpectroControl.SpectroControl(device_mode=False, noSVE=None, **extra_args)

The SpectroControl calls provides the interface to the spectrograph controller. It is expected that the application runs in DOS device mode, ie stand alone until connected to a DOS instance. In device mode applications are not started by the Architect but directly from the command line:: >>> python SpectroControl.py –role SPECTRO2 –service SpectroControl

commands = ['configure', 'get', 'set', 'suppress_alarms', 'illuminator', 'prepare_for_illumination', 'power', 'seal', 'hartmann', 'nir_shutter', 'exp_shutter', 'register_callback', 'clear_callback', 'expose', 'pause_exposure', 'resume_exposure', 'stop_exposure', 'prepare_for_exposure']

PML accessible commands

defaults = {'alarm_delay': 60, 'constants_version': 'DEFAULT', 'controller_type': 'SIMULATOR', 'logger_codeinfo': False, 'loglevel': 'INFO', 'service': 'SpectroControl', 'suppressed_alarms': [], 'telemetry_update_delay': 20.0, 'unit': 0}

Default configuration paramters

init(unit=None)

Initialize spectrograph application. Set up variables, import controller module, discovery

Keyword Arguments:
 unit – specifies the Spectrograph ID (0-9); when None, the number extracted from the role name
Raises:RuntimeError – Unable to locate constants, failed to update controller information
Returns str:SUCCESS
configure(constants='')

Restores the system to a known state. This includes the constants specified, defaults are used if none are specified. The default state for the spectrograph controller itself is that set by the underlying systems “initialize” command of the spectrocontroller library.

Keyword Arguments:
 constants (str) – Specifies the set of constants to use.
Raises:RuntimeError – Unable to load constants
Returns str:SUCCESS
initialize(*args, **kwargs)

Initialize the spectrograph controller by calling the initialize() function of the spectrocontroller library.

Raises:RuntimeError – Exception from underlying controller
Returns:The results from the initialize() call
get(args)

Getter function for configuration, spectrograph controller and similar parameters. Wraps spectrograph controller’s get function, automatically extracts control, exposure, and sensor fields.

Keyword Arguments:
 args (str) – Name of field being requested. Allowed values include: status, sensors, unit, mechanisms, controller_type, callback, telemetry_update_delay connected, version, controller_version, exposure, constants_version, illuminator_armed exposure_armed, suppressed alarms, alarms_enabled, connected (to an instance), information exposure_callback, illuminate_callback, report_progress, and any key of the config dictionary
Raises:RuntimeError – Invalid request
Returns:Requested value
set(*args, **kwargs)

Set parameters at run time. Values must be given in key=value notation.

Keyword:The value to set, includes telemetry_update_delay, alarms (enable/disable), controller (to set a value for this controller device), lock_sensor
Raises:RunitmeError – Invalid field
Returns:updated variable value
suppress_alarms(*args, **kwargs)

Manage alarms and suppress further messages. Options are passed via kwargs as key=value pairs.

Keyword:remove = all or remove=keyword (such as exposure, nir_shutter, slithead_temp…), add = keyword (to add an alarm to the suppressed list; such as exposure, nir_shutter, slithead_temp…)
Raises:RuntimeError – Invalid option, alarm already surpressed
Returns str:SUCCESS
illuminator(action='status', flash_time=0.05, use_callback=False, **callback_args)

Controls the illuminator. Wraps spectrograph controller’s illuminator function, with some argument checking.

Keyword Arguments:
 
  • action (str,default='status') – on, off, status, reset, (attempts to reset error condition)
  • flashtime (float,default='status') – LED on time in seconds (float). If None, the illuminator will just be turned on. Note that the current implementation of the spectro control firmware does not support setting the flash time. Instead a fixed 50 ms pulse is used. If flash time is larger than 50 ms, the call will be repeated. None, meaning constantly on, is currently not accepted.
  • use_callback (boolean,default=False) – If true, callback function is called when illumination completes
  • **callback_args (key/values) – These are passed to the callback function if it is called
Raises:

RuntimeError – Invalid inputs, illuminator failed to shut off

Returns str:

illuminator status (NOTREADY, ON, OFF, READY)

prepare_for_illumination(auto_arm=True)

Prepare spectrograph to use the illuminator. Fails when an exposure is going on. This routine does not power on any of the mechanisms but they are configured to allow the illuminator to be turned on. This includes, for example, closing both shutters and inflating the seals.

Keyword Arguments:
 auto_arm (boolean,default=True) – If True the illuminator update function will be armed so that the illuminator can be triggered with a shared variable.
Raises:RuntimeError – Illuminator did not fully prepare
Returns str:SUCCESS
hartmann(action=None, doors=None)

Controls the state of the Hartman doors This routine does not power on any of the mechanisms

Keyword Arguments:
 
  • action (str) – open, close, reset
  • doors (str) – left, right, both
Raises:

RuntimeError – Invalid request, door failed to operate

Returns str:

SUCCESS

power(device=None, action=None)

Changes power for components of the spectrograph.

Keyword Arguments:
 
  • device (str) – nir_shutter, exp_shutter, hartmann_left, hartmann_right
  • action (str) – on, off, reset
Raises:

RuntimeError – Invalid input, problems powering device

Returns str:

SUCCESS

seal(shutter=None, action=None)

Controls the two shutter seals

Keyword Arguments:
 
  • shutter (str) – can be nir_shutter or exp_shutter
  • action (str) – either inflate or deflate (reset not yet implemented)
Raises:

RuntimeError – Invalid action or state

Returns str:

SUCCESS

nir_shutter(action)

Controlls the NIR shutter

Keyword Arguments:
 action (str) – can be open, close, or reset
Raises:RuntimeError – Invalid action, error with shutter
Returns str:SUCCESS
exp_shutter(action)

Controlls the exposure shutter

Keyword Arguments:
 action (str) – can be open, close, or reset
Raises:RuntimeError – Invalid action, error with shutter
Returns str:SUCCESS
expose(expid, exptime=0.0, mode='dark', wait=False, use_callback=False, updater=None, action='expose', **callback_args)

Take an exposure of the requested type and duration The routine first checks if the spectrograh controller is ready for an exposure The call returns immediately, ie doesn’t wait for the exposure to complete and less wait is set to True (Note that an exposure can also be triggered using the SPECTROGRAPHS_EXPOSE shared variable and the arm mechanism)

Keyword Arguments:
 
  • expid (int) – the exposure number
  • exptime (float,default=0.0) – the requested exposure time in seconds
  • mode (str,default='dark') – the mode of the exposure, dark or normal
  • wait (boolean,default=False) – the return waits for the exposure to complete before returning.
  • use_callback (boolean,default=False) – if set and a callback function was registered, this function is called when the shutter closes.
  • updater (str/boolean/None,default=None) – can be a role name or boolean. If it matches the applications role or is True, the report_progress flag will be set
  • action (str,default='expose') – either expose or resume
  • **callback_args (key/values) – if given, these will be passed to the callback function
Raises:

RuntimeError – invalid requests, errors starting exposure

Returns str:

SUCCESS

synched_expose(args)

Runs an exposure using the multicast connection as a trigger. THIS IS STILL IN A TEST AND DEVELOPMENT STATE

Wraps spectrograph controller’s expose function, but waits for a multicast signal to actually expose. Calling program should send a multicast command with the message ‘expose’ to run the exposure and end the command.

Keyword Arguments:
 args (str) – Instructions for the exposure. Should be the exposure type, normal or dark, followed by a space and then the exposure time in seconds.
Returns:The results of calling the underlying exposure command with the arguments
stop_exposure(expid=None, use_callback=False)

Stops the current exposure

Keyword Arguments:
 
  • expid (int) – must be a currently active exposure number
  • use_callback (boolean,default=False) – if True, the (pre-registered) callback function is called when the shutter closes
Raises:

RuntimeError – Invalid ID, no exposure to stop, exposure is paused

Returns str:

SUCCESS

pause_exposure(expid=None, use_callback=False)

Pause the current exposure

Keyword Arguments:
 
  • expid (int) – must be a currently active exposure number
  • boolean,default=True – if True, the (pre-registered) callback function is called when the shutter closes
Raises:

RuntimeError – invalid input, no exposure to pause, exposure already paused

Returns str:

SUCCESS

resume_exposure(expid=None, wait=False, use_callback=False, updater=None, **callback_args)

Resume a paused exposure

Keyword Arguments:
 
  • expid (int) – must be a currently active exposure number in PAUSED or READY state.
  • wait – passed on to the func:~SpectroControl.SpectroControl.expose function
  • use_callback – passed on to the func:~SpectroControl.SpectroControl.expose function
  • updater – passed on to the func:~SpectroControl.SpectroControl.expose function
  • **callback_args – passed on to the func:~SpectroControl.SpectroControl.expose function
Raises:

RuntimeError – invalid input, no exposure to resume, exposure error

Returns str:

SUCCESS

register_callback(*args, **kwargs)

Register a PML interface and function to be called at the end of an exposure or when the shutter closes Only one callback can be registered per SpectroController application meaning that earlier values will be overwritten by subsequent calls. (Supports both PML callbacks and Pyro URIs)

Keyword Arguments:
 
  • interface (str) – The PML interface the callback function is on
  • function (str) – The name of the callback function
  • dos_args (dict,optional) – the dictionary of named args is passed to the callback function.
Raises:

RuntimeError – Invalid arguments

Returns str:

SUCCESS

clear_callback(what)

Clear the callback variables

Keyword Arguments:
 what (str) – specifies what to clear. Could be expose, illuminate, or all
Raises:RuntimeError – Invalid arguments
Returns str:SUCCESS
prepare_for_exposure(use_sv=False, force=False, expid=None)

Puts the spectrograph controller in the ready state for an exposure. This routine does not power on any of the mechanisms * The NIR shutter will be open, the seal deflated. * The exposure shutter will be closed, the seal deflated * The illuminator will be off

Keyword Arguments:
 
  • use_sv (boolean,default=False) – if True the exposure update function will be armed so that the exposure can be triggered with a shared variable.
  • force (boolean,default=True) – if True, any ongoing exposure is stopped. (not yet implemented)

“keyword int, default=None expid: Next exposure id (to match with EXPOSE SV if use_sv is True) :raises RuntimeError: Error with controller :returns str: SUCCESS or controller status

about_to_connect_to_instance(*args, **kwargs)

To be overridden by the user so that any actions can be taken when the device application is about to connect to an instance

did_connect_to_instance(*args, **kwargs)

To be overridden by the user so that any actions can be taken when the device application connects to an instance

about_to_disconnect_from_instance(*args, **kwargs)

To be overridden by the user so that any actions can be taken when the device application is about to disconnect from an instance

did_disconnect_from_instance(*args, **kwargs)

To be overridden by the user so that any actions can be taken when the device application disconnects from an instance