-
Notifications
You must be signed in to change notification settings - Fork 41
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
[DRAFT] Redesign/datasets ICA addition #56
base: develop-eeg
Are you sure you want to change the base?
Conversation
Implement in-memory caching for speed
Move this to the other PR. |
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.
Thanks for this Victor! Here are my recommendations
benchmarks/MOABB/dataio/ica.py
Outdated
def process( | ||
self, raw: mne.io.RawArray, raw_path: Union[str, Path] | ||
) -> mne.io.RawArray: | ||
"""Process raw data with ICA, computing or loading from cache.""" | ||
|
||
ica_path = self.get_ica_path(raw_path) | ||
|
||
if not ica_path.exists(): | ||
ica = self.compute_ica(raw, ica_path) | ||
else: | ||
ica = mne.preprocessing.read_ica(ica_path, verbose="ERROR") | ||
|
||
# Create a copy of the raw data before applying ICA | ||
raw_ica = raw.copy() | ||
ica.apply(raw_ica) | ||
|
||
return raw_ica |
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.
def process( | |
self, raw: mne.io.RawArray, raw_path: Union[str, Path] | |
) -> mne.io.RawArray: | |
"""Process raw data with ICA, computing or loading from cache.""" | |
ica_path = self.get_ica_path(raw_path) | |
if not ica_path.exists(): | |
ica = self.compute_ica(raw, ica_path) | |
else: | |
ica = mne.preprocessing.read_ica(ica_path, verbose="ERROR") | |
# Create a copy of the raw data before applying ICA | |
raw_ica = raw.copy() | |
ica.apply(raw_ica) | |
return raw_ica | |
@property | |
def dynamic_item(self): | |
@takes("raw", "fpath") | |
@provides("raw", "ica_path") | |
def process( | |
raw: mne.io.RawArray, fpath: Union[str, Path] | |
): | |
"""Process raw data with ICA, computing or loading from cache.""" | |
ica_path = self.get_ica_path(fpath) | |
if not ica_path.exists(): | |
ica = self.compute_ica(raw, ica_path) | |
else: | |
ica = mne.preprocessing.read_ica(ica_path, verbose="ERROR") | |
# Create a copy of the raw data before applying ICA | |
raw_ica = raw.copy() | |
ica.apply(raw_ica) | |
yield raw_ica | |
yield ica_path | |
return process |
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.
function inside one function is not super nice
Co-authored-by: Drew Wagner <[email protected]>
bids_path.root = bids_path.root / ".." / "derivatives" / folder_name | ||
# Keep the same base entities: | ||
bids_path.update( | ||
suffix="eeg", # override or confirm suffix | ||
extension=".fif", | ||
description=desc, # <-- This sets a desc=ica entity | ||
check=True, # If you do not want BIDSPath to fail on derivative checks | ||
) |
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.
bids_path.root = bids_path.root / ".." / "derivatives" / folder_name | |
# Keep the same base entities: | |
bids_path.update( | |
suffix="eeg", # override or confirm suffix | |
extension=".fif", | |
description=desc, # <-- This sets a desc=ica entity | |
check=True, # If you do not want BIDSPath to fail on derivative checks | |
) | |
ica_path = bids_path.update( | |
processing="ica", suffix="ica" | |
) |
check=True, # If you do not want BIDSPath to fail on derivative checks | ||
) | ||
# Make sure the folder is created | ||
bids_path.fpath.parent.mkdir(parents=True, exist_ok=True) |
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.
bids_path.fpath.parent.mkdir(parents=True, exist_ok=True) | |
ica_path.mkdir(parents=True, exist_ok=True) |
ica_path = bids_path.fpath | ||
metadata_path = ica_path.with_suffix(".json") |
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.
ica_path = bids_path.fpath | |
metadata_path = ica_path.with_suffix(".json") | |
metadata_path = bids_path.update( | |
suffix="metaica", extension=".json" | |
) |
if self.filter_params is not None: | ||
# Apply high-pass filter only if filter parameters are provided | ||
raw_filtered = raw.copy() | ||
raw_filtered.filter(**self.filter_params) | ||
else: | ||
# Use raw data directly if no filtering is needed | ||
raw_filtered = raw |
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.
if self.filter_params is not None: | |
# Apply high-pass filter only if filter parameters are provided | |
raw_filtered = raw.copy() | |
raw_filtered.filter(**self.filter_params) | |
else: | |
# Use raw data directly if no filtering is needed | |
raw_filtered = raw | |
raw.info['h_freq'] |
n_components=self.n_components, | ||
method=self.method, | ||
random_state=self.random_state, | ||
**self.fit_params, |
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.
**self.fit_params, | |
**self._fit_params, |
@@ -95,10 +95,12 @@ def __init__( | |||
data, | |||
preload=False, | |||
verbose=None, | |||
# ica_processor: Optional[ICAProcessor] = None, |
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.
# ica_processor: Optional[ICAProcessor] = None, |
description update Co-authored-by: Bru <[email protected]>
description update 2 Co-authored-by: Bru <[email protected]>
added ica as dynamic item to preprocessing pipeline. uses BIDSPath and exposes method and other features. still has issues with the use of caching.