python-intan
python-intan provides Python tools for reading Intan RHD recordings, working with RHX TCP streams, processing EMG/electrophysiology signals, and building optional visualization and machine-learning workflows. Hardware examples require the relevant Intan or microcontroller hardware and are not exercised by a normal package installation.
Quick links
Features
- Read RHD files and Intan per-signal
.datrecording directories. - Load and save CSV and NPZ datasets.
- Connect to RHX software over its command and waveform TCP ports.
- Filter, normalize, repair, synchronize, and extract features from channel-by-sample data.
- Publish and subscribe to Lab Streaming Layer (LSL) streams.
- Plot multichannel data and run optional GUI viewers.
- Train and run optional PyTorch EMG models.
Installation
Python 3.10 or later is required.
python -m pip install python-intan
The base install supports RHD/DAT/NPZ I/O, RHX/LSL streaming, and signal
processing. CSV/event tables, plotting, and scikit-learn are optional. To
retain the analysis features previously installed by default, use
python -m pip install 'python-intan[analysis]'.
For development from a repository checkout:
git clone https://github.com/Neuro-Mechatronics-Interfaces/python-intan.git
cd python-intan
python -m pip install -e '.[test]'
On Windows PowerShell, use double quotes around extras if your shell configuration does not accept single quotes.
Optional dependencies
Install only the groups required by your workflow:
python -m pip install 'python-intan[data]' # pandas CSV/event/metrics tables
python -m pip install 'python-intan[plot]' # Matplotlib plots
python -m pip install 'python-intan[analysis]' # data, plotting, and scikit-learn PCA
python -m pip install 'python-intan[gui]' # analysis features, PyQt5 and pyqtgraph
python -m pip install 'python-intan[ml]' # analysis features and PyTorch
python -m pip install 'python-intan[video]' # OpenCV and MediaPipe
python -m pip install 'python-intan[docs]' # Sphinx documentation build
python -m pip install 'python-intan[test]' # tests and release validation
The finger-kinematics landmark example can integrate with the separate handtrack project, but that project is intentionally not a package dependency. Install and evaluate it separately if you choose to run that example.
Getting started
RHD data is represented with channels on axis 0 and samples on axis 1.
from intan.io import load_rhd_file
from intan.processing import bandpass_filter, notch_filter
recording = load_rhd_file("path/to/recording.rhd")
emg = recording["amplifier_data"]
fs = recording["frequency_parameters"]["amplifier_sample_rate"]
filtered = notch_filter(emg, fs=fs, f0=60)
filtered = bandpass_filter(filtered, lowcut=20, highcut=450, fs=fs)
print(filtered.shape)
For RHX streaming, start the TCP server in Intan RHX software before connecting:
from intan.interface import IntanRHXDevice
with IntanRHXDevice(num_channels=32, auto_start=False) as device:
device.enable_wide_channel(range(32))
device.start_streaming()
window = device.get_latest_window(1000)
print(window.shape)
Synchronize with a digital pulse
Enable recording on the RHX digital input wired to the Pico. Start the recording before triggering the Pico, and keep the LED visible to the cameras. Read transitions without loading the amplifier data:
from intan.io import read_digital_edges
for edge in read_digital_edges("trial.rhd", stream_id="rhx-bench"):
if edge.line == 4:
print(edge.segment, edge.sample_number, edge.sample_rate, edge.rising)
Lines are one-based, so line 4 corresponds to packed bit 3. Use the sample
number difference divided by the sample rate to compare pulse intervals
within a segment. Match the same sequence of rising and falling transitions
to the LED turning on and off in the video. Keep time.dat and the digital
input files beside info.rhd for split recordings. Gaps and counter resets
suppress transitions at the first sample after the discontinuity.
For live timing, enable only the amplifier waveforms and the desired digital
inputs under Output to TCP in RHX. The parser expects one 16-bit packed
input word after the amplifier samples in each frame. Set num_channels
to the number of streamed amplifier values. For example:
from intan.interface import IntanRHXDevice, LSLOptions
def on_chunk(chunk):
for edge in chunk.digital_edges:
print(edge.sample_number, edge.rising)
with IntanRHXDevice(
num_channels=32,
digital_input_lines=(4,),
on_chunk=on_chunk,
use_lsl=True,
lsl_options=LSLOptions(device_timestamps=True),
) as device:
device.start_streaming()
input("Press Enter to stop.\n")
The callback runs on the receive thread and also gets the samples, unwrapped sample numbers, count of missing samples before the chunk, and host receipt time. Keep callback work short. The optional LSL mode anchors the device counter to the local LSL clock when the first chunk of each segment arrives and advances it at the nominal sample rate. TCP latency affects that anchor and hardware clocks can drift. Use the shared Pico pulse for measuring alignment. The default LSL mode continues to timestamp chunks at send time.
CLI usage
The optional GUI extra installs two console commands:
intan-emg-viewer --help
intan-trial-selector --help
intan-emg-viewer
intan-trial-selector
Most reproducible workflows are maintained as example CLIs. Run any command below from the repository root:
python examples/Read_Files/load_rhd_demo.py --help
python examples/Read_Files/load_dat_demo.py --help
python examples/gesture_classifier/1_build_dataset.py --help
python examples/gesture_classifier/2_train_model.py --help
python examples/gesture_classifier/3_predict.py --help
Examples
The example folders distinguish package workflows from external hardware integrations:
Read_Files: RHD, per-signal DAT, CSV, NPZ, and event segmentation.RHXDevice: live RHX recording and plotting.LSL: LSL viewers and marker subscriptions.gesture_classifier: maintained dataset, training, and prediction CLIs.applications: optional GUI applications.interface: optional Pico IMU and combined hardware acquisition.finger_kinematics: optional video/landmark integration.exo_classifierand3D_printed_arm_control: project-specific research and hardware examples; additional hardware/software may be required.
Examples that need data open a file picker or accept an explicit path. Microcontroller .py files and the bundled .uf2 firmware are intended for their device runtimes, not desktop Python.
Package structure
intan/
├── applications/ optional GUI applications
├── decomposition/ PCA and constrained ICA utilities
├── interface/ RHX TCP, LSL, and optional Pico interfaces
├── io/ RHD, DAT, CSV, NPZ, event, and config I/O
├── ml/ lazy-loaded PyTorch model workflows
├── plotting/ static and real-time visualization
├── processing/ filtering, features, synchronization, and QC
├── samples/ packaged sample assets
└── ui/ shared optional GUI helpers
Documentation
Published documentation is available on GitHub Pages. To build it locally, run these commands from a repository checkout. Documentation sources and media are kept in the repository rather than bundled in package distributions:
python -m pip install -e '.[docs]'
sphinx-build -W --keep-going -b html docs/source docs/build/html
Development and testing
python -m pip install -e '.[test]'
python -m pytest
python -m compileall -q intan examples
python -m build
python -m twine check dist/*
Hardware, LSL, and interactive GUI behavior requires the corresponding devices, streams, or display server. The automated suite confines itself to deterministic offline and headless checks.
Release workflow
- Update the version consistently in
pyproject.toml,intan/__init__.py, andCITATION.cff. - Update
CHANGELOG.md, run the full validation commands above, and inspect both archives. - Commit the release changes, create a matching annotated
vX.Y.Ztag, and rebuild from that clean tagged commit. - Upload to TestPyPI and validate an installation from TestPyPI.
- Upload the exact already-validated artifacts to PyPI.
Do not reuse a version or rebuild artifacts between TestPyPI and PyPI.
Contributing
Bug reports and focused pull requests are welcome. See CONTRIBUTING.md for environment and review guidance.
License
python-intan is distributed under the MIT License.
Metadata
Release files for python-intan 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_intan-0.3.0.tar.gz | 373.8 kB | Without provenance | Details for python_intan-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_intan-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for python_intan-0.3.0-py3-none-any.whl |
Total release size: 570.1 kB
Release files / python_intan-0.3.0.tar.gz
| Download URL | python_intan-0.3.0.tar.gz |
|---|---|
| Size | 373.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
462d28312908e2cc0103a36f8a22c8773c8083bbddceea5505dfa6e500ee7a62
|
|
BLAKE2b-256 checksum How to use checksums |
964afbd91ffef6837dde3200e19779e0f746a3211c20635e3ffa995dc0801c5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / python_intan-0.3.0-py3-none-any.whl
| Download URL | python_intan-0.3.0-py3-none-any.whl |
|---|---|
| Size | 196.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c96ba21c39b50739d1629d0c85ef1a1c822fbd44184857f3d5cf2d24ab908c8
|
|
BLAKE2b-256 checksum How to use checksums |
fbfc0072635dfe512a0514950332d9a6227f2fc78e37f27a42900a6769bf1de8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Security for python-intan 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.