Skip to content

WIP: Add support for reading and writing .wfdb archive files - #541

Open
tompollard wants to merge 14 commits into
mainfrom
tp/wfdb_file
Open

WIP: Add support for reading and writing .wfdb archive files#541
tompollard wants to merge 14 commits into
mainfrom
tp/wfdb_file

Conversation

@tompollard

@tompollardtompollard commented May 3, 2025

Copy link
Copy Markdown
Member

As discussed in wfdb/wfdb-spec#21 and #540 we would like to allow WFDB Records to be saved to a single file .wfdb.

This pull request introduces support for reading and writing .wfdb archive files, a ZIP-based format that stores .hea, .dat, and related files in a single container.

Implementation

  • Adds WFDBArchive class to handle reading/writing of .wfdb archives
  • Archives are implemented as uncompressed ZIP files for maximum simplicity
  • Two ways to create archives:
    1. Inline creation via wrsamp(..., wfdb_archive=...) which writes files directly to the archive
    2. Two-step creation via wrsamp(...) followed by WFDBArchive.create_archive(...) which writes files to disk first
  • Adds support for reading records directly from .wfdb archives via rdrecord()
  • Adds tests covering:
    • Round-trip read/write of archives
    • Reading subset of channels
    • Reading partial samples
    • Error handling for missing files
    • Both inline and two-step archive creation methods

Example usage

importwfdbfromwfdb.io.archiveimportWFDBArchiveimportnumpyasnp# 1. Read an existing WFDB recordrecord=wfdb.rdrecord('sample-data/test01_00s')
# 2. Convert physical signals to digital signals# Side note, but this shouldn't be necessary.# ...or at least the write error should be clearer.record.d_signal=record.adc()
# 3. Write the record to the archiverecord.wrsamp(wfdb_archive="new_archive.wfdb")
# 4. Read back from the archivearchive_record=wfdb.rdrecord('new_archive.wfdb')
# 5. Verify the data matchesassertrecord.fs==archive_record.fsassertrecord.n_sig==archive_record.n_sigassertrecord.sig_name==archive_record.sig_nameassertrecord.units==archive_record.unitsassertrecord.p_signal.shape==archive_record.p_signal.shape

@tompollard
tompollardforce-pushed the tp/wfdb_file branch 4 times, most recently from c4050c3 to ff7aba3CompareMay 29, 2025 18:19
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@tompollard