From 6fc9a2d407c6c3086da4cde2abfed16fa7288a2b Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Fri, 4 Dec 2026 16:22:25 -0500 Subject: [PATCH] Prepare wfdb 6.0.0 release --- changelog.d/header-text-roundtrip.rst | 9 ---- changelog.d/recorddata-read-record.rst | 8 ---- demo.ipynb | 66 ++++++++++++++++---------- docs/changes.rst | 35 ++++++++++++++ pyproject.toml | 2 +- 5 files changed, 76 insertions(+), 44 deletions(-) delete mode 100644 changelog.d/header-text-roundtrip.rst delete mode 100644 changelog.d/recorddata-read-record.rst diff --git a/changelog.d/header-text-roundtrip.rst b/changelog.d/header-text-roundtrip.rst deleted file mode 100644 index 723cada2..00000000 --- a/changelog.d/header-text-roundtrip.rst +++ /dev/null @@ -1,9 +0,0 @@ -**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. diff --git a/changelog.d/recorddata-read-record.rst b/changelog.d/recorddata-read-record.rst deleted file mode 100644 index 3f3f6c58..00000000 --- a/changelog.d/recorddata-read-record.rst +++ /dev/null @@ -1,8 +0,0 @@ -**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. diff --git a/demo.ipynb b/demo.ipynb index 3e1b8cec..6feba5a3 100644 --- a/demo.ipynb +++ b/demo.ipynb @@ -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." ] }, { @@ -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)" ] }, { @@ -64,7 +68,11 @@ "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()" ] }, @@ -72,9 +80,10 @@ "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." ] }, { @@ -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)" @@ -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()" @@ -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." ] }, { @@ -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", "])" ] }, @@ -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()" @@ -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." ] @@ -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", @@ -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", diff --git a/docs/changes.rst b/docs/changes.rst index f9a47da3..6f8566f9 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -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) ------------------------- diff --git a/pyproject.toml b/pyproject.toml index fecf2eb1..1e8ef8e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"