-
Notifications
You must be signed in to change notification settings - Fork 260
Add DetectAndRemoveBadChannelsRecording and DetectAndInterpolateBadChannelsRecording classes
#3685
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
Changes from 3 commits
db8849e
5138e1f
ef0cc53
719463a
a5e8af5
10c5d41
2a199e9
6c2fdee
3320d00
6b07bb4
4270885
658a015
437669f
4036938
badad10
baf887c
1f1d8c8
166d722
291993f
a959b35
56da71c
02540f4
bbe2a53
a2a6f18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,10 @@ | |
| from spikeinterface import NumpyRecording, get_random_data_chunks | ||
| from probeinterface import generate_linear_probe | ||
|
|
||
| from spikeinterface.generation import generate_recording | ||
|
|
||
| from spikeinterface.core import generate_recording | ||
| from spikeinterface.preprocessing import detect_bad_channels, highpass_filter | ||
| from spikeinterface.preprocessing import detect_bad_channels, highpass_filter, remove_bad_channels | ||
|
|
||
| try: | ||
| # WARNING : this is not this package https://pypi.org/project/neurodsp/ | ||
|
|
@@ -18,6 +20,45 @@ | |
| HAVE_NPIX = False | ||
|
|
||
|
|
||
| def test_remove_bad_channel(): | ||
| """ | ||
| Generate a recording, then remove bad channels with a low noise threshold, | ||
| so that some units are removed. Then check that the new recording has none | ||
| of the bad channels still in it and that the one changed kwarg is successfully | ||
| propogated to the new recording. | ||
| """ | ||
|
|
||
| recording = generate_recording(durations=[5, 6], seed=1205, num_channels=8) | ||
| recording.set_channel_offsets(0) | ||
| recording.set_channel_gains(1) | ||
|
|
||
| # set noisy_channel_threshold so that we do detect some bad channels | ||
| new_rec = remove_bad_channels(recording, noisy_channel_threshold=0, seed=1205) | ||
|
|
||
| # make sure they are removed | ||
| bad_channel_ids = new_rec._kwargs["bad_channel_ids"] | ||
| assert len(set(bad_channel_ids).intersection(new_rec.channel_ids)) == 0 | ||
| # and the good ones are kept | ||
| good_channel_ids = recording.channel_ids[~np.isin(recording.channel_ids, bad_channel_ids)] | ||
| assert set(good_channel_ids) == set(new_rec.channel_ids) | ||
|
|
||
| # and that the kwarg is propogatged to the kwargs of new_rec. | ||
| assert set(new_rec._kwargs["channel_ids"]) == set(good_channel_ids) | ||
| assert new_rec._kwargs["noisy_channel_threshold"] == 0 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything to worry about channel ordering here? I guess not (and this is a question for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ordering of the channel ids?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. erm like order of the channels on the recording itself (I'm not sure how exactly this is represented 😅 ). But like the default order when you do |
||
|
|
||
| # now apply `detec_bad_channels` directly and see that the outputs matches | ||
| bad_channel_ids_from_function, channel_labels_from_function = detect_bad_channels( | ||
| recording, noisy_channel_threshold=0, seed=1205 | ||
| ) | ||
|
|
||
| assert np.all(new_rec._kwargs["bad_channel_ids"] == bad_channel_ids_from_function) | ||
| assert np.all(new_rec._kwargs["channel_labels"] == channel_labels_from_function) | ||
|
|
||
| new_rec_from_function = recording.remove_channels(remove_channel_ids=bad_channel_ids_from_function) | ||
|
|
||
| assert np.all(new_rec_from_function.channel_ids == new_rec.channel_ids) | ||
|
|
||
|
|
||
| def test_detect_bad_channels_std_mad(): | ||
| num_channels = 4 | ||
| sampling_frequency = 30000.0 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.