# 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
```bash
git clone <your-repository-url>
cd pyNeuroDAP
pip install -e .
```
### Dependencies
```bash
pip install -r requirements.txt
```
## Quick Start
### Basic Usage
```python
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
```python
# 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
```python
# 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 events
- `get_decoders()`: Train neural decoders
- `get_mod_index()`: Calculate coding directions
- `make_orthogonal()`: Orthogonalize vectors
- `rSLDS`: Recurrent switching linear dynamical systems
- `fit_rslds()`: Fit rSLDS models
- `analyze_rslds_states()`: Analyze model states
### `trials.py`
Trial organization and management:
- `get_trial_table()`: Create trial information table
- `get_trial_conditions()`: Extract trial conditions
- `get_trial_events()`: Get trial event times
- `get_trial_data()`: Retrieve trial-specific data
### `sessions.py`
HDF5-based data management:
- `save_session_data()`: Save complete session
- `load_session_data()`: Load complete session
- `add_to_session()`: Add new data to existing session
- `save_aligned_spikes()`: Save spike alignment data
- `save_trial_table()`: Save trial information
### `plots.py`
Visualization tools:
- `plot_psth()`: Peri-stimulus time histograms
- `plot_raster()`: Spike raster plots
- `plot_tuning_curve()`: Response tuning curves
- `plot_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
```python
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
```python
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
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Citation
If you use this package in your research, please cite:
```bibtex
@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! 🧠✨**
Raw data
{
"_id": null,
"home_page": "https://github.com/shunnnli/pyNeuroDAP",
"name": "pyNeuroDAP",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "Shun Li <shunli@g.harvard.edu>",
"keywords": "neuroscience, neural data, spike analysis, electrophysiology, rSLDS, machine learning",
"author": "Shun Li",
"author_email": "Shun Li <shunli@g.harvard.edu>",
"download_url": "https://files.pythonhosted.org/packages/51/e5/86092ba7fab8422ae47f0b75210f71bff5aa814760bea5f567820f781956/pyneurodap-1.1.0.tar.gz",
"platform": null,
"description": "# NeuroDAP: Neural Data Analysis Package\n\nA 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).\n\n## Features\n\n### \ud83e\udde0 **Core Neural Analysis**\n- **Spike Processing**: Extract, clean, and analyze spike data\n- **Trial Management**: Organize and manage experimental trials\n- **Decoding**: Train and evaluate neural decoders\n- **Coding Directions**: Analyze neural population dynamics\n\n### \ud83d\udd04 **Advanced Modeling**\n- **rSLDS**: Recurrent Switching Linear Dynamical Systems for neural dynamics\n- **State Analysis**: Analyze discrete states and transitions\n- **Model Fitting**: Expectation-Maximization algorithm implementation\n\n### \ud83d\udcbe **Data Management**\n- **HDF5 Storage**: Efficient storage of large neural datasets\n- **Session Organization**: Hierarchical data structure for experiments\n- **Flexible I/O**: Save/load trial tables, aligned spikes, and models\n\n### \ud83d\udcca **Visualization**\n- **PSTH Plots**: Peri-stimulus time histograms\n- **Raster Plots**: Spike timing visualization\n- **Tuning Curves**: Response characterization\n- **Model Results**: Visualize rSLDS states and transitions\n\n## Installation\n\n### From Source\n```bash\ngit clone <your-repository-url>\ncd pyNeuroDAP\npip install -e .\n```\n\n### Dependencies\n```bash\npip install -r requirements.txt\n```\n\n## Quick Start\n\n### Basic Usage\n```python\nimport pyNeuroDAP as ndap\n\n# Load and process spikes\nspikes = ndap.get_spikes(spike_times, event_times, window_ms=500)\nspikes_clean = ndap.remove_nan_trials(spikes)\n\n# Get decoders\ndecoders = ndap.get_decoders(spikes_clean, labels, cv_folds=5)\n\n# Analyze coding directions\ncd_stimulus, cd_choice = ndap.get_mod_index(spikes_clean, stimulus_labels, choice_labels)\n\n# Make orthogonal\ncd_stimulus_ortho = ndap.make_orthogonal(cd_stimulus, cd_choice)\n```\n\n### Session Management\n```python\n# Save complete session\nsession_file = ndap.save_session_data(\n session_name='session_2024_01_15',\n trial_table=trial_table,\n aligned_spikes=aligned_spikes,\n metadata={'subject': 'mouse_001', 'experiment': 'opto_psth'}\n)\n\n# Add new data later\nndap.add_to_session(session_file, new_aligned_data, 'aligned_spikes')\n\n# Load session\nsession_data = ndap.load_session_data(session_file)\n```\n\n### rSLDS Modeling\n```python\n# Fit rSLDS model\nmodel = ndap.fit_rslds(\n data=spikes_clean,\n n_states=3,\n n_latent=5,\n max_iter=100\n)\n\n# Analyze states\nstate_analysis = ndap.analyze_rslds_states(model, spikes_clean, trial_labels)\n```\n\n## Package Structure\n\n```\npyNeuroDAP/\n\u251c\u2500\u2500 __init__.py # Main package interface\n\u251c\u2500\u2500 spikes.py # Core spike analysis and rSLDS\n\u251c\u2500\u2500 trials.py # Trial management\n\u251c\u2500\u2500 sessions.py # HDF5 data management\n\u2514\u2500\u2500 plots.py # Visualization tools\n```\n\n## Modules\n\n### `spikes.py`\nCore neural data processing and analysis:\n- `get_spikes()`: Extract spike data around events\n- `get_decoders()`: Train neural decoders\n- `get_mod_index()`: Calculate coding directions\n- `make_orthogonal()`: Orthogonalize vectors\n- `rSLDS`: Recurrent switching linear dynamical systems\n- `fit_rslds()`: Fit rSLDS models\n- `analyze_rslds_states()`: Analyze model states\n\n### `trials.py`\nTrial organization and management:\n- `get_trial_table()`: Create trial information table\n- `get_trial_conditions()`: Extract trial conditions\n- `get_trial_events()`: Get trial event times\n- `get_trial_data()`: Retrieve trial-specific data\n\n### `sessions.py`\nHDF5-based data management:\n- `save_session_data()`: Save complete session\n- `load_session_data()`: Load complete session\n- `add_to_session()`: Add new data to existing session\n- `save_aligned_spikes()`: Save spike alignment data\n- `save_trial_table()`: Save trial information\n\n### `plots.py`\nVisualization tools:\n- `plot_psth()`: Peri-stimulus time histograms\n- `plot_raster()`: Spike raster plots\n- `plot_tuning_curve()`: Response tuning curves\n- `plot_rslds_states()`: rSLDS state visualization\n\n## Data Structure\n\n### Session Organization\n```\nsession_name.h5\n\u251c\u2500\u2500 trial_table/ # Trial information\n\u251c\u2500\u2500 aligned_spikes/ # Spike alignments\n\u2502 \u251c\u2500\u2500 trial_start/\n\u2502 \u251c\u2500\u2500 choice_lick/\n\u2502 \u2514\u2500\u2500 reward/\n\u251c\u2500\u2500 models/ # Fitted models\n\u2502 \u251c\u2500\u2500 rslds_3states/\n\u2502 \u2514\u2500\u2500 decoders/\n\u2514\u2500\u2500 metadata # Session information\n```\n\n### Aligned Spike Data\n```python\naligned_spikes = {\n 'condition_name': {\n 'count': np.array, # Spike counts [neurons, trials, time_bins]\n 'rate': np.array, # Firing rates\n 'times': np.array, # Spike times\n 'params': dict # Alignment parameters\n }\n}\n```\n\n## Examples\n\n### Complete Analysis Pipeline\n```python\nimport pyNeuroDAP as ndap\n\n# 1. Load and process data\nspikes = ndap.get_spikes(spike_times, event_times, window_ms=500)\nspikes_clean = ndap.remove_nan_trials(spikes)\n\n# 2. Train decoders\ndecoders = ndap.get_decoders(spikes_clean, labels, cv_folds=5)\n\n# 3. Analyze coding directions\ncd_stimulus, cd_choice = ndap.get_mod_index(spikes_clean, stimulus_labels, choice_labels)\n\n# 4. Fit rSLDS model\nmodel = ndap.fit_rslds(spikes_clean, n_states=3, n_latent=5)\n\n# 5. Save everything\nsession_file = ndap.save_session_data(\n 'my_experiment',\n trial_table=trial_info,\n aligned_spikes=spikes_clean,\n models={'rslds': model, 'decoders': decoders}\n)\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests if applicable\n5. Submit a pull request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Citation\n\nIf you use this package in your research, please cite:\n\n```bibtex\n@software{pyNeuroDAP,\n title={pyNeuroDAP: Neural Data Analysis Package},\n author={Li, Shun},\n year={2025},\n url={https://github.com/shunnnli/pyNeuroDAP}\n}\n```\n\n## Support\n\nFor questions, issues, or feature requests, please:\n- Open an issue on GitHub\n- Check the documentation\n- Contact the maintainer\n\n---\n\n**Happy Neural Data Analysis! \ud83e\udde0\u2728**\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Neural Data Analysis Package for spike processing, trial management, and modeling",
"version": "1.1.0",
"project_urls": {
"Bug Tracker": "https://github.com/shunnnli/pyNeuroDAP/issues",
"Documentation": "https://github.com/shunnnli/pyNeuroDAP#readme",
"Homepage": "https://github.com/shunnnli/pyNeuroDAP",
"Repository": "https://github.com/shunnnli/pyNeuroDAP",
"Source Code": "https://github.com/shunnnli/pyNeuroDAP"
},
"split_keywords": [
"neuroscience",
" neural data",
" spike analysis",
" electrophysiology",
" rslds",
" machine learning"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "d4446536e4486b102f075447fa34d76082a1a4a139266f72f3a0cafb4739fe84",
"md5": "f992490e3b0abf9efbde43073fabceae",
"sha256": "ca545c0cea4ae0cae50eb55688731775263e4568202c062bec4aa8f194e99573"
},
"downloads": -1,
"filename": "pyneurodap-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f992490e3b0abf9efbde43073fabceae",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 45724,
"upload_time": "2025-08-30T03:58:44",
"upload_time_iso_8601": "2025-08-30T03:58:44.545261Z",
"url": "https://files.pythonhosted.org/packages/d4/44/6536e4486b102f075447fa34d76082a1a4a139266f72f3a0cafb4739fe84/pyneurodap-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "51e586092ba7fab8422ae47f0b75210f71bff5aa814760bea5f567820f781956",
"md5": "9b9348c343458767798ac0406a5059e4",
"sha256": "780ce636568959730d839b0d157f27f68fb4ad74cf33ee6cacf27f15469d08f6"
},
"downloads": -1,
"filename": "pyneurodap-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "9b9348c343458767798ac0406a5059e4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 45796,
"upload_time": "2025-08-30T03:58:45",
"upload_time_iso_8601": "2025-08-30T03:58:45.929426Z",
"url": "https://files.pythonhosted.org/packages/51/e5/86092ba7fab8422ae47f0b75210f71bff5aa814760bea5f567820f781956/pyneurodap-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-30 03:58:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "shunnnli",
"github_project": "pyNeuroDAP",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "numpy",
"specs": [
[
">=",
"1.20.0"
]
]
},
{
"name": "scipy",
"specs": [
[
">=",
"1.7.0"
]
]
},
{
"name": "pandas",
"specs": [
[
">=",
"1.3.0"
]
]
},
{
"name": "matplotlib",
"specs": [
[
">=",
"3.3.0"
]
]
},
{
"name": "seaborn",
"specs": [
[
">=",
"0.11.0"
]
]
},
{
"name": "scikit-learn",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "h5py",
"specs": [
[
">=",
"3.0.0"
]
]
},
{
"name": "tables",
"specs": [
[
">=",
"3.7.0"
]
]
},
{
"name": "tqdm",
"specs": [
[
">=",
"4.60.0"
]
]
},
{
"name": "dask",
"specs": [
[
">=",
"2022.0.0"
]
]
},
{
"name": "PySide6",
"specs": [
[
">=",
"6.0.0"
]
]
}
],
"lcname": "pyneurodap"
}