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 Source

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

git clone https://github.com/delvendahl/HekaDatReader.git
cd HekaDatReader
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.0

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.0
File Size Uploaded
pyheka-1.0.0.tar.gz 35.3 kB Details

Built distribution (wheel)

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

Total release size: 67.1 kB

Release files / pyheka-1.0.0.tar.gz

Download URL pyheka-1.0.0.tar.gz
Size 35.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8bf609d9e24146b7402a08d0aaf5abd30132fd6a7540a40adeb58211ac0be835
BLAKE2b-256 checksum
How to use checksums
1f1533e877d1a435b982c0d33d25fb30d809c83b665ba606aadc24f806d6d29d
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.0-py3-none-any.whl

Download URL pyheka-1.0.0-py3-none-any.whl
Size 31.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd07f04a59216faad68ff6b08395100320aa15e867862052762d9d85cb3d8698
BLAKE2b-256 checksum
How to use checksums
032d48bc1590fdab2fab662180198fcfb1fedca010bb48dbcb0d3c7461a10b15
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

1.0.1

2 release files

This release

1.0.0 This release

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