-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MRG] Allow marking channels as bad in existing datasets #491
Conversation
Codecov Report
@@ Coverage Diff @@
## master #491 +/- ##
==========================================
- Coverage 93.45% 93.14% -0.31%
==========================================
Files 14 15 +1
Lines 2079 2175 +96
==========================================
+ Hits 1943 2026 +83
- Misses 136 149 +13
Continue to review full report at Codecov.
|
good idea, some initial remarks:
not sure about the API for my second point |
Right. I assumed this column was REQUIRED but just checked the standard again and it is not. So I will insert it if not present and set all channels to "good", except for the ones to be marked as bad.
Good idea, will add. |
I would set as edit: actually no. That might not be smart. forget what I wrote :-D |
Forget what exactly? :) |
If I read the specs correctly, only "good" and "bad" are allowed. I guess this kind of makes sense... anything not bad should be good :) |
I would put |
I need advice on the API.
I'm now setting |
We could use keyword-only arguments: def mark_bad_channels(channels, *, descriptions=None, bids_basename,
bids_root, kind=None, verbose=True): This would allow users to pass Any objections? |
Did it such that both |
Removed the |
I started to wonder if maybe instead of having two arguments WDYT? |
Following a suggestion by @agramfort, I have added an |
If CIs pass, this is good to go from my end. I know it's quite a bit of code, but maybe you can start your review by looking at the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also can you add command line?
see mne_mark_bad_channels from mne-C
Unfortunately this won't work as the keys in params are diffeent than
what BIDSPath expects (e.g. sub vs subject etc)
really unfortunate design choise :(
|
^ what do we think about either making all the entity Params explicit (e.g. subject instead of sub) Or making it not short hand in the make_bids_basename and Bidspath? I’m in favor of #1. |
any consistent choice is fine with me.
|
+1 |
Done in 285d0a0 |
Missing functionality in the CLI: passing no bad channels and overwrite=True to reset all channels to "good". Will look into this tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked the API and examples in the docstr, and that looked very good to me. I think this will be very useful.
1a16386
to
f6bc027
Compare
I think I have addressed all review comments and this should be good to merge. |
Pybids has it: https://github.com/bids-standard/pybids/blob/master/examples/pybids_tutorial.ipynb the closest what we have in |
Now the question is -- 1) to what extent do you want to duplicate that functionality (cf also reviewer comments in mne-bids paper) rather than work with pybids folks, and 2) can you get something that does the job using regular expressions without employing something as fancy as pybids? Maybe it works only for ephys but that's fine for us |
I was suspecting pybids had something like this. I think we can do this
with 15 lines of code so I am not pushing for an extra dependency on pybids
… |
Yes definitely let's look into implementing this ourselves or just borrowing the relevant bits from pybids, but let's try not to introduce this dependency |
yes but definitely look into what |
Ok! |
# Update info['bads'] | ||
bads = _get_bads_from_tsv_data(tsv_data) | ||
raw.info['bads'] = bads | ||
# XXX (How) will this handle split files? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is your concern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh it's very easy, I've never worked with split files before. So here (actually in the next line, not shown here by github) we're only updating the very first file -- raw.filenames[0]
. In my current tests, there is always exactly ONE file in raw.filenames
. If we have split files, it could be multiple. I'm not sure if we would have to iterate over all of them, or if only the first one carries a (meaningful) info
dict, and updating that one is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for a split file then sidecar files should be identical. It's basically one file split over different files. metadata should be therefore exactly the same.
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
@agramfort Unless #491 (comment) needs more work, this is good to be merged once CI goes green. |
let's merge when green and let's iterate
… |
Thx @hoechenberger |
PR Description
I've started working on something we've needed for a long time now: marking channels of an existing BIDS dataset as "bad". This is needed because we'd like to encourage colleagues to convert to BIDS ASAP after data acquisition. Now, during data inspection / processing, they might discover problematic channels, and currently the only way to mark them as bad in the BIDS data is by editing the
channels.tsv
file(s) – not good! Even worse, some may opt to read the BIDS data, and mark channels as bad only in the derivative data they produce. Therefore we've figured we'd need a way to make it convenient to alter / amend existing metadata.This implementation is just a first draft, adding a
write.mark_bad_channels()
function. It will read the relevantchannels.tsv
file, mark the requested channels as bad, and write the altered metadata back to disk, replacing the existing file. I do realize that what I'm doing here can be further abstracted, e.g. to also allow users to mark bad channels as good; or to update other bits of the metadata as well. However I just wanted to move ahead for now with a concrete implementation that has actual real-world relevance for us and our colleagues. Totally open to rethink and refactor this later, and looking forward to your thoughts and suggestions!WIP because I also want to add a command line interface, and I haven't run extensive tests so far.
cc @agramfort
Merge checklist
Maintainer, please confirm the following before merging: