From f9bcba3c354654155a6e36832b07d642a3d3be35 Mon Sep 17 00:00:00 2001 From: Johann Benerradi Date: Fri, 9 Aug 2024 19:10:24 +0100 Subject: [PATCH] Add tmin to process_epochs --- benchnirs/learn.py | 4 ++-- benchnirs/process.py | 8 ++++++-- examples/dataset_size.py | 2 +- examples/generalised.py | 2 +- examples/personalised.py | 2 +- examples/sliding_window.py | 2 +- examples/tailored_generalised.py | 2 +- examples/tailored_window_size.py | 2 +- examples/window_size.py | 2 +- 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/benchnirs/learn.py b/benchnirs/learn.py index 1a2699b..b1970ce 100644 --- a/benchnirs/learn.py +++ b/benchnirs/learn.py @@ -942,8 +942,8 @@ def deep_transfer_learn(nirs, labels, groups, enc_class, dec_class, Processed NIRS data. labels : array of integers - List of labels matching the NIRS data. Must include values 8 for all - the unlabeled segments this should be performed by `process_epochs`. + List of labels matching the NIRS data. Must include values ``999`` for + all the unlabeled segments. groups : array of integers | None List of subject ID matching the epochs to perfrom a group k-fold diff --git a/benchnirs/process.py b/benchnirs/process.py index 5e73a1e..3826974 100644 --- a/benchnirs/process.py +++ b/benchnirs/process.py @@ -3,7 +3,7 @@ import numpy as np from scipy.stats import linregress, kurtosis -def process_epochs(mne_epochs, tmax=None, tslide=None, sort=False, +def process_epochs(mne_epochs, tmin=0, tmax=None, tslide=None, sort=False, reject_criteria=None): """ Perform processing on epochs including baseline cropping, bad epoch @@ -15,6 +15,10 @@ def process_epochs(mne_epochs, tmax=None, tslide=None, sort=False, MNE epochs of filtered data with associated labels. Subject IDs are contained in the ``metadata`` property. + tmin : float | None + Start time of selection in seconds. Defaults to ``0`` to crop the + baseline. + tmax : float | None End time of selection in seconds. Defaults to ``None`` to keep the initial end time. @@ -51,7 +55,7 @@ def process_epochs(mne_epochs, tmax=None, tslide=None, sort=False, # Process epochs epochs = mne_epochs.copy() epochs.baseline = None - epochs.crop(tmin=0, tmax=tmax) + epochs.crop(tmin=tmin, tmax=tmax) if reject_criteria is not None: reject = {'hbo': reject_criteria[0]*1e-6, 'hbr': reject_criteria[1]*1e-6} diff --git a/examples/dataset_size.py b/examples/dataset_size.py index 341ddb4..674d9ac 100644 --- a/examples/dataset_size.py +++ b/examples/dataset_size.py @@ -47,7 +47,7 @@ for dataset in DATASETS.keys(): classes = DATASETS[dataset] epochs_lab = epochs[classes] - all_nirs, all_labels, all_groups = process_epochs(epochs_lab, 9.9) + all_nirs, all_labels, all_groups = process_epochs(epochs_lab, tmax=9.9) dict_train_size = {'Dataset size': [], 'Chance': [], 'LDA': [], 'SVC': [], 'kNN': [], 'ANN': [], 'CNN': [], 'LSTM': []} for ts in DATASET_SIZES: diff --git a/examples/generalised.py b/examples/generalised.py index e88d898..4e4f69b 100644 --- a/examples/generalised.py +++ b/examples/generalised.py @@ -53,7 +53,7 @@ for dataset in DATASETS.keys(): epochs_lab = epochs[classes] # Run models - nirs, labels, groups = process_epochs(epochs_lab, 9.9) + nirs, labels, groups = process_epochs(epochs_lab, tmax=9.9) nirs_features = extract_features(nirs, ['mean', 'std', 'slope']) lda, hps_lda, _ = machine_learn( nirs_features, labels, groups, 'lda', output_folder=f'{out_path}lda') diff --git a/examples/personalised.py b/examples/personalised.py index 504e85a..467f718 100644 --- a/examples/personalised.py +++ b/examples/personalised.py @@ -52,7 +52,7 @@ for dataset in DATASETS.keys(): epochs_lab = epochs[classes] # Learn - all_nirs, all_labels, all_groups = process_epochs(epochs_lab, 9.9) + all_nirs, all_labels, all_groups = process_epochs(epochs_lab, tmax=9.9) dict_accuracies = {'Model': [], 'Accuracy': []} all_results = {'LDA': [], 'SVC': [], 'kNN': [], 'ANN': [], 'CNN': [], 'LSTM': []} diff --git a/examples/sliding_window.py b/examples/sliding_window.py index f69d272..6a2274c 100644 --- a/examples/sliding_window.py +++ b/examples/sliding_window.py @@ -53,7 +53,7 @@ for dataset in DATASETS.keys(): epochs_lab = epochs[classes] # Run models - nirs, labels, groups = process_epochs(epochs_lab, 9.9, tslide=2) + nirs, labels, groups = process_epochs(epochs_lab, tmax=9.9, tslide=2) nirs_features = extract_features(nirs, ['mean', 'std', 'slope']) lda, hps_lda, _ = machine_learn( nirs_features, labels, groups, 'lda', output_folder=f'{out_path}lda') diff --git a/examples/tailored_generalised.py b/examples/tailored_generalised.py index c01e81b..ad78834 100644 --- a/examples/tailored_generalised.py +++ b/examples/tailored_generalised.py @@ -77,7 +77,7 @@ for dataset in DATASETS.keys(): epochs_lab = epochs[classes] # Run models - nirs, labels, groups = process_epochs(epochs_lab, 39.9) + nirs, labels, groups = process_epochs(epochs_lab, tmax=39.9) nirs_features = extract_features(nirs, ['mean', 'std', 'slope']) lda, hps_lda, _ = machine_learn( nirs_features, labels, groups, 'lda', output_folder=f'{out_path}lda') diff --git a/examples/tailored_window_size.py b/examples/tailored_window_size.py index 1214573..af9def3 100644 --- a/examples/tailored_window_size.py +++ b/examples/tailored_window_size.py @@ -45,7 +45,7 @@ for dataset in DATASETS.keys(): 'LDA': [], 'SVC': [], 'kNN': [], 'ANN': [], 'LSTM': []} for ws in WINDOW_SIZES: print(f'-----\nWindow size {ws}\n-----') - nirs, labels, groups = process_epochs(epochs_lab, ws) + nirs, labels, groups = process_epochs(epochs_lab, tmax=ws) nirs_features = extract_features(nirs, ['mean', 'std', 'slope']) # Run models diff --git a/examples/window_size.py b/examples/window_size.py index 387ae10..b8b9325 100644 --- a/examples/window_size.py +++ b/examples/window_size.py @@ -48,7 +48,7 @@ for dataset in DATASETS.keys(): 'LDA': [], 'SVC': [], 'kNN': [], 'ANN': []} for ws in WINDOW_SIZES: print(f'-----\nWindow size {ws}\n-----') - nirs, labels, groups = process_epochs(epochs_lab, ws) + nirs, labels, groups = process_epochs(epochs_lab, tmax=ws) nirs_features = extract_features(nirs, ['mean', 'std', 'slope']) # Run models -- GitLab