[MRG] Add function that returns all defined channel types#4842
[MRG] Add function that returns all defined channel types#4842larsoner merged 5 commits intomne-tools:masterfrom
Conversation
…ctor channel_type
|
A use case for this functionality is described in cbrnr/mnelab#5 |
|
Looks reasonable to me, but not travis. Can you check for relative speed improvements or regressions? I know the function overhead will be small but it might be used a lot of places in the code. Using Did you look at If you have time, can you look to see if there is a way to (finally!) deduplicate the logic here with that of |
Codecov Report
@@ Coverage Diff @@
## master #4842 +/- ##
==========================================
+ Coverage 83.66% 83.68% +0.02%
==========================================
Files 348 348
Lines 62435 62401 -34
Branches 10738 10719 -19
==========================================
- Hits 52237 52222 -15
+ Misses 7442 7434 -8
+ Partials 2756 2745 -11 |
Should be fixed. I assumed that the keys always existed.
Let's check how often this function is called before prematurely optimizing.
No, I really need to know all supported channel types, not just the ones in the current data set.
OMG, I thought this would be a nice and quick PR 😝 . Yes, I'll take a look, but let's first assert that my change is usable in the first place before deduplicating this. |
Right now A quick check would be to try something like When combined with the deduplication idea (something we should do eventually), it would be used any time a
Yes that's why I added the "if you have time" -- it's not essential for this PR, but if you're in the mode to do it, it would be appreciated :) |
|
All tests (except the OSX ones) pass. Now on to the timing question. |
|
Master branch: This PR:
|
mne/io/pick.py
Outdated
|
|
||
| for t, rules in get_channel_types().items(): | ||
| for key, vals in rules.items(): | ||
| if isinstance(vals, int) and ch.get(key, None) != vals: |
There was a problem hiding this comment.
I find the logic hard to parse. Can you simplify the testing?
There was a problem hiding this comment.
for instance changing this to if ch.get(key, None) not in np.array(vals) might avoid the need for the conditional (depending on how well separated the logic currently is)
There was a problem hiding this comment.
Yes, this gets rid of the condition. @larsoner I was wondering if this is possible with simple lists, but apparently there is no list constructor that does something similar to np.array, or is there?
@agramfort I've also added comments. Is the logic clearer now?
|
And yes, as @larsoner mentioned deduplicating this is important! I just saw that this is also used in |
|
+1 for MRG when CIs are happy |
The function
get_channel_typesreturns a dict with known channel types as keys and their definitions in theinfodict as values. This PR has two benefits:channel_typeis now more generic and much shorter (because the logic is now in the dict defined inget_channel_typesWDYT? I can't believe I had to use the
elseclause of aforloop.