Skip to content

[MRG] Warn when removing channels needed to compensation matrices. - #5581

Merged
massich merged 12 commits into
mne-tools:masterfrom
bloyl:info_comp_chans_fix
Oct 12, 2018
Merged

massich merged 12 commits into
mne-tools:masterfrom
bloyl:info_comp_chans_fix

Conversation

@bloyl

@bloyl bloyl commented Oct 4, 2018 •

Copy link
Copy Markdown
Contributor

This is converts the RuntimeError that was raised when removing channels that were needed for applied compensation matrices to a Warning.

this is an initial PR in response to issue: #5342

If there are any other PRs that were made to skip this issue please add it to this list.

PRs to check

Closes #5384.

@larsoner larsoner added this to the 0.17 milestone Oct 6, 2018
@larsoner larsoner changed the title Warn when removing channels needed to compensation matrices. WIP: Warn when removing channels needed to compensation matrices. Oct 6, 2018
@bloyl
bloyl force-pushed the info_comp_chans_fix branch from 5a1a652 to ec8a248 Compare October 8, 2018 00:23
@bloyl

bloyl commented Oct 8, 2018

Copy link
Copy Markdown
Contributor Author

Is there a way to setup a local environment that mirrors one of the testing ones?

This test is passing locally and I'm not quite sure what the issue is. open to thoughts.

@larsoner

larsoner commented Oct 8, 2018

Copy link
Copy Markdown
Member

Use the environment.yml file, two of the Travis runs use it

Also Travis runs the PR merged with master so you might need to rebase (or merge) to see the same errors

@larsoner

larsoner commented Oct 8, 2018

Copy link
Copy Markdown
Member

It's also possible there is a default verbosity level difference, so you might need verbose=True in a call if you are checking an info level output.

Also due to how warnings are caught and emitted (sometimes only once) it's possible you will see the error with a make test run but not with just pytest mne/io or so. Hopefully it's not this issue because it can be a pain to find where the warning is first being emitted and silenced.

Comment thread mne/io/tests/test_pick.py Outdated
if len(pick) > 0:
pytest.raises(RuntimeError, pick_info, info, pick)
with catch_logging() as log:
pick_info(info, pick)

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.

you need verbose=True here because this is a info-level warning. This fails on my machine because I have MNE_LOGGING_LEVEL=warning in my config

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.

(and you'll need to add verbose kwarg and decorator to pick_info, too)

Comment thread mne/io/tests/test_meas_info.py Outdated
with catch_logging() as log:
Epochs(raw, events, None, -0.2, 0.2, preload=False,
picks=picks)
assert('Compensation grade 1' in log.getvalue())

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.

Even with verbose=True in the Epochs constructor (to get info-level messages) I get:

AssertionError: assert 'Compensation grade 1' in '10 matching events found\nApplying baseline correction (mode: mean)\nNot setting metadata\nRemoving 5 compensators from info because not all compensation channels were picked.\n0 projection items activated\n'

@larsoner

larsoner commented Oct 8, 2018

Copy link
Copy Markdown
Member

@bloyl okay with you if I push a commit to cover the problem observed in #5384?

Also if you want me to take care of the verbose business at the same time I can.

@larsoner

larsoner commented Oct 8, 2018

Copy link
Copy Markdown
Member

@bloyl I pushed a commit to add the test that fails on master but passes on this PR, feel free to force push over it if it gets in your way and I can add it later (or you can -- it's only a few extra lines if you look at it)

@bloyl

bloyl commented Oct 8, 2018

Copy link
Copy Markdown
Contributor Author

This should hopefully pass.

A downside is that this info message is going to crop up a fair amount (plotting data etc.) not sure if that is a problem.

@larsoner

larsoner commented Oct 8, 2018

Copy link
Copy Markdown
Member

info level output happening frequently is okay

@bloyl

bloyl commented Oct 8, 2018

Copy link
Copy Markdown
Contributor Author

Do you think I caught all the PRs/issues that were related to this issue?

@codecov

codecov Bot commented Oct 8, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5581 into master will decrease coverage by <.01%.
The diff coverage is 91.3%.

@@            Coverage Diff             @@
##           master    #5581      +/-   ##
==========================================
- Coverage   88.44%   88.44%   -0.01%     
==========================================
  Files         363      363              
  Lines       68071    68042      -29     
  Branches    11503    11494       -9     
==========================================
- Hits        60205    60177      -28     
+ Misses       5027     5026       -1     
  Partials     2839     2839

@larsoner

larsoner commented Oct 8, 2018

Copy link
Copy Markdown
Member

@bloyl I pushed a commit to add verbose=True in the Epochs constructor, hopefully that makes Travis green. I also added four other PRs to the top comment that might be relevant, can you check?

@bloyl

bloyl commented Oct 9, 2018

Copy link
Copy Markdown
Contributor Author

I quickly went through the 4 PRs you added. From what I can see none of them directly clear info['conps'] so are non destructive.

I would say we should leave them as most likely we will need them (or something like them) as part of #5342

@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.

LGTM +1 for merge after a whats_new.rst. @bloyl if you're done can you set to MRG and update whats_new.rst under the API section with an appropriate description?

Comment thread mne/io/ctf/tests/test_ctf.py Outdated
assert 'Removing 5 compensators' in log
raw_pick.save(out_fname, overwrite=True) # should work
read_raw_fif(out_fname)
read_raw_fif(out_fname, preload=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Either you test that save and reads do not raise, or you save+read and assert that the objects do the roundtrip without changing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

execution time without asserting is not worth in the testing

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.

I think these calls are mainly to test that save and read do not raise exceptions. how would you assert that no exception was raised?

I added some regression tests for the channels and some data...

Comment thread mne/io/ctf/tests/test_ctf.py Outdated
with pytest.raises(RuntimeError, match='Compensation grade 1 has been'):
raw.copy().pick_types(**pick_kwargs)
for comp_grade in [0, 1]:
if comp_grade != 0:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not needed. Apply it for 0 and 1. We just asserted that raw.compesation_grade is 0 two lines above.
raw.apply_gradient_compensation(comp_grade)

Comment thread mne/io/ctf/tests/test_ctf.py Outdated
assert 'Removing 5 compensators' in log
raw_pick.save(out_fname, overwrite=True) # should work
read_raw_fif(out_fname)
read_raw_fif(out_fname, preload=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

execution time without asserting is not worth in the testing

Comment thread mne/io/tests/test_pick.py Outdated
pytest.raises(RuntimeError, pick_info, info, pick)
with catch_logging() as log:
pick_info(info, pick, verbose=True)
assert msg in log.getvalue()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If assert 'Removing {} compensators'.format(len(info['comps']) in log.getvalue() does not fit in a single line, I would define msg closer to the assert. It helps when reading pytest trace

Comment thread mne/minimum_norm/inverse.py Resolved
@massich massich changed the title WIP: Warn when removing channels needed to compensation matrices. [MRG] Warn when removing channels needed to compensation matrices. Oct 10, 2018
@bloyl
bloyl force-pushed the info_comp_chans_fix branch from 7cf2925 to 4d6ff2e Compare October 10, 2018 20:15
@larsoner

Copy link
Copy Markdown
Member

@massich are you happy now?

@massich
massich merged commit 46f3fa1 into mne-tools:master Oct 12, 2018
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.

3 participants