CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyabf

Python library for reading electrophysiology data from Axon Binary Format (ABF) files

Pending
Overview
Eval results
Files

data-access.mddocs/

Data Access and Properties

Access to sweep data, time series, metadata, and file properties through the ABF/ATF object interfaces. All data access properties require calling setSweep() first to select the active sweep and channel.

Capabilities

Primary Data Properties

Core data access properties available after calling setSweep().

# Data attributes (set by setSweep method)
sweepY: np.ndarray
    """
    ADC data for the current sweep and channel.
    
    Returns:
    numpy array of voltage/current measurements in native units
    (typically mV for voltage clamp, pA for current clamp)
    
    Note: Must call setSweep() before accessing this attribute
    """

sweepX: np.ndarray
    """
    Time values for the current sweep.
    
    Returns:
    numpy array of time points in seconds
    
    Behavior depends on absoluteTime parameter in setSweep():
    - False (default): Time from start of current sweep
    - True: Absolute time from start of recording
    """

@property
def sweepC(self) -> np.ndarray:
    """
    Command waveform (DAC) data for the current sweep.
    
    Returns:
    numpy array of command values in native units
    (typically mV for voltage commands, pA for current commands)
    
    Note: Returns the stimulus waveform applied during this sweep.
    Can also be used as setter: abf.sweepC = new_data
    """

Advanced Data Access

Additional data access methods and properties.

def sweepD(self, digOutNumber: int = 0) -> np.ndarray:
    """
    Digital output data for the current sweep.
    
    Parameters:
    - digOutNumber: Digital output channel number (0-based)
    
    Returns:
    numpy array of digital output states (0 or 1)
    """

@property
def sweepTimesSec(self) -> np.ndarray:
    """
    Time values in seconds for current sweep.
    
    Returns:
    numpy array of time points in seconds
    """

@property  
def sweepTimesMin(self) -> np.ndarray:
    """
    Time values in minutes for current sweep.
    
    Returns:
    numpy array of time points in minutes
    """

@property
def sweepDerivative(self) -> np.ndarray:
    """
    Derivative of the current sweep data.
    
    Returns:
    numpy array representing dY/dt of current sweep
    """

Multi-Sweep Data Access

Methods for accessing data across all sweeps.

def getAllYs(self, channelIndex: int = 0) -> np.ndarray:
    """
    Get all sweep data for a specific channel.
    
    Parameters:
    - channelIndex: Zero-indexed channel number
    
    Returns:
    1D numpy array containing all data for the specified channel
    """

def getAllXs(self, channelIndex: int = 0) -> np.ndarray:
    """
    Get time array for a specific channel.
    
    Parameters:
    - channelIndex: Zero-indexed channel number
    
    Returns:
    1D numpy array of time points in seconds
    """

File Properties

Core properties describing the file and data structure.

@property
def sweepCount(self) -> int:
    """Number of sweeps in the file."""

@property
def channelCount(self) -> int:
    """Number of data channels."""

# File attributes
sweepPointCount: int
    """Number of data points per sweep."""

@property
def sampleRate(self) -> int:
    """Sample rate in Hz."""

dataRate: float
    """Data acquisition rate."""

Channel Information

Attributes for accessing channel names and units.

# Channel attributes (lists)
adcNames: List[str]
    """List of ADC channel names."""

adcUnits: List[str]
    """List of ADC channel units."""

dacNames: List[str]
    """List of DAC channel names."""

dacUnits: List[str]
    """List of DAC channel units."""

Usage Examples

import pyabf
import numpy as np

# Load file and access single sweep data
abf = pyabf.ABF("recording.abf")
abf.setSweep(0)

# Basic data access
voltage = abf.sweepY      # ADC data (e.g., membrane potential)
time = abf.sweepX         # Time points
command = abf.sweepC      # Command waveform (e.g., current injection)

print(f"Sweep duration: {time[-1]} seconds")
print(f"Data points: {len(voltage)}")
print(f"Sample rate: {abf.sampleRate} Hz")

# Access different sweeps
for sweep_num in range(abf.sweepCount):
    abf.setSweep(sweep_num)
    max_voltage = np.max(abf.sweepY)
    print(f"Sweep {sweep_num} max voltage: {max_voltage} mV")

# Multi-channel data
if abf.channelCount > 1:
    for channel in range(abf.channelCount):
        abf.setSweep(0, channel=channel)
        data = abf.sweepY
        print(f"Channel {channel} ({abf.adcNames[channel]}): "
              f"{len(data)} points in {abf.adcUnits[channel]}")

# Get all data at once
all_sweeps = abf.getAllYs(channelIndex=0)  # Shape: (sweeps, points)
all_times = abf.getAllXs(channelIndex=0)

# Calculate mean across all sweeps
mean_sweep = np.mean(all_sweeps, axis=0)

# Access digital outputs
abf.setSweep(0)
digital_out = abf.sweepD(digOutNumber=0)

# Absolute time mode
abf.setSweep(5, absoluteTime=True)
absolute_time = abf.sweepX  # Time from recording start

Data Units and Scaling

# Data is automatically scaled to appropriate units
# ADC data: typically mV (voltage) or pA (current) 
# DAC data: typically mV (voltage commands) or pA (current commands)
# Time data: always in seconds
# Digital data: 0 or 1 (boolean states)

# Channel units are available via:
voltage_units = abf.adcUnits[0]  # e.g., "mV"
command_units = abf.dacUnits[0]  # e.g., "pA"

Install with Tessl CLI

npx tessl i tessl/pypi-pyabf

docs

analysis-tools.md

core-file-access.md

data-access.md

file-information.md

index.md

utilities.md

tile.json