Skip to content

Allow get_samples to retrieve channels based on ID, not order in data array#41

Merged
jsiegle merged 3 commits intoopen-ephys:mainfrom
lillysanchez:main
Mar 19, 2025
Merged

Allow get_samples to retrieve channels based on ID, not order in data array#41
jsiegle merged 3 commits intoopen-ephys:mainfrom
lillysanchez:main

Conversation

@lillysanchez
Copy link
Copy Markdown
Contributor

Problem

The default behavior for get_samples is to return all channels in the order in which they are stored, typically in increasing numerical order. However, if the channel map plugin is placed in the signal chain before a record node, the order of channels will follow the order of the specified channel mapping, but no indication is given to the user that the channel ordering is not 1--n as without the channel map plugin.

Solution

The array index is looked-up from a dictionary that translates the channel ID (an integer of version of channel name, where 'CH22' = 22) to the index of the storage array.
Order is kept consistent with the channel map plugin as recorded in the
oebin file. By default, all channels are returned. If you board has
additional ADCn channels, they are sequentially numbered after reaching
the last CHnn labeled channel.

This PR allows for the user to specify channel by it's ID, not it's index. This will allow for a direct selection of channels via the channel_by_number argument, where index 1 == 'CH1' .

Changes

The get_samples method now includes the arguments:

  • selected_channels is a positional or keyword argument that allows channels to be selected via array index in the order stored in the sample array.
    Superficially similar to the existing approach, the selected channels area always selected using the channel map dictionary, such that the user gets the channel they intend, but indices are consistent with python 0-based arrays.

  • channel_by_number is a keyword-only argument allows channels to be selected by ID to extract specific channels by channel ID number (integers following CH in the oebin file). If your board has additional ADCn channels, they are sequentially numbered after reaching the last CHnn labeled channel.

The changes only apply to binary and oebin formats. I am not familiar with NWB format and I do not know if it needs such a change.

@jsiegle
Copy link
Copy Markdown
Member

jsiegle commented Mar 19, 2025

This looks very useful, thanks for adding this!

@jsiegle jsiegle merged commit f1721e7 into open-ephys:main Mar 19, 2025
@jsiegle
Copy link
Copy Markdown
Member

jsiegle commented Mar 27, 2025

Thanks again for this PR! I took a closer look at the implementation and decided to change the logic a bit, both for the sake of backwards compatibility and for generality.

It's important to keep the function of the selected_channels parameter the same, so people already using this package don't suddenly experience a breaking change. So I reverted that input argument to conform to the old behavior.

It is definitely useful to be able to specify channels by the original index in cases where they have been remapped. However, the way you implemented it won't work for all use cases. For example, if there are multiple headstages connected to an acquisition board, each with a CH1, what should index "1" refer to? So as an alternative I added the ability to select channels by name, using a list of strings as a selected_channel_names argument. I think this is easier for users to understand, and won't lead to the potentially ambiguous case that I mentioned.

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.

2 participants