-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
FIX: Fix grand_average
to support BaseSpectrum
objects
#13375
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
Merged
+42
−5
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5829fa0
Add spectrum nave setter
tsbinns 9b692f2
Add Spectrum input test for equalize_channels
tsbinns cdbd7b2
Use new nave setter in combine_spectrum test
tsbinns 9970507
Add changelog entry
tsbinns f65c6ff
Add BaseSpectrum support to equalize_channels
tsbinns 9604d11
Add grand_average test for spectrum data
tsbinns 2f7247e
Merge branch 'main' into grand_avg_spectrum_support
tsbinns 7481822
Merge branch 'main' into grand_avg_spectrum_support
tsbinns f160b55
Merge branch 'main' into grand_avg_spectrum_support
tsbinns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix bug with :func:`mne.grand_average` not working with :class:`mne.time_frequency.Spectrum` objects, by `Thomas Binns`_. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,14 @@ | |
from matplotlib.colors import same_color | ||
from numpy.testing import assert_allclose, assert_array_equal | ||
|
||
from mne import Annotations, BaseEpochs, create_info, make_fixed_length_epochs | ||
from mne import ( | ||
Annotations, | ||
BaseEpochs, | ||
create_info, | ||
grand_average, | ||
make_fixed_length_epochs, | ||
) | ||
from mne.channels import equalize_channels | ||
from mne.io import RawArray | ||
from mne.time_frequency import read_spectrum | ||
from mne.time_frequency.multitaper import _psd_from_mt | ||
|
@@ -200,8 +207,8 @@ def test_combine_spectrum(raw_spectrum, weights): | |
spectrum1 = raw_spectrum.copy() | ||
spectrum2 = raw_spectrum.copy() | ||
if weights == "nave": | ||
spectrum1._nave = 1 | ||
spectrum2._nave = 2 | ||
spectrum1.nave = 1 | ||
spectrum2.nave = 2 | ||
spectrum2._data *= 2 | ||
new_spectrum = combine_spectrum([spectrum1, spectrum2], weights=weights) | ||
assert_allclose(new_spectrum.data, spectrum1.data * (5 / 3)) | ||
|
@@ -243,6 +250,25 @@ def test_combine_spectrum_error_catch(raw_spectrum): | |
combine_spectrum([raw_spectrum, raw_spectrum2], weights="equal") | ||
|
||
|
||
def test_grand_average(raw_spectrum): | ||
"""Test `grand_average()` works for instances of `BaseSpectrum`.""" | ||
spectrum1 = raw_spectrum.copy() | ||
spectrum2 = raw_spectrum.copy() | ||
spectrum2._data *= 2 | ||
new_spectrum = grand_average([spectrum1, spectrum2]) | ||
assert_allclose(new_spectrum.data, spectrum1.data * 1.5) | ||
|
||
|
||
def test_equalize_channels(raw_spectrum): | ||
"""Test equalization of channels for instances of `BaseSpectrum`.""" | ||
spect1 = raw_spectrum.copy() | ||
spect2 = spect1.copy().pick(["MEG 0122", "MEG 0111"]) | ||
spect1, spect2 = equalize_channels([spect1, spect2]) | ||
|
||
assert spect1.ch_names == ["MEG 0111", "MEG 0122"] | ||
assert spect2.ch_names == ["MEG 0111", "MEG 0122"] | ||
Comment on lines
+262
to
+269
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. This follows the existing tests for checking |
||
|
||
|
||
def test_spectrum_reject_by_annot(raw): | ||
"""Test rejecting by annotation. | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small note: can't import
BaseSpectrum
directly from thetime_frequency
module, and it's not included in the API reference, butBaseTFR
is.