AvsFiberSpectrograph

class lsst.ts.fiberspectrograph.AvsFiberSpectrograph(serial_number=None, log=None, log_to_stdout=False)

Bases: object

Interface for the Avantes fiber spectrograph AvaSpec library.

This class follows Resource acquisition is initialization (RAII): when instantiated, it opens a connection; if it cannot open a connection, it raises an exception. To reconnect, delete the object and create a new one.

This class requires that libavs.so be installed in /usr/local/lib. It is compatible with libavs version 0.2.0.

Parameters:
serial_numberstr, optional

The serial number of the USB device to connect to. If None, then connect to the only available USB device, or raise RuntimeError if multiple devices are connected.

loglogging.Logger, optional

A Logger instance to send log messages to.

log_to_stdoutbool

Send all log info from DEBUG up to stdout. Useful when debugging the spectrograph in a python terminal.

Raises:
LookupError

Raised if there is no device with the specified serial number.

RuntimeError
  • Raised if multiple devices are connected and no serial number was specified.

  • Raised if there is an error connecting to the requested device.

Attributes Summary

device

AvsIdentityType of the connected spectrograph.

handle

The handle of the connected spectrograph.

Methods Summary

check_expose_ok(duration)

Check that an expose command would be allowed to succeed.

disconnect()

Close the connection with the connected USB spectrograph.

expose(duration)

Take an exposure with the currently connected spectrograph.

get_status([full])

Get the status of the currently connected spectrograph.

stop_exposure()

Cancel a currently running exposure and reset the spectrograph.

Attributes Documentation

device = None

AvsIdentityType of the connected spectrograph.

handle = None

The handle of the connected spectrograph.

Methods Documentation

check_expose_ok(duration)

Check that an expose command would be allowed to succeed.

Checks that parameters are in a valid range, and that no exposures are currently ongoing, returning a message describing the failure state if there would be one, or None otherwise.

Parameters:
durationfloat

Integration time of the exposure in seconds.

Returns:
msgstr or None

The string describing why expose would fail, or None if an it should not.

Notes

The Parameters of this method should match that of expose, as its purpose is to check the validity of those parameters.

disconnect()

Close the connection with the connected USB spectrograph.

If the attempt to disconnect fails, log an error message but still try to release the AVS library port.

Notes

This method should not raise.

async expose(duration)

Take an exposure with the currently connected spectrograph.

Parameters:
durationfloat

Integration time of the exposure in seconds.

Returns:
wavelengthastropy.units.Quantity

The 1-d wavelength solution provided by the instrument.

spectrumnumpy.ndarray

The 1-d spectrum measured by the instrument.

Raises:
RuntimeError

Raised if we cannot start the exposure for whatever reason (e.g. invalid duration, ongoing exposure).

AvsReturnError

Raised if there is an error in preparation, measurement, or readout from the device.

asyncio.CancelledError

Raised if the exposure is stopped before it is read out.

get_status(full=False)

Get the status of the currently connected spectrograph.

Parameters:
fullbool

Include the full AvsDeviceConfig structure in the output. This can be useful for understanding what other information is available from the spectrograph, but requires having the Avantes manual on hand to decode it.

Returns:
statusSpectrographStatus

The current status of the spectrograph, including temperature, exposure status, etc.

Raises:
AvsReturnError

Raised if there is an error querying the device.

stop_exposure()

Cancel a currently running exposure and reset the spectrograph.

If there is no currently active exposure, this does nothing.

Raises:
AvsReturnError

Raised if there is an error stopping the exposure on the device.