Skip to main content

moberg-h5

Read the HDF5 files that Moberg's connect-client writes from CNS archives, and HDF5 exports from the Moberg Clinical Platform.

The package lists the measurements in a file, finds each one's timestamps, and reads a time range without loading the whole dataset. It depends on h5py and numpy. pandas is optional and only needed for read_frame.

Documentation:

  • HDF5 format: groups, dataset names, timestamps, attributes, regions and gaps, and the layouts written before format versioning.
  • Format changelog: what changed in each format_version.

Install

pip install moberg-h5
# with pandas support
pip install "moberg-h5[pandas]"

Python 3.10 or newer.

Example

from datetime import datetime, timezone

import moberg_h5

with moberg_h5.open("Patient_2026_Nov_04__10_00_00_000000.h5") as rec:
    print(rec.format_version, rec.attrs.get("converter_name"))
    for signal in rec.signals(kind="trend"):
        print(signal.path, signal.units)

    start = datetime(2026, 11, 4, 12, 0, tzinfo=timezone.utc)
    end = datetime(2026, 11, 4, 12, 10, tzinfo=timezone.utc)
    timestamps_us, icp = rec.read("Trends/ICP_Mean", start, end)
    eeg = rec.read_frame(rec.eeg_channels(), start, end)  # DataFrame, UTC index
    gaps = rec.gaps("EEG/C3", start, end)

Choosing a time window

time_range returns the first sample time and the time 1 µs after the last sample, so it can go straight into read, which reads start <= t < end:

from datetime import timedelta

with moberg_h5.open(path) as rec:
    print(rec.time_range())                       # whole file
    print(rec.summary(kind="trend"))              # one row per signal
    span = rec.time_range("Trends/ICP_Mean")
    t, icp = rec.read("Trends/ICP_Mean", *span)   # every row
    t, icp = rec.read("Trends/ICP_Mean", span.start, span.start + timedelta(minutes=10))

A TimeRange unpacks to (start_us, end_us) in integer microseconds. start and end give the same bounds as UTC datetimes; last_us and duration are also available. In a file with several archives the whole-file range includes the time between archives, so use archive=, summary() or regions() to find where there is data.

The range comes from the first and last timestamps. The start_time and end_time dataset attributes can be up to 1 µs late, which can drop the first sample when used as start.

API

Call Returns
moberg_h5.open(path) Recording, usable as a context manager
rec.format_version The file's "1.x" version string, or None for files written before format versioning
rec.attrs Root attributes: converter name and version, source archive, creation time
rec.archives Patient_* group names in a file that holds several archives
rec.signals(kind=None, archive=None) Signal list; kinds are eeg, qeeg, waveform, trend, other
rec.signal(path) One Signal by HDF5 path
rec.eeg_channels(modality="EEG", archive=None) Per-channel EEG datasets; pass "HFEEG" for high-frequency EEG
rec.read(signal, start=None, end=None) (timestamps_us, values) for start <= t < end
rec.read_frame(signals, start=None, end=None) pandas DataFrame indexed by UTC time; the signals must share one timestamps dataset
rec.time_range(signal=None, kind=None, archive=None) TimeRange from the first sample to 1 µs after the last, for one signal or all matching signals; None without samples
rec.summary(kind=None, archive=None) pandas DataFrame, one row per signal: archive, kind, start, end, duration, rows, sampling rate, gap count
rec.regions(signal, start=None, end=None), rec.gaps(signal, start=None, end=None) int64 (n, 2) arrays of microsecond times; start/end select the intervals that overlap them, without trimming their ends
rec.annotations() Annotation list with microsecond start and end times

Times passed to read, read_frame, regions and gaps can be integer microseconds since the Unix epoch, datetime (naive values are read as UTC), numpy.datetime64 or pandas.Timestamp. Timestamps come back as int64 microseconds since the Unix epoch, UTC.

A Signal carries the dataset path, its timestamps path as timestamps_path, units, sampling_rate (Hz, format 1.x only), the CNS label, location, source_device, data_type and representation, and for EEG the modality and channel.

In the file, each dataset's timestamps attribute holds the path of its timestamps dataset; moberg-h5 exposes that path as Signal.timestamps_path. Signal has no timestamps field: rec.read returns the timestamp values.

read_frame puts several signals in one frame only when they share a timestamps dataset, such as one archive's EEG channels. In a file with several archives, pick one with rec.eeg_channels(archive=rec.archives[0]).

EEG channels that were not recorded for part of a session (a montage change) hold NaN for those rows, so every channel lines up with the shared timestamps.

Format versions

Files written by newer converters carry a root attribute format_version in MAJOR.MINOR form. MINOR goes up when something is added; MAJOR goes up when a group, dataset or attribute is renamed, moved, removed or changes meaning.

File Support
No format_version (legacy) Best effort. Timestamps are found by naming convention, including the comma-named datasets written before January 2026; region and gap attributes from older files are read.
1.x Supported
2.0 and later Rejected with UnsupportedFormatVersion. Install a newer moberg-h5.

The layout is described in docs/hdf5-format.md and the changes in each version in docs/format-changelog.md.

Development

uv run pytest

Package releases are listed in CHANGELOG.md. Pushing a vX.Y.Z tag publishes to PyPI after a maintainer approves the deployment; .agents/skills/release/SKILL.md has the steps.

License

MIT. See LICENSE.

Metadata

Release files for moberg-h5 0.1.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 moberg-h5 0.1.1
File Size Uploaded Provenance Actions
moberg_h5-0.1.1.tar.gz 167.5 kB With provenance Details for moberg_h5-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for moberg-h5 0.1.1
File Interpreter ABI Platform Actions
moberg_h5-0.1.1-py3-none-any.whl Python 3 none any Details for moberg_h5-0.1.1-py3-none-any.whl

Total release size: 182.3 kB

Release files / moberg_h5-0.1.1.tar.gz

Download URL moberg_h5-0.1.1.tar.gz
Size 167.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b0edd54b39cd94d7f04e73eab2d889a128f5612a58ae0f70edad04eb1a8dbbd1
BLAKE2b-256 checksum
How to use checksums
c0fd7d1248b61f7c4244f240537f6cee609aa6e1ddbd6efcd9e95a2170c47394
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / moberg_h5-0.1.1-py3-none-any.whl

Download URL moberg_h5-0.1.1-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e189c8d7c74f11414e23077c04306227095023fec8711246dc224562e98a889
BLAKE2b-256 checksum
How to use checksums
ccaa69339db20712b6bab6680dafa9f87532af73572c3c013e9057716a0be7a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for moberg-h5 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for moberg_h5-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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