Skip to content

Commit 768d833

Browse files
author
Benjamin Moody
committed
Record.wrsamp: ignore samps_per_frame when expanded is false.
When the expanded argument to wrsamp is false, we are writing the d_signal data, which contains one sample per frame by definition. Therefore, the header file must not claim that the signal files will contain multiple samples per frame. The samps_per_frame attribute of the Record object may or may not be set appropriately for the actual data contained in the Record object; for example, rdrecord(r, smooth_frames=True) will set samps_per_frame according to the number of samples per frame in the original record.
1 parent cac2af6 commit 768d833

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

wfdb/io/_header.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def set_defaults(self):
278278
for f in sfields:
279279
self.set_default(f)
280280

281-
def wrheader(self, write_dir=""):
281+
def wrheader(self, write_dir="", expanded=True):
282282
"""
283283
Write a WFDB header file. The signals are not used. Before
284284
writing:
@@ -290,6 +290,10 @@ def wrheader(self, write_dir=""):
290290
----------
291291
write_dir : str, optional
292292
The output directory in which the header is written.
293+
expanded : bool, optional
294+
Whether the header file should include `samps_per_frame` (this
295+
should only be true if the signal files are written using
296+
`expanded=True`).
293297
294298
Returns
295299
-------
@@ -305,6 +309,8 @@ def wrheader(self, write_dir=""):
305309
# sig_write_fields is a dictionary of
306310
# {field_name:required_channels}
307311
rec_write_fields, sig_write_fields = self.get_write_fields()
312+
if not expanded:
313+
sig_write_fields.pop("samps_per_frame", None)
308314

309315
# Check the validity of individual fields used to write the header
310316
# Record specification fields (and comments)

wfdb/io/record.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ def wrsamp(self, expanded=False, write_dir=""):
924924
"""
925925
# Perform field validity and cohesion checks, and write the
926926
# header file.
927-
self.wrheader(write_dir=write_dir)
927+
self.wrheader(write_dir=write_dir, expanded=expanded)
928928
if self.n_sig > 0:
929929
# Perform signal validity and cohesion checks, and write the
930930
# associated dat files.

0 commit comments

Comments
 (0)