You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rdrecord: smooth frames by invoking smooth_frames().
To simplify the implementation of _rd_segment and _rd_dat_signals, we
want to eliminate the smooth_frames argument, so that the return
values of these two functions will always have the same type (a list
of numpy arrays.)
Therefore, if the application requested frame smoothing, then instead
of calling _rd_segment with smooth_frames=True, we will call
_rd_segment with smooth_frames=False, and post-process the result by
calling Record.smooth_frames.
Record.smooth_frames (SignalMixin.smooth_frames) will give a result
equivalent to what _rd_segment gives with smooth_frames=True, but
there are likely differences in performance:
- Record.smooth_frames performs the computation by slicing along the
"long" axis and storing the intermediate results in an int64 numpy
array. _rd_dat_signals slices along the "short" axis and stores
the intermediate results in a Python list. Record.smooth_frames
should therefore be faster for large inputs.
- Record.smooth_frames only operates on the channels present in
e_d_signal, whereas _rd_dat_signals smooths all of the signals in
the input file. Record.smooth_frames therefore saves memory and
time when reading a subset of channels.
- Record.smooth_frames always returns an int64 array, whereas
_rd_dat_signals returns an array of the same type as the original
data. Record.smooth_frames therefore uses more memory in many
cases. (Note that rdrecord will post-process the result in any
case, making this change invisible to applications; the issue of
increased temporary memory usage can be addressed separately.)
- If there are multiple channels in a signal file, then calling
_rd_dat_signals with smooth_frames=False requires making an extra
copy of each signal that has multiple samples per frame (because of
the "reshape(-1)".) (This could be addressed in the future by
allowing _rd_segment, or at least _rd_dat_signals, to return a list
of *two-dimensional* arrays instead.)
In order for this to work correctly, Record.smooth_frames must be
called after setting both e_d_signal and samps_per_frame. In
particular, it must be done after Record._arrange_fields "rearranges"
samps_per_frame according to channels.
On the other hand, _arrange_fields is expected to set checksum and
init_value in different ways depending on whether the result is to be
smoothed. (This use of checksum and init_value is somewhat dubious.)
Therefore, smooth_frames is now invoked as part of _arrange_fields,
after setting channel-specific metadata and before setting checksum
and init_value.
_arrange_fields should never be invoked other than by rdrecord; it
doesn't make any sense to call this function at other times. Change
the signature of this function to reflect the fact that it actively
transforms the signal array, and make all arguments mandatory.
0 commit comments