From 8684e225109a369157c087a053efe1c6bb59157c Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 19 Jul 2021 20:33:56 +0200 Subject: [PATCH 001/128] Update detect_alpha_peak.py --- detect_alpha_peak.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect_alpha_peak.py b/detect_alpha_peak.py index ac7cb6b..deac4bb 100755 --- a/detect_alpha_peak.py +++ b/detect_alpha_peak.py @@ -100,7 +100,7 @@ def plot_psd_per_channels(freqs, alpha_freq_pic_per_channel, psd_in_alpha_freqs_ plt.figure() - for channel in range(0, len(alpha_freq_pic_per_channel)): + for channel in range(0, len(alpha_freq_pic_per_channel)): plt.plot(freqs, psd_welch[channel], zorder=1) # Define lim From b8a4d1d9862996fb79e80c59bf790257cb803a20 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 19 Jul 2021 20:37:59 +0200 Subject: [PATCH 002/128] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ed6c3c3..9ec5a9c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ # app-detect-alpha-peak + +[![Abcdspec-compliant](https://img.shields.io/badge/ABCD_Spec-v1.1-green.svg)](https://github.com/brain-life/abcd-spec) +[![Run on Brainlife.io](https://img.shields.io/badge/Brainlife-bl.app.469-blue.svg)](https://doi.org/10.25663/brainlife.app.469) + Detect individual alpha peak in MEG signals. # app-detect-alpha-peak documentation @@ -15,7 +19,7 @@ Detect individual alpha peak in MEG signals. - [Aurore Bussalb](aurore.bussalb@icm-institute.org) ### Contributors -- [Aurore Bussalb](aurore.bussalb@icm-institute.org) +- [Guiomar Niso](guiomar.niso@ctb.upm.es) - [Maximilien Chaumon](maximilien.chaumon@icm-institute.org) ### Funding Acknowledgement From 6284bc9de46a5ae45ed56b17ae03d685cace28dd Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 19 Jul 2021 20:39:18 +0200 Subject: [PATCH 003/128] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ec5a9c..c08f58f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Detect individual alpha peak in MEG signals. -# app-detect-alpha-peak documentation +## app-detect-alpha-peak documentation 1) Detect alpha peak frequency for each channel and for the mean over all channels 2) Input file is: From 361a71229aa5b79755f3f1dffc7383ca0a35907e Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Fri, 30 Jul 2021 21:38:47 +0200 Subject: [PATCH 004/128] Update detect_alpha_peak.py --- detect_alpha_peak.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/detect_alpha_peak.py b/detect_alpha_peak.py index deac4bb..5ad86b0 100755 --- a/detect_alpha_peak.py +++ b/detect_alpha_peak.py @@ -22,9 +22,11 @@ def get_alpha_freqs(freqs): def detect_alpha_peak_mean(psd_welch, alpha_freqs, indexes_alpha_freqs): # Average PSD across all channels + # MEAN OF THE PEAKS FOR EACH CHANNEL OR MEAN OF THE CHENNELS AND THEN PEAK?? (GUIO) psd_welch_mean = np.mean(psd_welch, axis=0) # Get the std of the mean + # STD OR STDERR?? (GUIO) psd_welch_std = np.std(psd_welch, axis=0) # Extract psd in alpha freqs @@ -33,6 +35,7 @@ def detect_alpha_peak_mean(psd_welch, alpha_freqs, indexes_alpha_freqs): # Find peak pic_loc = mne.preprocessing.peak_finder(psd_in_alpha_freqs_mean) + print(pic_loc) # Find the corresponding frequency index_of_the_pic = int(pic_loc[0]) alpha_freq_pic_mean = alpha_freqs[index_of_the_pic] # Apply the index of the pic in alpha_freqs, not in freqs! From aa1190681854c214caee06370d0c4ffbd8417b73 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 2 Aug 2021 14:40:47 +0200 Subject: [PATCH 005/128] Update detect_alpha_peak.py --- detect_alpha_peak.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/detect_alpha_peak.py b/detect_alpha_peak.py index 5ad86b0..4809d65 100755 --- a/detect_alpha_peak.py +++ b/detect_alpha_peak.py @@ -36,6 +36,8 @@ def detect_alpha_peak_mean(psd_welch, alpha_freqs, indexes_alpha_freqs): pic_loc = mne.preprocessing.peak_finder(psd_in_alpha_freqs_mean) print(pic_loc) + # If is empty (no peak found) + if pic_loc[0].size==0: pic_loc=([0],[0]) # Find the corresponding frequency index_of_the_pic = int(pic_loc[0]) alpha_freq_pic_mean = alpha_freqs[index_of_the_pic] # Apply the index of the pic in alpha_freqs, not in freqs! From 6461fd91487d1fa0c9d388c1f945b496bba3fbaf Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 2 Aug 2021 14:44:09 +0200 Subject: [PATCH 006/128] Update detect_alpha_peak.py --- detect_alpha_peak.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect_alpha_peak.py b/detect_alpha_peak.py index 4809d65..ae33660 100755 --- a/detect_alpha_peak.py +++ b/detect_alpha_peak.py @@ -37,7 +37,7 @@ def detect_alpha_peak_mean(psd_welch, alpha_freqs, indexes_alpha_freqs): print(pic_loc) # If is empty (no peak found) - if pic_loc[0].size==0: pic_loc=([0],[0]) + if pic_loc[0].size==0: pic_loc=(np.array([0]),np.array([0])) # Find the corresponding frequency index_of_the_pic = int(pic_loc[0]) alpha_freq_pic_mean = alpha_freqs[index_of_the_pic] # Apply the index of the pic in alpha_freqs, not in freqs! From 4778ccf7bc1ddc3aea8129a74d80c82ee7ef999f Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 2 Aug 2021 14:50:42 +0200 Subject: [PATCH 007/128] Update detect_alpha_peak.py --- detect_alpha_peak.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect_alpha_peak.py b/detect_alpha_peak.py index ae33660..042c3a4 100755 --- a/detect_alpha_peak.py +++ b/detect_alpha_peak.py @@ -147,7 +147,7 @@ def main(): # Extract freqs freqs = df_psd_welch.columns.to_numpy() - freqs = freqs.astype(np.float) + freqs = freqs.astype(float) # Get alpha freqs alpha_freqs, indexes_alpha_freqs = get_alpha_freqs(freqs) From d18bfcb7fbb8420f163b1dade09e8f174a12161c Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 2 Aug 2021 14:56:11 +0200 Subject: [PATCH 008/128] Update detect_alpha_peak.py --- detect_alpha_peak.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/detect_alpha_peak.py b/detect_alpha_peak.py index 042c3a4..dc98e2f 100755 --- a/detect_alpha_peak.py +++ b/detect_alpha_peak.py @@ -55,6 +55,10 @@ def detect_alpha_peak_per_channels(psd_welch, alpha_freqs, indexes_alpha_freqs): psd_in_alpha_freqs_per_channel = np.take(psd_welch[channel, :], indexes_alpha_freqs) # Find peak pic_loc = mne.preprocessing.peak_finder(psd_in_alpha_freqs_per_channel) + print(pic_loc) + # If is empty (no peak found) + if pic_loc[0].size==0: pic_loc=(np.array([0]),np.array([0])) + pic_loc = pic_loc[0] if len(pic_loc) > 1: # if more than 1 peak is found pic_loc = max(pic_loc) From 2dcf765f6a6a26151203c66df70d29c0e672ea6e Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 4 Aug 2021 21:36:30 +0200 Subject: [PATCH 009/128] Update detect_alpha_peak.py --- detect_alpha_peak.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect_alpha_peak.py b/detect_alpha_peak.py index dc98e2f..90396da 100755 --- a/detect_alpha_peak.py +++ b/detect_alpha_peak.py @@ -175,7 +175,7 @@ def main(): df_alpha_peaks = df_alpha_peaks.append(d_mean_channels, ignore_index=True) # Save it into a csv - df_alpha_peaks.to_csv('out_dir/alpha_peak_frequency.csv', index=False) + df_alpha_peaks.to_csv('out_dir2/alpha_peak_frequency.csv', index=False) # Plot spectrum # From b8344e6e8bede2bd12b209a446b31e116b00a9aa Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 4 Aug 2021 21:36:34 +0200 Subject: [PATCH 010/128] Update main --- main | 1 + 1 file changed, 1 insertion(+) diff --git a/main b/main index 5e9a970..b1fa105 100755 --- a/main +++ b/main @@ -16,6 +16,7 @@ set -x # Make output directories mkdir -p out_dir +mkdir -p out_dir2 # Run the actual python code singularity exec docker://brainlife/mne:0.23dev python3 detect_alpha_peak.py From 419faff199da5b49021b33e96d46ff0c9d1389e8 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 4 Aug 2021 21:42:24 +0200 Subject: [PATCH 011/128] Update main --- main | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main b/main index b1fa105..bb42fbf 100755 --- a/main +++ b/main @@ -8,7 +8,7 @@ # # This is the main file run by the brainlife.io orchestration system # -# Author: Franco Pestilli +# Author: Guiomar Niso, Aurore Bussalb set -e From 27e6a206a700602c40f104b29314b7ecffc331b8 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 13 Sep 2021 15:00:55 +0200 Subject: [PATCH 012/128] Update detect_alpha_peak.py --- detect_alpha_peak.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/detect_alpha_peak.py b/detect_alpha_peak.py index 90396da..0340829 100755 --- a/detect_alpha_peak.py +++ b/detect_alpha_peak.py @@ -22,7 +22,7 @@ def get_alpha_freqs(freqs): def detect_alpha_peak_mean(psd_welch, alpha_freqs, indexes_alpha_freqs): # Average PSD across all channels - # MEAN OF THE PEAKS FOR EACH CHANNEL OR MEAN OF THE CHENNELS AND THEN PEAK?? (GUIO) + # MEAN OF THE PEAKS FOR EACH CHANNEL OR MEAN OF THE CHANNELS AND THEN PEAK?? (GUIO) psd_welch_mean = np.mean(psd_welch, axis=0) # Get the std of the mean @@ -38,8 +38,11 @@ def detect_alpha_peak_mean(psd_welch, alpha_freqs, indexes_alpha_freqs): print(pic_loc) # If is empty (no peak found) if pic_loc[0].size==0: pic_loc=(np.array([0]),np.array([0])) + pic_loc = pic_loc[0] + if len(pic_loc) > 1: # if more than 1 peak is found + pic_loc = max(pic_loc) # Find the corresponding frequency - index_of_the_pic = int(pic_loc[0]) + index_of_the_pic = int(pic_loc) alpha_freq_pic_mean = alpha_freqs[index_of_the_pic] # Apply the index of the pic in alpha_freqs, not in freqs! return alpha_freq_pic_mean, psd_welch_mean, psd_welch_std, psd_in_alpha_freqs_mean @@ -53,16 +56,19 @@ def detect_alpha_peak_per_channels(psd_welch, alpha_freqs, indexes_alpha_freqs): for channel in range(0, psd_welch.shape[0]): # Extract psd in alpha freqs psd_in_alpha_freqs_per_channel = np.take(psd_welch[channel, :], indexes_alpha_freqs) - # Find peak + # Find peak: pic_loc=[index, value] pic_loc = mne.preprocessing.peak_finder(psd_in_alpha_freqs_per_channel) + print(pic_loc) # If is empty (no peak found) - if pic_loc[0].size==0: pic_loc=(np.array([0]),np.array([0])) - + if len(pic_loc[0])==0: pic_loc=(np.array([0]),np.array([0])) + # If more than one peak found (take the first peak) + #if len(pic_loc[0])>1: pic_loc=(np.array([pic_loc[0][0]]),np.array([pic_loc[1][0]])) + pic_loc = pic_loc[0] if len(pic_loc) > 1: # if more than 1 peak is found pic_loc = max(pic_loc) - # Find the corresponding frequency + # Find the corresponding frequency, GUIO: this should be equivalent to: pic_loc[1] index_of_the_pic = int(pic_loc) alpha_freq_pic = alpha_freqs[index_of_the_pic] # Apply the index of the pic in alpha_freqs, not in freqs! alpha_freq_pic_per_channel.append(alpha_freq_pic) From 91322f4d9128adda8c7ab16e60bf3bf13b29a0ad Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 19:01:16 +0200 Subject: [PATCH 013/128] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c08f58f..d3fe760 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Detect individual alpha peak in MEG signals. ## app-detect-alpha-peak documentation -1) Detect alpha peak frequency for each channel and for the mean over all channels +1) Detect alpha peak frequency for each channel 2) Input file is: * a `.csv` file containing the Power Spectral Densities 5) Ouput files are: @@ -16,10 +16,10 @@ Detect individual alpha peak in MEG signals. * plot of the mean Power Spectral density for each channel. ### Authors +- [Guiomar Niso](guiomar.niso@ctb.upm.es) - [Aurore Bussalb](aurore.bussalb@icm-institute.org) ### Contributors -- [Guiomar Niso](guiomar.niso@ctb.upm.es) - [Maximilien Chaumon](maximilien.chaumon@icm-institute.org) ### Funding Acknowledgement From a4e7738f78f1e3d5f7d71cfc6ee79db4de74c729 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 19:01:25 +0200 Subject: [PATCH 014/128] Create main.py --- main.py | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100755 main.py diff --git a/main.py b/main.py new file mode 100755 index 0000000..e49eb1c --- /dev/null +++ b/main.py @@ -0,0 +1,133 @@ +# Copyright (c) 2020 brainlife.io +# +# This file is a MNE python-based brainlife.io App +# +# Author: Guiomar Niso +# Indiana University + +# Required libraries +# pip install mne-bids coloredlogs tqdm pandas scikit-learn json_tricks fire + +# set up environment +#import mne-study-template +import os +import json +import mne +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt + +# Current path +__location__ = os.path.realpath( + os.path.join(os.getcwd(), os.path.dirname(__file__))) + +# Load brainlife config.json +with open(__location__+'/config.json') as config_json: + config = json.load(config_json) + + +# == GET CONFIG VALUES == + + + + + +# == LOAD DATA == +df_psd = pd.read_csv('psd.csv') +canales = df_psd['channels'].copy() + +#Number of frequencies computed for the PSD +nfreqs = df_psd.shape[1] +df = df_psd.iloc[:, 1:nfreqs].copy() # To avoid the case where changing df also changes df_psd +#List of frequencies +freqs = df.columns.to_numpy() +freqs = freqs.astype(float) +#PSD values +psd_welch = df.to_numpy() +#Number of channels +nchannels = psd_welch.shape[0] + + +# Extract the frequencies that fall inside the alpha band +fmin=6.9 +fmax=14.1 +ifreqs = [i for i, f in zip(range(0, len(freqs)), freqs) if f > fmin and f < fmax] +alpha_freqs = np.take(freqs, ifreqs) + + +# ==== FIND ALPHA PEAK ==== + +alpha_channel_peak = [] + +# Prepare for Figure 1 containing all the channels +plt.figure(1) +fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(20, math.ceil(nchannels/5)*3), facecolor='w', edgecolor='k') +fig.subplots_adjust(hspace = .5, wspace=.2) +axs = axs.ravel() + + +for channel in range(0, nchannels): + + # Find maxima with noise-tolerant fast peak-finding algorithm + psd_channel = np.take(psd_welch[channel, :], ifreqs) + pic_loc, pic_mag = mne.preprocessing.peak_finder(psd_channel, extrema=1, verbose=None); + + # From all the peaks found, get the main peak + peak=pic_loc[0] + + #If no peak found + if pic_loc.size==0: + peak=(np.array([0]),np.array([0])) + print('No peak found for channel: ',canales[channel]) + + #If more than one peak found + elif pic_loc.size>1: + pic_mag_list=pic_mag.tolist() + peak = pic_mag_list.index(max(pic_mag_list)) # max? average? (GUIO) + print('Multiple peaks found for channel: ',canales[channel]) + + #Get the frequency of the peak + pic_freq = np.take(alpha_freqs,pic_loc[peak]) + alpha_channel_peak.append(pic_freq) + + #Plot Figure 1 + axs[channel].plot(alpha_freqs,psd_channel); + axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); + axs[channel].axvline(x=pic_freq,c='k',ls=':'); + axs[channel].set_title(canales[channel]) + +#Save Figure 1 +plt.savefig(os.path.join('out_dir2','psd_allchannels.png')) + +# Average of the peak of all the channels +mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) + + +# == SAVE FILE == +# Save to CSV file (could be also TSV) +df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['alpha_peak']) +df_psd.to_csv(os.path.join('out_dir','alpha_peak.csv')) + + +# Read CSV file +#df = pd.read_csv("df_psd.csv") +#print(df) + + +# ==== PLOT FIGURES ==== + +# FIGURE 2 +# Plot MNE PSD +plt.figure(2) +raw.plot_psd(tmin=tmin, tmax=tmax, fmin=fmin, fmax=fmax, proj=proj, n_fft=n_fft, n_overlap=n_overlap, window=window, + ax=None, color='black', xscale='linear', area_mode='std', area_alpha=0.33, + dB=True, estimate='auto', show=True, n_jobs=1, average=False, + line_alpha=None, spatial_colors=True, sphere=None, verbose=None) + +# SHADE ALPHA BAND (GUIO) + +plt.axvline(x=mean_alpha_peak,c='k',ls=':'); +plt.set_title('PSD alpha peak: ',mean_alpha_peak,' Hz') +# Save fig +df_psd.to_csv(os.path.join('out_dir2','psd_alpha.png')) + From aea60bd6db631e14a2352093a39216d745a60c66 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 19:01:33 +0200 Subject: [PATCH 015/128] Update main --- main | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main b/main index bb42fbf..4dc71e9 100755 --- a/main +++ b/main @@ -19,7 +19,7 @@ mkdir -p out_dir mkdir -p out_dir2 # Run the actual python code -singularity exec docker://brainlife/mne:0.23dev python3 detect_alpha_peak.py +singularity exec docker://brainlife/mne:0.23dev python3 main.py # Store PSD plot with alpha peak on product.json cat << EOF > product.json From 5df21d1b61c751d4590d7d63c011dc3213832dc7 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 19:04:53 +0200 Subject: [PATCH 016/128] Update main --- main | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main b/main index 4dc71e9..aac7d3a 100755 --- a/main +++ b/main @@ -28,12 +28,12 @@ cat << EOF > product.json { "type": "image/png", "name": "Alpha peak on mean spectrum", - "base64": "$(base64 -w 0 out_dir/psd_mean.png)" + "base64": "$(base64 -w 0 out_dir2/psd_alpha_peak.png)" }, { "type": "image/png", "name": "Power spectrum for all channels", - "base64": "$(base64 -w 0 out_dir/psd_channels.png)" + "base64": "$(base64 -w 0 out_dir2/psd_channels.png)" } ] } From 9e8592be1ecfd5a2c77d621448ff27cdb91b0f9f Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 19:04:57 +0200 Subject: [PATCH 017/128] Update main.py --- main.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index e49eb1c..b9727e6 100755 --- a/main.py +++ b/main.py @@ -27,13 +27,10 @@ # == GET CONFIG VALUES == - - - - +fname = config['psd'] # == LOAD DATA == -df_psd = pd.read_csv('psd.csv') +df_psd = pd.read_csv(fname) canales = df_psd['channels'].copy() #Number of frequencies computed for the PSD @@ -129,5 +126,5 @@ plt.axvline(x=mean_alpha_peak,c='k',ls=':'); plt.set_title('PSD alpha peak: ',mean_alpha_peak,' Hz') # Save fig -df_psd.to_csv(os.path.join('out_dir2','psd_alpha.png')) +df_psd.to_csv(os.path.join('out_dir2','psd_alpha_peak.png')) From 3596f8f5e175c816694325f28317d65f0da904e9 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 19:12:32 +0200 Subject: [PATCH 018/128] Delete detect_alpha_peak.py --- detect_alpha_peak.py | 198 ------------------------------------------- 1 file changed, 198 deletions(-) delete mode 100755 detect_alpha_peak.py diff --git a/detect_alpha_peak.py b/detect_alpha_peak.py deleted file mode 100755 index 0340829..0000000 --- a/detect_alpha_peak.py +++ /dev/null @@ -1,198 +0,0 @@ -#!/usr/local/bin/python3 - -import json -import mne -import numpy as np -import matplotlib.pyplot as plt -import pandas as pd - - -def get_alpha_freqs(freqs): - - # Select band 7 - 14Hz # - - # Extract indices of alpha freqs - indexes_alpha_freqs = [i for i, f in zip(range(0, len(freqs)), freqs) if f > 6.9 and f < 14.1] - # Extract alpha freqs - alpha_freqs = np.take(freqs, indexes_alpha_freqs) - - return alpha_freqs, indexes_alpha_freqs - - -def detect_alpha_peak_mean(psd_welch, alpha_freqs, indexes_alpha_freqs): - - # Average PSD across all channels - # MEAN OF THE PEAKS FOR EACH CHANNEL OR MEAN OF THE CHANNELS AND THEN PEAK?? (GUIO) - psd_welch_mean = np.mean(psd_welch, axis=0) - - # Get the std of the mean - # STD OR STDERR?? (GUIO) - psd_welch_std = np.std(psd_welch, axis=0) - - # Extract psd in alpha freqs - psd_in_alpha_freqs_mean = np.take(psd_welch_mean, indexes_alpha_freqs) - - # Find peak - pic_loc = mne.preprocessing.peak_finder(psd_in_alpha_freqs_mean) - - print(pic_loc) - # If is empty (no peak found) - if pic_loc[0].size==0: pic_loc=(np.array([0]),np.array([0])) - pic_loc = pic_loc[0] - if len(pic_loc) > 1: # if more than 1 peak is found - pic_loc = max(pic_loc) - # Find the corresponding frequency - index_of_the_pic = int(pic_loc) - alpha_freq_pic_mean = alpha_freqs[index_of_the_pic] # Apply the index of the pic in alpha_freqs, not in freqs! - - return alpha_freq_pic_mean, psd_welch_mean, psd_welch_std, psd_in_alpha_freqs_mean - - -def detect_alpha_peak_per_channels(psd_welch, alpha_freqs, indexes_alpha_freqs): - - # Get alpha peak frequency for all channels # - - alpha_freq_pic_per_channel = [] - for channel in range(0, psd_welch.shape[0]): - # Extract psd in alpha freqs - psd_in_alpha_freqs_per_channel = np.take(psd_welch[channel, :], indexes_alpha_freqs) - # Find peak: pic_loc=[index, value] - pic_loc = mne.preprocessing.peak_finder(psd_in_alpha_freqs_per_channel) - - print(pic_loc) - # If is empty (no peak found) - if len(pic_loc[0])==0: pic_loc=(np.array([0]),np.array([0])) - # If more than one peak found (take the first peak) - #if len(pic_loc[0])>1: pic_loc=(np.array([pic_loc[0][0]]),np.array([pic_loc[1][0]])) - - pic_loc = pic_loc[0] - if len(pic_loc) > 1: # if more than 1 peak is found - pic_loc = max(pic_loc) - # Find the corresponding frequency, GUIO: this should be equivalent to: pic_loc[1] - index_of_the_pic = int(pic_loc) - alpha_freq_pic = alpha_freqs[index_of_the_pic] # Apply the index of the pic in alpha_freqs, not in freqs! - alpha_freq_pic_per_channel.append(alpha_freq_pic) - - - return alpha_freq_pic_per_channel, psd_in_alpha_freqs_per_channel - - -def plot_psd_mean(freqs, alpha_freq_pic_mean, psd_welch_mean, psd_welch_std, alpha_freqs, psd_in_alpha_freqs_mean): - - plt.figure() - - # Get the index of alpha peak - id_alpha_peak = np.where(freqs==alpha_freq_pic_mean) - - # Define lim - plt.xlim(xmin=0, xmax=max(freqs)) - - # Plot spectrum - plt.plot(freqs, psd_welch_mean, zorder=1) - - # Plot a red point on the alpha peak - plt.scatter(alpha_freq_pic_mean, psd_welch_mean[id_alpha_peak], marker='o', color="red", label='alpha peak frequency', zorder=3) - - # Plot std of the mean as shaded area - plt.fill_between(freqs, psd_welch_mean-psd_welch_std, psd_welch_mean+psd_welch_std, alpha=0.5, label='standard deviation', zorder=2) - - # Shadow the frequencies in which we look for the peak - # plt.ylim(ymin=min(psd_welch_mean)) - plt.axvline(x=min(alpha_freqs), zorder=4, color='r', linestyle='--', alpha=0.2, label='alpha band') - plt.axvline(x=max(alpha_freqs), zorder=4, color='r', linestyle='--', alpha=0.2) - - # Define labels - plt.xlabel('Frequency (Hz)') - plt.ylabel('Power Spectral Density') - plt.title('Mean power spectrum across all channels') - plt.legend() - - # Save fig - plt.savefig('out_dir/psd_mean.png') - - -def plot_psd_per_channels(freqs, alpha_freq_pic_per_channel, psd_in_alpha_freqs_per_channel, psd_welch, alpha_freqs): - - plt.figure() - - for channel in range(0, len(alpha_freq_pic_per_channel)): - plt.plot(freqs, psd_welch[channel], zorder=1) - - # Define lim - plt.xlim(xmin=0, xmax=max(freqs)) - - # Plot alpha band - plt.axvline(x=min(alpha_freqs), zorder=4, color='r', linestyle='--', alpha=0.6, label='alpha band') - plt.axvline(x=max(alpha_freqs), zorder=4, color='r', linestyle='--', alpha=0.6) - - # Define labels - plt.xlabel('Frequency (Hz)') - plt.ylabel('Power Spectral Density') - plt.title('Power spectrum for all channels') - plt.legend() - - # Save fig - plt.savefig('out_dir/psd_channels.png') - - -def main(): - - # Load inputs from config.json - with open('config.json') as config_json: - config = json.load(config_json) - - # Load csv - path_to_input_file = config.pop('psd') - # To be able to read input raw datatype - # if "out_dir/." in path_to_input_file: - # path_to_input_file = path_to_input_file.replace('out_dir/.', 'out_dir/psd.csv') - - - # Read the outputs of PSD app # - - # Extract PSD - df_psd_welch = pd.read_csv(path_to_input_file) - df_psd_welch = df_psd_welch.drop(["Unnamed: 0"], axis=1) - psd_welch = df_psd_welch.to_numpy() - - # Extract freqs - freqs = df_psd_welch.columns.to_numpy() - freqs = freqs.astype(float) - - # Get alpha freqs - alpha_freqs, indexes_alpha_freqs = get_alpha_freqs(freqs) - - # Detect alpha peak on average channels # - alpha_freq_pic_mean, psd_welch_mean, psd_welch_std, psd_in_alpha_freqs_mean = detect_alpha_peak_mean(psd_welch, alpha_freqs, indexes_alpha_freqs) - - # Detect alpha peak per channels # - alpha_freq_pic_per_channel, psd_in_alpha_freqs_per_channel = detect_alpha_peak_per_channels(psd_welch, alpha_freqs, indexes_alpha_freqs) - - - # Create a DataFrame with alpha peak values # - - # Values for each channel - channels = [f"channel_{i}" for i in range(0, len(alpha_freq_pic_per_channel))] - d_all_channels = {'channels': channels, 'alpha peak frequency': alpha_freq_pic_per_channel} - df_alpha_peaks = pd.DataFrame(data=d_all_channels) - - # Value for mean PSD across channels - d_mean_channels = {'channels': "mean channels", 'alpha peak frequency': alpha_freq_pic_mean} - df_alpha_peaks = df_alpha_peaks.append(d_mean_channels, ignore_index=True) - - # Save it into a csv - df_alpha_peaks.to_csv('out_dir2/alpha_peak_frequency.csv', index=False) - - - # Plot spectrum # - - # Mean spectrum - plot_psd_mean(freqs, alpha_freq_pic_mean, psd_welch_mean, psd_welch_std, alpha_freqs, psd_in_alpha_freqs_mean) - - # All channels - plot_psd_per_channels(freqs, alpha_freq_pic_per_channel, psd_in_alpha_freqs_per_channel, psd_welch, alpha_freqs) - - -if __name__ == '__main__': - main() - From 44915e0a7e70f8dbf63c15b077e8042378f2d27a Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 19:12:35 +0200 Subject: [PATCH 019/128] Create .DS_Store --- .DS_Store | Bin 0 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Tue, 14 Sep 2021 19:14:18 +0200 Subject: [PATCH 020/128] Update main.py --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index b9727e6..b9d367c 100755 --- a/main.py +++ b/main.py @@ -16,6 +16,7 @@ import numpy as np import pandas as pd import matplotlib.pyplot as plt +import math # Current path __location__ = os.path.realpath( From 20bd816ea1ac20322385de0dab6b8e8ae139638d Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 19:17:46 +0200 Subject: [PATCH 021/128] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3fe760..a934a60 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ Detect individual alpha peak in MEG signals. ### Authors - [Guiomar Niso](guiomar.niso@ctb.upm.es) -- [Aurore Bussalb](aurore.bussalb@icm-institute.org) ### Contributors +- [Aurore Bussalb](aurore.bussalb@icm-institute.org) - [Maximilien Chaumon](maximilien.chaumon@icm-institute.org) ### Funding Acknowledgement From fdfae6692b7b4f71c382710cd92896ab8a8f0748 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 19:20:50 +0200 Subject: [PATCH 022/128] Update main.py --- main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index b9d367c..9d6edf2 100755 --- a/main.py +++ b/main.py @@ -71,13 +71,16 @@ pic_loc, pic_mag = mne.preprocessing.peak_finder(psd_channel, extrema=1, verbose=None); # From all the peaks found, get the main peak - peak=pic_loc[0] + + #If one peak found + if pic_loc.size==1: + peak=pic_loc[0].copy() #If no peak found if pic_loc.size==0: peak=(np.array([0]),np.array([0])) print('No peak found for channel: ',canales[channel]) - + #If more than one peak found elif pic_loc.size>1: pic_mag_list=pic_mag.tolist() From 36a1928f3a60d10744fe2ab78a198a91898b821d Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 20:00:05 +0200 Subject: [PATCH 023/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 9d6edf2..944738b 100755 --- a/main.py +++ b/main.py @@ -88,7 +88,7 @@ print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak - pic_freq = np.take(alpha_freqs,pic_loc[peak]) + pic_freq = np.take(alpha_freqs,peak) alpha_channel_peak.append(pic_freq) #Plot Figure 1 From ec07eca6cb97146f6789737527756cb7e6047a09 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 20:01:52 +0200 Subject: [PATCH 024/128] Update main --- main | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main b/main index aac7d3a..04998cb 100755 --- a/main +++ b/main @@ -33,7 +33,7 @@ cat << EOF > product.json { "type": "image/png", "name": "Power spectrum for all channels", - "base64": "$(base64 -w 0 out_dir2/psd_channels.png)" + "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" } ] } From 47db0730f9e4b1040f462f3aae4e16e0f5031eda Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 20:11:05 +0200 Subject: [PATCH 025/128] Update main.py --- main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 944738b..6bd76b3 100755 --- a/main.py +++ b/main.py @@ -118,17 +118,18 @@ # ==== PLOT FIGURES ==== # FIGURE 2 -# Plot MNE PSD +# Plot PSD + plt.figure(2) -raw.plot_psd(tmin=tmin, tmax=tmax, fmin=fmin, fmax=fmax, proj=proj, n_fft=n_fft, n_overlap=n_overlap, window=window, - ax=None, color='black', xscale='linear', area_mode='std', area_alpha=0.33, - dB=True, estimate='auto', show=True, n_jobs=1, average=False, - line_alpha=None, spatial_colors=True, sphere=None, verbose=None) +plt.plot(freqs, psd_welch.transpose(), zorder=1) +plt.xlim(xmin=0, xmax=max(freqs)) +plt.xlabel('Frequency (Hz)') +plt.ylabel('Power Spectral Density') +plt.title('PSD alpha peak: ',mean_alpha_peak,' Hz') # SHADE ALPHA BAND (GUIO) plt.axvline(x=mean_alpha_peak,c='k',ls=':'); -plt.set_title('PSD alpha peak: ',mean_alpha_peak,' Hz') # Save fig df_psd.to_csv(os.path.join('out_dir2','psd_alpha_peak.png')) From 312bf6bac89210a47127fccfdc429e6cf1ad2f88 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 20:12:50 +0200 Subject: [PATCH 026/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 6bd76b3..f2905f0 100755 --- a/main.py +++ b/main.py @@ -125,7 +125,7 @@ plt.xlim(xmin=0, xmax=max(freqs)) plt.xlabel('Frequency (Hz)') plt.ylabel('Power Spectral Density') -plt.title('PSD alpha peak: ',mean_alpha_peak,' Hz') +plt.title('PSD alpha peak: ',mean_alpha_peak) # SHADE ALPHA BAND (GUIO) From bd12274d4a5f3e07f58b761ac83e929f9d89f780 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 20:15:20 +0200 Subject: [PATCH 027/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index f2905f0..abbb6a4 100755 --- a/main.py +++ b/main.py @@ -95,7 +95,7 @@ axs[channel].plot(alpha_freqs,psd_channel); axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); - axs[channel].set_title(canales[channel]) + axs[channel].title(canales[channel]) #Save Figure 1 plt.savefig(os.path.join('out_dir2','psd_allchannels.png')) From dd2d2e587d94caee9780021428eb5d7d72255163 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 20:17:14 +0200 Subject: [PATCH 028/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index abbb6a4..9be0d32 100755 --- a/main.py +++ b/main.py @@ -95,7 +95,7 @@ axs[channel].plot(alpha_freqs,psd_channel); axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); - axs[channel].title(canales[channel]) + #axs[channel].set_title(canales[channel]) #Save Figure 1 plt.savefig(os.path.join('out_dir2','psd_allchannels.png')) From 9fb838cb08aa8ae8671afaf5863625764cb58d4f Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 20:18:30 +0200 Subject: [PATCH 029/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 9be0d32..5099804 100755 --- a/main.py +++ b/main.py @@ -125,7 +125,7 @@ plt.xlim(xmin=0, xmax=max(freqs)) plt.xlabel('Frequency (Hz)') plt.ylabel('Power Spectral Density') -plt.title('PSD alpha peak: ',mean_alpha_peak) +#plt.title('PSD alpha peak: ',mean_alpha_peak) # SHADE ALPHA BAND (GUIO) From 5510c09ebe2cb8feb6dec0ead1beeb40d9527162 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 20:23:18 +0200 Subject: [PATCH 030/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 5099804..cc04874 100755 --- a/main.py +++ b/main.py @@ -98,7 +98,7 @@ #axs[channel].set_title(canales[channel]) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png')) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),quality=30) # Average of the peak of all the channels mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) From 7d418cb94f1296b083aa1e145005aa053ad94922 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:21:24 +0200 Subject: [PATCH 031/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index cc04874..94b3d72 100755 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(20, math.ceil(nchannels/5)*3), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(10, math.ceil(nchannels/5)*1), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.2) axs = axs.ravel() @@ -98,7 +98,7 @@ #axs[channel].set_title(canales[channel]) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),quality=30) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=50) # Average of the peak of all the channels mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) From 8e12076ad357877a3671c7a6cba6937f45fd968c Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:23:26 +0200 Subject: [PATCH 032/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 94b3d72..e6ff0e2 100755 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(10, math.ceil(nchannels/5)*1), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(10, math.ceil(nchannels/10)*1), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.2) axs = axs.ravel() @@ -98,7 +98,7 @@ #axs[channel].set_title(canales[channel]) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=50) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=10) # Average of the peak of all the channels mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) From 0078e572724aa37d158f5256763134de64167fe5 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:25:24 +0200 Subject: [PATCH 033/128] Update main --- main | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main b/main index 04998cb..bcc71e7 100755 --- a/main +++ b/main @@ -29,12 +29,13 @@ cat << EOF > product.json "type": "image/png", "name": "Alpha peak on mean spectrum", "base64": "$(base64 -w 0 out_dir2/psd_alpha_peak.png)" - }, - { - "type": "image/png", - "name": "Power spectrum for all channels", - "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" } ] } EOF + +# { + # "type": "image/png", +# "name": "Power spectrum for all channels", + # "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" + # } From 0d5d9af4edd5d1fc78698770bfa926775cbe762c Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:25:27 +0200 Subject: [PATCH 034/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index e6ff0e2..5551138 100755 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(10, math.ceil(nchannels/10)*1), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(10, math.ceil(nchannels/10*0.5)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.2) axs = axs.ravel() From f4a31e568885bacc0c5b39548be2eb6b88ed93a7 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:26:51 +0200 Subject: [PATCH 035/128] Update main --- main | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main b/main index bcc71e7..7b2bf69 100755 --- a/main +++ b/main @@ -26,16 +26,16 @@ cat << EOF > product.json { "brainlife": [ { - "type": "image/png", - "name": "Alpha peak on mean spectrum", - "base64": "$(base64 -w 0 out_dir2/psd_alpha_peak.png)" + "type": "image/png", + "name": "Alpha peak on mean spectrum", + "base64": "$(base64 -w 0 out_dir2/psd_alpha_peak.png)" } ] } EOF -# { - # "type": "image/png", -# "name": "Power spectrum for all channels", - # "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" - # } +# { +# "type": "image/png", +# "name": "Power spectrum for all channels", +# "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" +# } From dc1e1a7487f78f5a2c79139633d3e7d2c5d2ec7c Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:26:54 +0200 Subject: [PATCH 036/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 5551138..037b7c9 100755 --- a/main.py +++ b/main.py @@ -98,7 +98,7 @@ #axs[channel].set_title(canales[channel]) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=10) +#plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=10) # Average of the peak of all the channels mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) From 49c06095cec728411933048b2a6631d73cf5fac1 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:28:38 +0200 Subject: [PATCH 037/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 037b7c9..f5a9701 100755 --- a/main.py +++ b/main.py @@ -131,5 +131,5 @@ plt.axvline(x=mean_alpha_peak,c='k',ls=':'); # Save fig -df_psd.to_csv(os.path.join('out_dir2','psd_alpha_peak.png')) +df_psd.to_csv(os.path.join('out_dir2','psd_alpha_peak.png'),dpi=10) From d59b66e2afc603293c5dc0efc4ca876af4e60ae0 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:28:57 +0200 Subject: [PATCH 038/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index f5a9701..b77623a 100755 --- a/main.py +++ b/main.py @@ -98,7 +98,7 @@ #axs[channel].set_title(canales[channel]) #Save Figure 1 -#plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=10) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=10) # Average of the peak of all the channels mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) From 598e4d0a6bb64a0870d6eb2f9f332c5e1ad3081a Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:30:15 +0200 Subject: [PATCH 039/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index b77623a..bf8eb9b 100755 --- a/main.py +++ b/main.py @@ -131,5 +131,5 @@ plt.axvline(x=mean_alpha_peak,c='k',ls=':'); # Save fig -df_psd.to_csv(os.path.join('out_dir2','psd_alpha_peak.png'),dpi=10) +plt.savefig(os.path.join('out_dir2','psd_alpha_peak.png'),dpi=10) From 8f11bce188e2cd221eeb1d6466d08be94d582cce Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:31:05 +0200 Subject: [PATCH 040/128] Update main --- main | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/main b/main index 7b2bf69..dc5e48b 100755 --- a/main +++ b/main @@ -29,13 +29,15 @@ cat << EOF > product.json "type": "image/png", "name": "Alpha peak on mean spectrum", "base64": "$(base64 -w 0 out_dir2/psd_alpha_peak.png)" - } + }, + + { + "type": "image/png", + "name": "Power spectrum for all channels", + "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" + } ] } EOF -# { -# "type": "image/png", -# "name": "Power spectrum for all channels", -# "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" -# } + From 61dfc521001822a1c63e88de795e517293f3eed0 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:32:40 +0200 Subject: [PATCH 041/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index bf8eb9b..a37ec75 100755 --- a/main.py +++ b/main.py @@ -98,7 +98,7 @@ #axs[channel].set_title(canales[channel]) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=10) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=20) # Average of the peak of all the channels mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) @@ -131,5 +131,5 @@ plt.axvline(x=mean_alpha_peak,c='k',ls=':'); # Save fig -plt.savefig(os.path.join('out_dir2','psd_alpha_peak.png'),dpi=10) +plt.savefig(os.path.join('out_dir2','psd_alpha_peak.png'),dpi=20) From 4fbc5fe5f25e4f0f85fcdb82873c3f478ebf069f Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:34:15 +0200 Subject: [PATCH 042/128] Update main.py --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index a37ec75..ea7863d 100755 --- a/main.py +++ b/main.py @@ -99,6 +99,7 @@ #Save Figure 1 plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=20) +plt.close() # Average of the peak of all the channels mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) @@ -132,4 +133,5 @@ plt.axvline(x=mean_alpha_peak,c='k',ls=':'); # Save fig plt.savefig(os.path.join('out_dir2','psd_alpha_peak.png'),dpi=20) +plt.close() From fe68c37ae990f8f5460ba3e3978f06d85020d54a Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:36:09 +0200 Subject: [PATCH 043/128] Update main.py --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index ea7863d..d696257 100755 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(10, math.ceil(nchannels/10*0.5)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(20, math.ceil(nchannels/5*1)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.2) axs = axs.ravel() @@ -98,7 +98,7 @@ #axs[channel].set_title(canales[channel]) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=20) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=50) plt.close() # Average of the peak of all the channels @@ -132,6 +132,6 @@ plt.axvline(x=mean_alpha_peak,c='k',ls=':'); # Save fig -plt.savefig(os.path.join('out_dir2','psd_alpha_peak.png'),dpi=20) +plt.savefig(os.path.join('out_dir2','psd_alpha_peak.png')) plt.close() From 470b2d9e870b29d18bb0f81f599435520a00e55a Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:38:34 +0200 Subject: [PATCH 044/128] Update main.py --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index d696257..ad71c06 100755 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(20, math.ceil(nchannels/5*1)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(10, math.ceil(nchannels/5*1)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.2) axs = axs.ravel() @@ -98,7 +98,7 @@ #axs[channel].set_title(canales[channel]) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=50) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=20) plt.close() # Average of the peak of all the channels @@ -130,7 +130,7 @@ # SHADE ALPHA BAND (GUIO) -plt.axvline(x=mean_alpha_peak,c='k',ls=':'); +plt.axvline(x=mean_alpha_peak,c='k',ls=':') # Save fig plt.savefig(os.path.join('out_dir2','psd_alpha_peak.png')) plt.close() From 5b4e28fe84f590528d30f4e0f4a96cb35c59a0a2 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 14 Sep 2021 21:46:45 +0200 Subject: [PATCH 045/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ad71c06..b308c0a 100755 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(10, math.ceil(nchannels/5*1)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(10, math.ceil(nchannels/5*0.5)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.2) axs = axs.ravel() @@ -108,7 +108,7 @@ # == SAVE FILE == # Save to CSV file (could be also TSV) df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['alpha_peak']) -df_psd.to_csv(os.path.join('out_dir','alpha_peak.csv')) +df_alpha.to_csv(os.path.join('out_dir','alpha_peak.csv')) # Read CSV file From fc7b8c0d13607748f5c422fd20b0694a850a0631 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 00:43:03 +0200 Subject: [PATCH 046/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index b308c0a..c5f7670 100755 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(10, math.ceil(nchannels/5*0.5)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(10, math.ceil(nchannels/5*0.2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.2) axs = axs.ravel() From b26d48f31d4632854873ea8104ab7809df865387 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 16:14:26 +0200 Subject: [PATCH 047/128] Update main --- main | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main b/main index dc5e48b..1462108 100755 --- a/main +++ b/main @@ -28,7 +28,7 @@ cat << EOF > product.json { "type": "image/png", "name": "Alpha peak on mean spectrum", - "base64": "$(base64 -w 0 out_dir2/psd_alpha_peak.png)" + "base64": "$(base64 -w 0 out_dir2/hist_alpha_peak.png)" }, { From fd2c7c346a86fb1afa9af7bba4c8f4ecfb4d0f7e Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 16:14:28 +0200 Subject: [PATCH 048/128] Update main.py --- main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c5f7670..ed749d3 100755 --- a/main.py +++ b/main.py @@ -17,6 +17,7 @@ import pandas as pd import matplotlib.pyplot as plt import math +import seaborn as sns # Current path __location__ = os.path.realpath( @@ -59,7 +60,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(10, math.ceil(nchannels/5*0.2)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(20, math.ceil(nchannels/5*0.2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.2) axs = axs.ravel() @@ -78,7 +79,7 @@ #If no peak found if pic_loc.size==0: - peak=(np.array([0]),np.array([0])) + peak=(np.array([0]),np.array([0]))#Nan (GUIO) print('No peak found for channel: ',canales[channel]) #If more than one peak found @@ -135,3 +136,10 @@ plt.savefig(os.path.join('out_dir2','psd_alpha_peak.png')) plt.close() +# FIGURE 3 + +#custom_params = {"axes.spines.right": False, "axes.spines.top": False} +#sns.set_theme(style="ticks", rc=custom_params) +sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True) +plt.xlabel('Alpha peak frequency (Hz)') +sns.despine() From 9ab0c40a7fbfb30c8c63aa66bfaab4f24a54304f Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 16:21:49 +0200 Subject: [PATCH 049/128] Update main --- main | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/main b/main index 1462108..a031ec1 100755 --- a/main +++ b/main @@ -25,18 +25,17 @@ singularity exec docker://brainlife/mne:0.23dev python3 main.py cat << EOF > product.json { "brainlife": [ - { - "type": "image/png", - "name": "Alpha peak on mean spectrum", - "base64": "$(base64 -w 0 out_dir2/hist_alpha_peak.png)" - }, - - { - "type": "image/png", - "name": "Power spectrum for all channels", - "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" - } -] + { + "type": "image/png", + "name": "Alpha peak frequencies", + "base64": "$(base64 -w 0 out_dir2/hist_alpha_peak.png)" + }, + { + "type": "image/png", + "name": "Power spectrum for all channels", + "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" + } + ] } EOF From ed781889d9a9beac899e4aa30c24e3bef1a516f4 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 16:21:54 +0200 Subject: [PATCH 050/128] Update main.py --- main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ed749d3..182d477 100755 --- a/main.py +++ b/main.py @@ -60,7 +60,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(20, math.ceil(nchannels/5*0.2)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(30, math.ceil(nchannels/5*1)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.2) axs = axs.ravel() @@ -137,9 +137,12 @@ plt.close() # FIGURE 3 - +plt.figure(3) #custom_params = {"axes.spines.right": False, "axes.spines.top": False} #sns.set_theme(style="ticks", rc=custom_params) sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True) plt.xlabel('Alpha peak frequency (Hz)') sns.despine() +# Save fig +plt.savefig(os.path.join('out_dir2','hist_alpha_peak.png')) +plt.close From a2da3569e4c42cd7b18081f16f21c00cb4f70818 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 16:30:13 +0200 Subject: [PATCH 051/128] Update main.py --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 182d477..b47b1c8 100755 --- a/main.py +++ b/main.py @@ -60,7 +60,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/5),5, figsize=(30, math.ceil(nchannels/5*1)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(30, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace = .5, wspace=.2) axs = axs.ravel() @@ -99,7 +99,7 @@ #axs[channel].set_title(canales[channel]) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=20) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=30) plt.close() # Average of the peak of all the channels @@ -145,4 +145,4 @@ sns.despine() # Save fig plt.savefig(os.path.join('out_dir2','hist_alpha_peak.png')) -plt.close +plt.close() From 7c76b5f4e7ff093f2602c618335a9b8677f20e4a Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 17:16:53 +0200 Subject: [PATCH 052/128] Update main.py --- main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index b47b1c8..05ca72d 100755 --- a/main.py +++ b/main.py @@ -79,7 +79,7 @@ #If no peak found if pic_loc.size==0: - peak=(np.array([0]),np.array([0]))#Nan (GUIO) + peak=NaN #(np.array([0]),np.array([0]))#Nan print('No peak found for channel: ',canales[channel]) #If more than one peak found @@ -96,7 +96,9 @@ axs[channel].plot(alpha_freqs,psd_channel); axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); - #axs[channel].set_title(canales[channel]) + #axs[channel].set_title(canales[channel]) + plt.xlim(fmin,fmax) + plt.ylim(fmin,fmax) #Save Figure 1 plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=30) From 230d562df0ce55fa5c2bb1df4579c5524cb0f7c6 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 17:20:57 +0200 Subject: [PATCH 053/128] Update main.py --- main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 05ca72d..1a7a816 100755 --- a/main.py +++ b/main.py @@ -54,17 +54,17 @@ alpha_freqs = np.take(freqs, ifreqs) -# ==== FIND ALPHA PEAK ==== - -alpha_channel_peak = [] - # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(30, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') -fig.subplots_adjust(hspace = .5, wspace=.2) +fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(30, math.ceil(nchannels/10*1.5)), facecolor='w', edgecolor='k') +fig.subplots_adjust(hspace = .3, wspace=.2) axs = axs.ravel() +# ==== FIND ALPHA PEAK ==== + +alpha_channel_peak = [] + for channel in range(0, nchannels): # Find maxima with noise-tolerant fast peak-finding algorithm From 735cd55323836dd5ae4a91d8e959529f6e34e1f0 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 17:47:30 +0200 Subject: [PATCH 054/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 1a7a816..e9d17e2 100755 --- a/main.py +++ b/main.py @@ -101,7 +101,7 @@ plt.ylim(fmin,fmax) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=30) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=40) plt.close() # Average of the peak of all the channels From eac71271a74cc50fee011ebfe3ec8bf766c301a4 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 17:47:39 +0200 Subject: [PATCH 055/128] Update main.py --- main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index e9d17e2..5fa8f6a 100755 --- a/main.py +++ b/main.py @@ -79,13 +79,12 @@ #If no peak found if pic_loc.size==0: - peak=NaN #(np.array([0]),np.array([0]))#Nan + peak=math.nan #(np.array([0]),np.array([0]))#NaN print('No peak found for channel: ',canales[channel]) #If more than one peak found elif pic_loc.size>1: - pic_mag_list=pic_mag.tolist() - peak = pic_mag_list.index(max(pic_mag_list)) # max? average? (GUIO) + peak = psd_channel.index(max(pic_mag)) # max? average? (GUIO) print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak From c6aa8b30ada7c11688c2b0e9c41c2e29542bd93c Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 17:52:22 +0200 Subject: [PATCH 056/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 5fa8f6a..94a980e 100755 --- a/main.py +++ b/main.py @@ -84,7 +84,7 @@ #If more than one peak found elif pic_loc.size>1: - peak = psd_channel.index(max(pic_mag)) # max? average? (GUIO) + peak = np.where(psd_channel==max(pic_mag))[0] # max? average? (GUIO) print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak From c0ddd7e685f7df0bec2f331ee7a28fba096248d2 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 17:56:49 +0200 Subject: [PATCH 057/128] Update main.py --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 94a980e..c807013 100755 --- a/main.py +++ b/main.py @@ -56,8 +56,8 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(30, math.ceil(nchannels/10*1.5)), facecolor='w', edgecolor='k') -fig.subplots_adjust(hspace = .3, wspace=.2) +fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(30, math.ceil(nchannels/10*1)), facecolor='w', edgecolor='k') +fig.subplots_adjust(hspace = .1, wspace=.2) axs = axs.ravel() @@ -84,7 +84,7 @@ #If more than one peak found elif pic_loc.size>1: - peak = np.where(psd_channel==max(pic_mag))[0] # max? average? (GUIO) + peak = np.where(psd_channel==max(pic_mag))[0][0] # max? average? (GUIO) print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak @@ -100,7 +100,7 @@ plt.ylim(fmin,fmax) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=40) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=50) plt.close() # Average of the peak of all the channels From 20ce20b84c4face2e5244bca8f23fd3233b30499 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 17:58:04 +0200 Subject: [PATCH 058/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index c807013..7c7f7d4 100755 --- a/main.py +++ b/main.py @@ -100,7 +100,7 @@ plt.ylim(fmin,fmax) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=50) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=40) plt.close() # Average of the peak of all the channels From 08e84ccf8486e0a9dea28725928718d1bd134fd0 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 17:59:52 +0200 Subject: [PATCH 059/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 7c7f7d4..fc08a3e 100755 --- a/main.py +++ b/main.py @@ -57,7 +57,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(30, math.ceil(nchannels/10*1)), facecolor='w', edgecolor='k') -fig.subplots_adjust(hspace = .1, wspace=.2) +fig.subplots_adjust(hspace = .3, wspace=.2) axs = axs.ravel() From 6111e83361375240ac64c241dfbb8a301381f674 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 15 Sep 2021 18:20:32 +0200 Subject: [PATCH 060/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index fc08a3e..5b0da7f 100755 --- a/main.py +++ b/main.py @@ -56,8 +56,8 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(30, math.ceil(nchannels/10*1)), facecolor='w', edgecolor='k') -fig.subplots_adjust(hspace = .3, wspace=.2) +fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(30, math.ceil(nchannels/10*1.2)), facecolor='w', edgecolor='k') +fig.subplots_adjust(hspace =.3, wspace=.2) axs = axs.ravel() From e68fb83f4a77a71f9331b2428a8032fc29a23a26 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Thu, 16 Sep 2021 08:01:17 +0200 Subject: [PATCH 061/128] Update main.py --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index 5b0da7f..ddf334f 100755 --- a/main.py +++ b/main.py @@ -141,6 +141,7 @@ plt.figure(3) #custom_params = {"axes.spines.right": False, "axes.spines.top": False} #sns.set_theme(style="ticks", rc=custom_params) +sns.set_theme(style="ticks") sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True) plt.xlabel('Alpha peak frequency (Hz)') sns.despine() From 39d68fae4b635aad837e529aa8150c35f0bd8357 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Thu, 16 Sep 2021 15:27:56 +0200 Subject: [PATCH 062/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ddf334f..6c5687c 100755 --- a/main.py +++ b/main.py @@ -48,8 +48,8 @@ # Extract the frequencies that fall inside the alpha band -fmin=6.9 -fmax=14.1 +fmin=8 +fmax=12 ifreqs = [i for i, f in zip(range(0, len(freqs)), freqs) if f > fmin and f < fmax] alpha_freqs = np.take(freqs, ifreqs) From a0bbf6e27f469f8809c4f1797275e0bbe617be8d Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Thu, 16 Sep 2021 16:17:32 +0200 Subject: [PATCH 063/128] Update main.py --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 6c5687c..0878092 100755 --- a/main.py +++ b/main.py @@ -84,7 +84,8 @@ #If more than one peak found elif pic_loc.size>1: - peak = np.where(psd_channel==max(pic_mag))[0][0] # max? average? (GUIO) + peak = np.where(psd_channel==max(pic_mag))[0][0] # take the max + if peak==0: peak = pic_loc[np.argmax(pic_mag[1:,])+1] # if it's the first value, take the next max print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak @@ -143,6 +144,7 @@ #sns.set_theme(style="ticks", rc=custom_params) sns.set_theme(style="ticks") sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True) +plt.xlim(xmin=fmin, xmax=fmax) plt.xlabel('Alpha peak frequency (Hz)') sns.despine() # Save fig From 89fc3b5714d8790fda15a0ed6dfc62b6028aea8e Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Thu, 16 Sep 2021 16:32:21 +0200 Subject: [PATCH 064/128] Update main.py --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index 0878092..521924f 100755 --- a/main.py +++ b/main.py @@ -76,6 +76,7 @@ #If one peak found if pic_loc.size==1: peak=pic_loc[0].copy() + if peak==0: peak = math.nan # if it's the first value, then ignore, maybe just a decreasing curve #If no peak found if pic_loc.size==0: From 3de589758b0e5e3926fdcd25035b909fbf868c5e Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Thu, 16 Sep 2021 16:38:48 +0200 Subject: [PATCH 065/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 521924f..ba95a39 100755 --- a/main.py +++ b/main.py @@ -90,7 +90,7 @@ print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak - pic_freq = np.take(alpha_freqs,peak) + if not math.isnan(peak): pic_freq = np.take(alpha_freqs,peak); pic_freq = math.nan alpha_channel_peak.append(pic_freq) #Plot Figure 1 From 68100ba82fe5544ea19e5721967912b3d93d55d1 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Thu, 16 Sep 2021 16:40:31 +0200 Subject: [PATCH 066/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index ba95a39..fc7be9c 100755 --- a/main.py +++ b/main.py @@ -90,7 +90,7 @@ print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak - if not math.isnan(peak): pic_freq = np.take(alpha_freqs,peak); pic_freq = math.nan + if not math.isnan(peak): pic_freq = np.take(alpha_freqs,peak); pic_freq = 0 alpha_channel_peak.append(pic_freq) #Plot Figure 1 From 16b1ce0f421c3f61032e1a30e63e8020c11f9bc1 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Thu, 16 Sep 2021 16:45:00 +0200 Subject: [PATCH 067/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index fc7be9c..c46b7d7 100755 --- a/main.py +++ b/main.py @@ -90,7 +90,7 @@ print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak - if not math.isnan(peak): pic_freq = np.take(alpha_freqs,peak); pic_freq = 0 + pic_freq = np.take(alpha_freqs,peak) if not math.isnan(peak) else 0 # to avoid nans alpha_channel_peak.append(pic_freq) #Plot Figure 1 From 54bb0884fa6907f089110d158347a9e3aba19d86 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Thu, 16 Sep 2021 16:48:04 +0200 Subject: [PATCH 068/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c46b7d7..fa08234 100755 --- a/main.py +++ b/main.py @@ -98,8 +98,8 @@ axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); #axs[channel].set_title(canales[channel]) - plt.xlim(fmin,fmax) - plt.ylim(fmin,fmax) + axs[channel].xlim(fmin,fmax) + axs[channel].ylim(fmin,fmax) #Save Figure 1 plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=40) From cf717e782bd95849dc87b8fe5004193e90146d64 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Thu, 16 Sep 2021 16:57:43 +0200 Subject: [PATCH 069/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index fa08234..591a96a 100755 --- a/main.py +++ b/main.py @@ -98,8 +98,8 @@ axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); #axs[channel].set_title(canales[channel]) - axs[channel].xlim(fmin,fmax) - axs[channel].ylim(fmin,fmax) + axs[channel].set_xlim(fmin,fmax) + axs[channel].set_ylim(fmin,fmax) #Save Figure 1 plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=40) From 9a2974edc50e79a17f87a4b83df41f4e341c2554 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Fri, 17 Sep 2021 18:55:22 +0200 Subject: [PATCH 070/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 591a96a..ac8261c 100755 --- a/main.py +++ b/main.py @@ -97,7 +97,7 @@ axs[channel].plot(alpha_freqs,psd_channel); axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); - #axs[channel].set_title(canales[channel]) + axs[channel].set_title(canales[channel]) axs[channel].set_xlim(fmin,fmax) axs[channel].set_ylim(fmin,fmax) From b9763c2927ae15aeeb7eb6932032731857eec1c8 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Fri, 17 Sep 2021 18:57:45 +0200 Subject: [PATCH 071/128] Update main.py --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index ac8261c..adc0b76 100755 --- a/main.py +++ b/main.py @@ -56,8 +56,8 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(30, math.ceil(nchannels/10*1.2)), facecolor='w', edgecolor='k') -fig.subplots_adjust(hspace =.3, wspace=.2) +fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*1.2)), facecolor='w', edgecolor='k') +fig.subplots_adjust(hspace =.5, wspace=.2) axs = axs.ravel() @@ -98,8 +98,8 @@ axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); axs[channel].set_title(canales[channel]) - axs[channel].set_xlim(fmin,fmax) - axs[channel].set_ylim(fmin,fmax) + #axs[channel].set_xlim(fmin,fmax) + #axs[channel].set_ylim(fmin,fmax) #Save Figure 1 plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=40) From 84d8af0f7c8cdcf2e771f876d27f8ae14af04760 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Fri, 17 Sep 2021 18:59:05 +0200 Subject: [PATCH 072/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index adc0b76..64bcfd9 100755 --- a/main.py +++ b/main.py @@ -97,7 +97,7 @@ axs[channel].plot(alpha_freqs,psd_channel); axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); - axs[channel].set_title(canales[channel]) + #axs[channel].set_title(canales[channel]) #axs[channel].set_xlim(fmin,fmax) #axs[channel].set_ylim(fmin,fmax) From 33f5730a64e104bd0e47cb90f2c013588d5d37f0 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Fri, 17 Sep 2021 18:59:19 +0200 Subject: [PATCH 073/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 64bcfd9..adc0b76 100755 --- a/main.py +++ b/main.py @@ -97,7 +97,7 @@ axs[channel].plot(alpha_freqs,psd_channel); axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); - #axs[channel].set_title(canales[channel]) + axs[channel].set_title(canales[channel]) #axs[channel].set_xlim(fmin,fmax) #axs[channel].set_ylim(fmin,fmax) From 56a6639f0bdd50fab7badee2745def67acd10167 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Fri, 17 Sep 2021 20:05:39 +0200 Subject: [PATCH 074/128] Update main.py --- main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index adc0b76..1de2181 100755 --- a/main.py +++ b/main.py @@ -56,7 +56,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*1.2)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(50, math.ceil(nchannels/10*1.2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace =.5, wspace=.2) axs = axs.ravel() @@ -98,8 +98,7 @@ axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); axs[channel].set_title(canales[channel]) - #axs[channel].set_xlim(fmin,fmax) - #axs[channel].set_ylim(fmin,fmax) + axs[channel].set_xlim(fmin,fmax) #Save Figure 1 plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=40) From 6ffffa8c041cb29deacb63a82ef57669495783f0 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Fri, 17 Sep 2021 21:03:34 +0200 Subject: [PATCH 075/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 1de2181..2cc6104 100755 --- a/main.py +++ b/main.py @@ -56,7 +56,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(50, math.ceil(nchannels/10*1.2)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/15),15, figsize=(50, math.ceil(nchannels/15*1.5)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace =.5, wspace=.2) axs = axs.ravel() From 14e0e264bdfce09b3fdf855eba61cb1ca3b85e76 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Fri, 17 Sep 2021 21:05:00 +0200 Subject: [PATCH 076/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 2cc6104..efbd172 100755 --- a/main.py +++ b/main.py @@ -56,7 +56,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/15),15, figsize=(50, math.ceil(nchannels/15*1.5)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/15),15, figsize=(50, math.ceil(nchannels/15*2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace =.5, wspace=.2) axs = axs.ravel() From 2b22746d1df41e6af765e9bd7109b72a6d9c5b01 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 20 Sep 2021 11:56:49 +0200 Subject: [PATCH 077/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index efbd172..8867cce 100755 --- a/main.py +++ b/main.py @@ -143,7 +143,7 @@ #custom_params = {"axes.spines.right": False, "axes.spines.top": False} #sns.set_theme(style="ticks", rc=custom_params) sns.set_theme(style="ticks") -sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True) +sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True,kde_kws={'cut':1}) plt.xlim(xmin=fmin, xmax=fmax) plt.xlabel('Alpha peak frequency (Hz)') sns.despine() From fae56f6e566d87d61d41c8947316d8089322559b Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 20 Sep 2021 11:58:24 +0200 Subject: [PATCH 078/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 8867cce..158fb5b 100755 --- a/main.py +++ b/main.py @@ -143,7 +143,7 @@ #custom_params = {"axes.spines.right": False, "axes.spines.top": False} #sns.set_theme(style="ticks", rc=custom_params) sns.set_theme(style="ticks") -sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True,kde_kws={'cut':1}) +sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True,kde_kws={'cut':2}) plt.xlim(xmin=fmin, xmax=fmax) plt.xlabel('Alpha peak frequency (Hz)') sns.despine() From a95392439483d34973608531b0882d01a3436230 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 20 Sep 2021 11:59:13 +0200 Subject: [PATCH 079/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 158fb5b..194bf0d 100755 --- a/main.py +++ b/main.py @@ -143,7 +143,7 @@ #custom_params = {"axes.spines.right": False, "axes.spines.top": False} #sns.set_theme(style="ticks", rc=custom_params) sns.set_theme(style="ticks") -sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True,kde_kws={'cut':2}) +sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True,kde_kws={'cut':10}) plt.xlim(xmin=fmin, xmax=fmax) plt.xlabel('Alpha peak frequency (Hz)') sns.despine() From d25d5989cdd7666565fc566aa1a5c69fdd5b4a30 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 20 Sep 2021 12:00:38 +0200 Subject: [PATCH 080/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 194bf0d..4d085b4 100755 --- a/main.py +++ b/main.py @@ -143,7 +143,7 @@ #custom_params = {"axes.spines.right": False, "axes.spines.top": False} #sns.set_theme(style="ticks", rc=custom_params) sns.set_theme(style="ticks") -sns.histplot(data=alpha_channel_peak, binwidth=0.5,kde=True,kde_kws={'cut':10}) +sns.histplot(data=alpha_channel_peak, binwidth=0.25,kde=True,kde_kws={'cut':10}) plt.xlim(xmin=fmin, xmax=fmax) plt.xlabel('Alpha peak frequency (Hz)') sns.despine() From 53e59cf2a4d78a7da615dc9ea97b845cda9817e3 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 20 Sep 2021 17:31:22 +0200 Subject: [PATCH 081/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 4d085b4..e630bf9 100755 --- a/main.py +++ b/main.py @@ -48,8 +48,8 @@ # Extract the frequencies that fall inside the alpha band -fmin=8 -fmax=12 +fmin=7 +fmax=14 ifreqs = [i for i, f in zip(range(0, len(freqs)), freqs) if f > fmin and f < fmax] alpha_freqs = np.take(freqs, ifreqs) From d07dae360148a6ae4b7cc3e0db152b721c8ef731 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 20 Sep 2021 17:56:27 +0200 Subject: [PATCH 082/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index e630bf9..a836117 100755 --- a/main.py +++ b/main.py @@ -101,7 +101,7 @@ axs[channel].set_xlim(fmin,fmax) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=40) +plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=20) plt.close() # Average of the peak of all the channels From b2d552dbed42ffe8722663cf9847be28104098bd Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 21 Sep 2021 19:11:23 +0200 Subject: [PATCH 083/128] Update main.py --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index a836117..b9c0310 100755 --- a/main.py +++ b/main.py @@ -87,6 +87,8 @@ elif pic_loc.size>1: peak = np.where(psd_channel==max(pic_mag))[0][0] # take the max if peak==0: peak = pic_loc[np.argmax(pic_mag[1:,])+1] # if it's the first value, take the next max + if peak==psd_channel.size-1: peak = pic_loc[np.argmax(pic_mag[0:-1])] # if it's the last value, take the next max + print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak From cf7649270239cc1b332994554de092a06f1aaae1 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 21 Sep 2021 19:36:50 +0200 Subject: [PATCH 084/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index b9c0310..42ddeaa 100755 --- a/main.py +++ b/main.py @@ -49,7 +49,7 @@ # Extract the frequencies that fall inside the alpha band fmin=7 -fmax=14 +fmax=13 ifreqs = [i for i, f in zip(range(0, len(freqs)), freqs) if f > fmin and f < fmax] alpha_freqs = np.take(freqs, ifreqs) From 0383f3b63c134bf87f86191e56dd26f09664b55f Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 4 Oct 2021 14:42:23 +0200 Subject: [PATCH 085/128] Update main.py --- main.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 42ddeaa..2dde021 100755 --- a/main.py +++ b/main.py @@ -54,17 +54,20 @@ alpha_freqs = np.take(freqs, ifreqs) -# Prepare for Figure 1 containing all the channels -plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/15),15, figsize=(50, math.ceil(nchannels/15*2)), facecolor='w', edgecolor='k') -fig.subplots_adjust(hspace =.5, wspace=.2) -axs = axs.ravel() # ==== FIND ALPHA PEAK ==== +''' + alpha_channel_peak = [] +# Prepare for Figure 1 containing all the channels +plt.figure(1) +fig, axs = plt.subplots(math.ceil(nchannels/15),15, figsize=(50, math.ceil(nchannels/15*2)), facecolor='w', edgecolor='k') +fig.subplots_adjust(hspace =.5, wspace=.2) +axs = axs.ravel() + for channel in range(0, nchannels): # Find maxima with noise-tolerant fast peak-finding algorithm @@ -106,7 +109,15 @@ plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=20) plt.close() -# Average of the peak of all the channels +''' + +# ==== FIND ALPHA MEAN VALUE ==== +alpha_channel_peak = np.mean(psd_welch[:,ifreqs], axis=1) + + + + +# Average value across all channels mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) From 8d18b0685e99fcab2df045971337d02d8af7a3c2 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 4 Oct 2021 14:44:58 +0200 Subject: [PATCH 086/128] Update main --- main | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main b/main index a031ec1..be24bb3 100755 --- a/main +++ b/main @@ -29,14 +29,14 @@ cat << EOF > product.json "type": "image/png", "name": "Alpha peak frequencies", "base64": "$(base64 -w 0 out_dir2/hist_alpha_peak.png)" - }, - { - "type": "image/png", - "name": "Power spectrum for all channels", - "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" } ] } +# { +# "type": "image/png", +# "name": "Power spectrum for all channels", +# "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" +# } EOF From 6ee4d2d154b3f2c812f60b89e93c9e00341c1f21 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 4 Oct 2021 14:52:19 +0200 Subject: [PATCH 087/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 2dde021..7d3b489 100755 --- a/main.py +++ b/main.py @@ -157,7 +157,7 @@ #sns.set_theme(style="ticks", rc=custom_params) sns.set_theme(style="ticks") sns.histplot(data=alpha_channel_peak, binwidth=0.25,kde=True,kde_kws={'cut':10}) -plt.xlim(xmin=fmin, xmax=fmax) +#plt.xlim(xmin=fmin, xmax=fmax) plt.xlabel('Alpha peak frequency (Hz)') sns.despine() # Save fig From 39ebe2125e9393552b53f3c056254b4240494680 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 18 Oct 2021 13:51:44 +0200 Subject: [PATCH 088/128] Create workspace.code-workspace --- workspace.code-workspace | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 workspace.code-workspace diff --git a/workspace.code-workspace b/workspace.code-workspace new file mode 100644 index 0000000..46f440b --- /dev/null +++ b/workspace.code-workspace @@ -0,0 +1,13 @@ +{ + "folders": [ + { + "path": "../app-psd" + }, + { + "path": "." + }, + { + "path": "../app-meg-split-ctf" + } + ] +} \ No newline at end of file From c7e63b34eb27dca44f202c9fd96dbbd63ba8d23a Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 18 Oct 2021 14:28:12 +0200 Subject: [PATCH 089/128] Update main.py --- main.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 7d3b489..998acf3 100755 --- a/main.py +++ b/main.py @@ -56,9 +56,7 @@ -# ==== FIND ALPHA PEAK ==== - -''' +# ==== FIND ALPHA PEAK FREQUENCY ==== alpha_channel_peak = [] @@ -98,7 +96,7 @@ pic_freq = np.take(alpha_freqs,peak) if not math.isnan(peak) else 0 # to avoid nans alpha_channel_peak.append(pic_freq) - #Plot Figure 1 + # FIGURE 1 axs[channel].plot(alpha_freqs,psd_channel); axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); axs[channel].axvline(x=pic_freq,c='k',ls=':'); @@ -114,7 +112,7 @@ # ==== FIND ALPHA MEAN VALUE ==== alpha_channel_peak = np.mean(psd_welch[:,ifreqs], axis=1) - +''' # Average value across all channels @@ -127,16 +125,10 @@ df_alpha.to_csv(os.path.join('out_dir','alpha_peak.csv')) -# Read CSV file -#df = pd.read_csv("df_psd.csv") -#print(df) - - # ==== PLOT FIGURES ==== # FIGURE 2 # Plot PSD - plt.figure(2) plt.plot(freqs, psd_welch.transpose(), zorder=1) plt.xlim(xmin=0, xmax=max(freqs)) @@ -151,6 +143,7 @@ plt.savefig(os.path.join('out_dir2','psd_alpha_peak.png')) plt.close() + # FIGURE 3 plt.figure(3) #custom_params = {"axes.spines.right": False, "axes.spines.top": False} From 246b24bec8fcc93cd8d8d2919098c4709853859b Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 18 Oct 2021 14:30:36 +0200 Subject: [PATCH 090/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 998acf3..157420a 100755 --- a/main.py +++ b/main.py @@ -48,8 +48,8 @@ # Extract the frequencies that fall inside the alpha band -fmin=7 -fmax=13 +fmin = 7 +fmax = 13 ifreqs = [i for i, f in zip(range(0, len(freqs)), freqs) if f > fmin and f < fmax] alpha_freqs = np.take(freqs, ifreqs) From 8fac9f7b15901ab3d4ef23493b9dfc53714e9656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 18 Oct 2021 18:14:07 +0200 Subject: [PATCH 091/128] Update README.md --- README.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a934a60..9a979d5 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# app-detect-alpha-peak +# app-peak-frequency [![Abcdspec-compliant](https://img.shields.io/badge/ABCD_Spec-v1.1-green.svg)](https://github.com/brain-life/abcd-spec) [![Run on Brainlife.io](https://img.shields.io/badge/Brainlife-bl.app.469-blue.svg)](https://doi.org/10.25663/brainlife.app.469) Detect individual alpha peak in MEG signals. -## app-detect-alpha-peak documentation +## app-peak-frequency documentation -1) Detect alpha peak frequency for each channel +1) Detect peak frequency for each channel for a guiven bandwith 2) Input file is: * a `.csv` file containing the Power Spectral Densities 5) Ouput files are: @@ -18,10 +18,6 @@ Detect individual alpha peak in MEG signals. ### Authors - [Guiomar Niso](guiomar.niso@ctb.upm.es) -### Contributors -- [Aurore Bussalb](aurore.bussalb@icm-institute.org) -- [Maximilien Chaumon](maximilien.chaumon@icm-institute.org) - ### Funding Acknowledgement brainlife.io is publicly funded and for the sustainability of the project it is helpful to Acknowledge the use of the platform. We kindly ask that you acknowledge the funding below in your code and publications. Copy and past the following lines into your repository when using this code. From 6d6fc171ae3919501bbf6bf3b009f8cfe495908e Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 18 Oct 2021 18:14:48 +0200 Subject: [PATCH 092/128] Update main --- main | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main b/main index be24bb3..a8d1d72 100755 --- a/main +++ b/main @@ -28,15 +28,16 @@ cat << EOF > product.json { "type": "image/png", "name": "Alpha peak frequencies", - "base64": "$(base64 -w 0 out_dir2/hist_alpha_peak.png)" + "base64": "$(base64 -w 0 out_figs/hist_alpha_peak.png)" + }, + { + "type": "image/png", + "name": "Power spectrum for all channels", + "base64": "$(base64 -w 0 out_figs/psd_allchannels.png)" } ] } -# { -# "type": "image/png", -# "name": "Power spectrum for all channels", -# "base64": "$(base64 -w 0 out_dir2/psd_allchannels.png)" -# } + EOF From 8bd1c71dcb69fc6469af845e4686ca32edcc8575 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Tue, 19 Oct 2021 19:18:19 +0200 Subject: [PATCH 093/128] Update main --- main | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main b/main index a8d1d72..c4cf4b3 100755 --- a/main +++ b/main @@ -16,7 +16,7 @@ set -x # Make output directories mkdir -p out_dir -mkdir -p out_dir2 +mkdir -p out_figs # Run the actual python code singularity exec docker://brainlife/mne:0.23dev python3 main.py From c5e4a8ec5f89aeb98be886354258a1565c220db0 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 20 Oct 2021 09:36:43 +0200 Subject: [PATCH 094/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 157420a..9d7f10b 100755 --- a/main.py +++ b/main.py @@ -104,7 +104,7 @@ axs[channel].set_xlim(fmin,fmax) #Save Figure 1 -plt.savefig(os.path.join('out_dir2','psd_allchannels.png'),dpi=20) +plt.savefig(os.path.join('out_figs','psd_allchannels.png'),dpi=20) plt.close() ''' From 03be80d950c271e9fba90a1f06152afcaabc4eb3 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Wed, 20 Oct 2021 09:37:57 +0200 Subject: [PATCH 095/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 9d7f10b..c2101e9 100755 --- a/main.py +++ b/main.py @@ -140,7 +140,7 @@ plt.axvline(x=mean_alpha_peak,c='k',ls=':') # Save fig -plt.savefig(os.path.join('out_dir2','psd_alpha_peak.png')) +plt.savefig(os.path.join('out_figs','psd_alpha_peak.png')) plt.close() @@ -154,5 +154,5 @@ plt.xlabel('Alpha peak frequency (Hz)') sns.despine() # Save fig -plt.savefig(os.path.join('out_dir2','hist_alpha_peak.png')) +plt.savefig(os.path.join('out_figs','hist_alpha_peak.png')) plt.close() From 3db226f18c5264a755d2c84fdad7a6923490b5c2 Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Fri, 22 Oct 2021 12:31:23 +0200 Subject: [PATCH 096/128] Update main.py --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index c2101e9..3e58a0f 100755 --- a/main.py +++ b/main.py @@ -121,8 +121,8 @@ # == SAVE FILE == # Save to CSV file (could be also TSV) -df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['alpha_peak']) -df_alpha.to_csv(os.path.join('out_dir','alpha_peak.csv')) +df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['peak_frequency']) +df_alpha.to_csv(os.path.join('out_dir','peak_frequency.csv')) # ==== PLOT FIGURES ==== @@ -140,7 +140,7 @@ plt.axvline(x=mean_alpha_peak,c='k',ls=':') # Save fig -plt.savefig(os.path.join('out_figs','psd_alpha_peak.png')) +plt.savefig(os.path.join('out_figs','psd_peak_frequency.png')) plt.close() @@ -154,5 +154,5 @@ plt.xlabel('Alpha peak frequency (Hz)') sns.despine() # Save fig -plt.savefig(os.path.join('out_figs','hist_alpha_peak.png')) +plt.savefig(os.path.join('out_figs','hist_peak_frequency.png')) plt.close() From 40de100efe30d017a3820ec9a84cf432f6ac640d Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Fri, 22 Oct 2021 13:12:31 +0200 Subject: [PATCH 097/128] Update main --- main | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main b/main index c4cf4b3..2a3b95f 100755 --- a/main +++ b/main @@ -28,7 +28,7 @@ cat << EOF > product.json { "type": "image/png", "name": "Alpha peak frequencies", - "base64": "$(base64 -w 0 out_figs/hist_alpha_peak.png)" + "base64": "$(base64 -w 0 out_figs/hist_peak_frequency.png)" }, { "type": "image/png", From c4936e79fc7aade6175445782d36cf1d9c72b18c Mon Sep 17 00:00:00 2001 From: Guiomar Niso Date: Mon, 25 Oct 2021 09:41:17 +0200 Subject: [PATCH 098/128] Update README.md --- README.md | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 9a979d5..793149f 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,17 @@ [![Abcdspec-compliant](https://img.shields.io/badge/ABCD_Spec-v1.1-green.svg)](https://github.com/brain-life/abcd-spec) [![Run on Brainlife.io](https://img.shields.io/badge/Brainlife-bl.app.469-blue.svg)](https://doi.org/10.25663/brainlife.app.469) -Detect individual alpha peak in MEG signals. +Detects peak frequency of PSD for each channel on a given bandwith ## app-peak-frequency documentation -1) Detect peak frequency for each channel for a guiven bandwith +1) Detect peak frequency for each channel for a given bandwith 2) Input file is: * a `.csv` file containing the Power Spectral Densities 5) Ouput files are: - * a `.csv` file containing the alpha peak frequency for each channel and the mean over all channels, - * plot of the mean Power Spectral density over all channels, - * plot of the mean Power Spectral density for each channel. + * a `.csv` file containing the peak frequency for each channel + * a plot with the distribution of all peak frequencies across channels + * a plot the PSD frequency peak for each channel (peak found in the psd) ### Authors - [Guiomar Niso](guiomar.niso@ctb.upm.es) @@ -30,32 +30,8 @@ brainlife.io is publicly funded and for the sustainability of the project it is ### Citations 1. Avesani, P., McPherson, B., Hayashi, S. et al. The open diffusion data derivatives, brain data upcycling via integrated publishing of derivatives and reproducible open cloud services. Sci Data 6, 69 (2019). [https://doi.org/10.1038/s41597-019-0073-y](https://doi.org/10.1038/s41597-019-0073-y) -## Running the App - -### On Brainlife.io - -This App is still private on Brainlife.io. - -### Running Locally (on your machine) - -1. git clone this repo -2. Inside the cloned directory, create `config.json` with the same keys as in `config.json.example` but with paths to your input - files and values of the input parameters. For instance: - -```json -{ - "fif": "rest1-raw.fif" -} -``` - -3. Launch the App by executing `main` - -```bash -./main -``` - -## Output - -The output files are a `.csv` file and two plots in `.png`. + + +#### MIT Copyright (c) 2021 brainlife.io The University of Texas at Austin and Indiana University From acb4997d1443421f366cceee65ee7f0b35bd180e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 15 Nov 2021 11:20:26 +0100 Subject: [PATCH 099/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 3e58a0f..3d62b83 100755 --- a/main.py +++ b/main.py @@ -32,7 +32,7 @@ fname = config['psd'] # == LOAD DATA == -df_psd = pd.read_csv(fname) +df_psd = pd.read_csv(fname, sep='\t') canales = df_psd['channels'].copy() #Number of frequencies computed for the PSD @@ -122,7 +122,7 @@ # == SAVE FILE == # Save to CSV file (could be also TSV) df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['peak_frequency']) -df_alpha.to_csv(os.path.join('out_dir','peak_frequency.csv')) +df_alpha.to_csv(os.path.join('out_dir','psd.tsv'), sep = '\t', index=False)) # ==== PLOT FIGURES ==== From 541c7f9078de5ee02066df785778aecdaf71d6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 15 Nov 2021 11:43:09 +0100 Subject: [PATCH 100/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 3d62b83..2aba013 100755 --- a/main.py +++ b/main.py @@ -122,7 +122,7 @@ # == SAVE FILE == # Save to CSV file (could be also TSV) df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['peak_frequency']) -df_alpha.to_csv(os.path.join('out_dir','psd.tsv'), sep = '\t', index=False)) +df_alpha.to_csv(os.path.join('out_dir','psd.tsv'), sep = '\t', index=False) # ==== PLOT FIGURES ==== From 30593b2bf4e96e7106e149b8b3693310ea2b47ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 15 Nov 2021 12:03:25 +0100 Subject: [PATCH 101/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 2aba013..0455f06 100755 --- a/main.py +++ b/main.py @@ -122,7 +122,7 @@ # == SAVE FILE == # Save to CSV file (could be also TSV) df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['peak_frequency']) -df_alpha.to_csv(os.path.join('out_dir','psd.tsv'), sep = '\t', index=False) +df_alpha.to_csv(os.path.join('out_dir','psd.tsv'), sep='\t') # ==== PLOT FIGURES ==== From 27e5cf0c6ab010a3a27cee52e99a82c2869b8a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 15 Nov 2021 12:06:49 +0100 Subject: [PATCH 102/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 0455f06..2d6e293 100755 --- a/main.py +++ b/main.py @@ -121,7 +121,7 @@ # == SAVE FILE == # Save to CSV file (could be also TSV) -df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['peak_frequency']) +df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['peak']) df_alpha.to_csv(os.path.join('out_dir','psd.tsv'), sep='\t') From ca319d8da196cc3fb37957827dd5390381a81800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Thu, 18 Nov 2021 18:43:03 +0100 Subject: [PATCH 103/128] Update main.py --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 2d6e293..cbec0c5 100755 --- a/main.py +++ b/main.py @@ -48,8 +48,8 @@ # Extract the frequencies that fall inside the alpha band -fmin = 7 -fmax = 13 +fmin = 7.9 +fmax = 12.1 ifreqs = [i for i, f in zip(range(0, len(freqs)), freqs) if f > fmin and f < fmax] alpha_freqs = np.take(freqs, ifreqs) From af9129172d296da011268ae74bec813e74a42e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Tue, 30 Nov 2021 18:35:29 +0100 Subject: [PATCH 104/128] Update README.md --- README.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 793149f..e0f113f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# app-peak-frequency +# Find frequency peak [![Abcdspec-compliant](https://img.shields.io/badge/ABCD_Spec-v1.1-green.svg)](https://github.com/brain-life/abcd-spec) -[![Run on Brainlife.io](https://img.shields.io/badge/Brainlife-bl.app.469-blue.svg)](https://doi.org/10.25663/brainlife.app.469) +[![Run on Brainlife.io](https://img.shields.io/badge/Brainlife-bl.app.531-blue.svg)](https://doi.org/10.25663/brainlife.app.531) Detects peak frequency of PSD for each channel on a given bandwith @@ -9,16 +9,19 @@ Detects peak frequency of PSD for each channel on a given bandwith 1) Detect peak frequency for each channel for a given bandwith 2) Input file is: - * a `.csv` file containing the Power Spectral Densities + * a `.tsv` file containing the Power Spectral Densities 5) Ouput files are: - * a `.csv` file containing the peak frequency for each channel + * a `.tsv` file containing the peak frequency for each channel * a plot with the distribution of all peak frequencies across channels * a plot the PSD frequency peak for each channel (peak found in the psd) ### Authors - [Guiomar Niso](guiomar.niso@ctb.upm.es) -### Funding Acknowledgement +### Citations +Avesani, P., McPherson, B., Hayashi, S. et al. The open diffusion data derivatives, brain data upcycling via integrated publishing of derivatives and reproducible open cloud services. Sci Data 6, 69 (2019). https://doi.org/10.1038/s41597-019-0073-y + +## Funding Acknowledgement brainlife.io is publicly funded and for the sustainability of the project it is helpful to Acknowledge the use of the platform. We kindly ask that you acknowledge the funding below in your code and publications. Copy and past the following lines into your repository when using this code. [![NSF-BCS-1734853](https://img.shields.io/badge/NSF_BCS-1734853-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1734853) @@ -27,11 +30,5 @@ brainlife.io is publicly funded and for the sustainability of the project it is [![NSF-IIS-1912270](https://img.shields.io/badge/NSF_IIS-1912270-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1912270) [![NIH-NIBIB-R01EB029272](https://img.shields.io/badge/NIH_NIBIB-R01EB029272-green.svg)](https://grantome.com/grant/NIH/R01-EB029272-01) -### Citations -1. Avesani, P., McPherson, B., Hayashi, S. et al. The open diffusion data derivatives, brain data upcycling via integrated publishing of derivatives and reproducible open cloud services. Sci Data 6, 69 (2019). [https://doi.org/10.1038/s41597-019-0073-y](https://doi.org/10.1038/s41597-019-0073-y) - - - - #### MIT Copyright (c) 2021 brainlife.io The University of Texas at Austin and Indiana University From 23a7f60a2f2de7fb1df568b3a83a291854192549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Tue, 30 Nov 2021 18:43:55 +0100 Subject: [PATCH 105/128] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e0f113f..c97190e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Find frequency peak +# Find frequency peak of PSD data [![Abcdspec-compliant](https://img.shields.io/badge/ABCD_Spec-v1.1-green.svg)](https://github.com/brain-life/abcd-spec) [![Run on Brainlife.io](https://img.shields.io/badge/Brainlife-bl.app.531-blue.svg)](https://doi.org/10.25663/brainlife.app.531) @@ -24,10 +24,10 @@ Avesani, P., McPherson, B., Hayashi, S. et al. The open diffusion data derivativ ## Funding Acknowledgement brainlife.io is publicly funded and for the sustainability of the project it is helpful to Acknowledge the use of the platform. We kindly ask that you acknowledge the funding below in your code and publications. Copy and past the following lines into your repository when using this code. -[![NSF-BCS-1734853](https://img.shields.io/badge/NSF_BCS-1734853-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1734853) -[![NSF-BCS-1636893](https://img.shields.io/badge/NSF_BCS-1636893-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1636893) -[![NSF-ACI-1916518](https://img.shields.io/badge/NSF_ACI-1916518-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1916518) -[![NSF-IIS-1912270](https://img.shields.io/badge/NSF_IIS-1912270-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1912270) +[![NSF-BCS-1734853](https://img.shields.io/badge/NSF_BCS-1734853-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1734853) +[![NSF-BCS-1636893](https://img.shields.io/badge/NSF_BCS-1636893-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1636893) +[![NSF-ACI-1916518](https://img.shields.io/badge/NSF_ACI-1916518-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1916518) +[![NSF-IIS-1912270](https://img.shields.io/badge/NSF_IIS-1912270-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1912270) [![NIH-NIBIB-R01EB029272](https://img.shields.io/badge/NIH_NIBIB-R01EB029272-green.svg)](https://grantome.com/grant/NIH/R01-EB029272-01) #### MIT Copyright (c) 2021 brainlife.io The University of Texas at Austin and Indiana University From e8d80327bc4b6bc93986c0d938f930f2d363cadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Tue, 30 Nov 2021 18:44:01 +0100 Subject: [PATCH 106/128] Update main.py --- main.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/main.py b/main.py index cbec0c5..867a036 100755 --- a/main.py +++ b/main.py @@ -1,15 +1,9 @@ -# Copyright (c) 2020 brainlife.io -# -# This file is a MNE python-based brainlife.io App -# +# Copyright (c) 2021 brainlife.io +## # Author: Guiomar Niso # Indiana University -# Required libraries -# pip install mne-bids coloredlogs tqdm pandas scikit-learn json_tricks fire - # set up environment -#import mne-study-template import os import json import mne @@ -30,6 +24,8 @@ # == GET CONFIG VALUES == fname = config['psd'] +fmin = config['fmin'] +fmax = config['fmax'] # == LOAD DATA == df_psd = pd.read_csv(fname, sep='\t') @@ -48,15 +44,12 @@ # Extract the frequencies that fall inside the alpha band -fmin = 7.9 -fmax = 12.1 ifreqs = [i for i, f in zip(range(0, len(freqs)), freqs) if f > fmin and f < fmax] alpha_freqs = np.take(freqs, ifreqs) - -# ==== FIND ALPHA PEAK FREQUENCY ==== +# ==== FIND FREQUENCY PEAK ==== alpha_channel_peak = [] @@ -108,19 +101,16 @@ plt.close() ''' - # ==== FIND ALPHA MEAN VALUE ==== alpha_channel_peak = np.mean(psd_welch[:,ifreqs], axis=1) - ''' - # Average value across all channels mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) # == SAVE FILE == -# Save to CSV file (could be also TSV) +# Save to TSV file df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['peak']) df_alpha.to_csv(os.path.join('out_dir','psd.tsv'), sep='\t') @@ -151,7 +141,7 @@ sns.set_theme(style="ticks") sns.histplot(data=alpha_channel_peak, binwidth=0.25,kde=True,kde_kws={'cut':10}) #plt.xlim(xmin=fmin, xmax=fmax) -plt.xlabel('Alpha peak frequency (Hz)') +plt.xlabel('Peak frequency (Hz)') sns.despine() # Save fig plt.savefig(os.path.join('out_figs','hist_peak_frequency.png')) From db2352f21414bf7cff7c58a876b718d952c78388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Tue, 30 Nov 2021 19:03:46 +0100 Subject: [PATCH 107/128] Update main.py --- main.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index 867a036..c763d05 100755 --- a/main.py +++ b/main.py @@ -45,17 +45,17 @@ # Extract the frequencies that fall inside the alpha band ifreqs = [i for i, f in zip(range(0, len(freqs)), freqs) if f > fmin and f < fmax] -alpha_freqs = np.take(freqs, ifreqs) +band_freqs = np.take(freqs, ifreqs) # ==== FIND FREQUENCY PEAK ==== -alpha_channel_peak = [] +channel_peak = [] # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/15),15, figsize=(50, math.ceil(nchannels/15*2)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(50, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace =.5, wspace=.2) axs = axs.ravel() @@ -86,13 +86,13 @@ print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak - pic_freq = np.take(alpha_freqs,peak) if not math.isnan(peak) else 0 # to avoid nans - alpha_channel_peak.append(pic_freq) + pic_freq = np.take(band_freqs,peak) if not math.isnan(peak) else 0 # to avoid nans + channel_peak.append(pic_freq) # FIGURE 1 - axs[channel].plot(alpha_freqs,psd_channel); - axs[channel].plot(np.take(alpha_freqs,pic_loc),pic_mag,'*'); - axs[channel].axvline(x=pic_freq,c='k',ls=':'); + axs[channel].plot(band_freqs,psd_channel) + axs[channel].plot(np.take(band_freqs,pic_loc),pic_mag,'*') + axs[channel].axvline(x=pic_freq,c='k',ls=':') axs[channel].set_title(canales[channel]) axs[channel].set_xlim(fmin,fmax) @@ -106,12 +106,12 @@ ''' # Average value across all channels -mean_alpha_peak=np.mean(alpha_channel_peak, axis=0) +mean_peak=np.nanmean(channel_peak, axis=0) # == SAVE FILE == # Save to TSV file -df_alpha = pd.DataFrame(alpha_channel_peak, index=canales, columns=['peak']) +df_alpha = pd.DataFrame(channel_peak, index=canales, columns=['peak']) df_alpha.to_csv(os.path.join('out_dir','psd.tsv'), sep='\t') @@ -124,11 +124,8 @@ plt.xlim(xmin=0, xmax=max(freqs)) plt.xlabel('Frequency (Hz)') plt.ylabel('Power Spectral Density') -#plt.title('PSD alpha peak: ',mean_alpha_peak) -# SHADE ALPHA BAND (GUIO) - -plt.axvline(x=mean_alpha_peak,c='k',ls=':') +plt.axvline(x=mean_peak,c='k',ls=':') # Save fig plt.savefig(os.path.join('out_figs','psd_peak_frequency.png')) plt.close() @@ -139,7 +136,7 @@ #custom_params = {"axes.spines.right": False, "axes.spines.top": False} #sns.set_theme(style="ticks", rc=custom_params) sns.set_theme(style="ticks") -sns.histplot(data=alpha_channel_peak, binwidth=0.25,kde=True,kde_kws={'cut':10}) +sns.histplot(data=channel_peak, binwidth=0.25,kde=True,kde_kws={'cut':10}) #plt.xlim(xmin=fmin, xmax=fmax) plt.xlabel('Peak frequency (Hz)') sns.despine() From 33ad5ed983d732df003cba82f14a386fda2bb664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Tue, 30 Nov 2021 19:04:14 +0100 Subject: [PATCH 108/128] Update main --- main | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main b/main index 2a3b95f..bb3434d 100755 --- a/main +++ b/main @@ -27,7 +27,7 @@ cat << EOF > product.json "brainlife": [ { "type": "image/png", - "name": "Alpha peak frequencies", + "name": "Peak frequencies", "base64": "$(base64 -w 0 out_figs/hist_peak_frequency.png)" }, { From 1186fc39baa18fe9d720e11753268fd61ecd46bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Tue, 30 Nov 2021 19:06:32 +0100 Subject: [PATCH 109/128] Update main.py --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index c763d05..d9c2305 100755 --- a/main.py +++ b/main.py @@ -55,7 +55,7 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(50, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') +fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace =.5, wspace=.2) axs = axs.ravel() @@ -63,7 +63,7 @@ # Find maxima with noise-tolerant fast peak-finding algorithm psd_channel = np.take(psd_welch[channel, :], ifreqs) - pic_loc, pic_mag = mne.preprocessing.peak_finder(psd_channel, extrema=1, verbose=None); + pic_loc, pic_mag = mne.preprocessing.peak_finder(psd_channel, extrema=1, verbose=None) # From all the peaks found, get the main peak @@ -86,7 +86,7 @@ print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak - pic_freq = np.take(band_freqs,peak) if not math.isnan(peak) else 0 # to avoid nans + pic_freq = np.take(band_freqs,peak) #if not math.isnan(peak) else 0 # to avoid nans channel_peak.append(pic_freq) # FIGURE 1 From 8f0f6afa0ceed41161df55dd3a837d1b8cfb55f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Tue, 30 Nov 2021 19:08:16 +0100 Subject: [PATCH 110/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index d9c2305..1b7913f 100755 --- a/main.py +++ b/main.py @@ -86,7 +86,7 @@ print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak - pic_freq = np.take(band_freqs,peak) #if not math.isnan(peak) else 0 # to avoid nans + pic_freq = np.take(band_freqs,peak) if not math.isnan(peak) else math.nan # to avoid nans channel_peak.append(pic_freq) # FIGURE 1 From 9bba2f9cdac3a150c7e0cf09a9d4dd52a659a342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Tue, 30 Nov 2021 19:09:49 +0100 Subject: [PATCH 111/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 1b7913f..d0c2c77 100755 --- a/main.py +++ b/main.py @@ -86,7 +86,7 @@ print('Multiple peaks found for channel: ',canales[channel]) #Get the frequency of the peak - pic_freq = np.take(band_freqs,peak) if not math.isnan(peak) else math.nan # to avoid nans + pic_freq = np.take(band_freqs,peak) if not math.isnan(peak) else math.nan channel_peak.append(pic_freq) # FIGURE 1 From f52dd17f6a8094c40740514e9b0f62e3fd6388e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Fri, 10 Dec 2021 18:51:04 +0100 Subject: [PATCH 112/128] Delete config.json.example --- config.json.example | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 config.json.example diff --git a/config.json.example b/config.json.example deleted file mode 100644 index 60e8979..0000000 --- a/config.json.example +++ /dev/null @@ -1,3 +0,0 @@ -{ - "psd_welch": "/network/lustre/iss01/home/aurore.bussalb/Repositories/app-detect-alpha-peak/inputs/psd_eeg.csv" -} From 987a53bc2612970dd9745e89a25ab36619deb656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Fri, 10 Dec 2021 18:51:07 +0100 Subject: [PATCH 113/128] Update main.py --- main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index d0c2c77..7a9aed6 100755 --- a/main.py +++ b/main.py @@ -29,7 +29,8 @@ # == LOAD DATA == df_psd = pd.read_csv(fname, sep='\t') -canales = df_psd['channels'].copy() +#canales = df_psd['channels'].copy() +canales = df_psd_avg.index.values #Number of frequencies computed for the PSD nfreqs = df_psd.shape[1] From 2a2a2ffda76217d781606a8c31bf5b3e89ae13ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Fri, 10 Dec 2021 18:52:53 +0100 Subject: [PATCH 114/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 7a9aed6..6fefd0f 100755 --- a/main.py +++ b/main.py @@ -30,7 +30,7 @@ # == LOAD DATA == df_psd = pd.read_csv(fname, sep='\t') #canales = df_psd['channels'].copy() -canales = df_psd_avg.index.values +canales = df_psd.index.values #Number of frequencies computed for the PSD nfreqs = df_psd.shape[1] From 425624d4dc21616faa8d14c1606511a2cc6f7c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Fri, 10 Dec 2021 18:56:22 +0100 Subject: [PATCH 115/128] Update main.py --- main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.py b/main.py index 6fefd0f..d0c2c77 100755 --- a/main.py +++ b/main.py @@ -29,8 +29,7 @@ # == LOAD DATA == df_psd = pd.read_csv(fname, sep='\t') -#canales = df_psd['channels'].copy() -canales = df_psd.index.values +canales = df_psd['channels'].copy() #Number of frequencies computed for the PSD nfreqs = df_psd.shape[1] From 583423878090bdab6977eea137dc2648d77d3df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Fri, 10 Dec 2021 18:56:43 +0100 Subject: [PATCH 116/128] Update main.py --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index d0c2c77..1651956 100755 --- a/main.py +++ b/main.py @@ -30,6 +30,7 @@ # == LOAD DATA == df_psd = pd.read_csv(fname, sep='\t') canales = df_psd['channels'].copy() +#canales = df_psd.index.values #Number of frequencies computed for the PSD nfreqs = df_psd.shape[1] From 7af692a7a2767cf2e439449ac5f5595ea2479de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 13 Dec 2021 11:28:10 +0100 Subject: [PATCH 117/128] Update main.py --- main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 1651956..4a76695 100755 --- a/main.py +++ b/main.py @@ -56,7 +56,12 @@ # Prepare for Figure 1 containing all the channels plt.figure(1) -fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') + +if nchannels==1: + fig, axs = plt.subplots(nchannels,1, figsize=(40, 20), facecolor='w', edgecolor='k') +else: + fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') + fig.subplots_adjust(hspace =.5, wspace=.2) axs = axs.ravel() From 392fa25719310201934dafe62f54136a9e60d4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 13 Dec 2021 11:33:03 +0100 Subject: [PATCH 118/128] Update main.py --- main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 4a76695..1d58c63 100755 --- a/main.py +++ b/main.py @@ -61,9 +61,8 @@ fig, axs = plt.subplots(nchannels,1, figsize=(40, 20), facecolor='w', edgecolor='k') else: fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') - -fig.subplots_adjust(hspace =.5, wspace=.2) -axs = axs.ravel() + fig.subplots_adjust(hspace =.5, wspace=.2) + axs = axs.ravel() for channel in range(0, nchannels): From 0aaccde2c3c08f46db3661bb44ddb61b4dd185dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 13 Dec 2021 13:29:39 +0100 Subject: [PATCH 119/128] Update main.py --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 1d58c63..426c69b 100755 --- a/main.py +++ b/main.py @@ -58,7 +58,9 @@ plt.figure(1) if nchannels==1: - fig, axs = plt.subplots(nchannels,1, figsize=(40, 20), facecolor='w', edgecolor='k') + axs=[0] + fig, axs1 = plt.subplots(nchannels,1, figsize=(40, 20), facecolor='w', edgecolor='k') + axs[0]=axs1 else: fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace =.5, wspace=.2) From bb19c866f329d941f9ae308ac7df10d3b1bdf0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 13 Dec 2021 13:31:01 +0100 Subject: [PATCH 120/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 426c69b..3659b23 100755 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ if nchannels==1: axs=[0] - fig, axs1 = plt.subplots(nchannels,1, figsize=(40, 20), facecolor='w', edgecolor='k') + fig, axs1 = plt.subplots(nchannels,1, facecolor='w', edgecolor='k') axs[0]=axs1 else: fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') From 8404eed739a0bd62b75324759cab842958af4249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 13 Dec 2021 13:33:03 +0100 Subject: [PATCH 121/128] Update main.py --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 3659b23..c9d45af 100755 --- a/main.py +++ b/main.py @@ -61,10 +61,12 @@ axs=[0] fig, axs1 = plt.subplots(nchannels,1, facecolor='w', edgecolor='k') axs[0]=axs1 + dpi=300 else: fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace =.5, wspace=.2) axs = axs.ravel() + dpi=20 for channel in range(0, nchannels): @@ -104,7 +106,7 @@ axs[channel].set_xlim(fmin,fmax) #Save Figure 1 -plt.savefig(os.path.join('out_figs','psd_allchannels.png'),dpi=20) +plt.savefig(os.path.join('out_figs','psd_allchannels.png'),dpi=dpi) plt.close() ''' From 426d56276e8ee3c7cec6dd3238e22e4815a48f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 13 Dec 2021 13:51:45 +0100 Subject: [PATCH 122/128] Update main.py --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c9d45af..d21afc7 100755 --- a/main.py +++ b/main.py @@ -145,8 +145,9 @@ #custom_params = {"axes.spines.right": False, "axes.spines.top": False} #sns.set_theme(style="ticks", rc=custom_params) sns.set_theme(style="ticks") -sns.histplot(data=channel_peak, binwidth=0.25,kde=True,kde_kws={'cut':10}) -#plt.xlim(xmin=fmin, xmax=fmax) +#sns.histplot(data=channel_peak, binwidth=0.25,kde=True,kde_kws={'cut':10}) +sns.histplot(data=channel_peak, kde=True) +plt.xlim(xmin=fmin, xmax=fmax) plt.xlabel('Peak frequency (Hz)') sns.despine() # Save fig From 63037630cb2685e5751ad8480afe248c4484806c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 13 Dec 2021 13:56:32 +0100 Subject: [PATCH 123/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index d21afc7..0f439e3 100755 --- a/main.py +++ b/main.py @@ -61,7 +61,7 @@ axs=[0] fig, axs1 = plt.subplots(nchannels,1, facecolor='w', edgecolor='k') axs[0]=axs1 - dpi=300 + dpi=200 else: fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace =.5, wspace=.2) From 80c704de2b90a2bcaee4dba1de7417b13dc20ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 13 Dec 2021 14:06:14 +0100 Subject: [PATCH 124/128] Update main.py --- main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 0f439e3..5bd3323 100755 --- a/main.py +++ b/main.py @@ -63,7 +63,8 @@ axs[0]=axs1 dpi=200 else: - fig, axs = plt.subplots(math.ceil(nchannels/10),10, figsize=(40, math.ceil(nchannels/10*2)), facecolor='w', edgecolor='k') + Nfigs = 10 + fig, axs = plt.subplots(math.ceil(nchannels/Nfigs),Nfigs, figsize=(40, math.ceil(nchannels/Nfigs*2)), facecolor='w', edgecolor='k') fig.subplots_adjust(hspace =.5, wspace=.2) axs = axs.ravel() dpi=20 @@ -105,6 +106,11 @@ axs[channel].set_title(canales[channel]) axs[channel].set_xlim(fmin,fmax) +# Delete empty axes +if nchannels>1: + for i in range(nchannels, math.ceil(nchannels/Nfigs)*Nfigs): + fig.delaxes(axs.flatten()[i]) + #Save Figure 1 plt.savefig(os.path.join('out_figs','psd_allchannels.png'),dpi=dpi) plt.close() From cfefd6edb77c2acbf1a0c3677abc6357470cb3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 13 Dec 2021 14:10:55 +0100 Subject: [PATCH 125/128] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 5bd3323..e80ce67 100755 --- a/main.py +++ b/main.py @@ -152,7 +152,7 @@ #sns.set_theme(style="ticks", rc=custom_params) sns.set_theme(style="ticks") #sns.histplot(data=channel_peak, binwidth=0.25,kde=True,kde_kws={'cut':10}) -sns.histplot(data=channel_peak, kde=True) +sns.histplot(data=channel_peak, binwidth=0.25, kde=True) plt.xlim(xmin=fmin, xmax=fmax) plt.xlabel('Peak frequency (Hz)') sns.despine() From a2c3a44813856932a0ad41152870671e76fba5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Mon, 13 Dec 2021 14:18:57 +0100 Subject: [PATCH 126/128] Update main.py --- main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index e80ce67..cbcdd30 100755 --- a/main.py +++ b/main.py @@ -151,8 +151,12 @@ #custom_params = {"axes.spines.right": False, "axes.spines.top": False} #sns.set_theme(style="ticks", rc=custom_params) sns.set_theme(style="ticks") -#sns.histplot(data=channel_peak, binwidth=0.25,kde=True,kde_kws={'cut':10}) -sns.histplot(data=channel_peak, binwidth=0.25, kde=True) + +if nchannels==1: + sns.histplot(data=channel_peak, kde=True) # doesn't allow binwidth=0.25 for one value data +else: + sns.histplot(data=channel_peak, binwidth=0.25,kde=True,kde_kws={'cut':10}) + plt.xlim(xmin=fmin, xmax=fmax) plt.xlabel('Peak frequency (Hz)') sns.despine() From 75a6ac4e4a0fe07cca300709a02b3e243da09571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Thu, 8 Feb 2024 16:41:09 +0100 Subject: [PATCH 127/128] Update README.md --- README.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c97190e..51956fd 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ [![Abcdspec-compliant](https://img.shields.io/badge/ABCD_Spec-v1.1-green.svg)](https://github.com/brain-life/abcd-spec) [![Run on Brainlife.io](https://img.shields.io/badge/Brainlife-bl.app.531-blue.svg)](https://doi.org/10.25663/brainlife.app.531) -Detects peak frequency of PSD for each channel on a given bandwith +## Documentation -## app-peak-frequency documentation +Detects peak frequency of PSD for each channel on a given bandwith 1) Detect peak frequency for each channel for a given bandwith 2) Input file is: @@ -15,20 +15,22 @@ Detects peak frequency of PSD for each channel on a given bandwith * a plot with the distribution of all peak frequencies across channels * a plot the PSD frequency peak for each channel (peak found in the psd) -### Authors -- [Guiomar Niso](guiomar.niso@ctb.upm.es) +## Authors +- [Guiomar Niso](guiomar.niso@ctb.upm.es), Instituto Cajal, CSIC, Spain + +## Citations +We kindly ask that you cite the following articles when publishing papers and code using this app. -### Citations -Avesani, P., McPherson, B., Hayashi, S. et al. The open diffusion data derivatives, brain data upcycling via integrated publishing of derivatives and reproducible open cloud services. Sci Data 6, 69 (2019). https://doi.org/10.1038/s41597-019-0073-y +1. **brainlife. io: A decentralized and open source cloud platform to support neuroscience research**. Hayashi, S., Caron, B. A., et al. & Pestilli, F. (2023). ArXiv. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10274934/ ## Funding Acknowledgement -brainlife.io is publicly funded and for the sustainability of the project it is helpful to Acknowledge the use of the platform. We kindly ask that you acknowledge the funding below in your code and publications. Copy and past the following lines into your repository when using this code. +brainlife.io is publicly funded and for the sustainability of the project we kindly ask that you acknowledge the following funding sources: -[![NSF-BCS-1734853](https://img.shields.io/badge/NSF_BCS-1734853-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1734853) -[![NSF-BCS-1636893](https://img.shields.io/badge/NSF_BCS-1636893-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1636893) -[![NSF-ACI-1916518](https://img.shields.io/badge/NSF_ACI-1916518-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1916518) -[![NSF-IIS-1912270](https://img.shields.io/badge/NSF_IIS-1912270-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1912270) -[![NIH-NIBIB-R01EB029272](https://img.shields.io/badge/NIH_NIBIB-R01EB029272-green.svg)](https://grantome.com/grant/NIH/R01-EB029272-01) +[![NSF-BCS-1734853](https://img.shields.io/badge/NSF_BCS-1734853-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1734853) +[![NSF-BCS-1636893](https://img.shields.io/badge/NSF_BCS-1636893-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1636893) +[![NSF-ACI-1916518](https://img.shields.io/badge/NSF_ACI-1916518-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1916518) +[![NSF-IIS-1912270](https://img.shields.io/badge/NSF_IIS-1912270-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1912270) +[![NIH-NIBIB-R01EB030896](https://img.shields.io/badge/NIH_NIBIB-R01EB030896-green.svg)](https://grantome.com/grant/NIH/R01-EB030896-01) -#### MIT Copyright (c) 2021 brainlife.io The University of Texas at Austin and Indiana University +#### MIT Copyright (c) 2021 brainlife.io The University of Texas at Austin and Indiana University \ No newline at end of file From f8bee3a992ba3d965c41cf2b225516c913b69cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Guiomar=20Niso=20Gal=C3=A1n?= Date: Thu, 8 Feb 2024 16:42:38 +0100 Subject: [PATCH 128/128] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 51956fd..c498311 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Detects peak frequency of PSD for each channel on a given bandwith 1) Detect peak frequency for each channel for a given bandwith 2) Input file is: - * a `.tsv` file containing the Power Spectral Densities + * a `.tsv` file containing the signal PSD, Power Spectral Densities 5) Ouput files are: * a `.tsv` file containing the peak frequency for each channel * a plot with the distribution of all peak frequencies across channels