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

New feature for removing heart artifacts from EEG or ESG data using a Principal Component Analysis - Optimal Basis Sets (PCA-OBS) algorithm #13037

Merged
merged 92 commits into from
Jan 19, 2025

Conversation

steinnhauser
Copy link
Contributor

What does this implement/fix?

Our PR implements the PCA-OBS algorithm for removal of heart-artefacts from EEG or ESG datasets. The PCA-OBS algorithm was originally designed to remove the ballistocardiographic artefact in simultaneous EEG-fMRI. Here, it has been adapted to remove the delay between the detected R-peak and the ballistocardiographic artefact such that the algorithm can be applied to remove the cardiac artefact in EEG (electroencephalogrpahy) and ESG (electrospinography) data.

Positive and negative tests have been implemented for the feature, and we have also included an example script which is implemented using data from openneuro (dataset ID: ds004388).

Authors:
Emma Bailey [email protected]
Steinn Hauser Magnusson [email protected]

emma-bailey and others added 30 commits September 1, 2024 12:57
Updating master with most recent package features
feat: add initial source code
…ove more unused variables and imports, add some types
…et data from, how we call functions, how we assert outputs
Update PCA OBS fork with most recent changes in main MNE repo
…ogging to use mne logger instead of prints, add wrapper method in front of private _pca_obs method to handle parallel processing
@steinnhauser
Copy link
Contributor Author

Added this as I think it's misleading to return anything if the function modifies the raw instance in-place. Happy to change this though if it clashes with the library patterns

we usually do return the instance even when modifying in-place, to allow method chaining. So it should always return modified (copy of) orig raw

Sounds good! Thanks for the feedback. Removed conditional return in d170c39

steinnhm and others added 9 commits January 13, 2025 10:08
* upstream/main:
  [DOC] extend documentation for add_channels (mne-tools#13051)
  Add `combine_tfr` to API (mne-tools#13054)
  Add `combine_spectrum()` function and allow `grand_average()` to support `Spectrum` data (mne-tools#13058)
  BUG: Fix bug with helium anon (mne-tools#13056)
  [ENH] Add option to store and return TFR taper weights (mne-tools#12910)
Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

Just a few last minor comments from me, @drammock did you want to look before merge?

mne/preprocessing/tests/test_pca_obs.py Outdated Show resolved Hide resolved
mne/preprocessing/tests/test_pca_obs.py Outdated Show resolved Hide resolved
mne/preprocessing/tests/test_pca_obs.py Outdated Show resolved Hide resolved
Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

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

marking as "request changes" because openneuro was added as a dependency but not added to pyproject.toml. The rest is almost all cosmetic. Nice work!

examples/preprocessing/esg_rm_heart_artefact_pcaobs.py Outdated Show resolved Hide resolved
examples/preprocessing/esg_rm_heart_artefact_pcaobs.py Outdated Show resolved Hide resolved
examples/preprocessing/esg_rm_heart_artefact_pcaobs.py Outdated Show resolved Hide resolved
examples/preprocessing/esg_rm_heart_artefact_pcaobs.py Outdated Show resolved Hide resolved
examples/preprocessing/esg_rm_heart_artefact_pcaobs.py Outdated Show resolved Hide resolved
examples/preprocessing/esg_rm_heart_artefact_pcaobs.py Outdated Show resolved Hide resolved
examples/preprocessing/esg_rm_heart_artefact_pcaobs.py Outdated Show resolved Hide resolved
mne/datasets/utils.py Show resolved Hide resolved
mne/datasets/utils.py Show resolved Hide resolved
mne/preprocessing/_pca_obs.py Outdated Show resolved Hide resolved
@steinnhauser
Copy link
Contributor Author

Thank you for the suggestions and changes! @drammock @larsoner it's looking far better

@larsoner
Copy link
Member

pip-pre will fail until #13069 lands, which contains a fix

@drammock drammock enabled auto-merge (squash) January 17, 2025 20:39
@drammock drammock disabled auto-merge January 17, 2025 20:39
@larsoner larsoner enabled auto-merge (squash) January 17, 2025 21:39
@larsoner
Copy link
Member

Marking for merge-when-green, thanks in advance @emma-bailey @steinnhauser !

@larsoner larsoner merged commit 4f53a37 into mne-tools:main Jan 19, 2025
30 checks passed
Copy link

welcome bot commented Jan 19, 2025

🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪

qian-chu pushed a commit to qian-chu/mne-python that referenced this pull request Jan 20, 2025
… Principal Component Analysis - Optimal Basis Sets (PCA-OBS) algorithm (mne-tools#13037)

Co-authored-by: Emma Bailey <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Steinn Magnusson <[email protected]>
Co-authored-by: Eric Larson <[email protected]>
Co-authored-by: emma-bailey <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel McCloy <[email protected]>
larsoner added a commit to larsoner/mne-python that referenced this pull request Jan 24, 2025
* upstream/main: (57 commits)
  Allow lasso selection sensors in a plot_evoked_topo (mne-tools#12071)
  MAINT: Fix doc build (mne-tools#13076)
  BUG: Improve sklearn compliance (mne-tools#13065)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13073)
  MAINT: Add Numba to 3.13 test (mne-tools#13075)
  Bump autofix-ci/action from ff86a557419858bb967097bfc916833f5647fa8c to 551dded8c6cc8a1054039c8bc0b8b48c51dfc6ef in the actions group (mne-tools#13071)
  [BUG] Correct annotation onset for exportation to EDF and EEGLAB (mne-tools#12656)
  New feature for removing heart artifacts from EEG or ESG data using a Principal Component Analysis - Optimal Basis Sets (PCA-OBS) algorithm (mne-tools#13037)
  [BUG] Fix taper weighting in computation of TFR multitaper power (mne-tools#13067)
  [FIX] Reading an EDF with preload=False and mixed frequency (mne-tools#13069)
  Fix evoked topomap colorbars, closes mne-tools#13050 (mne-tools#13063)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13060)
  BUG: Fix bug with interval calculation (mne-tools#13062)
  [DOC] extend documentation for add_channels (mne-tools#13051)
  Add `combine_tfr` to API (mne-tools#13054)
  Add `combine_spectrum()` function and allow `grand_average()` to support `Spectrum` data (mne-tools#13058)
  BUG: Fix bug with helium anon (mne-tools#13056)
  [ENH] Add option to store and return TFR taper weights (mne-tools#12910)
  BUG: viz plot window's 'title' argument showed no effect. (mne-tools#12828)
  MAINT: Ensure limited set of tests are skipped (mne-tools#13053)
  ...
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.

6 participants