Dear all,
I am having issues understanding the cleaned resting-state EEG data I receive from MNE-BIDS. I have EEG data available from a Brainvision recording system (I did not acquire these data myself).
System information:
- MNE version: 1.8.0
- operating system: Linux-3.10.0
When looking at the data with the plot function, it looks normal and cleaned (*_cean_raw.fif). Just to make sure, this is the preprocessed file I need to use for further analyses, right? (I do not need the epoched data)
However, when I try to calculate the mean bandpower in different frequency bands, the value seems way too low (0.00000000000154386107709975 for the delta band for example). I have been struggling for a couple of weeks to get down to the issue, but I believe there is something in the MNE-BIDS preprocessing pipeline, which leads to these values. I came to this conclusion because I calculated the band power with the same code for the uncleaned data, which has values in normal ranges for power I believe (30.55).
The preprocessing steps that I used were “extended_infomax” for ICA, autoreject_local and filtering (between 0.5 and 45), and these all seem to work normal when looking at the html report of MNE-BIDS.
Here is the code that I used for calculating bandpower:
def bandpower(data, sf, band, window_sec=None, relative=False):
band = np.asarray(band)
low, high = band
# Define window length for Welch method
if window_sec is not None:
nperseg = window_sec * sf
else:
nperseg = (2 / low) * sf
# Compute Welch's periodogram
freqs, psd = welch(data, sf, nperseg=nperseg)
plt.semilogy(freqs, psd)
# Frequency resolution
freq_res = freqs[1] - freqs[0]
# Find indices corresponding to the frequency band
idx_band = np.logical_and(freqs >= low, freqs <= high)
# Calculate the band power using Simpson's rule for numerical integration
bp = simpson(psd[idx_band], dx=freq_res)
if relative:
bp /= simpson(psd, dx=freq_res)
return bp
# Function to process subjects and calculate band powers
def process_subjects(subject_list):
results = []
# Frequency bands of interest
bands = {
'Delta': (0.5, 4),
'Theta': (4, 8),
'Alpha': (8, 13),
'Beta': (13, 30)
}
# Loop over all subjects
for sub in subject_list:
file_preprocessed = f"{data_path_root}/eyesclosed/derivatives/mne-bids-pipeline/{sub}/{ses}/eeg/{sub}_{ses}_task-{task}_proc-clean_raw.fif"
try:
# Load preprocessed data
prepr = mne.io.read_raw_fif(file_preprocessed, preload=True)
# Get the sampling frequency
sfreq = prepr.info['sfreq']
# Get the data for all EEG channels
eeg_data = prepr.get_data(picks='eeg') # Shape: (n_channels, n_times)
# Initialize a dictionary to store band powers
band_powers = {band: [] for band in bands.keys()}
# Loop over each channel and compute band power
for ch_idx in range(eeg_data.shape[0]):
data = eeg_data[ch_idx, :] # Get data for the current channel
# Calculate band power for each frequency band
for band_name, band_range in bands.items():
bp = bandpower(data, sfreq, band_range)
band_powers[band_name].append(bp)
# Average band powers across all channels for this subject
mean_band_powers = {band: np.mean(band_powers[band]) for band in bands.keys()}
# Append the results for this subject
results.append({'Subject': sub, **mean_band_powers})
I hope my question is clear and maybe came across the same problem.
Thanks in advance.