Neural Data Analysis Package for spike processing, trial management, and modeling
Project description
NeuroDAP: Neural Data Analysis Package
A comprehensive Python package for analyzing neural data, including spike processing, trial management, session data organization, and advanced modeling with rSLDS (recurrent Switching Linear Dynamical Systems).
Features
🧠 Core Neural Analysis
- Spike Processing: Extract, clean, and analyze spike data
- Trial Management: Organize and manage experimental trials
- Decoding: Train and evaluate neural decoders
- Coding Directions: Analyze neural population dynamics
🔄 Advanced Modeling
- rSLDS: Recurrent Switching Linear Dynamical Systems for neural dynamics
- State Analysis: Analyze discrete states and transitions
- Model Fitting: Expectation-Maximization algorithm implementation
💾 Data Management
- HDF5 Storage: Efficient storage of large neural datasets
- Session Organization: Hierarchical data structure for experiments
- Flexible I/O: Save/load trial tables, aligned spikes, and models
📊 Visualization
- PSTH Plots: Peri-stimulus time histograms
- Raster Plots: Spike timing visualization
- Tuning Curves: Response characterization
- Model Results: Visualize rSLDS states and transitions
Installation
From Source
git clone <your-repository-url>
cd pyNeuroDAP
pip install -e .
Dependencies
pip install -r requirements.txt
Quick Start
Basic Usage
import pyNeuroDAP as ndap
# Load and process spikes
spikes = ndap.get_spikes(spike_times, event_times, window_ms=500)
spikes_clean = ndap.remove_nan_trials(spikes)
# Get decoders
decoders = ndap.get_decoders(spikes_clean, labels, cv_folds=5)
# Analyze coding directions
cd_stimulus, cd_choice = ndap.get_mod_index(spikes_clean, stimulus_labels, choice_labels)
# Make orthogonal
cd_stimulus_ortho = ndap.make_orthogonal(cd_stimulus, cd_choice)
Session Management
# Save complete session
session_file = ndap.save_session_data(
session_name='session_2024_01_15',
trial_table=trial_table,
aligned_spikes=aligned_spikes,
metadata={'subject': 'mouse_001', 'experiment': 'opto_psth'}
)
# Add new data later
ndap.add_to_session(session_file, new_aligned_data, 'aligned_spikes')
# Load session
session_data = ndap.load_session_data(session_file)
rSLDS Modeling
# Fit rSLDS model
model = ndap.fit_rslds(
data=spikes_clean,
n_states=3,
n_latent=5,
max_iter=100
)
# Analyze states
state_analysis = ndap.analyze_rslds_states(model, spikes_clean, trial_labels)
Package Structure
pyNeuroDAP/
├── __init__.py # Main package interface
├── spikes.py # Core spike analysis and rSLDS
├── trials.py # Trial management
├── sessions.py # HDF5 data management
└── plots.py # Visualization tools
Modules
spikes.py
Core neural data processing and analysis:
get_spikes(): Extract spike data around eventsget_decoders(): Train neural decodersget_mod_index(): Calculate coding directionsmake_orthogonal(): Orthogonalize vectorsrSLDS: Recurrent switching linear dynamical systemsfit_rslds(): Fit rSLDS modelsanalyze_rslds_states(): Analyze model states
trials.py
Trial organization and management:
get_trial_table(): Create trial information tableget_trial_conditions(): Extract trial conditionsget_trial_events(): Get trial event timesget_trial_data(): Retrieve trial-specific data
sessions.py
HDF5-based data management:
save_session_data(): Save complete sessionload_session_data(): Load complete sessionadd_to_session(): Add new data to existing sessionsave_aligned_spikes(): Save spike alignment datasave_trial_table(): Save trial information
plots.py
Visualization tools:
plot_psth(): Peri-stimulus time histogramsplot_raster(): Spike raster plotsplot_tuning_curve(): Response tuning curvesplot_rslds_states(): rSLDS state visualization
Data Structure
Session Organization
session_name.h5
├── trial_table/ # Trial information
├── aligned_spikes/ # Spike alignments
│ ├── trial_start/
│ ├── choice_lick/
│ └── reward/
├── models/ # Fitted models
│ ├── rslds_3states/
│ └── decoders/
└── metadata # Session information
Aligned Spike Data
aligned_spikes = {
'condition_name': {
'count': np.array, # Spike counts [neurons, trials, time_bins]
'rate': np.array, # Firing rates
'times': np.array, # Spike times
'params': dict # Alignment parameters
}
}
Examples
Complete Analysis Pipeline
import pyNeuroDAP as ndap
# 1. Load and process data
spikes = ndap.get_spikes(spike_times, event_times, window_ms=500)
spikes_clean = ndap.remove_nan_trials(spikes)
# 2. Train decoders
decoders = ndap.get_decoders(spikes_clean, labels, cv_folds=5)
# 3. Analyze coding directions
cd_stimulus, cd_choice = ndap.get_mod_index(spikes_clean, stimulus_labels, choice_labels)
# 4. Fit rSLDS model
model = ndap.fit_rslds(spikes_clean, n_states=3, n_latent=5)
# 5. Save everything
session_file = ndap.save_session_data(
'my_experiment',
trial_table=trial_info,
aligned_spikes=spikes_clean,
models={'rslds': model, 'decoders': decoders}
)
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use this package in your research, please cite:
@software{pyNeuroDAP,
title={pyNeuroDAP: Neural Data Analysis Package},
author={Li, Shun},
year={2025},
url={https://github.com/shunnnli/pyNeuroDAP}
}
Support
For questions, issues, or feature requests, please:
- Open an issue on GitHub
- Check the documentation
- Contact the maintainer
Happy Neural Data Analysis! 🧠✨
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 pyneurodap-1.0.0.tar.gz.
File metadata
- Download URL: pyneurodap-1.0.0.tar.gz
- Upload date:
- Size: 45.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ee33ac55583b92955c53effb48ae1d518c517144781ff748eaa9468387c8450
|
|
| MD5 |
9418a4559378bd8b948fac536a68a9bb
|
|
| BLAKE2b-256 |
8a1dc87295fa0af94d89658a5ee44248645ca46f66543448d620c4f8dd664023
|
File details
Details for the file pyneurodap-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyneurodap-1.0.0-py3-none-any.whl
- Upload date:
- Size: 45.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
843af82918d7576297ddfe581c3ebdcc5f2bca8c871abc14b1cc3a4c74c99bb7
|
|
| MD5 |
d1acd4d02fe9f477dcb72c6812802329
|
|
| BLAKE2b-256 |
6f4bd78592aef3c00988319affac2bc126441fdc1eedf69052572a4db284553d
|