When I perform Epoch, Valueerror will appear: Some of the values to be plotted are NaN.

  • MNE version: e.g. 0.24.0
  • operating system: e.g. Windows 10

My code such as:
events = mne.events_from_annotations(raw_recons)
print(events)
event_dict = {‘pain’: events[1][‘Stimulus/S 14’], ‘noPain’: events[1][‘Stimulus/S 24’]}
reject_criteria = dict(eeg=100e-6) # 100 µV
epochs = mne.Epochs(raw_recons, events[0], event_id=event_dict, preload=True,
tmax=1, tmin=-0.2, reject=reject_criteria)
########################################
pain_epochs = epochs[‘pain’]
noPain_epochs = epochs[‘noPain’]
pain_evoked = pain_epochs.average()
noPain_evoked = noPain_epochs.average()
pain_evoked.plot()
noPain_evoked.plot()
Error:

evoked object is empty (based on less than 1 epoch)

Please help me answer it

Hello,

For starters, could you copy/paste the full traceback instead of screenshots of the last part of the traceback?
Could you also print the content of events?

Mathieu

1 Like

The full process is here:



D:\ProgramData\Anaconda\lib\site-packages\numpy\core\fromnumeric.py:3372: RuntimeWarning: Mean of empty slice.
return _methods._mean(a, axis=axis, dtype=dtype,
D:\ProgramData\Anaconda\lib\site-packages\numpy\core_methods.py:162: RuntimeWarning: invalid value encountered in true_divide
ret = um.true_divide(
:85: RuntimeWarning: evoked object is empty (based on less than 1 epoch)
pain_evoked = pain_epochs.average()
:86: RuntimeWarning: evoked object is empty (based on less than 1 epoch)
noPain_evoked = noPain_epochs.average()

ValueError Traceback (most recent call last)
in
11 raw_list.append(file_path)
12 for file_path in raw_list:
—> 13 Preprocesing(file_path)

in Preprocesing(file_path)
85 pain_evoked = pain_epochs.average()
86 noPain_evoked = noPain_epochs.average()
—> 87 pain_evoked.plot()
88 noPain_evoked.plot()
89 plt.show(block=False)

D:\ProgramData\Anaconda\lib\site-packages\mne\evoked.py in plot(self, picks, exclude, unit, show, ylim, xlim, proj, hline, units, scalings, titles, axes, gfp, window_title, spatial_colors, zorder, selectable, noise_cov, time_unit, sphere, verbose)
387 spatial_colors=False, zorder=‘unsorted’, selectable=True,
388 noise_cov=None, time_unit=‘s’, sphere=None, verbose=None):
→ 389 return plot_evoked(
390 self, picks=picks, exclude=exclude, unit=unit, show=show,
391 ylim=ylim, proj=proj, xlim=xlim, hline=hline, units=units,

in plot_evoked(evoked, picks, exclude, unit, show, ylim, xlim, proj, hline, units, scalings, titles, axes, gfp, window_title, spatial_colors, zorder, selectable, noise_cov, time_unit, sphere, verbose)

D:\ProgramData\Anaconda\lib\site-packages\mne\viz\evoked.py in plot_evoked(evoked, picks, exclude, unit, show, ylim, xlim, proj, hline, units, scalings, titles, axes, gfp, window_title, spatial_colors, zorder, selectable, noise_cov, time_unit, sphere, verbose)
764 mne.viz.plot_evoked_white
765 “”"
→ 766 return _plot_evoked(
767 evoked=evoked, picks=picks, exclude=exclude, unit=unit, show=show,
768 ylim=ylim, proj=proj, xlim=xlim, hline=hline, units=units,

D:\ProgramData\Anaconda\lib\site-packages\mne\viz\evoked.py in _plot_evoked(evoked, picks, exclude, unit, show, ylim, proj, xlim, hline, units, scalings, titles, axes, plot_type, cmap, gfp, window_title, spatial_colors, selectable, zorder, noise_cov, colorbar, mask, mask_style, mask_cmap, mask_alpha, time_unit, show_names, group_by, sphere)
345
346 if plot_type == ‘butterfly’:
→ 347 _plot_lines(evoked.data, info, picks, fig, axes, spatial_colors, unit,
348 units, scalings, hline, gfp, types, zorder, xlim, ylim,
349 times, bad_ch_idx, titles, ch_types_used, selectable,

D:\ProgramData\Anaconda\lib\site-packages\mne\viz\evoked.py in _plot_lines(data, info, picks, fig, axes, spatial_colors, unit, units, scalings, hline, gfp, types, zorder, xlim, ylim, times, bad_ch_idx, titles, ch_types_used, selectable, psd, line_alpha, nave, time_unit, sphere)
436 # Set amplitude scaling
437 D = this_scaling * data[idx, :]
→ 438 _check_if_nan(D)
439 gfp_only = gfp == ‘only’
440 if not gfp_only:

D:\ProgramData\Anaconda\lib\site-packages\mne\utils\check.py in _check_if_nan(data, msg)
450 “”“Raise if any of the values are NaN.”“”
451 if not np.isfinite(data).all():
→ 452 raise ValueError(“Some of the values {} are NaN.”.format(msg))
453
454

ValueError: Some of the values to be plotted are NaN.

The strange thing is that the first data can complete the run, the second can not pass

Just looking at the code, I suspect @mscheltienne is right that there is something off about the events. Note that
events_from_annotations returns a tuple of a numpy array and a dictionary, so something like

events, event_dict = mne.events_from_annotations(raw_recons)

will probably be more useful than assigning both the array and the dictionary to the same variable, and then needing to use [0] and [1] all the time to access them.

I can’t offer much more help without seeing what the content of the event array is.

Is it true?

So it looks like you do have several events for your 2 conditions. Maybe the data scaling is off and all the epochs are dropped by the 100 uV rejection criterium. Can you paste the logging output from epochs = mne.Epochs?

Also you can show the result of epochs after it’s been created. That will tell you how many epochs there are in each condition. Maybe all the epochs in the noPain condition got rejected/dropped?

I think there’s something wrong with my standard of rejection, which is usually what
events = mne.events_from_annotations(raw_recons)
print(events)
event_dict = {‘pain’: events[1][‘Stimulus/S 14’], ‘noPain’: events[1][‘Stimulus/S 24’]}
reject_criteria = dict(eeg=100e-6) # 100 µV
epochs = mne.Epochs(raw_recons, events[0], event_id=event_dict, preload=True,
tmax=1, tmin=-0.2, reject=reject_criteria)

Yes, as you can see on your last screenshot:

Rejecting epoch based on EEG : [...]

I suspect all your epochs have been rejected because the peak to peak signal on those electrodes exceeds 100 uV. Maybe the signal is badly scaled: MNE expects Volts; or maybe those channels are bad and are not reflecting brain activity but noise with higher amplitude.
In any case, you have to look at those channels individually and understand why they exceed the peak-to-peak threshold.

2 Likes

I don’t quite understand how to look at those channels
“you have to look at those channels individually and understand why they exceed the peak-to-peak threshold”

For instance, raw_recons.plot(picks=["FP1", "AF7", "FP2", "AF8"]). How do those channels look like?
And if you plot all channels together, with raw_recons.plot(), how do their amplitude compare to the other channels?

You can also retrieve the underlying data array for those channels to look at the exact peak-to-peak ampltitudes: data = raw_recons.get_data(picks=["FP1", "AF7", "FP2", "AF8"]).

2 Likes