我曾经问过自己同样的问题。
我认为这可能会有所帮助。
TVB的TimeSeries.h5是一个带有2个数据集的hdf5文件:
- 数据(EEG跟踪)
- 时间
我们需要数据数据集(如果需要,也可以两个一起使用)。
import mne
import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import welch
import h5py
with h5py.File('TVB_EEG.h5', 'r') as f:
data = np.array(f['data'])
data = np.reshape(data, (data.shape[0], -1)).T
使用这些代码,我们将把TVB EEG数据转换为数组。
现在,我们需要创建信息和其他必要的内容,以完成转换为mne数据集(通道、采样频率等):
ch_names = ['Ch' + str(i + 1) for i in range(data.shape[0])]
ch_types = ['eeg' for i in range(data.shape[0])]
sfreq = 1 / (data.shape[1] / 1000)
info = mne.create_info(ch_names=ch_names, ch_types=ch_types, sfreq=sfreq)
raw = mne.io.RawArray(data, info)
print(raw.info)
print('Duration:', raw.times[-1], 'seconds')
输出:
Creating RawArray with float64 data, n_channels=63, n_times=10000
Range : 0 ... 9999 = 0.000 ... 99990.000 secs
Ready.
<Info | 7 non-empty values
bads: []
ch_names: Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7, Ch8, Ch9, Ch10, Ch11, Ch12, ...
chs: 63 EEG
custom_ref_applied: False
highpass: 0.0 Hz
lowpass: 0.1 Hz
meas_date: unspecified
nchan: 63
projs: []
sfreq: 0.1 Hz
>
Duration: 99990.0 seconds
现在您可以在mne上处理TVB EEG文件:
示例:
fig, ax = plt.subplots(figsize=[20, 5])
start_time = 0
end_time = 99990
ax.plot(raw.get_data(picks=2, tmin=start_time, tmax=end_time).T)
plt.show()
raw.plot_psd(fmin= 0, fmax=0.045)
plt.show()