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.

serial

Run serial threshold scanning for detector characterization.

Data#

app

API#

haniwers.v1.cli.threshold.app#

‘Typer(…)’

haniwers.v1.cli.threshold.write(ctx: typer.Context, config: Optional[pathlib.Path] = ConfigOptions.config, port: Optional[str] = DeviceOptions.port, baudrate: Optional[int] = DeviceOptions.baudrate, timeout: Optional[float] = DeviceOptions.timeout, device_label: Optional[str] = DeviceOptions.device_label, thresholds: str = ThresholdOptions.thresholds, max_retry: int = ThresholdOptions.max_retry, history: pathlib.Path = ThresholdOptions.history, workspace: Optional[pathlib.Path] = OutputOptions.workspace, filename_prefix: Optional[str] = OutputOptions.filename_prefix, filename_suffix: Optional[str] = OutputOptions.filename_suffix, events_per_file: Optional[int] = OutputOptions.events_per_file, number_of_files: Optional[int] = OutputOptions.number_of_files, stream_mode: bool = OutputOptions.stream_mode, mock: bool = TestingOptions.mock, verbose: bool = LoggerOptions.verbose, logfile: str = LoggerOptions.logfile) 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.

haniwers.v1.cli.threshold.serial(ctx: typer.Context, config: Optional[pathlib.Path] = ConfigOptions.config, port: Optional[str] = DeviceOptions.port, baudrate: Optional[int] = DeviceOptions.baudrate, timeout: Optional[float] = DeviceOptions.timeout, device_label: Optional[str] = DeviceOptions.device_label, nsteps: int = ScanOptions.nsteps, step: int = ScanOptions.step, duration: float = ScanOptions.duration, thresholds: str = ThresholdOptions.thresholds, max_retry: int = ThresholdOptions.max_retry, history: pathlib.Path = ThresholdOptions.history, workspace: Optional[pathlib.Path] = OutputOptions.workspace, mock: bool = TestingOptions.mock, verbose: bool = LoggerOptions.verbose, logfile: str = LoggerOptions.logfile) None#

Run serial threshold scanning for detector characterization.

Scans one or more detector channels across a range of threshold values, collecting cosmic ray event data at each threshold level. Results are saved to CSV files for analysis.

This command is useful for:

  • Measuring detector sensitivity curves

  • Comparing channel responses

  • Characterizing detector behavior

Example commands:

Single-channel scan with mock device:
$ haniwers-v1 threshold serial --thresholds "1:250" \
    --nsteps 5 --step 10 --duration 2 --mock

Multi-channel scan with TOML config:
$ haniwers-v1 threshold serial --config config.toml

Override TOML parameters with CLI:
$ haniwers-v1 threshold serial --config config.toml \
    --thresholds "1:300;2:320" --duration 3

Output files (saved in workspace/YYYYMMDD/):

  • scan_results_ch1.csv, scan_results_ch2.csv, …: Threshold scan data

  • threshold_operations.csv: Audit log of all threshold changes

Note: Requires a TOML configuration file with sensor definitions, unless all parameters are provided via CLI options.