Skip to content

Fix check compensation on ica with EEG - #5270

Merged
larsoner merged 6 commits into
mne-tools:masterfrom
bloyl:eeg_comps
Jun 15, 2018
Merged

larsoner merged 6 commits into
mne-tools:masterfrom
bloyl:eeg_comps

Conversation

@bloyl

@bloyl bloyl commented Jun 7, 2018 •

Copy link
Copy Markdown
Contributor

closes #5265.

The problem arises because the ica object inherits the info of the object used to fit it with supplied 'picks' applied. however to avoid making a copy of time domain data the picks are never applied to the supplied object. This causes a discrepancy between the channels in ica.info and raw.info (or epoch.info) and the check fails.

I modified the _check_compensation_grade to accept channel names so the infos of both objects are mapped to the same channels before computing compensation_grade.

one case not tested is a ctf/eeg test where compensation can be applied. Are there any datasets like that which we could include in the test data?

@larsoner

larsoner commented Jun 7, 2018

Copy link
Copy Markdown
Member

@agramfort

Copy link
Copy Markdown
Member

@larsoner I'll have a look after you if ok with you

thx @bloyl

@cbrnr

cbrnr commented Jun 7, 2018

Copy link
Copy Markdown
Contributor

I can confirm that the example code snippet from #5265 works with these changes.

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me other than a few minor issues

Comment thread mne/preprocessing/tests/test_ica.py Outdated
ica.get_sources(inst)



Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opps

# test apply and get_sources
for inst in [raw, epochs, evoked]:
ica.apply(inst)
ica.get_sources(inst)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much time does this test add? Looks like it should be "not much" because the max_iter is so small, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the entire test on my laptop takes ~8 seconds

$ pytest mne/preprocessing/tests/test_ica.py::test_ica_eeg -x --verbose
============ 1 passed, 4 warnings in 8.20 seconds ============

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a bit much, is it possible to reduce it by picking channels or cropping in time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best I can do is ...
====== 1 passed in 5.19 seconds =======

Comment thread mne/utils.py
from .io.pick import pick_channels, pick_info
from .io.compensator import get_current_comp

if None in [inst.info, inst2.info]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we have inst.info is None?

@bloyl bloyl Jun 8, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ica objects have a info is None until they are fit.

the check is needed so this part of the tests pass:

# test fit checker
assert_raises(RuntimeError, ica.get_sources, raw)
assert_raises(RuntimeError, ica.get_sources, epochs)

An alternative would be to move the fit checking out the private _transform_* methods but that would likely be two checks as I think it makes sense to have it in the private method aswell since they are used in a number of places.

eeglab_fname = op.join(test_base_dir, 'EEGLAB', 'test_raw.set')
eeglab_montage = op.join(test_base_dir, 'EEGLAB', 'test_chans.locs')

ctf_fname2 = op.join(test_base_dir, 'CTF', 'catch-alp-good-f.ds')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this indeed have EEG channels?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. at somepoint I'm going to go through the ctf data and see what it actually is but thats for another day :)

@codecov

codecov Bot commented Jun 8, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5270 into master will increase coverage by 0.03%.
The diff coverage is 96.77%.

@@            Coverage Diff             @@
##           master    #5270      +/-   ##
==========================================
+ Coverage   88.18%   88.22%   +0.03%     
==========================================
  Files         358      358              
  Lines       65898    66187     +289     
  Branches    11207    11242      +35     
==========================================
+ Hits        58114    58393     +279     
- Misses       4975     4976       +1     
- Partials     2809     2818       +9

method=method)
with warnings.catch_warnings(record=True): # convergence
ica.fit(raw)
ica.fit(inst)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch !

@agramfort

Copy link
Copy Markdown
Member

@agramfort

Copy link
Copy Markdown
Member

+1 for MRG

@larsoner merge if ok with you.

@larsoner
larsoner merged commit 5fb47e0 into mne-tools:master Jun 15, 2018
@larsoner

Copy link
Copy Markdown
Member

Thanks @bloyl

britta-wstnr pushed a commit to britta-wstnr/mne-python that referenced this pull request Jul 5, 2018
* Add test re: issue mne-tools#5265

* Fix

* Add ctf test with apply compensation channels

* Appease travis

* Shorten test

* Fix Flake
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.

Error in _check_compensation_grade for ICA on EEG data after switching from v15 to v16

4 participants