haniwers.v1.threshold#
Threshold writer module for OSECHI detector.
This module provides functions to write threshold values to detector channels, with support for validation, retry logic, CSV integration, and logging.
Public API: Data Models: - ScanDataPoint: Immutable data point from a single threshold measurement - ThresholdOperation: Immutable record of a threshold write operation for audit - ChannelScanResult: Immutable result from scanning one detector channel - ScanResult: Immutable result from complete serial threshold scanning
Scanning (serial threshold scanning):
- run_serial_threshold_scan: Main orchestrator for threshold scanning
- scan_single_channel: Scan one channel across all threshold values
- write_scan_results: Save scan data to CSV file
- write_audit_log: Log all threshold operations for reproducibility
Writing (low-level):
- write_threshold: Write single threshold (raw integers)
- write_threshold_with_retry: Write with automatic retry
High-level API (recommended):
- apply_threshold: Apply single sensor config with retry and logging
- apply_thresholds: Apply multiple sensor configs in batch
- set_threshold: Write with retry and logging (legacy, for compatibility)
- set_thresholds_from_csv: Batch write from CSV file (legacy)
CSV and logging:
- load_thresholds_from_csv: Load threshold config from CSV
- log_threshold_operation: Record operation to CSV log
Exceptions:
- InvalidChannelError: Channel not in range 1-3
- InvalidThresholdError: Threshold not in range 1-1023
- **Note**: Moved to v1/helpers/exceptions.py
Example (recommended API): >>> from haniwers.v1.threshold import apply_threshold >>> from haniwers.v1.daq.device import Device >>> from haniwers.v1.config.model import SensorConfig >>> device = Device(“/dev/tty.usbserial”) >>> device.connect() >>> sensor = SensorConfig(id=1, name=“ch1”, label=“top”, step_size=1, threshold=280, center=512, nsteps=10) >>> result = apply_threshold(device, sensor) >>> if result.success: … print(f"Set to {result.vth} in {result.attempts} attempts")
Example (serial threshold scanning): >>> from haniwers.v1.threshold import run_serial_threshold_scan >>> from haniwers.v1.config.loader import ConfigLoader >>> cfg = ConfigLoader(“config.toml”).config >>> device = Device(cfg.device) >>> device.connect() >>> results = run_serial_threshold_scan(cfg, device) >>> print(results.success) >>> device.disconnect()
Submodules#
Package Contents#
Data#
API#
- haniwers.v1.threshold.__all__#
[‘ScanDataPoint’, ‘ThresholdOperation’, ‘ChannelScanResult’, ‘ScanResult’, 'run_serial_threshold_sca…