Skip to content

Conversation

bparks13
Copy link
Member

@bparks13 bparks13 commented Sep 29, 2025

This PR adds the ability for data nodes to OrderByDepth, so that instead of following the conventional channel ordering (0 -> 383), the channels are instead ordered by their physical location along the shank. Therefore, if channel 0 corresponds to electrode 384 (Bank B), but all other channels are on Bank A (1 -> 383), then the channels will be ordered so that channel 0 is electrode 1 (normally channel 1), channel 1 is electrode 2 (normally channel 2), and so on until the very last channel is electrode 384 (normally channel 0).

This option is added as a boolean to all data nodes, and is false by default, so that if the user loads an old workflow but doesn't change anything, their channel map remains unchanged.

The algorithm logic is first proposed in the issue itself, and has been updated to reflect the current logic in the code.

Note: Currently this is only tested in the NeuropixelsV1e devices, so that we can confirm the logic/structure before applying to all other devices. The Neuropixels devices are easily implemented in the same manner as the NeuropixelsV1e, as they all share a common structure.

Fixes #440

@bparks13 bparks13 added this to the 0.7.0 milestone Sep 29, 2025
@bparks13 bparks13 requested a review from jonnew September 29, 2025 21:21
@bparks13 bparks13 self-assigned this Sep 29, 2025
- Changed ChannelHelper method name to be more specific, that it only applies to Neuropixels channels
- Move private RawToChannel array to where it needs to be
- Assign the channelOrder array a single time before creating the observable, in one place, and it can never be null
@bparks13 bparks13 requested a review from jonnew September 30, 2025 20:22
jonnew
jonnew previously requested changes Oct 7, 2025
Copy link
Member

@jonnew jonnew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@bparks13
Copy link
Member Author

bparks13 commented Oct 9, 2025

The main challenge here is mapping between the channel index (i.e., frameIndex / RawToChannel values) and the raw frame index (row/column coordinates in the 2D array).

The initial idea (issue comment) was to use a dictionary with the channel as the key and its row/column as the value. I explored alternatives but couldn’t avoid this without pushing the complexity to O(N²), since we need to retrieve the row/column from a given channel index to remap for spatial ordering.

We could do this in one pass, but it would require four nested loops (row/col iteration + searching for the matching channel), which might not be worth the tradeoff.

The current approach uses O(N) time for this mapping step and O(N log N) overall due to sorting (ref). The dictionary increases space complexity, but it avoids the nested search.

I also removed a redundant remapping operation and verified the algorithm on a 2×3 array by hand, which matched the expected behavior (testing with the SingleColumn preset).

@bparks13 bparks13 requested a review from jonnew October 9, 2025 18:51
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

Successfully merging this pull request may close these issues.

Add options to order Neuropixels channels by depth

2 participants