How to calculate DWT using MNE ?

Hi,
Kindly , i have a dataset which is for a specific disease ( EEG). I read the data ( raw) using MNE. I trying to calculate the DWT to extract the delta, alpha , …etc from EEG file, but could not do that !!

import os
import numpy as np
import mne
import pywt

data_folder = ‘/Users/HT/Desktop/EEGData1’
data_raw_file = os.path.join(data_folder, “sub-001”,“eeg”,“sub-001_task-eyesclosed_eeg.set”)
raw = mne.io.read_raw_eeglab(data_raw_file)
print(raw)
print(raw.info)
raw.compute_psd(fmax=50).plot(picks=“data”, exclude=“bads”, amplitude=False)
raw.plot(duration=5, n_channels=30)
print(pywt.families(short=False))
(data, coeff_d) = pywt.dwt(raw, ‘db1’)
coeffs = wavedec(raw, ‘db1’, level=2)

ERROR is
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (19, 2) + inhomogeneous part.

please could you help
Best

Hello, I don’t have a solution for your problem, but:

the filenames indicate that you’re dealing with BIDS data here. You should use MNE-BIDS to read the data, not mne.io.read_raw_eeglab().

Best wishes,
Richard

The RAW dataset is from EEGLab
.set format
https://openneuro.org/datasets/ds004504/versions/1.0.7

Yes. But in a BIDS dataset. You should use MNE-BIDS to read it.

I tried the code below for my dataset.

  1. changed the accession number
  2. sub-001/*task-run1 will read the first file , sub-001 ???
  3. Path(‘/tmp/ds004504’)
    the path temp is by MNE ! or should change it !!!

from pathlib import Path
import openneuro
import mne_bids

bids_root = Path(‘C:/User/High_Tech/Desktop/EEGML/EEGBIDS’)

%%

openneuro.download(
dataset=‘ds004504’,
target_dir=bids_root,
include=[‘sub-001’]
)

%%

bids_path = mne_bids.BIDSPath(
subject=‘001’,
task=‘run1’,
suffix=‘eeg’,
extension=‘.set’,
datatype=‘eeg’,
root=bids_root
)
raw = mne_bids.read_raw_bids(bids_path=bids_path)

C:\User\Desktop\EEGML\EEGBIDS\sub-001\eeg\sub-001_task-run1_eeg.set
Did you mean one of:
sub-001_task-eyesclosed_eeg.set
sub-001_task-eyesclosed_eeg.json
instead of:
sub-001_task-run1_eeg.set

Skipping README: already downloaded.: 100%|##########| 4.07k/4.07k [00:00<?, ?B/s]
Skipping participants.tsv: already downloaded.: 100%|##########| 1.67k/1.67k [00:00<?, ?B/s]
Skipping participants.json: already downloaded.: 100%|##########| 613/613 [00:00<?, ?B/s]
Skipping CHANGES: already downloaded.: 100%|##########| 409/409 [00:00<?, ?B/s]
Skipping dataset_description.json: already downloaded.: 100%|##########| 2.17k/2.17k [00:00<?, ?B/s]
Skipping sub-001_task-eyesclosed_eeg.json: already downloaded.: 100%|##########| 868/868 [00:00<?, ?B/s]
Skipping sub-001_task-eyesclosed_channels.tsv: already downloaded.: 100%|##########| 284/284 [00:00<?, ?B/s]
Skipping sub-001_task-eyesclosed_eeg.set: already downloaded.: 100%|##########| 22.9M/22.9M [00:00<?, ?B/s]

This path leads nowhere… you probably simply want something like include=['sub-001'].

I changed( updated ) the code.
but still get error !!! it is not reading .set extension file ?
openneuro.download(
…)
will download the dataset or i must download the dataset manually ???