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
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Unreleased
**Raise minimum versions of dependencies**
The minimum versions of ``soundfile`` (0.12.1), ``matplotlib`` (3.8.0) and ``requests`` (2.31.0) have been raised. The minimum versions of the other dependencies are unchanged.

**Read units containing any non-whitespace characters**
Header files with units containing characters such as ``.`` or ``*`` (for example ``a.u.`` or ``uV*s``) are now read correctly. The units used to be cut off at the first such character, and the rest of the signal line (ADC resolution, ADC zero and so on) ended up in the signal name.

**Add timeouts to requests for remote files**
Requests for files on PhysioNet (and other web servers) now time out if the server does not respond (10 seconds to connect, and 60 seconds to wait for data), instead of waiting indefinitely. A ``requests.exceptions.Timeout`` (``ConnectTimeout`` or ``ReadTimeout``) is raised in this case.

Expand Down
2 changes: 1 addition & 1 deletion src/wfdb/io/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HeaderSyntaxError(ValueError):
\+?(?P<byte_offset>\d*)
[ \t]* (?P<adc_gain>-?\d*\.?\d*e?[\+-]?\d*)
\(?(?P<baseline>-?\d*)\)?
/?(?P<units>[\w\^\-\?%\/]*)
/?(?P<units>\S*)
[ \t]* (?P<adc_res>\d*)
[ \t]* (?P<adc_zero>-?\d*)
[ \t]* (?P<init_value>-?\d*)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,25 @@ def test_header_with_non_utf8(self):
]
assert record.units.__eq__(sig_units_target)

@pytest.mark.parametrize("units", ["mV", "a.u.", "uV*s", "mmHg/s", "10^-3"])
def test_units_round_trip(self, units, temp_path):
"""Units with any non-whitespace characters are read back unchanged."""
wfdb.wrsamp(
"units",
fs=100,
units=[units],
sig_name=["ECG II"],
d_signal=np.array([[1], [2]]),
fmt=["16"],
adc_gain=[1.5],
baseline=[0],
write_dir=temp_path,
)
header = wfdb.rdheader(os.path.join(temp_path, "units"))
assert header.units == [units]
assert header.sig_name == ["ECG II"]
assert header.adc_res == [16]


class TestMultiRecord:
"""Test read and write of multi segment WFDB records, including PhysioNet streaming.
Expand Down
Loading