Python library for reading electrophysiology data from Axon Binary Format (ABF) files
—
Functions and properties for accessing file metadata, header information, and generating various output formats. These provide detailed information about ABF file structure, recording parameters, and experimental conditions.
Properties and methods for accessing and displaying comprehensive header information in various formats.
@property
def headerText(self) -> str:
"""
Get header information as formatted text.
Returns:
Multi-line string containing detailed file header information
including acquisition parameters, channel settings, and protocol details
"""
@property
def headerMarkdown(self) -> str:
"""
Get header information formatted as markdown.
Returns:
Markdown-formatted string with header information
suitable for documentation or reports
"""
@property
def headerHTML(self) -> str:
"""
Get header information formatted as HTML.
Returns:
HTML-formatted string with header information
suitable for web display
"""
def headerLaunch(self) -> None:
"""
Launch header information in default web browser.
Creates a temporary HTML file with header information
and opens it in the system's default browser
"""Properties for uniquely identifying and verifying files.
@property
def fileGUID(self) -> str:
"""
File GUID (Globally Unique Identifier).
Returns:
String representation of the file's GUID
"""
@property
def md5(self) -> str:
"""
MD5 hash of the file.
Returns:
Hexadecimal string representing the file's MD5 checksum
Useful for verifying file integrity
"""
@property
def fileUUID(self) -> str:
"""
File UUID (Universally Unique Identifier).
Returns:
String representation of the file's UUID
"""Methods for saving and converting ABF files to different formats.
def saveABF1(self, filePath: Union[str, pathlib.Path]) -> None:
"""
Save current ABF data as ABF1 format file.
Parameters:
- filePath: Path where the ABF1 file should be saved
Note: Converts ABF2 files to ABF1 format for compatibility
with older software that requires ABF1 format
"""
def launchInClampFit(self) -> None:
"""
Launch the current ABF file in ClampFit software.
Attempts to open the file using the system's associated
application for ABF files (typically ClampFit)
Raises:
- Exception: If ClampFit is not installed or file cannot be opened
"""Attributes providing information about the recording session and experimental conditions.
# Recording metadata attributes
abfDateTime: datetime
"""Date and time when the recording was made."""
abfDateTimeString: str
"""Human-readable date/time string for the recording."""
protocol: str
"""Name of the acquisition protocol used."""
abfFileComment: str
"""User comment associated with the recording."""
creator: str
"""Name of the software that created the file."""
creatorVersion: str
"""Version of the creator software."""Additional file format and version information.
# File format attributes
abfVersion: str
"""ABF file format version (e.g., '1.83', '2.0')."""
dataPointCount: int
"""Total number of data points in the file."""
dataLengthSec: float
"""Total recording duration in seconds."""
dataLengthMin: float
"""Total recording duration in minutes."""import pyabf
from datetime import datetime
# Load ABF file
abf = pyabf.ABF("recording.abf")
# Basic file information
print(f"File GUID: {abf.fileGUID}")
print(f"MD5 hash: {abf.md5}")
print(f"Recording date: {abf.abfDateTimeString}")
print(f"Protocol: {abf.protocol}")
# Display header information (properties, not methods)
header_text = abf.headerText
print("=== Header Information ===")
print(header_text)
# Launch header in browser for detailed viewing
abf.headerLaunch()
# Get markdown formatted header for documentation
markdown_header = abf.headerMarkdown
with open("recording_info.md", "w") as f:
f.write(markdown_header)
# File verification using MD5
file_hash = abf.md5
print(f"File integrity hash: {file_hash}")
# Recording metadata
print(f"Created by: {abf.creator} v{abf.creatorVersion}")
print(f"Comment: {abf.abfFileComment}")
print(f"Protocol: {abf.protocol}")
# File format information
print(f"ABF version: {abf.abfVersion}")
print(f"Total data points: {abf.dataPointCount}")
print(f"Recording duration: {abf.dataLengthSec} seconds")
# Export to ABF1 format
abf.saveABF1("converted_recording.abf")
# Launch in ClampFit (if installed)
try:
abf.launchInClampFit()
except Exception as e:
print(f"Could not launch ClampFit: {e}")def __str__(self) -> str:
"""
String representation of the ABF object.
Returns:
Human-readable string with basic file information
"""
def __repr__(self) -> str:
"""
Developer representation of the ABF object.
Returns:
String suitable for debugging and development
"""Install with Tessl CLI
npx tessl i tessl/pypi-pyabf