Python library for reading electrophysiology data from Axon Binary Format (ABF) files
npx @tessl/cli install tessl/pypi-pyabf@2.3.0A Python library for reading electrophysiology data from Axon Binary Format (ABF) files. pyabf provides an intuitive Pythonic API to access ABF file contents including sweep data, time series information, and command waveforms, making it ideal for electrophysiology research and data analysis workflows.
pip install pyabfimport pyabfFor accessing main classes:
from pyabf import ABF, ATFimport pyabf
# Load an ABF file
abf = pyabf.ABF("data.abf")
# Access basic file information
print(f"File contains {abf.sweepCount} sweeps")
print(f"Sample rate: {abf.sampleRate} Hz")
# Set the active sweep and access data
abf.setSweep(0)
voltage_data = abf.sweepY # ADC data (mV)
time_data = abf.sweepX # Time values (seconds)
command_data = abf.sweepC # Command waveform (DAC)
# Iterate through all sweeps
for sweepNumber in range(abf.sweepCount):
abf.setSweep(sweepNumber)
print(f"Sweep {sweepNumber}: {len(abf.sweepY)} data points")
# For ATF files (Axon Text Format)
atf = pyabf.ATF("data.atf")
atf.setSweep(0)
data = atf.sweepYpyabf is built around two main classes that provide similar interfaces:
The library uses a sweep-based access pattern where you set an active sweep and then access data through properties like sweepY, sweepX, and sweepC. This design allows efficient memory usage and intuitive data access patterns familiar to electrophysiologists.
Primary classes for loading and accessing ABF and ATF files, with sweep-based data access patterns and comprehensive metadata extraction.
class ABF:
def __init__(
self,
abfFilePath: Union[str, pathlib.Path],
loadData: bool = True,
cacheStimulusFiles: bool = True,
stimulusFileFolder: Union[str, None] = None
): ...
def setSweep(
self,
sweepNumber: int = 0,
channel: int = 0,
absoluteTime: bool = False
) -> None: ...
class ATF:
def __init__(
self,
atfFilePath: Union[str, pathlib.Path],
loadData: bool = True
): ...
def setSweep(self, sweepNumber: int = 0, channel: int = 0) -> None: ...Access to sweep data, time series, metadata, and file properties through the ABF/ATF object interfaces.
# Data access properties (available after setSweep)
@property
def sweepY(self) -> np.ndarray: ...
@property
def sweepX(self) -> np.ndarray: ...
@property
def sweepC(self) -> np.ndarray: ...
# File properties
@property
def sampleRate(self) -> int: ...
@property
def sweepCount(self) -> int: ...
def getAllYs(self, channelIndex: int = 0) -> np.ndarray: ...
def getAllXs(self, channelIndex: int = 0) -> np.ndarray: ...Functions and properties for accessing file metadata, header information, and generating various output formats.
def headerText(self) -> str: ...
def headerMarkdown(self) -> str: ...
def headerHTML(self) -> str: ...
def headerLaunch(self) -> None: ...
@property
def fileGUID(self) -> str: ...
@property
def md5(self) -> str: ...
@property
def fileUUID(self) -> str: ...Specialized analysis modules for action potential detection, membrane test analysis, and sweep-level measurements.
from pyabf.tools import ap, memtest, sweep
# Action potential analysis
def ap_points_currentSweep(
abf,
dVthresholdPos: float = 15,
betweenSec1: Union[float, None] = None,
betweenSec2: Union[float, None] = None
) -> List[int]: ...
class Memtest:
def __init__(self, abf: ABF, channel: int = 0): ...
def summary(self) -> str: ...Additional functionality including file writing, filtering, stimulus waveform handling, and deprecated plotting functions.
from pyabf import abfWriter, filter, stimulus
def writeABF1(
sweepData: np.ndarray,
filename: Union[str, pathlib.Path],
sampleRateHz: float,
units: str = 'pA'
) -> None: ...
def gaussian(abf: ABF, sigmaMs: float = 5, channel: int = 0) -> ABF: ...def info() -> None: ...
def showInfo() -> None: ...
def help() -> None: ...
__version__: strimport numpy as np
from typing import Union, List, Tuple
import pathlib
# Main types used throughout the API
Union[str, pathlib.Path] # File paths
np.ndarray # Data arrays
List[int] # Index lists
Tuple[str, str] # Name/unit pairs