Skip to content

Commit d2406cf

Browse files
author
Benjamin Moody
committed
rdrecord: reformat for readability/maintainability.
All four of the calls to _rd_segment were identical apart from the 'no_file' and 'sig_data' arguments. Rearrange the code so there is only one call to _rd_segment, to avoid redundancy. Furthermore, since _rd_segment takes a huge number of arguments, convert all of them to keyword style to avoid confusion.
1 parent f2b8ab6 commit d2406cf

File tree

1 file changed

+27
-56
lines changed

1 file changed

+27
-56
lines changed

wfdb/io/record.py

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,39 +3507,37 @@ def rdrecord(record_name, sampfrom=0, sampto=None, channels=None,
35073507

35083508
# A single segment record
35093509
elif isinstance(record, Record):
3510+
if record_name.endswith('.edf') or record_name.endswith('.wav'):
3511+
no_file = True
3512+
sig_data = record.d_signal
3513+
else:
3514+
no_file = False
3515+
sig_data = None
3516+
3517+
signals = _signal._rd_segment(
3518+
file_name=record.file_name,
3519+
dir_name=dir_name,
3520+
pn_dir=pn_dir,
3521+
fmt=record.fmt,
3522+
n_sig=record.n_sig,
3523+
sig_len=record.sig_len,
3524+
byte_offset=record.byte_offset,
3525+
samps_per_frame=record.samps_per_frame,
3526+
skew=record.skew,
3527+
sampfrom=sampfrom,
3528+
sampto=sampto,
3529+
channels=channels,
3530+
smooth_frames=smooth_frames,
3531+
ignore_skew=ignore_skew,
3532+
no_file=no_file,
3533+
sig_data=sig_data,
3534+
return_res=return_res)
35103535

35113536
# Only 1 sample/frame, or frames are smoothed. Return uniform numpy array
35123537
if smooth_frames or max([record.samps_per_frame[c] for c in channels]) == 1:
35133538
# Read signals from the associated dat files that contain
35143539
# wanted channels
3515-
if record_name.endswith('.edf') or record_name.endswith('.wav'):
3516-
record.d_signal = _signal._rd_segment(record.file_name,
3517-
dir_name, pn_dir,
3518-
record.fmt,
3519-
record.n_sig,
3520-
record.sig_len,
3521-
record.byte_offset,
3522-
record.samps_per_frame,
3523-
record.skew, sampfrom,
3524-
sampto, channels,
3525-
smooth_frames,
3526-
ignore_skew,
3527-
no_file=True,
3528-
sig_data=record.d_signal,
3529-
return_res=return_res)
3530-
else:
3531-
record.d_signal = _signal._rd_segment(record.file_name,
3532-
dir_name, pn_dir,
3533-
record.fmt,
3534-
record.n_sig,
3535-
record.sig_len,
3536-
record.byte_offset,
3537-
record.samps_per_frame,
3538-
record.skew, sampfrom,
3539-
sampto, channels,
3540-
smooth_frames,
3541-
ignore_skew,
3542-
return_res=return_res)
3540+
record.d_signal = signals
35433541

35443542
# Arrange/edit the object fields to reflect user channel
35453543
# and/or signal range input
@@ -3552,34 +3550,7 @@ def rdrecord(record_name, sampfrom=0, sampto=None, channels=None,
35523550

35533551
# Return each sample of the signals with multiple samples per frame
35543552
else:
3555-
if record_name.endswith('.edf') or record_name.endswith('.wav'):
3556-
record.e_d_signal = _signal._rd_segment(record.file_name,
3557-
dir_name, pn_dir,
3558-
record.fmt,
3559-
record.n_sig,
3560-
record.sig_len,
3561-
record.byte_offset,
3562-
record.samps_per_frame,
3563-
record.skew, sampfrom,
3564-
sampto, channels,
3565-
smooth_frames,
3566-
ignore_skew,
3567-
no_file=True,
3568-
sig_data=record.d_signal,
3569-
return_res=return_res)
3570-
else:
3571-
record.e_d_signal = _signal._rd_segment(record.file_name,
3572-
dir_name, pn_dir,
3573-
record.fmt,
3574-
record.n_sig,
3575-
record.sig_len,
3576-
record.byte_offset,
3577-
record.samps_per_frame,
3578-
record.skew, sampfrom,
3579-
sampto, channels,
3580-
smooth_frames,
3581-
ignore_skew,
3582-
return_res=return_res)
3553+
record.e_d_signal = signals
35833554

35843555
# Arrange/edit the object fields to reflect user channel
35853556
# and/or signal range input

0 commit comments

Comments
 (0)