LabJackAccelerometerDataClient

class lsst.ts.ess.labjack.LabJackAccelerometerDataClient(config: SimpleNamespace, topics: Controller | SimpleNamespace, log: Logger, simulation_mode: int = 0)

Bases: BaseLabJackDataClient

Read 3-axis accelerometer data from a LabJack T7 or similar, and report using the accelerometerPSD topic.

Parameters:
namestr
configtypes.SimpleNamespace

The configuration, after validation by the schema returned by get_config_schema and conversion to a types.SimpleNamespace.

topicssalobj.Controller

The telemetry topics this model can write, as a struct with attributes such as tel_temperature.

loglogging.Logger

Logger.

simulation_modeint, optional

Simulation mode; 0 for normal operation.

Attributes:
accel_array_lenint

The number of raw samples in each accelerometer telemetry array.

accelerometerslist [types.SimpleNamespace]

List of configuration for each accelerometer.

acquisition_timefloat | None

How long it takes to acquire one set of raw data samples*: sampling_interval * (accel_array_len - 1)

num_channelsint

Number of accelerometer channels to read (3 per accelerometer).

psd_array_lenint

The number of samples in each accelerometerPSD telemetry array.

psd_frequenciesnp.ndarray

Array of frequences for the computed PSD, starting from 0.

sampling_intervalfloat | None

Interval between samples for one channel (seconds)*.

offsetsndarray

Offset for each accelerometer channel. scaled acceleration = (raw acceleration - offset) * scale

scalesndarray

Scale for each accelerometer channel; see offsets for details.

make_random_mock_raw_1d_data: `bool`

In simulation mode controls whether the client generates random mock_raw_1d_data (producing garbage PSDs). By default it is True, so that some output is produced. Set it to False if you would rather generate the raw data yourself, in which case the topic is not written until you set mock_raw_1d_data.

mock_raw_1d_data: `list` [`float`] | `None`

Unit tests may set this to a list of floats with length containing raw acceleration values for: [v0_chan0, v0_chan1, v0_chan2, v1_chan0, v1_chan1, v1_chan2, …, vn_chan0, vn_chan1, vn_chan2]. In simulation mode this will be cycled over to provide the raw acceleration data. If None and if make_random_mock_raw_1d_data is true then it will be set to random data when first needed.

wrote_psd_event: `asyncio.Event`

An event that unit tests can use to wait for PSD data to be written. A test can clear the event, then wait for it to be set.

Notes

In simulation mode the mock LabJack returns unspecified values, and those values may change in future versions of the LabJack software.

Attributes marked with * are set when sampling begins, because the exact values depend on a value returned by the LabJack.

Attributes Summary

connected

Methods Summary

blocking_data_stream_callback(handle)

Called in a thread when a full set of stream data is available.

connect()

Connect to the LabJack.

descr()

Return a brief description, without the class name.

disconnect()

Disconnect from the LabJack.

get_config_schema()

Get the config schema as jsonschema dict.

process_data(scaled_data, end_tai, backlogs)

Process one set of data.

psd_from_scaled_data(scaled_data)

Compute the PSD from scaled data.

read_data()

Read data.

read_data_once()

read_loop()

Call the read_data method in a loop.

run()

Read and process data from the LabJack.

run_in_thread(func, timeout)

Run a blocking function in a thread pool executor.

scaled_data_from_raw(raw_1d_data)

Convert a list of 1-D raw readings to 2-d scaled data.

setup_reading()

Perform any tasks before starting the read loop.

start()

Override start method to handle auto reconnecting if necessary.

start_data_stream()

Start the data stream from the LabJack.

start_mock_stream()

Start a mock stream, since ljm demo mode does not stream.

start_processing_data(scaled_data, end_tai, ...)

Start process_data as a background task, unless still running.

start_tasks()

Call disconnect, connect, and start the run task.

stop()

Delegate handling of stop tasks to the stop_tasks method.

stop_tasks()

Stop reading and publishing data.

Attributes Documentation

connected

Methods Documentation

blocking_data_stream_callback(handle: int) None

Called in a thread when a full set of stream data is available.

A full set is self.accel_array_len * self.num_channels values.

async connect() None

Connect to the LabJack.

Disconnect first, if connected.

Raises:
RuntimeError

If we cannot read the data.

descr() str

Return a brief description, without the class name.

This should be just enough information to distinguish one instance of this client from another. For example RPiDataClient should return something like:

f"host={self.config.host}, port={self.config.port}"
async disconnect() None

Disconnect from the LabJack. A no-op if disconnected.

classmethod get_config_schema() dict[str, Any]

Get the config schema as jsonschema dict.

async process_data(scaled_data: ndarray, end_tai: float, backlogs: tuple[int, int]) None

Process one set of data.

Parameters:
scaled_datanp.ndarray

x, y, z acceleration data of shape (self.num_channels, n) after applying offset and scale

end_taifloat

The time (TAI unix seconds) at which data collection ended.

backlogstuple

Two measures of the number of backlogged messages. Both values should be nearly zero if the data client is keeping up with the LabJack.

Raises:
RuntimeError

If streaming has not yet begun (because self.sampling_interval is None until streaming begins).

psd_from_scaled_data(scaled_data: ndarray) ndarray

Compute the PSD from scaled data.

async read_data() None

Read data.

Notes

This method should never be called because this class overrides the run method which, in the super class, calls this read_data method.

async read_data_once() None
async read_loop() None

Call the read_data method in a loop.

Allow for max_timeouts timeouts before raising a TimeoutError.

async run() None

Read and process data from the LabJack.

async run_in_thread(func: Callable[[], Any], timeout: float) Any

Run a blocking function in a thread pool executor.

Only one function will run at a time, because all calls use the same thread pool executor, which only has a single thread.

Parameters:
funcCallable

The blocking function to run; The function must take no arguments. For example: self._blocking_connect.

timeoutfloat

Time limit (seconds).

scaled_data_from_raw(raw_1d_data: list[float]) ndarray

Convert a list of 1-D raw readings to 2-d scaled data.

Parameters:
raw_1d_datalist[float]

Raw voltage data read from the LabJack in the form: [v0_chan0, v0_chan1, v0_chan2, v1_chan0, v1_chan1, v1_chan2, …, vn_chan0, vn_chan1, vn_chan2]

Returns:
scaled_datanp.ndarray

Raw data reshaped to size (self.num_channels, voltages) with offsets and scales applied:

scaled = (raw - offset) * scaled
async setup_reading() None

Perform any tasks before starting the read loop.

async start() None

Override start method to handle auto reconnecting if necessary.

async start_data_stream() None

Start the data stream from the LabJack.

start_mock_stream() None

Start a mock stream, since ljm demo mode does not stream.

start_processing_data(scaled_data: ndarray, end_tai: float, backlogs: tuple[int, int]) None

Start process_data as a background task, unless still running.

Parameters:
scaled_datanp.ndarray

Acceleration data of shape (self.num_channels, self.accel_array_len) after applying offset and scale.

end_taifloat

The time (TAI unix seconds) at which data collection ended.

backlogstuple

Two measures of the number of backlogged messages. Both values should be nearly zero if the data client is keeping up with the LabJack.

async start_tasks() None

Call disconnect, connect, and start the run task.

Raises the same exceptions as connect. If disconnect raises, this logs the exception and continues.

async stop() None

Delegate handling of stop tasks to the stop_tasks method.

This allows implementing classes to customize stop behavior.

async stop_tasks() None

Stop reading and publishing data.

This is alway safe to call, whether connected or not. This should raise no exceptions except asyncio.CancelledError. If disconnect raises, this logs the exception and continues.