Skip to content

DaqInfo

Module for defining data acquisition (DAQ) information.

This module provides classes to represent and manipulate the configuration information for data acquisition systems. The primary classes are DaqInfo, which encapsulates the DAQ system's configuration, and InputInfo, which holds detailed information about each input channel, along with BoardInfo to define board-level properties.

Usage

The DaqInfo class serves as the main interface for managing DAQ configuration, including loading from and saving to different formats such as dictionaries and binary data. The InputInfo class defines the attributes of individual input channels, such as gain, offset, delay, and unit, while BoardInfo captures system-level settings such as sample rate and board type.

Examples:

Creating a DaqInfo instance from a dictionary:

>>> info_dict = {
>>>     "board": {
>>>         "samplerate": 48000,
>>>         "type": "default"
>>>     },
>>>     "channel": {
>>>         "U1": {"gain": 1.0, "offset": 1.0, "delay": 1, "unit": "V", "ai_pin": "A0"},
>>>         "U2": {"gain": 2.0, "offset": 2.0, "delay": 2, "unit": "V", "ai_pin": "A1"}
>>>     }
>>> }
>>> myDaqInfo = DaqInfo.from_dict(info_dict)

Classes:

Name Description
DaqInfo

Represents the configuration of the DAQ system.

InputInfo

Defines the properties of an input channel.

BoardInfo

Defines the properties of the DAQ board.

BoardInfo dataclass

Represents the configuration of the DAQ board.

BoardInfo stores board-level settings, such as the sample rate, board type, and whether the configuration is differential or single-ended. It also allows configuration of the gain and offset mode settings.

Attributes:

Name Type Description
type str

The type of the board.

samplerate float

The sampling rate in Hz.

differential bool

Specifies if the configuration is differential (default: False).

gain str

Gain setting for the board (default: "SGL_1X").

offset_enabled bool

Specifies if offset mode is enabled (default: False).

adc_range list

Range of the ADC [min, max] to calculate the physical range (default: [0, 4095])

Examples:

>>> board_info = BoardInfo(type="duedaq", samplerate=50000)

DaqInfo

Bases: object

Represents the configuration of the data acquisition (DAQ) system.

DaqInfo contains information about the DAQ system's sampling rate and the configuration of each input channel. It provides methods for creating an instance from various formats (e.g., dictionary, binary data) and for applying sensor adjustments to channels.

Attributes:

Name Type Description
board BoardInfo

The board-level information of the DAQ system.

channel dict

A dictionary of InputInfo objects, keyed by channel name.

ai_pin_name dict

Maps channel names to their analog-to-digital (AD) indices.

channel_name dict

Maps AD indices to channel names.

Methods:

Name Description
from_dict

Class method to create a DaqInfo instance from a dictionary.

get_default

Class method to create a default DaqInfo instance.

to_dict

Converts the DaqInfo instance into a dictionary format.

apply_sensor_to_channel

Applies sensor configuration to a specific channel.

__str__

Returns a string representation of the DaqInfo instance.

Examples:

>>> info_dict = {
>>>     "board": {
>>>         "samplerate": 48000,
>>>         "type": "default"
>>>     },
>>>     "channel": {
>>>         "U1": {"gain": 1.0, "offset": 1.0, "delay": 1, "unit": "V", "ai_pin": "A0"},
>>>         "U2": {"gain": 2.0, "offset": 2.0, "delay": 2, "unit": "V", "ai_pin": "A1"}
>>>     }
>>> }
>>> myDaqInfo = DaqInfo.from_dict(info_dict)

__init__(board_info, channel_info)

Initialize the DaqInfo instance with the specified board and channel information.

Sets up the DAQ configuration, mapping channel names to their analog-to-digital (AD) indices and vice versa. Stores the input channel configurations provided in channel_info.

Parameters:

Name Type Description Default
board_info BoardInfo

The board information as an instance of BoardInfo.

required
channel_info dict

A dictionary mapping channel names to InputInfo instances.

required

Examples:

>>> channel_info = {
>>>     "U1": InputInfo(gain=1.0, offset=1.0, delay=1, unit="V", ai_pin="A0"),
>>>     "U2": InputInfo(gain=2.0, offset=2.0, delay=2, unit="V", ai_pin="A1")
>>> }
>>> board_info = BoardInfo(samplerate=50000)
>>> daq_info = DaqInfo(board_info=board_info, channel_info=channel_info)

__str__()

Return a string representation of the DaqInfo instance.

Provides a concise string summary of the DAQ configuration, primarily showing the sampling rate.

Returns:

Type Description
str

A string describing the DaqInfo instance.

Examples:

>>> daq_info = DaqInfo(...)
>>> print(str(daq_info))
DaqInfo(type=duedaq,samplerate=48000)

apply_sensor_to_channel(ch_name, sensor_info)

Apply sensor configuration to a specific channel.

Adjusts the gain, offset, and delay of the specified channel based on the provided sensor information. The sensor's configuration is combined with the existing channel configuration.

Parameters:

Name Type Description Default
ch_name str

The name of the channel to which the sensor configuration is applied.

required
sensor_info InputInfo

An InputInfo instance containing the sensor's configuration.

required

Examples:

>>> sensor_info = InputInfo(gain=2.0, offset=1.0, delay=0)
>>> daq_info.apply_sensor_to_channel("U1", sensor_info)

from_dict(data) classmethod

Create a DaqInfo instance from a dictionary.

Converts a dictionary containing DAQ configuration information into a DaqInfo instance. The dictionary should include a board key with board information, and a channel key that maps channel names to their configurations.

Parameters:

Name Type Description Default
data dict

A dictionary containing DAQ configuration data.

required

Returns:

Name Type Description
DaqInfo

A new instance of DaqInfo populated with the provided data.

Notes

Expected format: { "board": { "samplerate": float, "type": str }, "channel": { "ChannelName": { "gain": float, "offset": float, "delay": int, "unit": str, "ai_pin": str }, ... } }

get_default() classmethod

Create a default DaqInfo Object

Returns a DaqInfo instance with default board and channel configurations.

Returns:

Name Type Description
DaqInfo

A new DaqInfo instance with default values.

to_dict()

Convert the DaqInfo instance into a dictionary.

Serializes the DAQ configuration into a dictionary format, suitable for storage or further processing.

Returns:

Type Description
dict

A dictionary representation of the DaqInfo instance.

InputInfo dataclass

Represents the configuration of a single input channel.

InputInfo stores the properties of an individual input channel, including the gain, offset, delay, unit, and analog-to-digital (AD) index. This class is used to encapsulate the settings for each channel in a DAQ system.

Attributes:

Name Type Description
gain float

The gain applied to the input channel.

offset float

The offset applied to the input channel.

delay int

The delay in sample periods for this channel.

unit str

The unit of the measurement.

ai_pin str

The analog input pin name (e.g., "A0").

Examples:

>>> input_info = InputInfo(gain=2.0, offset=1.0, delay=5, unit="V", ai_pin="A0")