Skip to main content

pyHEKA

Python Version License: GNU AGPL

pyHEKA (python Handling and Extraction Kit for .dat file Analysis) is a lightweight, efficient, and easy-to-use Python library for parsing and reading bundled .dat files created by HEKA Patchmaster or Patchmaster Next software. It supports several HEKA file versions including v9, v1000, and v2000 formats.

The library allows neuroscience researchers and electrophysiologists to load complex electrophysiology data tree structures directly into Python, access metadata, and read raw traces as NumPy arrays.


Features

  • Multi-version Support: Automatically detects and reads v9, v1000, and v2000 Patchmaster file versions.
  • Efficient Memory Footprint: Built on highly optimized data structures (e.g., using StructArray with indexed slicing for $O(N)$ parsing, and direct attribute lookup instead of bulky internal dictionary storage).
  • Comprehensive Metadata Access: Easily extract stimulation protocols, group/series/sweep labels, recording modes, and amplifier configurations.
  • Hierarchical Access: Reflects HEKA's internal structure: Group → Series → Sweep → Trace.
  • NumPy Integration: Directly access electrophysiology traces as standard NumPy arrays.

Installation

From PyPI

The pyheka package is available on PyPI.

pip install pyheka

From Source

Ensure you have Python 3.9+ and numpy installed. You can install pyHeka from source using pip:

git clone https://github.com/delvendahl/pyheka.git
cd pyheka
pip install .

For development work, you can install it in editable mode:

pip install -e .

Example Usage

Here is a quick overview of how to use pyHeka to load and inspect your .dat files. We recommend using a context manager when reading files:

1. Load a .dat Bundle

import pyheka

# Load your HEKA .dat file
with pyheka.Bundle("path/to/your/file.dat") as bundle:
    # Print basic info about the bundle format and metadata
    print(bundle)

For legacy support, you can also load a .DAT bundle without a context manager:

from pyheka import Bundle

# Load your HEKA .dat file
bundle = Bundle("path/to/your/file.dat")

# Print basic info about the bundle format and metadata
print(bundle)

2. Print a Summary of the Bundle

You can quickly get a brief or a detailed summary of the file content, including groups, series, sweeps, and stimulus protocols:

# Print brief summary
bundle.summary()

# Print detailed summary with recording modes and sweep counts
bundle.summary(detailed=True)

3. Navigate the HEKA Tree Hierarchy

HEKA's pulsed tree maps to standard Python indices:

# Access the pulsed tree
pul = bundle.pul

# Iterate over groups and series
for group in pul.children:
    print(f"Group: {group.Label}")
    for series in group.children:
        print(f"  Series: {series.Label}, Sweeps: {len(series)}")

4. Fetch Raw Electrophysiological Data

You can load the actual raw trace data into NumPy arrays using the .data property:

group_idx = 0
series_idx = 0
sweep_idx = 0
trace_idx = 0

# Retrieve data for the specific trace as a NumPy array
trace_data = bundle.data[group_idx, series_idx, sweep_idx, trace_idx]

print("Shape of trace data array:", trace_data.shape)
print("Trace sample values:", trace_data[:10])

There are convenience methods to fetch entire series or sweeps, with options to concatenate or average sweeps. The following example shows how to fetch series #0 from group #0 without concatenating or averaging sweeps:

with pyheka.Bundle('path/to/your/file.dat') as bundle:
    series_data = bundle.get_series(group_index=0, series_index=0, concatenate_sweeps=False, average_sweeps=False)

plt.plot(series_data.x, series_data.y[0])  # Plotting the first sweep
plt.xlabel(f'Time ({series_data.x_unit})')
plt.ylabel(f'Data ({series_data.y_unit})')
plt.title(f'Series {series_data.series_idx} data from {series_data.filename}')
plt.show()

Development & Testing

To run the unit tests, run:

python3 -m unittest discover -s tests -p "test_*.py"

Acknowledgements

The code is based on work by Luke Campagnola (https://github.com/campagnola/heka_reader). Additional contributions and improvements have been made to enhance performance, usability, and compatibility with different .dat file versions.

Note: "Heka" in the package name refers to HEKA Elektronik (now part of Harvard Bioscience), the manufacturer of the Patchmaster software and amplifiers this package supports. The backronym above is just a fun reinterpretation for the README — not an official expansion.

License

This project is licensed under the GNU AGPL License. See the LICENSE file for details.

Metadata

Release files for pyheka 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyheka 1.0.1
File Size Uploaded
pyheka-1.0.1.tar.gz 35.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyheka 1.0.1
File Interpreter ABI Platform
pyheka-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 67.3 kB

Release files / pyheka-1.0.1.tar.gz

Download URL pyheka-1.0.1.tar.gz
Size 35.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d799bf4f4d7c839af988830593950e218cb02c1920c5cd496c1cb6227511924e
BLAKE2b-256 checksum
How to use checksums
cb0c3f6f4fd69caee30bd3bc0429df7a70ba1b1717a4ee6ec3e6c2c450bc28b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Release files / pyheka-1.0.1-py3-none-any.whl

Download URL pyheka-1.0.1-py3-none-any.whl
Size 31.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
218cb7910eb6b3b31db5bb946ec19ed11db8f41ffacbc0804e70a808a7346883
BLAKE2b-256 checksum
How to use checksums
ccf65c6d0fd45f0e9e28ddc1e4a16605668b24969319774967b83f18af322571
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.14

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page