| related |
|
|---|
ScanArgument(...) enables a scan to attach rich metadata to one of its inputs.
As a result, the signature can provide more information to users and clients, such as which units an input uses, which bounds apply, and how the input should be labeled in a GUI.
!!! Warning "It is highly recommended to use ScanArgument for any scan input."
from typing import Annotated
from bec_lib.scan_args import ScanArgument, Units
exp_time: Annotated[
float,
ScanArgument(display_name="Exposure Time", units=Units.s, ge=0),
] = 0This says several things at once:
- the input should be treated as a
float - GUIs should label it as
Exposure Time - the value is expressed in seconds
- the value must be greater than or equal to zero
Writing out full Annotated[..., ScanArgument(...)] definitions is useful when a scan needs a
custom input definition. However, BEC already provides shared aliases for the common internal scan
parameters that are represented in scan info{data-preview} and used in many scans.
To avoid repeating those annotations in every scan class, these common definitions are collected in
DefaultArgType.
For example, the typical example above is equivalent to:
from bec_lib.scan_args import DefaultArgType
exp_time: DefaultArgType.ExposureTime = 0The same pattern is used for other internal scan parameters such as FramesPerTrigger,
SettlingTime, SettlingTimeAfterTrigger, ReadoutTime, BurstAtEachPoint, and also for common
boolean scan options such as Relative.
This keeps scan signatures shorter while still preserving the same ScanArgument metadata for
validation, GUI generation, and scan discovery.
Some of the most commonly used fields are listed below.
| Field | Role | Typical use |
|---|---|---|
display_name |
Provides a clearer user-facing label than the raw Python parameter name. | GUI labels |
description |
Provides a longer explanation of what the input means. | help text or documentation |
tooltip |
Adds short explanatory text for interactive UIs. | GUI hover text |
units |
Declares the explicit unit for the input, such as seconds or degrees. | user-facing display |
reference_units |
Tells BEC to interpret the value in the units of another input, such as a motor argument. | user-facing display |
gt, ge, lt, le |
Applies numeric bounds to the input. | validation |
Two patterns are especially common.
Explicit units:
Annotated[float, ScanArgument(units=Units.s)]Annotated[float, ScanArgument(units=Units.eV)]Annotated[float, ScanArgument(units=Units.deg)]
Reference units:
Annotated[float, ScanArgument(reference_units="motor1")]Annotated[float, ScanArgument(reference_units="motor2")]Annotated[float, ScanArgument(reference_units="device")]
Reference units are especially useful for scan inputs such as start, stop, or step size, where the value should automatically use the same unit as a related device input.
After ScanArgument, continue with argument bundles{data-preview} for
repeated positional inputs and GUI config{data-preview} for graphical grouping.
!!! info "What to remember"
- ScanArgument attaches rich metadata to individual scan inputs.
- It is usually used through Annotated[..., ScanArgument(...)].
- It helps BEC validate inputs and present them clearly in GUIs and clients.