I am attempting to ica 30-second epochs of data. My datasets are about 8 hours long, and I only have six channels, so an ica of the entire recording is useless.
When I ica.apply()
with exclude=[]
and verifying ica.exclude
==[]
, the eeg data is still radically altered.
This may be similar to this post, which apparently was due to a bad composition. This happens on different epochs within my data.
I read an eeg file and apply an average reference.
Drop a couple of channels so that 6 remain.
Epoch, resample, high-pass filter >1Hz
ann_eeg = mne.io.read_raw(annotated_eeg_filename, preload=True)
ann_eeg = fix_channels(
ann_eeg,
[
# "F7",
# "F8",
"F3",
"F4",
"C3",
"C4",
"O1",
"O2",
# "EOG ROC-A2",
# "EOG LOC-A2",
# "EMG CHIN",
],
)
events, _ = mne.events_from_annotations(
ann_eeg,
event_id=MIXEDCASE_CLASSES_TO_IDS,
chunk_duration=EPOCH_LENGTH,
verbose="INFO",
)
epoched_eeg = mne.Epochs(
raw=ann_eeg,
events=events,
tmin=0,
tmax=EPOCH_LENGTH - 1.0 / FS,
baseline=None,
preload=True,
)
epoched_eeg.resample(FS)
epoched_eeg.filter(l_freq=1,h_freq=None)
ica=ICA(
n_components=6,
max_iter='auto', method='infomax',random_state=42,fit_params=dict(extended=True))
begin_time=1470 #780
end_time=begin_time+30
for epoch_num in range(begin_time//30,end_time//30):
eeg_cropped=epoched_eeg[epoch_num].copy().crop(tmin=0,tmax=30-1/FS)
eeg_cropped.plot(scalings=dict(eeg=20e-5))
ica.fit(eeg_cropped)
ica.plot_sources(eeg_cropped)
reconst=eeg_cropped.copy()
reconst.plot(scalings=dict(eeg=20e-5))
reconst=ica.apply(reconst,exclude=[]) #exclude_idx)
channel_data=reconst.get_data()
pred_freq=find_predominant_frequency(channel_data)
print(f"{epoch_num*30:<5}-{epoch_num*30+30:<5}: {pred_freq:6.3f}")
reconst.plot(scalings=dict(eeg=20e-5))
Excerpts from the respective plot() commands: