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

[ENH, MRG] Add EpochsSpectrumArray and SpectrumArray classes #11803

Merged
merged 62 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
395a758
[ENH, MRG] Add EpochsSpectrumArray and SpectrumArray classes [skip ci
alexrockhill Jul 13, 2023
710cef4
update latest
alexrockhill Jul 13, 2023
e34bc38
fix refs
alexrockhill Jul 13, 2023
3fcb557
wrong versionadded
alexrockhill Jul 13, 2023
597c48c
Update mne/time_frequency/spectrum.py
alexrockhill Jul 14, 2023
6a54f68
Update mne/time_frequency/spectrum.py
alexrockhill Jul 14, 2023
125903e
epoch not epochs
alexrockhill Jul 14, 2023
e0fb07f
edit seealso [ci skip]
drammock Jul 14, 2023
8cee941
Dan review
alexrockhill Jul 14, 2023
738c8d3
Merge branch 'defaults' of https://github.com/alexrockhill/mne-python…
alexrockhill Jul 14, 2023
0cd6ec8
style
alexrockhill Jul 14, 2023
5d18ff3
Merge branch 'main' into defaults
alexrockhill Jul 14, 2023
27be8d8
cruft, test plot
alexrockhill Jul 14, 2023
145b6bb
style
alexrockhill Jul 14, 2023
71016d6
very picky style
alexrockhill Jul 14, 2023
1ccf8a4
add fixtures
alexrockhill Jul 18, 2023
ece2b39
Merge branch 'main' into defaults
alexrockhill Jul 18, 2023
ff203ff
Merge branch 'main' into defaults
alexrockhill Jul 19, 2023
725446d
Dan review
alexrockhill Jul 26, 2023
ecbd0a8
Merge branch 'main' of https://github.com/mne-tools/mne-python into d…
alexrockhill Jul 26, 2023
f8e98ce
Merge branch 'defaults' of https://github.com/alexrockhill/mne-python…
alexrockhill Jul 26, 2023
cb80688
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2023
fd830e9
style
alexrockhill Jul 26, 2023
e5bd6a9
Merge branch 'defaults' of https://github.com/alexrockhill/mne-python…
alexrockhill Jul 26, 2023
e1bcbd9
fix repr raising error
drammock Jul 26, 2023
4a76c9f
make repr more honest
drammock Jul 26, 2023
7ef0626
readability
drammock Jul 26, 2023
f031c8b
fix wrong docstring
drammock Jul 26, 2023
62e25f4
make docstrings parallel
drammock Jul 26, 2023
f8e74c9
add note about assuming power
drammock Jul 26, 2023
36df9b5
through version with bug fixes, plots were checked
alexrockhill Jul 27, 2023
147d110
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 27, 2023
ba24ebb
style'
alexrockhill Jul 27, 2023
026e8e6
Merge branch 'defaults' of https://github.com/alexrockhill/mne-python…
alexrockhill Jul 27, 2023
7340ea2
Merge branch 'main' into defaults
alexrockhill Jul 27, 2023
e4ca8ca
Merge branch 'defaults' of https://github.com/alexrockhill/mne-python…
alexrockhill Jul 27, 2023
4d48f42
style
alexrockhill Jul 27, 2023
b98d2b8
fix tests
alexrockhill Jul 28, 2023
d8fefc8
fix one last tests
alexrockhill Jul 28, 2023
3c4da24
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 28, 2023
9c2cd25
style
alexrockhill Jul 28, 2023
10a2667
Merge branch 'main' into defaults
alexrockhill Aug 1, 2023
92d8a9d
spelling
alexrockhill Aug 2, 2023
5a33651
Merge branch 'defaults' of https://github.com/alexrockhill/mne-python…
alexrockhill Aug 2, 2023
6404aaa
Merge branch 'main' of https://github.com/mne-tools/mne-python into d…
alexrockhill Aug 2, 2023
da45d5c
refactor tests
alexrockhill Aug 2, 2023
1a42bf6
oops switched psd, psd2
alexrockhill Aug 3, 2023
e71672a
style
alexrockhill Aug 3, 2023
04262f2
Merge branch 'main' of https://github.com/mne-tools/mne-python into d…
alexrockhill Aug 18, 2023
b099177
resolve conflicts
alexrockhill Aug 18, 2023
265f009
cruft
alexrockhill Aug 18, 2023
2427b9f
Merge branch 'main' into defaults
alexrockhill Aug 25, 2023
54488ed
try skip h5io
alexrockhill Aug 25, 2023
1a1e57f
Merge branch 'defaults' of https://github.com/alexrockhill/mne-python…
alexrockhill Aug 25, 2023
9f45402
Merge branch 'main' into defaults
alexrockhill Aug 29, 2023
8f49d05
remove complex support
alexrockhill Aug 29, 2023
831c1ee
Merge branch 'defaults' of https://github.com/alexrockhill/mne-python…
alexrockhill Aug 29, 2023
b6707f3
Merge branch 'main' into defaults
alexrockhill Aug 29, 2023
e178231
simplifications and fixes
drammock Sep 1, 2023
88c790e
Merge remote-tracking branch 'upstream/main' into defaults
drammock Sep 1, 2023
f735e12
oops missed this
drammock Sep 1, 2023
40627ac
Update tutorials/simulation/10_array_objs.py
drammock Sep 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/devel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Enhancements
- Added public :func:`mne.io.write_info` to complement :func:`mne.io.read_info` (:gh:`11918` by `Eric Larson`_)
- Added option ``remove_dc`` to to :meth:`Raw.compute_psd() <mne.io.Raw.compute_psd>`, :meth:`Epochs.compute_psd() <mne.Epochs.compute_psd>`, and :meth:`Evoked.compute_psd() <mne.Evoked.compute_psd>`, to allow skipping DC removal when computing Welch or multitaper spectra (:gh:`11769` by `Nikolai Chapochnikov`_)
- Add the possibility to provide a float between 0 and 1 as ``n_grad``, ``n_mag`` and ``n_eeg`` in `~mne.compute_proj_raw`, `~mne.compute_proj_epochs` and `~mne.compute_proj_evoked` to select the number of vectors based on the cumulative explained variance (:gh:`11919` by `Mathieu Scheltienne`_)
- Add :class:`mne.time_frequency.EpochsSpectrumArray` and :class:`mne.time_frequency.SpectrumArray` to allow for instantiating power spectra from scratch (:gh:`11803` by `Alex Rockhill`_)

Bugs
~~~~
Expand Down
2 changes: 2 additions & 0 deletions doc/time_frequency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Time-Frequency
EpochsTFR
CrossSpectralDensity
Spectrum
SpectrumArray
EpochsSpectrum
EpochsSpectrumArray

Functions that operate on mne-python objects:

Expand Down
28 changes: 28 additions & 0 deletions mne/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,19 @@ def raw_ctf():
return raw_ctf


@pytest.fixture(scope="function")
def raw_psds(raw):
"""Get raw with power spectral density computed from mne.io.tests.data."""
return [
raw.compute_psd(
output="complex",
method=method,
**dict(average=None) if method == "welch" else dict(),
)
for method in ("welch", "multitaper")
]


@pytest.fixture(scope="function")
def events():
"""Get events from mne.io.tests.data."""
Expand Down Expand Up @@ -349,6 +362,21 @@ def epochs_full():
return _get_epochs(None).load_data()


@pytest.fixture()
def epochs_psds():
"""Get epochs with power spectral density computed from mne.io.tests.data."""
return [
_get_epochs()
.load_data()
.compute_psd(
output="complex",
method=method,
**dict(average=False) if method == "welch" else dict(),
)
for method in ("welch", "multitaper")
]


@pytest.fixture(scope="session", params=[testing._pytest_param()])
def _evoked():
# This one is session scoped, so be sure not to modify it (use evoked
Expand Down
37 changes: 7 additions & 30 deletions mne/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3165,40 +3165,17 @@ class EpochsArray(BaseEpochs):
measure.
%(info_not_none)s Consider using :func:`mne.create_info` to populate this
structure.
events : None | array of int, shape (n_events, 3)
The events typically returned by the read_events function.
If some events don't match the events of interest as specified
by event_id, they will be marked as 'IGNORED' in the drop log.
If None (default), all event values are set to 1 and event time-samples
are set to range(n_epochs).
tmin : float
Start time before event. If nothing provided, defaults to 0.
event_id : int | list of int | dict | None
The id of the event to consider. If dict,
the keys can later be used to access associated events. Example:
dict(auditory=1, visual=3). If int, a dict will be created with
the id as string. If a list, all events with the IDs specified
in the list are used. If None, all events will be used with
and a dict is created with string integer names corresponding
to the event id integers.
%(events_epochs)s
%(tmin_epochs)s
%(event_id)s
%(reject_epochs)s
%(flat)s
reject_tmin : scalar | None
Start of the time window used to reject epochs (with the default None,
the window will start with tmin).
reject_tmax : scalar | None
End of the time window used to reject epochs (with the default None,
the window will end with tmax).
%(epochs_reject_tmin_tmax)s
%(baseline_epochs)s
Defaults to ``None``, i.e. no baseline correction.
proj : bool | 'delayed'
Apply SSP projection vectors. See :class:`mne.Epochs` for details.
on_missing : str
See :class:`mne.Epochs` docstring for details.
metadata : instance of pandas.DataFrame | None
See :class:`mne.Epochs` docstring for details.

.. versionadded:: 0.16
%(proj_epochs)s
%(on_missing_epochs)s
%(metadata_epochs)s
%(selection)s
%(drop_log)s

Expand Down
11 changes: 11 additions & 0 deletions mne/time_frequency/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@
],
},
)
from .ar import fit_iir_model_raw
from .multitaper import dpss_windows, psd_array_multitaper, tfr_array_multitaper
from .spectrum import (
EpochsSpectrum,
EpochsSpectrumArray,
Spectrum,
SpectrumArray,
read_spectrum,
)
from ._stft import stft, istft, stftfreq
from ._stockwell import tfr_stockwell, tfr_array_stockwell
Loading
Loading