Currently BaseRecordingSegment has no concept of channel count. It knows its time dimension (sampling frequency, time vector, num_samples) but not its channel dimension. This forces segment subclasses to work around the limitation in various ways:
Passing num_channels from parent to segment at construction:
Inferring channel count from data shape:
Fetching a sample just to get the shape:
The parent Recording always knows num_channels at the time it calls add_recording_segment. The proposal is to have BaseRecording.add_recording_segment() set num_channels on the segment automatically. This would:
- Give all segments a
num_channels attribute for free, with the Recording as the single source of truth
- Eliminate the need for subclasses to store it independently
- Remove workarounds like 1-sample fetches to get channel count
- Make pre-allocation of output arrays straightforward without fetching data first
The change is small (a few lines in BaseRecordingSegment.__init__ and BaseRecording.add_recording_segment) and fully backwards compatible since existing subclasses that set num_channels themselves would continue to work.
Currently
BaseRecordingSegmenthas no concept of channel count. It knows its time dimension (sampling frequency, time vector, num_samples) but not its channel dimension. This forces segment subclasses to work around the limitation in various ways:Passing
num_channelsfrom parent to segment at construction:BinaryRecordingSegmentNoiseGeneratorRecordingSegmentZeroChannelPaddedRecordingSegmentTracePaddedRecordingSegmentInferring channel count from data shape:
InjectTemplatesRecordingSegmentinfers from template array shapeDriftingTemplatesRecordingSegmentinfers from template objectFetching a sample just to get the shape:
ResampleRecordingSegment._get_traces_gappedfetches 1 sample from the parent to determine output channel count (introduced in Fix resampling of gapped recordings. #4499)The parent
Recordingalways knowsnum_channelsat the time it callsadd_recording_segment. The proposal is to haveBaseRecording.add_recording_segment()setnum_channelson the segment automatically. This would:num_channelsattribute for free, with the Recording as the single source of truthThe change is small (a few lines in
BaseRecordingSegment.__init__andBaseRecording.add_recording_segment) and fully backwards compatible since existing subclasses that setnum_channelsthemselves would continue to work.