Electrophysiology Response Alignment Toolkit - Automatically detect and align stimulus-evoked responses in ABF recordings with sub-millisecond precision
Project description
ephyalign
Electrophysiology Response Alignment Toolkit
A Python package for automatically detecting and aligning stimulus-evoked responses in ABF (Axon Binary Format) electrophysiological recordings with sub-millisecond precision.
This toolkit was designed in collaboration with the Imre Vida Lab of Charité Berlin.
Features
- 🎯 Automatic stimulus detection - Detects stimulus artifacts from the signal derivative without requiring a separate trigger channel
- ⚡ Sub-millisecond alignment - Refines epoch alignment by locking to the exact artifact onset
- 📊 Comprehensive metrics - Calculates peak amplitude, rise time, time-to-peak, AUC, and more
- 🔧 Highly configurable - YAML/TOML configuration files, environment variables, or programmatic API
- 📁 Multiple output formats - NPZ (Python), ATF (Stimfit text), HDF5 (Stimfit binary)
- 📈 Diagnostic plots - Automatic generation of overlay, average, zoom, and concatenated plots
- 🖥️ Professional CLI - Full-featured command-line interface for batch processing
- 🧪 Well tested - Comprehensive test suite with pytest
Installation
From PyPI (when published)
pip install ephyalign
From source
git clone https://github.com/SMLoureiro/ephyalign.git
cd ephyalign
pip install -e .
With optional dependencies
# With YAML config support
pip install ephyalign[yaml]
# With development tools
pip install ephyalign[dev]
# Everything
pip install ephyalign[all]
Offline Installation (Windows without Internet)
For Windows computers without internet access, we provide an offline installation bundle:
-
On a computer with internet, create the bundle:
cd ephyalign uv pip install build uv run python scripts/build_offline_bundle.py --platform win_amd64 --python 3.11
-
Copy to USB: Transfer
dist/ephyalign-offline-win_amd64-py3.11.zipto USB -
On the offline Windows computer:
- Extract the ZIP file
- Run
install.bat
📖 See docs/OFFLINE_INSTALLATION.md for detailed instructions.
Quick Start
Command Line
# Process a single file
ephyalign process data/recording.abf
# Process with custom parameters
ephyalign process data/recording.abf --pre-time 0.5 --post-time 3.0 --channel 0
# Process multiple files
ephyalign batch data/*.abf --output-dir results/
# Get file information
ephyalign info data/recording.abf
# Generate example config
ephyalign init-config my_config.yaml
Python API
import ephyalign
# Simple one-liner
result = ephyalign.align_recording("data/recording.abf")
print(f"Found {result.n_epochs} epochs with {result.jitter_ms:.2f}ms jitter")
# Access aligned data
epochs = result.epochs_aligned # Shape: (n_epochs, epoch_length)
time = result.alignment.time_axis # Time axis in seconds
# Access metrics
print(f"Peak amplitude: {result.metrics.peak_amp_mean:.2f} ± {result.metrics.peak_amp_std:.2f}")
With Custom Configuration
from ephyalign import AlignmentConfig, align_recording
# Create configuration
config = AlignmentConfig(
input_file="data/recording.abf",
reference_channel=0,
)
# Customize detection parameters
config.detection.threshold_multiplier = 5.0
config.detection.min_interval_s = 3.0
# Customize epoch extraction
config.epoch.pre_time_s = 0.5
config.epoch.post_time_s = 3.0
# Customize output
config.output.save_plots = True
config.output.save_hdf5 = True
# Run alignment
result = align_recording(config=config)
Using Configuration Files
Create a config.yaml:
input_file: data/recording.abf
reference_channel: 0
detection:
threshold_multiplier: 5.0
min_interval_s: 3.0
epoch:
pre_time_s: 0.5
post_time_s: 3.0
output:
save_npz: true
save_atf: true
save_hdf5: true
save_plots: true
Then use it:
from ephyalign import AlignmentConfig, align_recording
config = AlignmentConfig.from_yaml("config.yaml")
result = align_recording(config=config)
Or from CLI:
ephyalign process data/recording.abf -c config.yaml
Output Structure
aligned/<recording_name>/
├── <name>_aligned.npz # NumPy archive for Python analysis
├── <name>_aligned.atf # Stimfit-compatible text format
├── <name>_aligned.h5 # Stimfit-compatible HDF5 format
└── plots/
├── <name>_zoom_alignment.png # Alignment quality check
├── <name>_overlay_epochs.png # All epochs overlaid
├── <name>_average_response.png # Mean response ± SEM
├── <name>_concatenated_epochs.png
└── <name>_stats.txt # Statistics report
Key Concepts
How Detection Works
- Computes the derivative of the signal to detect sharp transients
- Sets threshold at
threshold_multiplier × std(derivative) - Finds samples exceeding threshold with minimum inter-stimulus interval
- Reports timing statistics (mean ISI, detection rate)
How Alignment Works
- Extracts raw epochs around each detected stimulus
- Searches early portion of each epoch for exact artifact onset
- Re-cuts all epochs to start at detected onset
- Reports alignment jitter (sub-millisecond precision)
Multi-Channel Support
For multi-channel recordings, detection is performed on a reference channel and the same alignment is applied to all channels:
result = align_recording(
"data/multichannel.abf",
reference_channel=0, # Use channel 0 for detection
)
# Access all channels
all_channels = result.epochs_all_aligned # Shape: (n_channels, n_epochs, length)
API Reference
Main Functions
align_recording(input_file, config=None, **kwargs)- Process a single recordingbatch_align(input_files, config=None)- Process multiple files
Core Classes
AlignmentConfig- Main configuration classPipelineResult- Container for all processing resultsEpochMetrics- Response metrics container
Low-Level Functions
from ephyalign.core import (
load_recording, # Load ABF file
detect_stim_onsets, # Detect stimuli
build_epochs, # Extract epochs
refine_alignment, # Refine alignment
compute_epoch_metrics, # Calculate metrics
)
Development
Setup
git clone https://github.com/SMLoureiro/ephyalign.git
cd ephyalign
pip install -e ".[dev]"
Running Tests
pytest # Run all tests
pytest -v # Verbose
pytest --cov=ephyalign # With coverage
pytest -m "not slow" # Skip slow tests
Code Quality
black src tests # Format code
ruff check src tests # Lint
mypy src # Type check
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
pytest) - Submit a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use this software in your research, please cite:
@software{ephyalign,
author = {Loureiro, Samuel Matthews Mckay},
title = {ephyalign: Electrophysiology Response Alignment Toolkit},
year = {2025},
url = {https://github.com/SMLoureiro/ephyalign}
}
Acknowledgments
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 ephyalign-0.1.0.tar.gz.
File metadata
- Download URL: ephyalign-0.1.0.tar.gz
- Upload date:
- Size: 40.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f246e3468f8190828361ab01989fe35b1de8b022cea7d1969aae2eef901830d
|
|
| MD5 |
c2245ccce9f6bf0c5e7eda079394bb5c
|
|
| BLAKE2b-256 |
e2b1d9ba95809ddb1df3b03b231e317e9df0714ae0e8287d5814c7877b320cc6
|
Provenance
The following attestation bundles were made for ephyalign-0.1.0.tar.gz:
Publisher:
publish.yml on SMLoureiro/ephyalign
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ephyalign-0.1.0.tar.gz -
Subject digest:
7f246e3468f8190828361ab01989fe35b1de8b022cea7d1969aae2eef901830d - Sigstore transparency entry: 764212418
- Sigstore integration time:
-
Permalink:
SMLoureiro/ephyalign@174f7fbb41ef16c5b8b03002c9968c17242d30fd -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/SMLoureiro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@174f7fbb41ef16c5b8b03002c9968c17242d30fd -
Trigger Event:
release
-
Statement type:
File details
Details for the file ephyalign-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ephyalign-0.1.0-py3-none-any.whl
- Upload date:
- Size: 43.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 |
1cc62f34fecdb7862e40b1ffb5d3399037d4fce0a38dec678ff2993927acb61f
|
|
| MD5 |
c9b558170f3d9bf9b15807d7c5486521
|
|
| BLAKE2b-256 |
d331397d764aa0272452f7841f6fc8e1506700e4763512b4c92ce9692c461863
|
Provenance
The following attestation bundles were made for ephyalign-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on SMLoureiro/ephyalign
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ephyalign-0.1.0-py3-none-any.whl -
Subject digest:
1cc62f34fecdb7862e40b1ffb5d3399037d4fce0a38dec678ff2993927acb61f - Sigstore transparency entry: 764212420
- Sigstore integration time:
-
Permalink:
SMLoureiro/ephyalign@174f7fbb41ef16c5b8b03002c9968c17242d30fd -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/SMLoureiro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@174f7fbb41ef16c5b8b03002c9968c17242d30fd -
Trigger Event:
release
-
Statement type: