Skip to main content

Python interface and utilities for working with Intan RHX devices and electrophysiology data

Project description

Logo

Python Intan

Docs Python License: MIT PyPI version Downloads

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 .npz files 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


๐Ÿ“ฆ 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 .rhd recordings
  • 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:


๐ŸŽ“ 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


๐Ÿšฆ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_intan-0.0.3.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_intan-0.0.3-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

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

Hashes for python_intan-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ba5b56ad8c6ee1f1dc2e11fb05a3aab0deb13ce01ed379026de453bd74dc55fb
MD5 956473d5d94449ab53768ecb4c8cc0b0
BLAKE2b-256 390c51f0330972f63a91edd91012f5e55c0618c0bc6efa1be46da532d59a4755

See more details on using hashes here.

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

Hashes for python_intan-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9e3e1f453f8dfc1ac9623a1a435902a30f7be4e7c353d1bc0823880af4db7245
MD5 03373f959fb22e4c732830aa4520042d
BLAKE2b-256 1f89acbcee303455c7e70dfe56fd9ed67f79b630f405d8ddc3a0aa81d93caedc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page