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.- 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.
- Attributes:
- accel_array_len
int
The number of raw samples in each accelerometer telemetry array.
- accelerometers
list
[types.SimpleNamespace
] List of configuration for each accelerometer.
- acquisition_time
float
|None
How long it takes to acquire one set of raw data samples*: sampling_interval * (accel_array_len - 1)
- num_channels
int
Number of accelerometer channels to read (3 per accelerometer).
- psd_array_len
int
The number of samples in each accelerometerPSD telemetry array.
- psd_frequencies
np.ndarray
Array of frequences for the computed PSD, starting from 0.
- sampling_interval
float
|None
Interval between samples for one channel (seconds)*.
- offsets
ndarray
Offset for each accelerometer channel. scaled acceleration = (raw acceleration - offset) * scale
- scales
ndarray
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.
- accel_array_len
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
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 from the LabJack.
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.
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.
Perform any tasks before starting the read loop.
start
()Override start method to handle auto reconnecting if necessary.
Start the data stream from the LabJack.
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.
Call disconnect, connect, and start the run task.
stop
()Delegate handling of stop tasks to the stop_tasks method.
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 process_data(scaled_data: ndarray, end_tai: float, backlogs: tuple[int, int]) None ¶
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.
- scaled_data
- Raises:
- RuntimeError
If streaming has not yet begun (because self.sampling_interval is None until streaming begins).
- 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_loop() None ¶
Call the read_data method in a loop.
Allow for max_timeouts timeouts before raising a TimeoutError.
- 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:
- func
Callable
The blocking function to run; The function must take no arguments. For example:
self._blocking_connect
.- timeout
float
Time limit (seconds).
- func
- 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
- 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_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.
- scaled_data
- async start_tasks() None ¶
Call disconnect, connect, and start the run task.
Raises the same exceptions as
connect
. Ifdisconnect
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.