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

Open
wants to merge 84 commits into
base: main
Choose a base branch
from

Conversation

steinnhauser
Copy link

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
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.

Looks like a good start! A few code cleanup/MNE-ization comments, plus an idea about the API

mne/preprocessing/pca_obs.py Outdated Show resolved Hide resolved
tutorials/preprocessing/50_artifact_correction_ssp.py Outdated Show resolved Hide resolved
mne/preprocessing/pca_obs.py Outdated Show resolved Hide resolved
mne/preprocessing/pca_obs.py Outdated Show resolved Hide resolved
mne/preprocessing/pca_obs.py Outdated Show resolved Hide resolved
mne/preprocessing/pca_obs.py Outdated Show resolved Hide resolved
mne/preprocessing/pca_obs.py Outdated Show resolved Hide resolved
mne/preprocessing/pca_obs.py Outdated Show resolved Hide resolved
mne/preprocessing/pca_obs.py Outdated Show resolved Hide resolved
mne/preprocessing/pca_obs.py Outdated Show resolved Hide resolved
steinnhauser and others added 4 commits January 10, 2025 17:42
make fit_ecg_template a private function

Co-authored-by: Eric Larson <[email protected]>
improve docstring for PCA-OBS function, adds citation

Co-authored-by: Eric Larson <[email protected]>
@steinnhauser
Copy link
Author

After adding the copy kwarg I added an additional check in the end of the function:

    if copy:
        return raw

and reflected this "optional return" in the function typehinting:

@verbose
def apply_pca_obs(
    ...
) -> Raw | None:

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

@drammock
Copy link
Member

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

@steinnhauser
Copy link
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 8 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)
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