Skip to content

Commit df07fc5

Browse files
committed
correct segment channels and add digital fmt
1 parent 9afa121 commit df07fc5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

wfdb/io/record.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def multi_to_single(self, physical, return_res=64):
697697
Create a Record object from the MultiRecord object. All signal
698698
segments will be combined into the new object's `p_signal` or
699699
`d_signal` field. For digital format, the signals must have
700-
the same storage format, baseline, and adcgain in all segments.
700+
the same storage format, baseline, and adc_gain in all segments.
701701
702702
Parameters
703703
----------
@@ -722,7 +722,7 @@ def multi_to_single(self, physical, return_res=64):
722722
del(fields[attr])
723723

724724
# Get the formats, signal names and units from the first segment
725-
for attr in ['fmt', 'adcgain', 'baseline', 'units', 'sig_name']:
725+
for attr in ['fmt', 'adc_gain', 'baseline', 'units', 'sig_name']:
726726
fields[attr] = getattr(self.segments[0], attr)
727727

728728
# Figure out attribute to set, and dtype.
@@ -742,8 +742,10 @@ def multi_to_single(self, physical, return_res=64):
742742
# pass the test.
743743
if self.layout == 'variable':
744744
for seg in self.segments[1:]:
745-
segment_channels = get_wanted_channels(fields['sig_name'], seg, pad=True)
746-
for attr in ['fmt', 'adcgain', 'baseline', 'units', 'sig_name']:
745+
segment_channels = get_wanted_channels(fields['sig_name'],
746+
seg.sig_name,
747+
pad=True)
748+
for attr in ['fmt', 'adc_gain', 'baseline', 'units', 'sig_name']:
747749
for ch in range(self.n_sig):
748750
# Skip if the signal is not contained in the segment
749751
if segment_channels[ch] is None:
@@ -752,7 +754,10 @@ def multi_to_single(self, physical, return_res=64):
752754
raise Exception('This variable layout multi-segment record cannot be converted to single segment, in digital format.')
753755

754756
sig_attr = 'd_signal'
755-
dtype = ???
757+
# Figure out the largest required dtype
758+
dtype = _signal.npdtype(_signal.wfdbfmtres(fields['fmt'],
759+
maxres=True),
760+
discrete=True)
756761
nan_vals = _signal.digi_nan(fields['fmt'])
757762

758763
combined_signal = np.zeros([self.sig_len, self.n_sig], dtype=dtype)
@@ -780,15 +785,16 @@ def multi_to_single(self, physical, return_res=64):
780785
# Get the segment channels to copy over for each
781786
# overall channel
782787
segment_channels = get_wanted_channels(fields['sig_name'],
783-
seg, pad=True)
788+
seg.sig_name,
789+
pad=True)
784790
for ch in range(self.n_sig):
785791
# Fill with invalids if segment does not contain
786792
# signal
787793
if segment_channels[ch] is None:
788794
combined_signal[start_samps[i]:end_samps[i], ch] = nan_vals[ch]
789795
# Copy over relevant signal
790796
else:
791-
combined_signal[start_samps[i]:end_samps[i], ch] = getattr(seg, sig_attr)
797+
combined_signal[start_samps[i]:end_samps[i], ch] = getattr(seg, sig_attr)[:, segment_channels[ch]]
792798

793799
# Create the single segment Record object and set attributes
794800
record = Record()

0 commit comments

Comments
 (0)