Skip to content

Commit 5ff3563

Browse files
author
Benjamin Moody
committed
multi_to_single: set samps_per_frame attribute.
When reading a multi-segment record, the samps_per_frame attribute must be copied from the layout segment into the resulting flattened record. (Unlike most other signal attributes, samples per frame must be uniform for a particular signal. The layout header must be used to determine the correct number of samples per frame for signals that are not present in the selected segments.)
1 parent 89cfe76 commit 5ff3563

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

wfdb/io/record.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,14 @@ def multi_to_single(self, physical, return_res=64):
13001300
# Figure out single segment fields to set for the new Record
13011301
if self.layout == "fixed":
13021302
# Get the fields from the first segment
1303-
for attr in ["fmt", "adc_gain", "baseline", "units", "sig_name"]:
1303+
for attr in [
1304+
"fmt",
1305+
"adc_gain",
1306+
"baseline",
1307+
"units",
1308+
"sig_name",
1309+
"samps_per_frame",
1310+
]:
13041311
fields[attr] = getattr(self.segments[0], attr)
13051312
else:
13061313
# For variable layout records, inspect the segments for the
@@ -1311,9 +1318,14 @@ def multi_to_single(self, physical, return_res=64):
13111318
# must have the same fmt, gain, baseline, and units for all
13121319
# segments.
13131320

1321+
# For either physical or digital conversion, all signals
1322+
# of the same name must have the same samps_per_frame,
1323+
# which must match the value in the layout header.
1324+
13141325
# The layout header should be updated at this point to
1315-
# reflect channels. We can depend on it for sig_name, but
1316-
# not for fmt, adc_gain, units, and baseline.
1326+
# reflect channels. We can depend on it for sig_name and
1327+
# samps_per_frame, but not for fmt, adc_gain, units, and
1328+
# baseline.
13171329

13181330
# These signal names will be the key
13191331
signal_names = self.segments[0].sig_name
@@ -1325,6 +1337,7 @@ def multi_to_single(self, physical, return_res=64):
13251337
"adc_gain": n_sig * [None],
13261338
"baseline": n_sig * [None],
13271339
"units": n_sig * [None],
1340+
"samps_per_frame": self.segments[0].samps_per_frame,
13281341
}
13291342

13301343
# For physical signals, mismatched fields will not be copied
@@ -1346,7 +1359,19 @@ def multi_to_single(self, physical, return_res=64):
13461359
reference_fields[field][ch] = item_ch
13471360
# mismatch case
13481361
elif reference_fields[field][ch] != item_ch:
1349-
if physical:
1362+
if field == "samps_per_frame":
1363+
raise ValueError(
1364+
"Incorrect samples per frame (%s != %s) "
1365+
"for signal %s in segment %s of %s"
1366+
% (
1367+
item_ch,
1368+
reference_fields[field][ch],
1369+
signal_names[ch],
1370+
seg.record_name,
1371+
self.record_name,
1372+
)
1373+
)
1374+
elif physical:
13501375
mismatched_fields.append(field)
13511376
else:
13521377
raise Exception(

0 commit comments

Comments
 (0)