Skip to content

Make num_channels available on BaseRecordingSegment #4510

Open

Description

@h-mayorquin

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.

Activity

  1. alejoe91 commented on Apr 14, 2026

    @alejoe91
    Member

    Makes sense to me :)

  2. samuelgarcia commented on Apr 15, 2026

    @samuelgarcia
    Member

    Deep analysis of the situation.
    I am a bit regreting the design with 2 classes recording+recording segment.
    What could also be done is to have a weakref in recording_segment to the recording and so we could have access to all metadata also probe channel properties...

  3. added
    enhancement
    on Apr 16, 2026
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions