Core ephys and behavior processing utilities for the Akrami Lab.
Project description
XdetectionCore
XdetectionCore is the foundational data processing engine for the Akrami Lab (LIM Lab). It provides standardized utilities for electrophysiology (ephys) and behavioral analysis, specifically designed to bridge the gap between Windows workstations and Linux-based HPC clusters.
๏ฟฝ Table of Contents
- Features
- Installation
- Quick Start
- Core Modules
- Components
- Usage Examples
- Project Structure
- Contributing
- License
โจ Features
- Unified Session Management: Centralized
Sessionclass for managing ephys and behavior data - Spike Analysis: Tools for spike time processing, PSTH computation, and neural decoding
- Behavioral Analysis: Utilities for sound events, lick detection, and pupil tracking
- Cross-Platform Support: Seamless path handling between Windows and Linux systems
- Scalable Processing: Integration with parallel processing via
joblibfor large datasets - Statistical Analysis: Built-in filtering, z-scoring, and neural population analysis
- Visualization: Matplotlib-based plotting with custom styling and publication-ready figures
๏ฟฝ๐ Installation
From PyPI
The easiest way to install the stable version is via pip:
pip install XdetectionCore```
### From Source
For development or to access the latest version:
```bash
git clone https://github.com/Akrami-Lab/XdetectionCore.git
cd XdetectionCore
pip install -e .
Requirements
- Python >= 3.8
- numpy < 2.0
- pandas >= 1.3
- matplotlib
- scipy
- tqdm
- joblib
๐ฏ Quick Start
Basic Session Setup
from xdetectioncore.session import Session
# Initialize a session
session = Session(
sessname='my_experiment',
ceph_dir='path/to/ceph/data',
pkl_dir='path/to/pkl/data'
)
# Initialize spike data
session.init_spike_obj(
spike_times_path='spike_times.npy',
spike_cluster_path='spike_clusters.npy',
start_time=0,
parent_dir='path/to/data'
)
# Initialize sound events
session.init_sound_event_dict(
sound_write_path='sound_writes.bin',
format_kwargs={'sampling_rate': 30000}
)
Loading and Processing Data
from xdetectioncore.io_utils import load_sess_pkl, load_spikes
from xdetectioncore.paths import posix_from_win
# Load spike data
spike_times, spike_clusters = load_spikes(
spike_times_path='spike_times.npy',
spike_clusters_path='spike_clusters.npy'
)
# Cross-platform path handling
linux_path = posix_from_win('C:\\data\\recording', '/nfs/nhome/live')
๐ฆ Core Modules
session.py
Central session management class that coordinates ephys and behavioral data:
- Manages spike objects, events, and behavioral measurements
- Handles trial data (td_df) and inter-trial-interval (ITI) statistics
- Integrates decoders for neural population analysis
- Aggregates multi-session data via
load_aggregate_td_df()
ephys/
Electrophysiology analysis tools:
spike_time_utils.py:SessionSpikesclass for spike handling, raster generation, PSTH computationgenerate_synthetic_spikes.py: Synthetic neural data generation for validation and testing
components/
Modular components for specific data types:
events.py:SoundEventclass for sound stimulus representation and PSTH analysislicks.py:SessionLicksfor lick behavior tracking and analysispupil.py:SessionPupilfor pupil tracking and statisticsutils.py: Utility functions including z-scoring and normalization
decoding/
Neural population decoding and classification:
decoding_funcs.py:Decoderclass for various decoding algorithms
Utility Modules
io_utils.py: File I/O operations (spike loading, sound binary reading, pickle handling)paths.py: Cross-platform path utilities and date extractionplotting.py: Publication-ready visualization and styling (format_axis(),unique_legend(),apply_style())behaviour.py: Behavioral data processing and formattingstats.py: Statistical analysis functions
๐ง Components
SoundEvent
Represents a sound stimulus event with associated spike responses:
from xdetectioncore.components.events import SoundEvent
event = SoundEvent(idx=0, times=[1.0, 2.0, 3.0], lbl='stim_A')
# Compute PSTH (peri-stimulus time histogram)
event.get_psth(
sess_spike_obj=session.spike_obj,
window=[-0.5, 1.0],
baseline_dur=0.25,
zscore_flag=True
)
# Save visualization
event.save_plot_as_svg('figures/', suffix='trial_001')
SessionSpikes
Core class for spike time processing:
from xdetectioncore.ephys.spike_time_utils import SessionSpikes
spike_obj = SessionSpikes(
spike_times_path='spike_times.npy',
spike_cluster_path='spike_clusters.npy',
start_time=0,
parent_dir='data/'
)
# Get spike raster for specific time window
raster = spike_obj.get_spike_raster(start_time=0, end_time=10)
SessionLicks
Track and analyze lick behavior:
from xdetectioncore.components.licks import SessionLicks
licks = SessionLicks()
lick_times = licks.get_lick_times(lick_data_path='lick_times.csv')
SessionPupil
Analyze pupil dynamics:
from xdetectioncore.components.pupil import SessionPupil
pupil = SessionPupil()
# Process pupil tracking data
๐ Usage Examples
Example 1: Single Session PSTH Analysis
from xdetectioncore.session import Session
from xdetectioncore.components.events import SoundEvent
import numpy as np
# Create session
session = Session('exp_001', 'ceph_dir', 'pkl_dir')
session.init_spike_obj('spikes.npy', 'clusters.npy', 0, 'data/')
# Create sound event
sound_times = np.array([1.5, 5.2, 9.8]) # Second times
event = SoundEvent(idx=0, times=sound_times, lbl='tone_1khz')
# Compute and plot PSTH
event.get_psth(
sess_spike_obj=session.spike_obj,
window=[-0.5, 2.0],
baseline_dur=0.25,
zscore_flag=True,
title='Tone Response'
)
event.save_plot_as_svg('output/', suffix='psth_analysis')
Example 2: Multi-Session Data Aggregation
from xdetectioncore.behaviour import load_aggregate_td_df
from pathlib import Path
# Load trial data from multiple sessions
td_df = load_aggregate_td_df(
session_topology=session_info_df,
home_dir=Path('/home/user/data')
)
# Filter and analyze
learning_window = td_df[td_df['trial_type'] == 'learning']
print(f"Average performance: {learning_window['correct'].mean():.3f}")
Example 3: Cross-Platform Data Access
from xdetectioncore.paths import posix_from_win
# Convert Windows path to Linux HPC path
win_path = 'C:\\data\\recordings\\exp_2024'
linux_path = posix_from_win(win_path, '/nfs/nhome/live/aonih')
# Now use linux_path for HPC analysis
print(linux_path) # /nfs/nhome/live/aonih/data/recordings/exp_2024
๐ Project Structure
XdetectionCore/
โโโ xdetectioncore/
โ โโโ __init__.py # Package exports
โ โโโ session.py # Central Session class
โ โโโ behaviour.py # Behavioral data processing
โ โโโ io_utils.py # File I/O utilities
โ โโโ paths.py # Cross-platform path handling
โ โโโ plotting.py # Visualization utilities
โ โโโ stats.py # Statistical functions
โ โโโ components/
โ โ โโโ events.py # SoundEvent class
โ โ โโโ licks.py # SessionLicks class
โ โ โโโ pupil.py # SessionPupil class
โ โ โโโ utils.py # Component utilities
โ โโโ decoding/
โ โ โโโ decoding_funcs.py # Neural decoding algorithms
โ โโโ ephys/
โ โโโ __init__.py
โ โโโ spike_time_utils.py # SessionSpikes class
โ โโโ generate_synthetic_spikes.py # Data generation
โโโ pyproject.toml # Project metadata
โโโ setup.py # Setup configuration
โโโ README.md # This file
โโโ LICENSE # License file
๐ค Contributing
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -am 'Add my feature') - Push to the branch (
git push origin feature/my-feature) - Open a Pull Request
๐ License
This project is licensed under the License specified in the LICENSE file.
๐ Related Projects
- Neo: Neural data standards and I/O
- Elephant: Electrophysiology analysis toolkit
Maintained by the Akrami Lab (LIM Lab)
For issues, questions, or suggestions, please open an issue on the GitHub repository or contact the 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 xdetectioncore-0.1.7.4.tar.gz.
File metadata
- Download URL: xdetectioncore-0.1.7.4.tar.gz
- Upload date:
- Size: 86.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36bdb450db8866ec1aa74809eb44947207b06e21c9b34ffeb0370ce76173c4d1
|
|
| MD5 |
f74f70d58f5a641e9eb50e97418cea82
|
|
| BLAKE2b-256 |
f1041e8f3633db20be8b6b9cfc6d821d93b555878fed72c6595cee504ba6bc03
|
Provenance
The following attestation bundles were made for xdetectioncore-0.1.7.4.tar.gz:
Publisher:
publish.yml on LIMLabSWC/XdetectionCore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xdetectioncore-0.1.7.4.tar.gz -
Subject digest:
36bdb450db8866ec1aa74809eb44947207b06e21c9b34ffeb0370ce76173c4d1 - Sigstore transparency entry: 1181442844
- Sigstore integration time:
-
Permalink:
LIMLabSWC/XdetectionCore@f2d6cd54f2c988906f02875dda71664016ddccea -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LIMLabSWC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f2d6cd54f2c988906f02875dda71664016ddccea -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file xdetectioncore-0.1.7.4-py3-none-any.whl.
File metadata
- Download URL: xdetectioncore-0.1.7.4-py3-none-any.whl
- Upload date:
- Size: 96.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
254bfe78d65f153c2d54db4ed053b9ce90bb55d66e1e8810e0bea76cc0f0118b
|
|
| MD5 |
a9e7ccedbf4bd8a14d5e3e1ce6ded913
|
|
| BLAKE2b-256 |
a9cf4ee600f45cfb7c77c95f24a5c7728b3e5856ec18dc4142460e5e5e8a84fa
|
Provenance
The following attestation bundles were made for xdetectioncore-0.1.7.4-py3-none-any.whl:
Publisher:
publish.yml on LIMLabSWC/XdetectionCore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xdetectioncore-0.1.7.4-py3-none-any.whl -
Subject digest:
254bfe78d65f153c2d54db4ed053b9ce90bb55d66e1e8810e0bea76cc0f0118b - Sigstore transparency entry: 1181442846
- Sigstore integration time:
-
Permalink:
LIMLabSWC/XdetectionCore@f2d6cd54f2c988906f02875dda71664016ddccea -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LIMLabSWC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f2d6cd54f2c988906f02875dda71664016ddccea -
Trigger Event:
workflow_dispatch
-
Statement type: