How woolen-yarn/kohdalab-trkr works
Purpose and entry points
KohdaLab TRKR is a Python 3.13+ laboratory-control toolkit for time-resolved Kerr rotation measurement workflows: Signal Monitor, TRKR, SRKR, STRKR, and SRKR 2D. It exposes a typed automation API, a CLI, and an optional Qt GUI. Primary entry modules are src/kohdalab/api/cli.py and src/kohdalab/apps/trkr_gui.py; desktop launch support exists at desktop/KohdaLab TRKR.vbs.
Public experiment orchestration
The API layer defines experiment-facing models, scan plans, measurement generation, session ownership, status, and provenance. Experiment code should compose these APIs rather than talk directly to drivers. Central orchestration paths are:
• src/kohdalab/api/experiment.py
• src/kohdalab/api/session.py
• src/kohdalab/api/measurements.py
A session controls hardware lifecycle and per-device access boundaries. Planning and target validation occur before hardware sessions are opened, enabling rejection of invalid scans without instrument side effects.
Configuration, planning, and preflight
Configuration is loaded and interpreted into typed models, device requirements, scan constraints, and executable scan plans. Default settings are packaged in both repository and package-resource form:
• config/default.json
• src/kohdalab/resources/default.json
• src/kohdalab/api/config.py
The planning boundary is implemented through src/kohdalab/api/scan_plan.py, src/kohdalab/api/scan_limits.py, and src/kohdalab/api/device_requirements.py. This layer translates user/configured coordinates and measurement parameters into validated targets and required devices, separating configuration errors from physical I/O.
Device-facing API and abstraction boundary
Device APIs normalize delay-stage, lock-in, and scanner operations for experiments and applications. They sit between orchestration and hardware-specific drivers:
• src/kohdalab/api/devices/delay_stage.py
• src/kohdalab/api/devices/lockin.py
• src/kohdalab/api/devices/scanner.py
Shared protocols and interfaces establish the expected behavior and allow simulated transports in tests, decoupling callers from vendor controllers:
• src/kohdalab/interfaces/protocols.py
• src/kohdalab/interfaces/delay_stage.py
• src/kohdalab/interfaces/lockin.py
Instrument implementations
Concrete driver implementations target lab controllers for motion, signal acquisition, and scanning. Drivers are grouped by physical subsystem and carry controller-specific transport/validation behavior:
• Delay stages: src/kohdalab/instruments/delay_stage/gsc01.py, src/kohdalab/instruments/delay_stage/gsc01a.py, src/kohdalab/instruments/delay_stage/shot302.py
• Lock-ins: src/kohdalab/instruments/lockin/sr830.py, src/kohdalab/instruments/lockin/sr7265.py, src/kohdalab/instruments/lockin/li5640.py
• Scanners: src/kohdalab/instruments/scanner/conexagap.py, src/kohdalab/instruments/scanner/conexcc.py
Controller capability metadata is externalized in stages.toml and actuator.toml, keeping supported hardware definitions distinct from orchestration logic.
Measurement output and reproducibility
Measurement rows are constructed separately from execution, then written with run metadata/provenance. UTC timestamps and measurement CSV-associated metadata are first-class outputs:
• src/kohdalab/api/measurement_rows.py
• src/kohdalab/api/run_metadata.py
• src/kohdalab/api/models.py
Conversion and notebook helpers support downstream analysis without making Jupyter a base-runtime dependency: src/kohdalab/api/conversion.py and src/kohdalab/api/notebook.py.
GUI workflow runtime
The optional GUI is a specialized operator client over the API/device layer, not the hardware implementation itself. It divides configuration, device connection, measurement control, live signals, plotting, output, snapshots, and worker execution:
• src/kohdalab/apps/trkr_gui.py
• src/kohdalab/apps/trkr_gui_measurement.py
• src/kohdalab/apps/trkr_gui_workers.py
Qt/Jupyter are optional extras; base installations support headless API and CLI operation. Hardware operation depends on attached instrument controllers, while simulated transports permit automated driver verification without physical devices.
Main entry points: experiment.py Experiment API · measurements.py Measurement Generation · protocols.py Protocols & Interfaces · session.py Hardware Session
Components 20
Entry Points
- CLI
src/kohdalab/api/cli.py
Experiment API
- Experiment API · Public composition boundary for measurement workflows.
src/kohdalab/api/experiment.py - Hardware Session · Owns hardware lifecycle and per-device access.
src/kohdalab/api/session.py - Measurement Generation
src/kohdalab/api/measurements.py - Typed Configuration · Loads settings into experiment and device models.
src/kohdalab/api/config.py - Default Settings
src/kohdalab/resources/default.json - Scan Planning · Validates targets and derives executable plans before I/O.
src/kohdalab/api/scan_plan.py - Device Requirements
src/kohdalab/api/device_requirements.py
Hardware Stack
- Device APIs · Normalizes stage, lock-in, and scanner operations.
src/kohdalab/api/devices/delay_stage.py - Protocols & Interfaces · Decouples callers and simulated transports from controllers.
src/kohdalab/interfaces/protocols.py - Delay Stage Drivers · GSC01, GSC01A, and SHOT302 controllers.
src/kohdalab/instruments/delay_stage/gsc01.py - Lock-in Drivers · SR830, SR7265, and LI5640 controllers.
src/kohdalab/instruments/lockin/sr830.py - Scanner Drivers · CONEX-AGAP and CONEX-CC controllers.
src/kohdalab/instruments/scanner/conexagap.py - Controller Capabilities · External definitions for supported stages and actuators.
src/kohdalab/instruments/delay_stage/stages.toml
Outputs
- Measurement Rows · Constructs rows independently from execution.
src/kohdalab/api/measurement_rows.py - Run Metadata · Captures UTC timestamps and run metadata.
src/kohdalab/api/run_metadata.py - Conversion & Notebooks · Optional downstream conversion and notebook support.
src/kohdalab/api/conversion.py
Optional GUI
- TRKR GUI · Optional GUI over the API and device layers.
src/kohdalab/apps/trkr_gui.py - GUI Measurement Control
src/kohdalab/apps/trkr_gui_measurement.py - GUI Workers
src/kohdalab/apps/trkr_gui_workers.py
Connections 21
- CLI → Experiment API: invokes
- Typed Configuration → Default Settings: loads defaults
- Experiment API → Typed Configuration: uses
- Experiment API → Scan Planning: plans scan
- Scan Planning → Device Requirements: derives devices
- Scan Planning → Hardware Session: validated plan opens
- Experiment API → Measurement Generation: generates
- Measurement Generation → Hardware Session: executes through
- Hardware Session → Device APIs: accesses
- Device APIs → Protocols & Interfaces: implements contracts
- Protocols & Interfaces → Delay Stage Drivers: implemented by
- Protocols & Interfaces → Lock-in Drivers: implemented by
- Protocols & Interfaces → Scanner Drivers: implemented by
- Controller Capabilities → Delay Stage Drivers: defines support
- Measurement Generation → Measurement Rows: builds
- Measurement Generation → Run Metadata: records
- Measurement Rows → Conversion & Notebooks: converted for
- TRKR GUI → GUI Measurement Control: hosts
- GUI Measurement Control → GUI Workers: runs via
- GUI Measurement Control → Experiment API: uses API
- GUI Workers → Hardware Session: controls