Python interface and utilities for working with Intan RHX devices and electrophysiology data
Project description
Python Intan
python-intan is a comprehensive Python package for working with Intan Technologies RHX systems and electrophysiology data. From file loading to real-time streaming, signal processing to machine learning, hardware integration to GUI applicationsโeverything you need for EMG/neural data analysis in one package.
โจ Key Features
- ๐ File I/O: Load
.rhd,.rhs,.dat,.csv, and.npzfiles with ease - ๐ด Real-time Streaming: TCP interface for live data acquisition from RHX devices
- ๐๏ธ Signal Processing: Filtering, normalization, RMS, feature extraction
- ๐ค Machine Learning: Complete gesture classification pipeline with TensorFlow
- ๐ Visualization: Waterfall plots, real-time plotting, GUI applications
- ๐ Hardware Integration: LSL support, Raspberry Pi Pico, robotic control
- ๐ฅ๏ธ GUI Applications: EMG viewer, trial selector, gesture pipeline interface
- ๐ Performance: GPU acceleration, optimized for real-time applications
๐ Quick Links
- Documentation - Full guides and API reference
- Examples - 60+ code examples
- FAQ - Frequently asked questions
- Contributing - How to contribute
- Changelog - Version history
๐ฆ Installation
From PyPI (Recommended)
pip install python-intan
From Source (Latest Features)
git clone https://github.com/Neuro-Mechatronics-Interfaces/python-intan.git
cd python-intan
pip install -e .
With Virtual Environment
# Using conda
conda create -n intan python=3.10
conda activate intan
pip install python-intan
# Or using venv
python -m venv intan
source intan/bin/activate # Windows: intan\Scripts\activate
pip install python-intan
GPU Support (Optional)
For faster machine learning training:
pip install tensorflow[and-cuda] nvidia-cudnn-cu12
๐ Getting Started
Load and Visualize EMG Data
import intan
# Load .rhd file (opens file picker)
result = intan.io.load_rhd_file()
# Or specify path directly
result = intan.io.load_rhd_file('path/to/file.rhd')
# Access data
emg_data = result['amplifier_data'] # Shape: (channels, samples)
fs = result['frequency_parameters']['amplifier_sample_rate']
t = result['t_amplifier']
# Quick filtering
emg_filtered = intan.processing.notch_filter(emg_data, fs, f0=60)
emg_filtered = intan.processing.filter_emg(emg_filtered, 'bandpass', fs,
lowcut=10, highcut=500)
# Visualize
intan.plotting.waterfall(emg_filtered, range(64), t,
plot_title='Filtered EMG Data')
Real-time Streaming from RHX Device
from intan.interface import IntanRHXDevice
# Connect to device
device = IntanRHXDevice()
device.enable_wide_channel(range(64))
device.start_streaming()
# Stream data
timestamps, data = device.stream(duration_sec=1.0)
print(f"Acquired data shape: {data.shape}")
device.close()
Train a Gesture Classifier
from intan.ml import ModelManager
import numpy as np
# Load training data
data = np.load('training_data.npz')
X_train, y_train = data['features'], data['labels']
# Train model
manager = ModelManager()
model, pca, scaler = manager.train_model(X_train, y_train,
model_type='CNN', epochs=50)
# Save for later use
manager.save_model('gesture_model.keras')
Real-time Gesture Recognition
from intan.interface import IntanRHXDevice
from intan.ml import EMGRealTimePredictor
import tensorflow as tf
# Load trained model
model = tf.keras.models.load_model('gesture_model.keras')
# Initialize device
device = IntanRHXDevice(num_channels=128)
device.start_streaming()
# Create predictor
predictor = EMGRealTimePredictor(device, model, pca, mean, std, label_names)
predictor.run_prediction_loop()
# Get predictions
while True:
prediction = predictor.get_prediction()
if prediction:
print(f"Gesture: {prediction['label']} ({prediction['confidence']:.1%})")
Lab Streaming Layer (LSL) Integration
from intan.interface import IntanRHXDevice, LSLPublisher
# Start device
device = IntanRHXDevice(num_channels=64)
device.start_streaming()
# Publish to LSL
publisher = LSLPublisher(name='IntanEMG', stream_type='EMG',
channel_count=64, sample_rate=4000)
while True:
_, data = device.stream(n_frames=40)
publisher.push_chunk(data.T)
๐๏ธ Package Structure
intan/
โโโ io/ # File loading (.rhd, .dat, .csv, .npz)
โโโ interface/ # RHX device, LSL, hardware interfaces
โโโ processing/ # Signal processing and filtering
โโโ ml/ # Machine learning pipeline
โโโ plotting/ # Visualization utilities
โโโ applications/ # GUI applications
โโโ decomposition/ # PCA, ICA decomposition
โโโ samples/ # Sample data utilities
examples/
โโโ Read_Files/ # File loading examples
โโโ RHXDevice/ # Device streaming examples
โโโ LSL/ # Lab Streaming Layer examples
โโโ gesture_classifier/ # ML training and prediction
โโโ applications/ # GUI application demos
โโโ 3D_printed_arm_control/ # Robotic control integration
โโโ interface/ # Hardware interfacing examples
๐ฏ Use Cases
๐ Data Analysis
- Load and analyze
.rhdrecordings - Batch process multiple files
- Extract specific time segments
- Generate publication-quality figures
๐ด Real-time Applications
- Live EMG visualization
- Online gesture recognition
- Closed-loop control systems
- Synchronized multi-modal recording
๐ค Machine Learning
- Train gesture classifiers
- Real-time prediction
- Cross-session validation
- Transfer learning
๐ฌ Research
- Impedance testing
- Signal quality monitoring
- Protocol automation
- Custom experimental setups
๐ Documentation
Comprehensive documentation is available at neuro-mechatronics-interfaces.github.io/python-intan
Key Sections:
- Installation Guide
- Loading Files
- Real-time Streaming
- Signal Processing
- Gesture Classification
- LSL Integration
- GUI Applications
- Hardware Control
- FAQ
- API Reference
๐ Examples
The examples/ directory contains 60+ working examples organized by category:
# File loading
python examples/Read_Files/load_rhd_demo.py
# Real-time streaming
python examples/RHXDevice/scrolling_live.py
# Gesture classification pipeline
python examples/gesture_classifier/1a_build_training_dataset_rhd.py
python examples/gesture_classifier/2_train_model.py
python examples/gesture_classifier/3d_predict_from_device_realtime.py
# GUI applications
python examples/applications/run_emg_viewer.py
python examples/applications/gesture_pipeline_gui.py
# LSL streaming
python examples/LSL/lsl_waveform_viewer.py
python examples/LSL/lsl_rms_barplot.py
See the Examples Documentation for complete guides.
๐ ๏ธ Supported Hardware
- Intan RHX Controllers: RHD USB Interface Board, RHD Recording Controller
- Amplifiers: RHD2000 series (RHD2132, RHD2164, RHD2216, etc.)
- Stimulation: RHS2000 series amplifiers
- Peripherals: Raspberry Pi Pico, servo controllers, IMU sensors
- Integration: Lab Streaming Layer (LSL) compatible devices
๐ค Contributing
We welcome contributions! Whether it's:
- ๐ Bug reports
- โจ Feature requests
- ๐ Documentation improvements
- ๐งช New examples
- ๐ง Code contributions
Please see our Contributing Guide for details.
Ways to contribute:
- Report bugs or request features via GitHub Issues
- Submit pull requests with improvements
- Share your use cases and examples
- Help answer questions in discussions
- Improve documentation
๐ Citation
If you use this package in your research, please cite:
@software{Shulgach_Python_Intan_2025,
author = {Shulgach, Jonathan and Murphy, Max and Foy, Adrian},
title = {{Python Intan Package}},
year = {2025},
month = {01},
version = {0.0.3},
url = {https://github.com/Neuro-Mechatronics-Interfaces/python-intan},
note = {Neuromechatronics Lab, Carnegie Mellon University}
}
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License means:
- โ Commercial use
- โ Modification
- โ Distribution
- โ Private use
๐ Acknowledgments
Developed by the Neuromechatronics Lab at Carnegie Mellon University.
Core Contributors:
- Jonathan Shulgach
- Max Murphy
- Adrian Foy
Special Thanks:
- Intan Technologies for hardware and support
- The open-source neuroscience community
๐ง Contact & Support
- Documentation: neuro-mechatronics-interfaces.github.io/python-intan
- Issues: GitHub Issues
- Email: jshulgac@andrew.cmu.edu
- Lab Website: Neuromechatronics Lab
๐ฆ Status & Roadmap
Current Version: 0.0.3 (January 2025)
Completed โ
- File loading (.rhd, .dat, .csv, .npz)
- Real-time TCP streaming from RHX
- Signal processing pipeline
- Machine learning (CNN, LSTM, Dense models)
- Real-time gesture recognition
- Lab Streaming Layer integration
- GUI applications (EMG viewer, trial selector, gesture pipeline)
- Hardware integration (Pico, robotic arms, IMU)
- Comprehensive documentation and examples
In Progress ๐ง
- Performance benchmarking suite
- Extended LSL marker synchronization
- Additional ML model architectures
- Mobile device integration
Planned ๐
- Public training datasets
- Cloud integration for distributed processing
- Advanced impedance testing tools
- Multi-language support (MATLAB, Julia wrappers)
See CHANGELOG.md for detailed version history.
โญ If you find this package useful, please consider giving it a star on GitHub! โญ
Made with โค๏ธ by the Neuromechatronics Lab
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_intan-0.0.3.tar.gz.
File metadata
- Download URL: python_intan-0.0.3.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba5b56ad8c6ee1f1dc2e11fb05a3aab0deb13ce01ed379026de453bd74dc55fb
|
|
| MD5 |
956473d5d94449ab53768ecb4c8cc0b0
|
|
| BLAKE2b-256 |
390c51f0330972f63a91edd91012f5e55c0618c0bc6efa1be46da532d59a4755
|
File details
Details for the file python_intan-0.0.3-py3-none-any.whl.
File metadata
- Download URL: python_intan-0.0.3-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e3e1f453f8dfc1ac9623a1a435902a30f7be4e7c353d1bc0823880af4db7245
|
|
| MD5 |
03373f959fb22e4c732830aa4520042d
|
|
| BLAKE2b-256 |
1f89acbcee303455c7e70dfe56fd9ed67f79b630f405d8ddc3a0aa81d93caedc
|