Skip to content

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

Closed

Description

@bemoody

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

Activity

  1. bemoody commented on Jul 8, 2021

    @bemoody
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions