From 0b6ee93b0caeb118fc94ca73f8e7982accdfba82 Mon Sep 17 00:00:00 2001 From: Johann Benerradi Date: Tue, 21 May 2024 09:33:08 +0100 Subject: [PATCH 1/2] Fix legacy functions and verbose --- benchnirs/load.py | 2 +- benchnirs/process.py | 11 ++++------- benchnirs/viz.py | 14 +++++--------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/benchnirs/load.py b/benchnirs/load.py index 36e7db3..90bbdbc 100644 --- a/benchnirs/load.py +++ b/benchnirs/load.py @@ -601,7 +601,7 @@ def load_dataset(dataset, path, bandpass=None, order=4, tddr=False, # Average channels by side if roi_sides is True: raw = combine_channels(raw, data['sides'], method='mean', - keep_stim=True) + keep_stim=True, verbose=False) # Get unlabelled possible segments events = mne.find_events(raw, consecutive=True, stim_channel='STI', diff --git a/benchnirs/process.py b/benchnirs/process.py index 89676ac..d7af192 100644 --- a/benchnirs/process.py +++ b/benchnirs/process.py @@ -50,20 +50,17 @@ def process_epochs(mne_epochs, tmax=None, tslide=None, sort=False, if reject_criteria is not None: reject = {'hbo': reject_criteria[0]*1e-6, 'hbr': reject_criteria[1]*1e-6} - original_verbose = epochs.verbose - epochs.verbose = True epochs.drop_bad(reject=reject) - epochs.verbose = original_verbose # Extract data labels = epochs.events[:, 2] - 1 # start at 0 groups = epochs.metadata['Subject_ID'].to_numpy() - 1 # start at 0 - nirs_epochs = epochs.pick_types(stim=False, fnirs=True) + nirs_epochs = epochs.pick('fnirs') if sort: - hbo_chs = epochs.copy().pick_types(stim=False, fnirs='hbo').ch_names - hbr_chs = epochs.copy().pick_types(stim=False, fnirs='hbr').ch_names + hbo_chs = epochs.copy().pick('hbo').ch_names + hbr_chs = epochs.copy().pick('hbr').ch_names nirs_epochs.reorder_channels(hbo_chs + hbr_chs) - nirs = nirs_epochs.get_data() + nirs = nirs_epochs.get_data(copy=True) nirs *= 1e6 # convert from M to uM # Create sliding window diff --git a/benchnirs/viz.py b/benchnirs/viz.py index 81dc518..0b5b405 100644 --- a/benchnirs/viz.py +++ b/benchnirs/viz.py @@ -1,4 +1,3 @@ -import mne import numpy as np from mne.viz import plot_epochs_image, plot_compare_evokeds @@ -46,16 +45,13 @@ def epochs_viz(mne_epochs, reject_criteria=None): if reject_criteria is not None: reject = {'hbo': reject_criteria[0]*1e-6, 'hbr': reject_criteria[1]*1e-6} - original_verbose = epochs.verbose - epochs.verbose = True epochs.drop_bad(reject=reject) - epochs.verbose = original_verbose # Plot all epochs epochs.plot(events=epochs.events, scalings='auto', n_epochs=10, block=True) # Plot power spectral density - epochs.plot_psd(fmin=0, fmax=5, average=True) + epochs.compute_psd(fmin=0, fmax=5).plot(average=True) # Visualise with average epochs superposed conditions = epochs.event_id.keys() @@ -67,8 +63,8 @@ def epochs_viz(mne_epochs, reject_criteria=None): styles_dict = {} linestyles = ['dotted', 'dashed', 'solid'] for idx, condition in enumerate(conditions): - evs_hbo = list(epochs[condition].pick_types(fnirs='hbo').iter_evoked()) - evs_hbr = list(epochs[condition].pick_types(fnirs='hbr').iter_evoked()) + evs_hbo = list(epochs[condition].copy().pick('hbo').iter_evoked()) + evs_hbr = list(epochs[condition].copy().pick('hbr').iter_evoked()) for ev in evs_hbo: ev.rename_channels(lambda x: x[:-4]) # remove ' HbO' from ch_names for ev in evs_hbr: @@ -85,12 +81,12 @@ def epochs_viz(mne_epochs, reject_criteria=None): title='Conditions with standard error') # Get only HbO and HbR and remove STIM channel - nirs_epochs = epochs.pick_types(stim=False, fnirs=True) + nirs_epochs = epochs.pick('fnirs') print(nirs_epochs) # Get fnirs data as a numpy array channels = nirs_epochs.info['ch_names'] - nirs = nirs_epochs.get_data() + nirs = nirs_epochs.get_data(copy=True) print(f'Channels: {channels}') print(f'NIRS data shape: {nirs.shape}') -- GitLab From 28147974525ffe2de3b2dc94e06dec300d1da3cc Mon Sep 17 00:00:00 2001 From: Johann Benerradi Date: Tue, 21 May 2024 09:43:34 +0100 Subject: [PATCH 2/2] Update version number --- docs/source/conf.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 59129b5..65db582 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -24,7 +24,7 @@ copyright = f'2021-{current_year}, Johann Benerradi' author = 'Johann Benerradi' # The full version, including alpha/beta/rc tags -release = '1.2.2' +release = '1.2.3' # -- General configuration --------------------------------------------------- diff --git a/setup.py b/setup.py index 1b77019..c1d83ac 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="benchnirs", - version="1.2.2", + version="1.2.3", author="Johann Benerradi", author_email="johann.benerradi@gmail.com", description="Benchmarking framework for machine learning with fNIRS", -- GitLab