resonance.api.core.ai¶
resonance.api.core.ai
¶
AIAccessor(conn)
¶
Accessor for analog input channels via the BCS server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
BCSServer
|
Active connection to the BCS hardware server. |
required |
Notes
Wraps acquire_data and get_acquired_array for typed, validated
access to AI channels defined in resonance.api.types.AI.
Examples:
>>> data = await bl.ai.read("Photodiode", "TEY signal", "AI 3 Izero")
>>> print(data)
{'Photodiode': [0.0], 'TEY signal': [0.0], 'AI 3 Izero': [0.0]}
Source code in src/resonance/api/core/ai.py
read(*channels)
async
¶
Return the last-acquired raw array for each channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*channels
|
str
|
One or more AI channel names from |
()
|
Returns:
| Type | Description |
|---|---|
dict[str, list[float]]
|
Mapping of channel name to raw sample array. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If any channel name is not a valid AI channel. |
AcquisitionError
|
If the BCS response contains an empty data array for a channel. |
Notes
Does not trigger a new acquisition. Returns the most recent data
buffered by BCS. Call trigger_and_read to acquire fresh data.
Use read only when data was already acquired (e.g. after acquire_data
was called externally).
Source code in src/resonance/api/core/ai.py
trigger_and_read(channels, acquisition_time=1.0)
async
¶
Trigger acquisition and return mean and standard error per channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
list[str]
|
AI channel names from |
required |
acquisition_time
|
float
|
Duration of acquisition in seconds. Must be positive. Default is 1.0. |
1.0
|
Returns:
| Type | Description |
|---|---|
dict[str, Variable]
|
Mapping of channel name to |
Raises:
| Type | Description |
|---|---|
KeyError
|
If any channel name is not a valid AI channel. |
ValueError
|
If |
AcquisitionError
|
If the BCS response contains an empty data array for a channel. |
Notes
Performs a blocking acquisition of acquisition_time seconds.
Use per scan point to get mean and standard error for each channel.
Standard error is computed as std_dev / sqrt(N). For N=1, std_err is 0.
Examples:
>>> data = await bl.ai.trigger_and_read(["Photodiode", "TEY signal"], acquisition_time=1.0)
>>> print(data["Photodiode"]) # ufloat(mean, std_err)