Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions changelog.d/header-text-roundtrip.rst

This file was deleted.

8 changes: 0 additions & 8 deletions changelog.d/recorddata-read-record.rst

This file was deleted.

66 changes: 40 additions & 26 deletions demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
"## Inspect a header and read a selection\n",
"\n",
"`read_header` returns an immutable description of the file. `read_record`\n",
"returns a mutable record containing the selected signal values. `stop`\n",
"is exclusive, and `channels` selects channels by index."
"returns `RecordData`, with editable signal values and fixed metadata.\n",
"Choose the sample layout explicitly. `stop` is exclusive, and `channels`\n",
"selects channels by index."
]
},
{
Expand All @@ -54,8 +55,11 @@
"print(header.record_name, header.fs, header.n_signals)\n",
"print([(signal.name, signal.format) for signal in header.signals])\n",
"\n",
"record = wfdb.read_record(data / \"100\", stop=2000, channels=[0])\n",
"print(record.signal_names, record.n_frames, record.p_signal.shape)"
"record = wfdb.read_record(\n",
" data / \"100\", stop=2000, channels=[0], layout=\"uniform\"\n",
")\n",
"print(record.metadata.signals[0].name, record.metadata.n_frames)\n",
"print(record.signals.values.shape)"
]
},
{
Expand All @@ -64,17 +68,22 @@
"metadata": {},
"outputs": [],
"source": [
"fig = wfdb.plot_wfdb(record=record, title=\"MIT-BIH record 100\", return_fig=True)\n",
"fig = wfdb.plot_wfdb(\n",
" record=record.to_legacy_record(),\n",
" title=\"MIT-BIH record 100\",\n",
" return_fig=True,\n",
")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`read_signals` is useful when you want exactly one signal representation.\n",
"Choose a layout explicitly: `\"uniform\"` gives one value per channel per\n",
"base frame; `\"expanded\"` retains every sample of each channel."
"`read_record` loads one signal representation at a time. `kind=\"digital\"`\n",
"returns masked integer arrays; `kind=\"physical\"` returns floating values.\n",
"`plot_wfdb` still takes a legacy `Record`, so the plot above uses\n",
"`to_legacy_record()` at that boundary."
]
},
{
Expand All @@ -83,8 +92,9 @@
"metadata": {},
"outputs": [],
"source": [
"selected = wfdb.read_signals(\n",
" data / \"100\", stop=2000, channels=[0], layout=\"uniform\"\n",
"selected = wfdb.read_record(\n",
" data / \"100\", stop=2000, channels=[0],\n",
" kind=\"digital\", layout=\"uniform\"\n",
")\n",
"print(selected.signals.kind, selected.signals.values.shape)\n",
"print(selected.metadata.n_frames, selected.metadata.signals[0].name)"
Expand Down Expand Up @@ -113,7 +123,8 @@
"print(annotations.symbols[:5])\n",
"\n",
"fig = wfdb.plot_wfdb(\n",
" record=record, annotation=annotations, title=\"Signal and annotations\",\n",
" record=record.to_legacy_record(), annotation=annotations,\n",
" title=\"Signal and annotations\",\n",
" return_fig=True,\n",
")\n",
"plt.show()"
Expand All @@ -127,8 +138,8 @@
"\n",
"A channel can contain more than one sample per base frame. Expanded\n",
"reads return a separate array for each channel. A multi-segment record\n",
"instead describes a sequence of segments; use `combine_segments=False`\n",
"to inspect the container and its segment records."
"instead describes a sequence of segments; use `read_segments` to\n",
"inspect the uncombined segments."
]
},
{
Expand All @@ -137,18 +148,17 @@
"metadata": {},
"outputs": [],
"source": [
"expanded = wfdb.read_signals(\n",
"expanded = wfdb.read_record(\n",
" data / \"test01_00s_frame\", stop=4, layout=\"expanded\"\n",
")\n",
"print(\"Samples per frame:\", expanded.signals.samples_per_frame)\n",
"print(\"Array lengths:\", [len(values) for values in expanded.signals.values])\n",
"\n",
"multi = wfdb.read_record(\n",
" data / \"multi-segment/041s/041s\", stop=10, combine_segments=False\n",
"multi = wfdb.read_segments(\n",
" data / \"multi-segment/041s/041s\", stop=10, layout=\"uniform\"\n",
")\n",
"print(\"Segments:\", [\n",
" segment.record_name if segment is not None else \"~\"\n",
" for segment in multi.segments\n",
" segment.name for segment in multi.segments\n",
"])"
]
},
Expand All @@ -169,16 +179,18 @@
"metadata": {},
"outputs": [],
"source": [
"ecg = wfdb.read_record(data / \"100\", stop=15000, channels=[0])\n",
"ecg = wfdb.read_record(\n",
" data / \"100\", stop=15000, channels=[0], layout=\"uniform\"\n",
")\n",
"reference = wfdb.read_annotations(data / \"100.atr\", stop=15000)\n",
"detected = processing.xqrs_detect(\n",
" signal=ecg.p_signal[:, 0], fs=ecg.fs, verbose=False\n",
" signal=ecg.signals.values[:, 0], fs=ecg.metadata.fs, verbose=False\n",
")\n",
"comparator = processing.compare_annotations(\n",
" ref_sample=reference.sample_indices[1:],\n",
" test_sample=detected,\n",
" window_width=int(0.1 * ecg.fs),\n",
" signal=ecg.p_signal[:, 0],\n",
" window_width=int(0.1 * ecg.metadata.fs),\n",
" signal=ecg.signals.values[:, 0],\n",
")\n",
"assert isinstance(comparator, processing.Comparator)\n",
"comparator.print_summary()"
Expand All @@ -199,7 +211,7 @@
"source": [
"## Write a copy safely\n",
"\n",
"These examples write into a temporary directory. `Record.write` takes\n",
"These examples write into a temporary directory. `RecordData.write` takes\n",
"a destination stem; `Annotation.write` takes the complete annotation\n",
"filename. Neither method changes the source object."
]
Expand All @@ -215,9 +227,9 @@
" record.write(stem)\n",
" annotations.write(stem.with_suffix(\".atr\"))\n",
"\n",
" copied_record = wfdb.read_record(stem)\n",
" copied_record = wfdb.read_record(stem, layout=\"uniform\")\n",
" copied_annotations = wfdb.read_annotations(stem.with_suffix(\".atr\"))\n",
" assert copied_record.p_signal.shape == record.p_signal.shape\n",
" assert copied_record.signals.values.shape == record.signals.values.shape\n",
" assert np.array_equal(\n",
" copied_annotations.sample_indices, annotations.sample_indices\n",
" )\n",
Expand All @@ -234,7 +246,9 @@
"explicit `physionet://` path reads the corresponding hosted files:\n",
"\n",
"```python\n",
"online = wfdb.read_record(\"physionet://mitdb/1.0.0/100\", stop=2000)\n",
"online = wfdb.read_record(\n",
" \"physionet://mitdb/1.0.0/100\", stop=2000, layout=\"uniform\"\n",
")\n",
"online_annotations = wfdb.read_annotations(\n",
" \"physionet://mitdb/1.0.0/100.atr\", stop=2000\n",
")\n",
Expand Down
35 changes: 35 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,41 @@ This page lists recent changes in the `wfdb` package (since version 4.0.0) that

.. towncrier release notes start

Version 6.0.0 (Dec 2026)
------------------------

This major release makes ``read_record`` the single modern reader for a
combined record. It now returns ``RecordData`` with editable signal arrays,
fixed metadata, and source provenance, instead of a mutable ``Record`` or
``MultiRecord``. Use ``rdrecord`` when the legacy mutable objects are needed,
and ``read_segments`` when segment boundaries must be retained. The modern
``read_signals`` function and public ``SignalRead`` aliases are removed. The
legacy API remains available. See :doc:`migration` for replacement calls and
field names.

Header reading now preserves Unicode and comment text across local, remote,
and archive sources. Some previously decoded text can therefore change;
signal values and file formats are unchanged by the API switch.

**Make read_record return RecordData in 6.0**
``read_record`` now returns a ``RecordData`` with one selected signal form,
fixed metadata, editable arrays, and source provenance. Use ``read_segments``
for uncombined segments. ``read_signals`` and the public ``SignalRead``
aliases are removed; ``wfdb.io.signal_values.SignalRead`` remains for old
pickles. Errors for removed names and the old ``combine_segments`` argument
name their replacements. The mutable ``Record`` and ``MultiRecord`` remain
available through ``rdrecord``. See the migration guide for code changes.

**Preserve Unicode and comment text in WFDB headers**
Header reads now decode each whole file as UTF-8, falling back to Latin-1
when the bytes are not valid UTF-8. Local, cloud, PhysioNet, and ``.wfdb``
archive sources use the same rule instead of silently dropping bytes or
interpreting UTF-8 as Latin-1. A Latin-1 source written again uses UTF-8.
Comments now retain leading and trailing spaces and ``#`` characters after
the comment marker. ``RecordData.with_channels`` and ``with_comments``
accept printable Unicode and comments with edge spaces or ``#``. Existing
code reading non-ASCII headers or comments may now receive different text.

Version 5.18.0 (Dec 2026)
-------------------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "uv_build"

[project]
name = "wfdb"
version = "5.18.0"
version = "6.0.0"
description = "Read, write, plot, and process physiologic waveforms and annotations."
authors = [{name = "The Laboratory for Computational Physiology", email = "contact@physionet.org"}]
license = "MIT"
Expand Down
Loading