Add exclude_after_unique option to mne.io.read_raw_edf/read_raw_edf to search for exclude channels after making channel names unique#12518
Conversation
Apply _unique_channel_names before checking exclude
…re unique channel names
This is a bit dangerous. Could we instead exclude before and after renaming? Then old code would work as would the new code you want.
Users should never make use of private attributes (those with a leading underscore) and we shouldn't facilitate them doing so. They can change at any time with no warning. So -1 on including them in |
…ep backward compatibility
|
@larsoner
How is this?
I understand. On the other hand, sometimes I actually need these information. |
Sure but we should think about how. Ideally it could live in |
larsoner
left a comment
There was a problem hiding this comment.
Just a couple if minor comments otherwise LGTM!
mne/io/edf/edf.py
Outdated
| exclude_after_unique : bool | ||
| If True, exclude channels are searched for after they have been made | ||
| unique. This is useful to choose channels that have been made unique | ||
| by adding a suffix. |
There was a problem hiding this comment.
| by adding a suffix. | |
| by adding a suffix. If False, the original names are checked. | |
| .. versionadded:: 1.7 |
mne/io/edf/edf.py
Outdated
| exclude_after_unique : bool | ||
| If True, exclude channels are searched for after they have been made | ||
| unique. This is useful to choose channels that have been made unique | ||
| by adding a suffix. |
There was a problem hiding this comment.
DRY (don't repeat yourself) -- this should live in an entry in mne/utils/docs.py and be used all three places
It sounds good. I will try to make functions to read these information directly in another PR. |
The doc for |
|
Failures unrelated and comments addressed, in it goes, thanks @rcmdnk ! |
* upstream/main: (50 commits) ENH: Improve OPM auditory dataset and example (mne-tools#12539) MAINT: Bump to latest pydata-sphinx-theme (mne-tools#12228) MRG: Simplify manual installation instructions a little by dropping explicit mention of (lib)mamba (mne-tools#12362) fix PSD weights handling when bad annotations present (mne-tools#12538) Fix phase loading (mne-tools#12537) align FFT windows to good data spans in psd_array_welch (mne-tools#12536) explicitly disallow multitaper in presence of bad annotations (mne-tools#12535) MAINT: Clean up PyVista contexts (mne-tools#12533) MAINT: Complete API change of ordered (mne-tools#12534) MAINT: Reinstall statsmodels and improve logging (mne-tools#12532) MAINT: Remove scipy.signal.morlet2 (mne-tools#12531) Update README badge links (mne-tools#12529) BUG: Fix bug with reading his_id from snirf (mne-tools#12526) [pre-commit.ci] pre-commit autoupdate (mne-tools#12524) Fix file format check in _check_eeglab_fname function (mne-tools#12523) MAINT: Reenable picard in pre testing (mne-tools#12525) MAINT: Bump to large resource class (mne-tools#12522) MAINT: Restore 2 jobs on Windows (mne-tools#12520) Add exclude_after_unique option to mne.io.read_raw_edf/read_raw_edf to search for exclude channels after making channel names unique (mne-tools#12518) Improve consistency of sensor types in code and documentation (mne-tools#12509) ...
What does this implement/fix?
This pull request addresses an issue with handling EDF/BDF/GDF files that contain channels with duplicate names. Previously, channels with duplicate names were assigned a suffix (-N) after the process of including/excluding channels, which made it impossible to selectively include or exclude specific instances of these channels.
The proposed solution is to apply the
_unique_channel_namesfunction before the inclusion/exclusion process. Additionally, the original channel names (orig_ch_names) are now stored inRaw._raw_extras. This inclusion is particularly useful as it allows users to determine whether channel names have been modified and facilitates a more detailed examination of the raw data alongside other contents of_raw_extras.Additional information
This modification could impact existing workflows. For instance, consider an EDF file with channels named ["A", "A", "B", "C"]. If a user attempts to exclude channels "A" and "C" using the following code:
The behavior will differ pre and post-PR:
If a channel is excluded using a string (interpreted as a regex), the outcome remains unchanged: