mne-python icon indicating copy to clipboard operation
mne-python copied to clipboard

Equivalent for mne_mark_bad_channels

Open larsoner opened this issue 14 years ago • 8 comments

Currently making system calls to accomplish this. Perhaps it could currently be done by reading a raw fif and writing it out again, but I imagine this will be slow as it will have to re-write all the channel data (I assume this is not what the C code does?).

larsoner avatar Sep 19 '12 23:09 larsoner

Wouldn't it be sufficient just to add the appropriate channel name to the respective raw.info['bads'] ?

On 20.09.2012, at 02:46, Eric89GXL [email protected] wrote:

Currently making system calls to accomplish this. Perhaps it could currently be done by reading a raw fif and writing it out again, but I imagine this will be slow as it will have to re-write all the channel data (I assume this is not what the C code does?).

— Reply to this email directly or view it on GitHub.

dengemann avatar Sep 20 '12 00:09 dengemann

I assume that that, followed by a save() would work---when I looked at the how Raw.save() was coded, I thought it would cause it to re-write all the data to disk, though. It's possible I mis-read the code, though, so I'll give it a shot tomorrow.

larsoner avatar Sep 20 '12 00:09 larsoner

You have to explicitly pass a name to save which is different from raw.info['filename'] if i understand you problem right.

-Denis

On 20.09.k2012, at 03:34, Eric89GXL [email protected] wrote:

I assume that that, followed by a save() would work---when I looked at the how Raw.save() was coded, I thought it would cause it to re-write all the data to disk, though. It's possible I mis-read the code, though, so I'll give it a shot tomorrow.

— Reply to this email directly or view it on GitHub.

dengemann avatar Sep 20 '12 04:09 dengemann

Yeah, I think that's what it was. mne_mark_bad_channels is nice because it operates on the file itself, I believe without needing to re-write / duplicate the data. In the meantime I'll probably just save to a different file and replace the old one until there's a more elegant solution.

larsoner avatar Sep 20 '12 05:09 larsoner

indeed mne_mark_bad_channels avoids duplicating the file. I could look into this. The thing is that since I work with python functions It just works to do raw.info['bads'] = ['...']

but I agree that its nice to store in the file the bad channels...

agramfort avatar Sep 20 '12 06:09 agramfort

mne_mark_bad_channels makes use of the fact that the tags in a fif file form a linked list. Therefore, you can add new tags, in this case the bad channel list, in the middle of the existing tag list without having to move the remainder of the file forward. The bad channel list is thus physically located at the end of the file but logically in the middle of it. Furthermore, when a bad channel list is modified, mne_mark_bad_channels marks the existing list as "free space" and writes a new bad channel tag according to the new bad channel specification. This was necessary because the tag data sizes can be different.

I suppose all of this could be done in Python, too. However, when I wrote the MNE Matlab code I felt it was not necessary to include support for the rarely used fif features employed in mne_mark_bad_channels.

  • Matti

On Sep 20, 2012, at 1:04 AM, Eric89GXL wrote:

Yeah, I think that's what it was. mne_mark_bad_channels is nice because it operates on the file itself, I believe without needing to re-write / duplicate the data. In the meantime I'll probably just save to a different file and replace the old one until there's a more elegant solution.

— Reply to this email directly or view it on GitHub.


Matti Hamalainen, Ph.D. Athinoula A. Martinos Center for Biomedical Imaging Massachusetts General Hospital

[email protected] [email protected]

The information in this e-mail is intended only for the person to whom it is addressed. If you believe this e-mail was sent to you in error and the e-mail contains patient information, please contact the Partners Compliance HelpLine at http://www.partners.org/complianceline . If the e-mail was sent to you in error but does not contain patient information, please contact the sender and properly dispose of the e-mail.

mshamalainen avatar Sep 20 '12 10:09 mshamalainen

That makes sense. It occurred to me that since we're porting our analysis stream to Python now, we should be able to just use what you all suggested and set the raw.info['bads'] directly, since we can combine that step in preprocessing with filtering, SSP, etc. before writing out the processed files. Feel free to close this issue!

larsoner avatar Sep 20 '12 15:09 larsoner

Is it alright if I add a function to fiff.raw called mark_bad_channels that reads in bad channels from a text file and marks them in raw.info? I think it would decrease the barrier of entry for folks who were already making use of saving bad channels in text files.

larsoner avatar Sep 21 '12 23:09 larsoner