Mohima_mohi33
Mohima_mohi33

Reputation: 9

Why am I getting this runtime warning in mne-python while trying to visualize from (.fif) files?

I'm struggling with eeg-channel visualization part of preprocessing using mne-python. These ('.fif') files were preprocessed from ('.mat') files.This is the code I used in my kaggle notebook:

import mne
import os
import numpy as np

# Define the directory where your .fif files are stored
data_dir = '/kaggle/input/preproccesed-dataset/128-channel-resting(2.0)/kaggle/working/preprocessed_mat_output_directory'

# List all .fif files in the directory
fif_files = [f for f in os.listdir(data_dir) if f.endswith('-epo.fif')]

# Load each .fif file
epochs_list = [mne.read_epochs(os.path.join(data_dir, fif_file)) for fif_file in fif_files]

# Concatenate all epochs into a single Epochs object
all_epochs = mne.concatenate_epochs(epochs_list)

# Preprocessing: Apply a high-pass filter
all_epochs.filter(l_freq=1.0, h_freq=40.0)

# Perform ICA
ica = mne.preprocessing.ICA(n_components=20, random_state=97)
ica.fit(all_epochs)

# Exclude components manually based on inspection or automated criteria
ica.exclude = [0, 1]  # Adjust based on identified artifact components

# Apply ICA to epochs
all_epochs = ica.apply(all_epochs)

# Plot evoked responses
evoked = all_epochs.average()
evoked.plot()

# Plot PSD
fig_psd = all_epochs.plot_psd(fmin=1.0, fmax=40.0, average=True, spatial_colors=False)

# Plot topographic maps
fig_topo = evoked.plot_topomap(times=[0.1, 0.2, 0.3], ch_type='eeg', average=0.05)

# Compute and plot TFR
from mne.time_frequency import tfr_morlet
freqs = np.arange(6, 30, 3)
n_cycles = freqs / 2
power = tfr_morlet(all_epochs, freqs=freqs, n_cycles=n_cycles, return_itc=False, average=True)
fig_tfr = power.plot([0])

# Ensure the save directory exists
save_dir = '/kaggle/working/mat_visuals/'
os.makedirs(save_dir, exist_ok=True)  # Create directory if it doesn't exist

# Save processed data
all_epochs.save(os.path.join(save_dir, 'processed-epochs.fif'), overwrite=True)
evoked.save(os.path.join(save_dir, 'evoked-ave.fif'), overwrite=True)

# Save figures if needed
fig_psd.savefig(os.path.join(save_dir, 'psd_plot.png'))
fig_topo.savefig(os.path.join(save_dir, 'topomap_plot.png'))
fig_tfr.savefig(os.path.join(save_dir, 'tfr_plot.png'))

This is the error I'm getting: [Runtime-ERROR] /tmp/ipykernel 34/2693702433.py:35: FutureWarning: The value of amplitude='auto' will be removed in MNE 1.8.0, and the new default will be amplitude alse. fig psd all epochs.plot psd(fmin=1.8, fmax=40.6, average=True, spatial colors=False) RuntimeError Traceback (most recent call last) Cell In[1]. Line 38 35 fig psd all epochs.plot psd(fmin-1.0, fmax 40.0, average True, spatial colors=False) 37 Plot topographic maps 38 fig topo evoked. plot topomap(times-10.1, 0.2, 6.31, ch type='eeg, average-0.05) 40 Compute and plot TFR 41 from mne.time_frequency import tfr morlet

I tried changing these two lines of code:

# Plot PSD
fig_psd = all_epochs.plot_psd(fmin=1.0, fmax=40.0, average=False, spatial_colors=False)

# Plot topographic maps
fig_topo = evoked.plot_topomap(times=False, ch_type='eeg', average=0.05)

I also tried reading these 2 documentation below: neurotechedu , mne-python
But I'm still can't get any solution.

Upvotes: 0

Views: 83

Answers (0)

Related Questions