LabJackAccelerometerDataClient#

class lsst.ts.ess.labjack.LabJackAccelerometerDataClient(config, topics, log, simulation_mode=0)#

Bases: BaseLabJackDataClient

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

Parameters:
  • name (str)

  • config (types.SimpleNamespace) – The configuration, after validation by the schema returned by get_config_schema and conversion to a types.SimpleNamespace.

  • topics (salobj.Controller) – The telemetry topics this model can write, as a struct with attributes such as tel_temperature.

  • log (logging.Logger) – Logger.

  • simulation_mode (int, optional) – Simulation mode; 0 for normal operation.

accel_array_len#

The number of raw samples in each accelerometer telemetry array.

Type:

int

accelerometers#

List of configuration for each accelerometer.

Type:

list [types.SimpleNamespace]

acquisition_time#

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

Type:

float | None

num_channels#

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

Type:

int

psd_array_len#

The number of samples in each accelerometerPSD telemetry array.

Type:

int

psd_frequencies#

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

Type:

np.ndarray

sampling_interval#

Interval between samples for one channel (seconds)*.

Type:

float | None

offsets#

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

Type:

ndarray

scales#

Scale for each accelerometer channel; see offsets for details.

Type:

ndarray

make_random_mock_raw_1d_data#

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.

Type:

bool

mock_raw_1d_data#

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.

Type:

list [float] | None

wrote_psd_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.

Type:

asyncio.Event

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.

Methods Summary

blocking_data_stream_callback(handle)

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

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.

run()

Read and process data from the LabJack.

scaled_data_from_raw(raw_1d_data)

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

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.

Methods Documentation

blocking_data_stream_callback(handle)#

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.

Parameters:

handle (int)

Return type:

None

async disconnect()#

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

Return type:

None

classmethod get_config_schema()#

Get the config schema as jsonschema dict.

Return type:

dict[str, Any]

async process_data(scaled_data, end_tai, backlogs)#

Process one set of data.

Parameters:
  • scaled_data (np.ndarray) – x, y, z acceleration data of shape (self.num_channels, n) after applying offset and scale

  • end_tai (float) – The time (TAI unix seconds) at which data collection ended.

  • backlogs (tuple) – 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).

Return type:

None

psd_from_scaled_data(scaled_data)#

Compute the PSD from scaled data.

Parameters:

scaled_data (ndarray)

Return type:

ndarray

async read_data()#

Read data.

Return type:

None

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 run()#

Read and process data from the LabJack.

Return type:

None

scaled_data_from_raw(raw_1d_data)#

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

Parameters:

raw_1d_data (list[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_data – Raw data reshaped to size (self.num_channels, voltages) with offsets and scales applied:

scaled = (raw - offset) * scaled

Return type:

np.ndarray

async start_data_stream()#

Start the data stream from the LabJack.

Return type:

None

start_mock_stream()#

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

Return type:

None

start_processing_data(scaled_data, end_tai, backlogs)#

Start process_data as a background task, unless still running.

Parameters:
  • scaled_data (np.ndarray) – Acceleration data of shape (self.num_channels, self.accel_array_len) after applying offset and scale.

  • end_tai (float) – The time (TAI unix seconds) at which data collection ended.

  • backlogs (tuple) – Two measures of the number of backlogged messages. Both values should be nearly zero if the data client is keeping up with the LabJack.

Return type:

None