Metadata-Version: 2.4
Name: pydaqx
Version: 0.5.0
Summary: A programmable front panel for scientific experiments: LabVIEW-style widgets bound to named signals, over a hardware-neutral data engine.
Author: Nikhil Verma
Maintainer: Nikhil Verma
License-Expression: MIT
Project-URL: Homepage, https://github.com/Nikhil299792458/pydaqx
Project-URL: Repository, https://github.com/Nikhil299792458/pydaqx
Project-URL: Issues, https://github.com/Nikhil299792458/pydaqx/issues
Project-URL: Changelog, https://github.com/Nikhil299792458/pydaqx/blob/main/CHANGELOG.md
Project-URL: Documentation, https://github.com/Nikhil299792458/pydaqx/blob/main/docs/MANUAL.md
Keywords: daq,data-acquisition,instrumentation,gui,front-panel,labview,measurement,test-stand,nidaqmx,thrust-stand,spectrogram,real-time,pyside6
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Manufacturing
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Topic :: Scientific/Engineering :: Visualization
Classifier: Topic :: System :: Hardware :: Hardware Drivers
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Provides-Extra: gui
Requires-Dist: PySide6>=6.6; extra == "gui"
Requires-Dist: pyqtgraph>=0.13; extra == "gui"
Provides-Extra: tdms
Requires-Dist: npTDMS>=1.9; extra == "tdms"
Provides-Extra: all
Requires-Dist: PySide6>=6.6; extra == "all"
Requires-Dist: pyqtgraph>=0.13; extra == "all"
Requires-Dist: npTDMS>=1.9; extra == "all"
Provides-Extra: dev
Requires-Dist: PySide6>=6.6; extra == "dev"
Requires-Dist: pyqtgraph>=0.13; extra == "dev"
Requires-Dist: npTDMS>=1.9; extra == "dev"
Requires-Dist: pytest>=7.4; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# PyDAQX

[![tests](https://github.com/Nikhil299792458/pydaqx/actions/workflows/tests.yml/badge.svg)](https://github.com/Nikhil299792458/pydaqx/actions/workflows/tests.yml)
[![PyPI](https://img.shields.io/pypi/v/pydaqx.svg)](https://pypi.org/project/pydaqx/)
[![Python](https://img.shields.io/pypi/pyversions/pydaqx.svg)](https://pypi.org/project/pydaqx/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

**A programmable front panel for scientific experiments.**

> Hardware produces signals. Processing transforms signals.
> Widgets observe or control signals. Loggers store signals.

You describe what you want to see; PyDAQX handles the acquisition threads, ring
buffers, decimation, Qt and frame rates.

```bash
pip install "pydaqx[gui]"
```

```python
import numpy as np
import pydaqx as dq

app = dq.application("Thrust Stand", theme="dark")

sim = dq.simulation(fs=10_000)
sim.add_channel("loadcell_v", lambda t: 0.4 + 0.01*np.sin(2*np.pi*7*t), unit="V")
dq.linear_calibration("loadcell_v", "thrust", slope=48.73, unit="N")

dq.numeric_indicator("thrust_now", source="thrust", unit="N", warning=40)
dq.waveform_chart("thrust_plot", source="thrust", history=10)
dq.button("start", text="START", action="daq.start")

app.run()
```

No hardware required: the simulation backend exists from day one, so the panel
above runs anywhere, including in CI.

**Install options**

| command | gives you |
|---|---|
| `pip install pydaqx` | the data engine only — headless acquisition, processing, NPZ |
| `pip install "pydaqx[gui]"` | the above plus every widget (PySide6 + pyqtgraph) |
| `pip install "pydaqx[all]"` | the above plus TDMS logging |

**Full documentation: [`docs/MANUAL.md`](docs/MANUAL.md)** — how each widget
works and the measurement theory behind it.
**Publishing runbook: [`docs/RELEASING.md`](docs/RELEASING.md)**.

## Status

**v0.5 -- consoles.** What is here:

| | |
|---|---|
| Data engine | `Block`, `DataBus`, `HistoryRing`, `EnvelopeRing`, cursors, derived signals |
| Sources | simulation, replay-from-file, NPZ recorder |
| Processing | windowed spectra, Welch PSD, STFT, linear calibration |
| Execution | inline or partitioned worker pool (`processing="threads"`), bounded queues, gap-honest backpressure |
| Controls | `button` (interlock-gated), `numeric_input`, `numeric_indicator` (last/mean/rms/min/max/p-p) |
| Indicators | `gauge`, `led`, `tank`, `thermometer`, `progress_bar`, `signal_table`, `bus_inspector`, `alarm_indicator` |
| Time domain | `waveform_chart` (strip / scope / sweep), `waveform_graph` (edge-triggered), `xy_graph` |
| Frequency domain | `fft_graph`, `psd_graph`, `histogram`, `spectrogram` |
| Interaction | run-time widget handles, event bus with filter events, cursors, second y-axis, copy/save visible data |
| Safety | alarms with hysteresis / delay / latching / acknowledgement, named interlocks gating buttons |
| Outputs | fail-safe digital outputs, guarded kill switches, emergency stop, alarm trips, data-stall watchdogs, event log |
| Logging | NPZ + replay, TDMS with `wf_start_time`, `wf_increment` and file/channel properties |
| Rendering | PySide6 + pyqtgraph, single 30 Hz pull timer, min/max envelope decimation |
| Safety rails | startup validation of every signal name, action, limit and buffer length |

Not yet: stateful filters, an experiment state machine, YAML loading, HDF5,
sub-panels, and hardware backends.

![front panel](docs/images/06_front_panel.png)

![spectral panel](docs/images/05_spectral.png)

## Install

```bash
pip install -e ".[dev]"
python examples/01_thrust_stand.py     # simulated thrust-stand console
python examples/02_replay.py           # record a run, then replay the console
python examples/03_chart_modes.py      # strip vs scope vs sweep, side by side
python examples/04_scope_and_xy.py     # edge trigger, XY graph, live spectrum
python examples/05_spectral.py         # FFT, PSD, histogram, spectrogram
python examples/06_front_panel.py      # gauges, alarms, interlocks, live control
python examples/thrust_stand/console_1_operator.py   # five full test-stand consoles
pytest -q                              # 75 tests, no display needed
```

## Does it hold up?

`bench/bench_throughput.py` runs acquisition, a full-rate exactly-once logger,
per-channel derived signals and a GUI-equivalent consumer (10 s window pulled
and decimated to 900 columns, 30 times a second) all at once:

| configuration | acquired | logger drops | GUI frame p99 | buffers | CPU |
|---|---|---|---|---|---|
| 8 ch x 100 kHz, 30 s | 24.0 M samples (99.99% of ideal) | 0 | 3.9 ms of 33 ms | 27.7 MB | 12.2% of one core |
| 16 ch x 10 kHz, 10 s | 1.6 M samples (99.97%) | 0 | 3.8 ms of 33 ms | 9.2 MB | 7.6% of one core |

*(Linux, Python 3.11, no GPU, one core. Reproduce with
`python bench/bench_throughput.py --channels 8 --fs 100000 --seconds 30`.)*

The first version of this benchmark **failed**: pulling a 10 s window at
100 kHz meant copying 8 MB per curve per frame, which put the GUI at 72% of a
core and a p99 frame time of 42 ms. That is what produced the min/max pyramid
in `EnvelopeRing` -- reduce once in the producer, read a few thousand pairs in
the GUI. Same picture on screen, 6x less CPU, and every transient still
visible. Benchmarks are for changing the design, not for the README.

## Design notes

- [`docs/MANUAL.md`](docs/MANUAL.md) -- the user manual: every widget, with the measurement theory behind it.
- [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) -- the seven rules the code follows and why.
- [`docs/TIMEBASE.md`](docs/TIMEBASE.md) -- time, alignment, zero-order hold, and what the library refuses to guess for you.

Three that matter most:

**The unit of data is a block, not a scalar.** Scalars are views on blocks.
Building scalar-first would force a rewrite the moment a stateful filter or an
FFT panel appears.

**The GUI pulls; nothing pushes into the event loop.** One `QTimer` refreshes
visible widgets. Sample rate and display rate are fully independent.

**Nothing in the data engine imports Qt.** `pydaqx.core` and `pydaqx.sources`
are pure Python/NumPy, so acquisition runs headless and the panel description
is renderer-agnostic.

## Citing

If PyDAQX contributes to published work, `CITATION.cff` in this repository has
the metadata; GitHub will render a "Cite this repository" button from it.

## Safety

Nothing here is a safety function and it must never be used as one. A software
interlock in a Python GUI on a general-purpose OS can be delayed indefinitely
by a GC pause, a blocked event loop or a USB re-enumeration. The emergency stop
is a hardware contactor in series with the motor supply.

## Roadmap

1. **Processing layer** -- stateful `sosfilt` filter stages and tare/calibration objects, with the group-delay accounting `docs/TIMEBASE.md` describes. (Spectral estimation and the parallel execution layer have landed.)
2. **STM32 serial backend** -- packet-framed, MCU-owned timestamps, the first real hardware.
3. **Logging** -- TDMS/HDF5 with the full config embedded, so opening a file reconstructs the dashboard that recorded it.
4. **YAML panels** -- one-to-one with the Python API through the same specs.
5. **NI-DAQmx backend**, then alarms, interlocks and the experiment state machine.
