Skip to content

rdrecord(smooth_frames=False) fails if max(spf) == 1 #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bemoody opened this issue Jul 8, 2021 · 1 comment
Closed

rdrecord(smooth_frames=False) fails if max(spf) == 1 #312

bemoody opened this issue Jul 8, 2021 · 1 comment

Comments

@bemoody
Copy link
Collaborator

bemoody commented Jul 8, 2021

If rdrecord is invoked with:

  • smooth_frames=True and physical=True (default), it should set rec.p_signal to a two-dimensional floating-point array.
  • smooth_frames=True and physical=False, it should set rec.d_signal to a two-dimensional integer array.
  • smooth_frames=False and physical=True, it should set rec.e_p_signal to a list of floating-point arrays.
  • smooth_frames=False and physical=False, it should set rec.e_d_signal to a list of integer arrays.

For example:

>>> type(wfdb.rdrecord('sample-data/03700181', smooth_frames=True, physical=True).p_signal)
<class 'numpy.ndarray'>
>>> type(wfdb.rdrecord('sample-data/03700181', smooth_frames=True, physical=False).d_signal)
<class 'numpy.ndarray'>
>>> type(wfdb.rdrecord('sample-data/03700181', smooth_frames=False, physical=True).e_p_signal)
<class 'list'>
>>> type(wfdb.rdrecord('sample-data/03700181', smooth_frames=False, physical=False).e_d_signal)
<class 'list'>

However, if every signal in the record has exactly one sample per frame, this doesn't work:

>>> type(wfdb.rdrecord('sample-data/100', smooth_frames=True, physical=True).p_signal)
<class 'numpy.ndarray'>
>>> type(wfdb.rdrecord('sample-data/100', smooth_frames=True, physical=False).d_signal)
<class 'numpy.ndarray'>
>>> type(wfdb.rdrecord('sample-data/100', smooth_frames=False, physical=True).e_p_signal)
<class 'NoneType'>
>>> type(wfdb.rdrecord('sample-data/100', smooth_frames=False, physical=False).e_d_signal)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/benjamin/wfdb-python/wfdb/io/record.py", line 3637, in rdrecord
    record.convert_dtype(physical, return_res, smooth_frames)
  File "/home/benjamin/wfdb-python/wfdb/io/_signal.py", line 726, in convert_dtype
    current_dtype = self.e_d_signal[ch].dtype
TypeError: 'NoneType' object is not subscriptable
@bemoody
Copy link
Collaborator Author

bemoody commented Jul 8, 2021

Of course it gets even thornier if the record has multiple spf but you select signal(s) that have only one spf:

>>> wfdb.rdrecord('sample-data/03700181', smooth_frames=False, channels=[1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/benjamin/wfdb-python/wfdb/io/record.py", line 3536, in rdrecord
    expanded=False)
  File "/home/benjamin/wfdb-python/wfdb/io/record.py", line 706, in _arrange_fields
    if self.sig_len != self.d_signal.shape[0]:
AttributeError: 'list' object has no attribute 'shape'

(because then _rd_dat_signals and _rd_segment return a list of arrays but rdrecord is expecting a 2D array.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant