Skip to content

Commit b252a0b

Browse files
committed
add samps_per_frame segment validation
1 parent 857916a commit b252a0b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

wfdb/io/record.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,34 @@ def _check_segment_cohesion(self):
12261226
f"The signal length of segment {seg_num} does not match the corresponding segment length"
12271227
)
12281228

1229+
# If segment has expanded signals, validate samps_per_frame and signal lengths
1230+
if segment.e_d_signal is not None or segment.e_p_signal is not None:
1231+
expanded_signal = (
1232+
segment.e_d_signal
1233+
if segment.e_d_signal is not None
1234+
else segment.e_p_signal
1235+
)
1236+
1237+
if segment.samps_per_frame is None:
1238+
raise ValueError(
1239+
f"Segment {seg_num} has expanded signals but 'samps_per_frame' is not set"
1240+
)
1241+
1242+
for ch in range(segment.n_sig):
1243+
if segment.samps_per_frame[ch] is None:
1244+
raise ValueError(
1245+
f"Segment {seg_num}, channel {ch}: 'samps_per_frame' must be set for expanded signals"
1246+
)
1247+
1248+
expected_len = segment.samps_per_frame[ch] * segment.sig_len
1249+
actual_len = len(expanded_signal[ch])
1250+
1251+
if actual_len != expected_len:
1252+
raise ValueError(
1253+
f"Segment {seg_num}, channel {ch}: expanded signal length ({actual_len}) "
1254+
f"does not match samps_per_frame[{ch}] * sig_len ({expected_len})"
1255+
)
1256+
12291257
# No need to check the sum of sig_lens from each segment object against sig_len
12301258
# Already effectively done it when checking sum(seg_len) against sig_len
12311259

0 commit comments

Comments
 (0)