From 80404e4b149e633be2c84e86dbb24741c69f5b44 Mon Sep 17 00:00:00 2001 From: Chetan Gohil Date: Fri, 9 Feb 2024 09:13:56 +0000 Subject: [PATCH] Fix PSD of epoched data. --- osl/source_recon/parcellation/parcellation.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/osl/source_recon/parcellation/parcellation.py b/osl/source_recon/parcellation/parcellation.py index d3f1bdc5..8c4713c7 100644 --- a/osl/source_recon/parcellation/parcellation.py +++ b/osl/source_recon/parcellation/parcellation.py @@ -476,12 +476,16 @@ def plot_psd(parc_ts, fs, freq_range, parcellation_file, filename): Output filename. """ if parc_ts.ndim == 3: - # (parcels, time, epochs) -> (parcels, time) - shape = parc_ts.shape - parc_ts = parc_ts.reshape(shape[0], shape[1] * shape[2]) + # Calculate PSD for each epoch individually and average + psd = [] + for i in range(parc_ts.shape[-1]): + f, p = welch(parc_ts[..., i], fs=fs) + psd.append(p) + psd = np.mean(psd, axis=0) + else: + # Calcualte PSD of continuous data + f, psd = welch(parc_ts, fs=fs) - # Calculate PSD - f, psd = welch(parc_ts, fs=fs) n_parcels = psd.shape[0] # Re-order to use colour to indicate anterior->posterior location