Skip to content
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

Refactor of NoisyChannels tests and split into separate methods #84

Merged
merged 7 commits into from
May 11, 2021

Conversation

a-hurst
Copy link
Collaborator

@a-hurst a-hurst commented May 10, 2021

PR Description

This PR takes the test_findnoisychannels function and splits it into separate unit tests for each type of bad channel, making it easier to maintain and figure out which specific part(s) are broken by a given change.

I also changed the test file from the current (very noisy) one to one with only two noisy channels to start with, saving time repeatedly running NoisyChannels and interpolating bads at the start to try and produce a clean recording for subsequent tests. This also has the advantage of not depending on NoisyChannels working properly in order to produce a dataset suitable for testing NoisyChannels. To address #83 I manually set the Z threshold to 3.29 (as suggested) and added a note so we don't forget.

Let me know what you think!

Merge Checklist

  • the PR has been reviewed and all comments are resolved
  • all CI checks pass
  • (if applicable): the PR description includes the phrase closes #<issue-number> to automatically close an issue
  • (if applicable): bug fixes, new features, or API changes are documented in whats_new.rst

@codecov-commenter
Copy link

codecov-commenter commented May 10, 2021

Codecov Report

Merging #84 (616c057) into master (bc46978) will not change coverage.
The diff coverage is n/a.

❗ Current head 616c057 differs from pull request most recent head b9ac92e. Consider uploading reports for the commit b9ac92e to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##           master      #84   +/-   ##
=======================================
  Coverage   98.37%   98.37%           
=======================================
  Files           7        7           
  Lines         677      677           
=======================================
  Hits          666      666           
  Misses         11       11           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc46978...b9ac92e. Read the comment docs.

@a-hurst
Copy link
Collaborator Author

a-hurst commented May 10, 2021

Huh, looks like this had the unintended effect of making other sections of the test suite slower? Looking back at the old tests it looks like the current test_findnoisychannels makes direct modifications to the raw fixture that's used across tests, such that the PrepPipeline and Reference tests were taking a modified raw as input:

raw.set_montage(montage)
nd = NoisyChannels(raw, random_state=rng)
nd.find_all_bads(ransac=True)
bads = nd.get_bads()
iterations = (
10 # remove any noisy channels by interpolating the bads for 10 iterations
)
for iter in range(0, iterations):
if len(bads) == 0:
continue
raw.info["bads"] = bads
raw.interpolate_bads()
nd = NoisyChannels(raw, random_state=rng)
nd.find_all_bads(ransac=True)
bads = nd.get_bads()
# make sure no bad channels exist in the data
raw.drop_channels(ch_names=bads)

Since the above code tries to clean bad channels from the recording, I'm guessing that meant it took fewer iterations to re-reference during later tests. Regardless, I doubt that was intentional so I guess this PR fixes that as well!

tests/conftest.py Outdated Show resolved Hide resolved
# The eegbci data has non-standard channel names. We need to rename them:
eegbci.standardize(raw)
# Re-reference the data after interpolating bad channels
mne.set_eeg_reference(raw, 'average', copy=False, ch_type='eeg')
Copy link
Owner

Choose a reason for hiding this comment

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

I am surprised that BLACK does not complain here. It usually formats all quotation marks as " instead of ', right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I honestly don't know, I haven't really used black formatting before! If you have a preference for double quotes over singles for this project I'll definitely stick to that.

Copy link
Owner

Choose a reason for hiding this comment

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

I mostly have a preference for using a consistent style - and preferably one that is enforced by a tool with a large community backing, such as black :-)

But if it doesn't enforce a format here, it's fine with me 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From the look of it, PyPREP doesn't have any sort of automatic linting for Black enabled other than the 88 line length, is that something that should be fixed?

And that make sense! My general habit to use single-quotes for data (e.g., variable names, argument strings, key names, etc.) and double-quotes for strings that are meant to be read as text (e.g. docstrings, print messages, exception messages, etc.), but I'm happy to conform to whatever conventions a project uses. From what I can tell the Black style guide prefers double-quotes to singles (like you thought), so up to you.

Copy link
Owner

Choose a reason for hiding this comment

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

argh, good point actually. This line is supposed to ensure in CI that all code is BLACK formatted:

But it should say black . --check instead of black . --> the former does a check, whereas the latter just applies the formatting, which is then obviously lost because it's not committed.

And for devs, the development environment should be setup automatically such that BLACK formatting is applied prior to each commit (pre-commit hook, see https://github.com/sappelhoff/pyprep#installation)

I'll make a PR for that.

Copy link
Owner

Choose a reason for hiding this comment

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

see: #85

Copy link
Owner

@sappelhoff sappelhoff left a comment

Choose a reason for hiding this comment

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

LGTM in general :) again -> a very helpful addition, thanks!

I left a few comments, but should be easy to address overall and then get it merged.

@sappelhoff sappelhoff added this to the 0.4.0 milestone May 11, 2021
@sappelhoff sappelhoff merged commit 47976eb into sappelhoff:master May 11, 2021
@sappelhoff
Copy link
Owner

Thanks! I'll fix the formatting in #85 and make sure that the CI will check this in the future.

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