Skip to content

Add initial tests for removeTrend & NoisyChannels - #79

Merged
sappelhoff merged 6 commits into
sappelhoff:masterfrom
a-hurst:matlab_comparison_tests
May 8, 2021
Merged

sappelhoff merged 6 commits into
sappelhoff:masterfrom
a-hurst:matlab_comparison_tests

Conversation

@a-hurst

@a-hurst a-hurst commented May 5, 2021 •

Copy link
Copy Markdown
Collaborator

PR Description

Closes #49. This PR aims to add direct CI comparison of PyPREP's matlab_strictresults to Matlab PREP's across every stage of the pipeline, verifying that we're not deviating from MatPREP in any ways we're not actively aware of.

This is currently in a draft state, with only removeTrend and NoisyChannels being tested for equivalence, but I figure this would be a useful stage at which to get some feedback.

Components currently tested

  • removeTrend
  • CleanLine (mne.filter.notch_filter)
  • NoisyChannels
    • Bad by NaN
    • Bad by flat
    • Bad by deviation
    • Bad by HF noise
    • Bad by correlation
    • Bad by low SNR
    • Bad by dropout
    • Bad by RANSAC
  • Robust re-referencing
  • Final bad channel interpolation
  • Full pipeline, start-to-finish

Current thoughts

  • The current test file I chose apparently only has two bad channels (T10 and FT8), none of which are bad by NaN, flat, SNR, or deviation. One possibility would be to try and find another test file that's noisier, another would be to try and simulate these types of noise as part of our matlab_artifacts script. Simulating bad-by-SNR is likely more trouble than just finding a noisier file, but I haven't found any data with bad-by-NaN or bad-by-dropout channels yet so I think simulation is the way to go for those.
  • What do we want to do about the examples/run_full_prep.py script? Once Numeric equivalence with MATLAB PREP #58 is finally finished it'll need to be rewritten a bit, but should we switch to using matprep_artifacts as the test data for that as well?
  • How do we want to approach merging this? Should I write tests for the whole thing and mark the ones that aren't numerically-equivalent yet as expected failures, or should we merge once NoisyChannels tests are complete and add to this with future PRs when adding matlab_strict modes for things like re-referencing and final interpolation?

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

codecov-commenter commented May 5, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #79 (45c59bd) into master (20e2941) will increase coverage by 0.56%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #79      +/-   ##
==========================================
+ Coverage   97.81%   98.37%   +0.56%     
==========================================
  Files           7        7              
  Lines         686      677       -9     
==========================================
- Hits          671      666       -5     
+ Misses         15       11       -4     
Impacted Files Coverage Δ
pyprep/find_noisy_channels.py 100.00% <100.00%> (+2.28%) ⬆️

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 20e2941...45c59bd. Read the comment docs.

@a-hurst a-hurst added this to the 0.4.0 milestone May 5, 2021

@sappelhoff sappelhoff left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the start :)

. One possibility would be to try and find another test file that's noisier, another would be to try and simulate these types of noise as part of our matlab_artifacts script.

I think testing 2 to 3 files instead of just one wouldn't hurt -> do you think that's feasible?

but I haven't found any data with bad-by-NaN or bad-by-dropout channels

I am not aware of such data either: just editing on of our datasets to contain NaN / dropout (whatever that is supposed to mean) might be fine enough?

What do we want to do about the examples/run_full_prep.py script? Once #58 is finally finished it'll need to be rewritten a bit, but should we switch to using matprep_artifacts as the test data for that as well?

Yes, we should switch to matprep data there as well - and the plotting code needs to be a little bit less "in your face"

How do we want to approach merging this? Should I write tests for the whole thing and mark the ones that aren't numerically-equivalent yet as expected failures, or should we merge once NoisyChannels tests are complete and add to this with future PRs when adding matlab_strict modes for things like re-referencing and final interpolation?

I think doing separate PRs would be a better way to go here. Add now what we can assure passes, and do the rest later

@a-hurst
a-hurst force-pushed the matlab_comparison_tests branch from 52f12dc to 0ec7cff Compare May 7, 2021 19:03
@a-hurst

a-hurst commented May 7, 2021

Copy link
Copy Markdown
Collaborator Author

@sappelhoff I've now switched matprep_artifacts to using a noisier test file, and added code in my MATLAB script for simulating NaN, flat, and dropout channels. NoisyChannels show now have full MATLAB-comparison test coverage!

Due to differences in how PyPREP and MatPREP generate their arrays of internal info, I also had to refactor NoisyChannels a bit to get this working properly with bad-by-NaN/bad-by-flat channels. Basically, PyPREP was dropping the bad-by-flat/bad-by-NaN channels completely such that for a dataset with two NaN channels, the arrays channel noisiness z-scores, RANSAC correlations, etc. would be 62 channels long/wide instead of 64 (which is how MatPREP outputs these arrays). Relatedly, because NaN and flat channels break the other bad_by detection methods in various spectacular ways, I got NoisyChannels to automatically run it during init.

Also I'm not sure what to do about the style check throwing the error: for that line, is False does something completely different than == False since it's comparing multiple elements in an array.

@a-hurst
a-hurst marked this pull request as ready for review May 7, 2021 19:22
Comment thread pyprep/find_noisy_channels.py Resolved
@a-hurst

a-hurst commented May 7, 2021

Copy link
Copy Markdown
Collaborator Author

I think codecov's upset I uncommented an untested line in find_bad_by_hf_noise. I added a quick test case to make it happy.

@sappelhoff sappelhoff left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

awesome work, thanks heaps :)

I think this is worth a big What's New entry, WDYT? -> or do you want to hold off with that until all things PREP are tested in CI?

Regarding the latter, where are we going to track the as of yet not tested in CI parts of PYPREP (to be done in later PRs)?

@a-hurst

a-hurst commented May 7, 2021

Copy link
Copy Markdown
Collaborator Author

Just updated the whats_new.rst to say we've added a framework for MATLAB comparison :)

For tracking the rest of the comparisons, I'd say we can use the checklist in #58 as a rough test coverage tracker, since it's essentially in the same state and I can add MATLAB-comparison tests as the remaining boxes in there get checked off.

@sappelhoff
sappelhoff merged commit bc46978 into sappelhoff:master May 8, 2021
@sappelhoff

Copy link
Copy Markdown
Owner

Great, thanks!

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.

Testing Matlab PREP in our CI? Directly comparing with pyprep

3 participants