haniwers.v1.cli.threshold

haniwers.v1.cli.threshold#

Threshold management commands.

This module provides commands for writing threshold values to OSECHI detector channels using a unified configuration interface.

Commands: write: Write threshold values to detector channels (single or multi-channel) fit: Placeholder for threshold fitting functionality optimize: Placeholder for optimal threshold optimization list: Placeholder for listing current threshold configurations

Dependencies: - ConfigLoader: Load configuration from TOML files - Device: Serial communication with detector - apply_thresholds: High-level batch threshold application with retry and logging - SensorConfig: Configuration model for detector channels - parse_thresholds: Parse and validate threshold configuration strings

Module Contents#

Functions#

write

Write threshold values to detector channels.

Data#

app

API#

haniwers.v1.cli.threshold.app#

‘Typer(…)’

haniwers.v1.cli.threshold.write(ctx: typer.Context, config: Optional[pathlib.Path] = typer.Option(None, '--config', help='Configuration file path (config.toml, etc). If not specified, ConfigLoader searches default locations.'), port: Optional[str] = typer.Option(None, '--port', help="Serial port path for OSECHI detector (e.g., /dev/ttyUSB0, COM3). Use 'haniwers-v1 port list' to find available ports.", rich_help_panel='Device Settings'), baudrate: Optional[int] = typer.Option(None, '--baudrate', min=1, help='Serial communication baud rate in bits per second (e.g., 9600, 115200).', rich_help_panel='Device Settings'), timeout: Optional[float] = typer.Option(None, '--timeout', min=0.1, help='Serial read timeout in seconds (e.g., 1.0, 2.0).', rich_help_panel='Device Settings'), device_label: Optional[str] = typer.Option(None, '--device-label', help='Device identifier label for logging and documentation.', rich_help_panel='Device Settings'), thresholds: str = typer.Option(..., '--thresholds', '-t', help="Threshold configuration: 'channel:threshold;channel:threshold;...'. Examples: '1:290' (single channel), '1:290;2:320;3:298' (all channels).", rich_help_panel='Threshold Settings'), max_retry: int = typer.Option(3, '--max-retry', min=1, help='Maximum number of retry attempts on communication failure (default: 3).', rich_help_panel='Threshold Settings'), history: pathlib.Path = typer.Option('threshold_history.csv', '--history', help='Audit log file for threshold operations (CSV format with timestamp). Automatically saved in workspace directory.', rich_help_panel='Threshold Settings'), workspace: Optional[pathlib.Path] = typer.Option(None, '--workspace', help='Output directory for data files. Timestamped subdirectory created automatically.', rich_help_panel='Output Settings'), filename_prefix: Optional[str] = typer.Option(None, '--filename-prefix', help="Prefix for output file names (e.g., 'run001').", rich_help_panel='Output Settings'), filename_suffix: Optional[str] = typer.Option(None, '--filename-suffix', help="File extension/suffix for output files (e.g., '.csv').", rich_help_panel='Output Settings'), events_per_file: Optional[int] = typer.Option(None, '--events-per-file', min=1, help='Number of detector events per output file before rollover.', rich_help_panel='Output Settings'), number_of_files: Optional[int] = typer.Option(None, '--number-of-files', min=1, help='Maximum number of files to create in a single DAQ session.', rich_help_panel='Output Settings'), stream_mode: bool = typer.Option(False, '--stream-mode', help='Enable continuous streaming mode (output buffering disabled).', rich_help_panel='Output Settings'), daq_label: Optional[str] = typer.Option(None, '--daq-label', help='Session identifier label for this DAQ run.', rich_help_panel='Output Settings'), mock: bool = typer.Option(False, '--mock', help='Use RandomMocker instead of real device for testing (no hardware required).', rich_help_panel='Testing')) None#

Write threshold values to detector channels.

This command writes threshold values to the three detector layers (top, middle, bottom). The threshold determines the detector’s sensitivity to cosmic ray signals.

Supports single-channel or multi-channel configuration using the unified –thresholds option. Includes automatic retry logic on communication failures and audit trail logging to CSV file.

Args: thresholds: Threshold configuration as ‘channel:value;channel:value;…’ Examples: - Single channel: ‘1:280’ - All channels: ‘1:290;2:320;3:298’

Output: For each channel, displays: - Status icon: ✓ (success) or ✗ (failed) - Channel number and status - Threshold value written (vth) - Number of attempts (1 = immediate success, >1 = retried)

Examples: Write to single channel: $ haniwers-v1 threshold write --port /dev/tty.usbserial --thresholds 1:280

Write to multiple channels:
    $ haniwers-v1 threshold write --port /dev/tty.usbserial --thresholds '1:290;2:320;3:298'

With custom workspace and max retries:
    $ haniwers-v1 threshold write --port /dev/tty.usbserial --thresholds '1:280' \
        --workspace data --max-retry 5

Note: The device must be powered on and connected before running this command. Logs are automatically created in YYYYMMDD directory matching DAQ structure. Each threshold write is logged to CSV with timestamp for audit trail.