Python library for reading electrophysiology data from Axon Binary Format (ABF) files
—
Primary classes and functions for loading and accessing Axon Binary Format (ABF) and Axon Text Format (ATF) files. These classes provide the foundation for all data access operations in pyabf.
Main class for reading ABF files (both ABF1 and ABF2 formats). Provides comprehensive access to electrophysiology data with sweep-based organization.
class ABF:
def __init__(
self,
abfFilePath: Union[str, pathlib.Path],
loadData: bool = True,
cacheStimulusFiles: bool = True,
stimulusFileFolder: Union[str, None] = None
):
"""
Load header and sweep data from an ABF file.
Parameters:
- abfFilePath: Path to the ABF file
- loadData: Whether to load sweep data immediately on instantiation.
Set to False for faster header-only access when iterating many files.
- cacheStimulusFiles: Whether stimulus files should be cached in memory
- stimulusFileFolder: Alternate search path for stimulus files
Raises:
- ValueError: If ABF file does not exist
- Exception: If path is a directory or if ATF file is passed
"""Class for reading Axon Text Format files with an API similar to the ABF class.
class ATF:
def __init__(
self,
atfFilePath: Union[str, pathlib.Path],
loadData: bool = True
):
"""
Load header and sweep data from an ATF file.
Parameters:
- atfFilePath: Path to the ATF file
- loadData: Whether to parse sweep data values on instantiation
Raises:
- Exception: If file does not exist, path is directory, or ABF file is passed
"""Both ABF and ATF classes use sweep-based data access. You must set the active sweep before accessing data properties.
def setSweep(
self,
sweepNumber: int,
channel: int = 0,
absoluteTime: bool = False,
baseline: List[float] = [None, None]
) -> None:
"""
Set the active sweep and channel for data access (ABF class).
Parameters:
- sweepNumber: Zero-indexed sweep number to access (required)
- channel: Zero-indexed channel number to access
- absoluteTime: If True, sweepX shows absolute time from recording start
If False, sweepX shows time from sweep start
- baseline: Time range in seconds for baseline subtraction [start, end].
Use [None, None] to disable baseline subtraction.
Note: After calling setSweep(), use sweepY, sweepX, sweepC properties to access data
"""def setSweep(self, sweepNumber: int = 0, channel: int = 0) -> None:
"""
Set the active sweep and channel for data access (ATF class).
Parameters:
- sweepNumber: Zero-indexed sweep number to access
- channel: Zero-indexed channel number to access
Note: ATF class does not support absoluteTime or baseline parameters
"""Functions for saving and launching ABF files in different formats and programs.
def saveABF1(self, filePath: Union[str, pathlib.Path]) -> None:
"""
Save this ABF file as an ABF1 file compatible with ClampFit and MiniAnalysis.
Parameters:
- filePath: Path where the ABF1 file should be saved
Note: Not all header values are saved, but the minimum necessary are included
for reading sweep data in older analysis programs.
"""
def launchInClampFit(self) -> None:
"""
Launch the ABF in the default ABF viewing program (usually ClampFit).
This opens the file as if it were double-clicked in Windows Explorer.
Assumes ClampFit is installed and will fail if ClampFit is already open.
Note: Windows-specific functionality
"""# ABF files (binary format)
abf = ABF("recording.abf")
# ATF files (text format)
atf = ATF("recording.atf")import pyabf
# Basic ABF file loading
abf = pyabf.ABF("data.abf")
print(f"Loaded ABF with {abf.sweepCount} sweeps")
# Header-only loading for fast iteration
abf_header_only = pyabf.ABF("data.abf", loadData=False)
print(f"File info: {abf_header_only.abfID}")
# ATF file loading
atf = pyabf.ATF("data.atf")
print(f"ATF version: {atf.atfVersion}")
# Sweep selection and data access
abf.setSweep(0, channel=0)
voltage = abf.sweepY
time = abf.sweepX
# Absolute time mode
abf.setSweep(0, absoluteTime=True)
absolute_time = abf.sweepX # Time from recording start
# Multi-channel access
for channel in range(abf.channelCount):
abf.setSweep(0, channel=channel)
channel_data = abf.sweepY
print(f"Channel {channel}: {len(channel_data)} points")# Available after instantiation
@property
def abfFilePath(self) -> str: ... # Absolute path to ABF file
@property
def abfFolderPath(self) -> str: ... # Directory containing ABF file
@property
def abfID(self) -> str: ... # Filename without extension
# For ATF files
@property
def atfFilePath(self) -> str: ...
@property
def atfID(self) -> str: ...Install with Tessl CLI
npx tessl i tessl/pypi-pyabf