Skip to content

All NaNs in raw.plot_psd() #11413

@cbrnr

Description

@cbrnr

Description of the problem

I have a (large) EEG file, which works fine when I compute and plot its PSD with raw.plot_psd(). However, I then manually mark some segments as bad, perform ICA, remove some ICs, and back-project. Using this data, I cannot compute the PSD anymore:

ValueError                                Traceback (most recent call last)
Cell In[3], line 1
----> 1 raw.plot_psd()

File <decorator-gen-213>:5, in plot_psd(self, fmin, fmax, tmin, tmax, picks, proj, reject_by_annotation, method, average, dB, estimate, xscale, area_mode, area_alpha, color, line_alpha, spatial_colors, sphere, exclude, ax, show, n_jobs, verbose, **method_kw)

File <decorator-gen-212>:12, in plot_psd(self, fmin, fmax, tmin, tmax, picks, proj, reject_by_annotation, method, average, dB, estimate, xscale, area_mode, area_alpha, color, line_alpha, spatial_colors, sphere, exclude, ax, show, n_jobs, verbose, **method_kw)

File ~/Projects/mne-python/mne/time_frequency/spectrum.py:114, in SpectrumMixin.plot_psd(self, fmin, fmax, tmin, tmax, picks, proj, reject_by_annotation, method, average, dB, estimate, xscale, area_mode, area_alpha, color, line_alpha, spatial_colors, sphere, exclude, ax, show, n_jobs, verbose, **method_kw)
    111 ci = 'sd' if area_mode == 'std' else area_mode
    112 # ↓ here picks="all" because we've already restricted the `info` to
    113 # ↓ have only `picks` channels
--> 114 fig = spectrum.plot(
    115     picks='all', average=average, dB=dB, amplitude=amplitude,
    116     xscale=xscale, ci=ci, ci_alpha=area_alpha, color=color,
    117     alpha=line_alpha, spatial_colors=spatial_colors, sphere=sphere,
    118     exclude=exclude, axes=ax, show=show)
    119 return fig

File ~/Projects/mne-python/mne/time_frequency/spectrum.py:611, in BaseSpectrum.plot(self, picks, average, dB, amplitude, xscale, ci, ci_alpha, color, alpha, spatial_colors, sphere, exclude, axes, show)
    609 xlabels_list = [False] * (len(axes) - 1) + [True]
    610 # plot
--> 611 _plot_psd(self, fig, self.freqs, psd_list, picks_list, titles_list,
    612           units_list, scalings_list, axes, make_label, color,
    613           area_mode=ci, area_alpha=ci_alpha, dB=dB, estimate=estimate,
    614           average=average, spatial_colors=spatial_colors,
    615           xscale=xscale, line_alpha=alpha,
    616           sphere=sphere, xlabels_list=xlabels_list)
    617 fig.subplots_adjust(hspace=0.3)
    618 plt_show(show, fig)

File ~/Projects/mne-python/mne/viz/utils.py:2277, in _plot_psd(inst, fig, freqs, psd_list, picks_list, titles_list, units_list, scalings_list, ax_list, make_label, color, area_mode, area_alpha, dB, estimate, average, spatial_colors, xscale, line_alpha, sphere, xlabels_list)
   2275     if not spatial_colors:
   2276         spatial_colors = color
-> 2277     _plot_lines(psd_array, info, picks, fig, ax_list, spatial_colors,
   2278                 unit, units=units, scalings=None, hline=None, gfp=False,
   2279                 types=types, zorder='std', xlim=(freqs[0], freqs[-1]),
   2280                 ylim=None, times=freqs, bad_ch_idx=[], titles=titles,
   2281                 ch_types_used=ch_types_used, selectable=True, psd=True,
   2282                 line_alpha=line_alpha, nave=None, time_unit='ms',
   2283                 sphere=sphere, highlight=None)
   2285 for ii, (ax, xlabel) in enumerate(zip(ax_list, xlabels_list)):
   2286     ax.grid(True, linestyle=':')

File ~/Projects/mne-python/mne/viz/evoked.py:462, 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, highlight)
    459 if len(idx) > 0:
    460     # Set amplitude scaling
    461     D = this_scaling * data[idx, :]
--> 462     _check_if_nan(D)
    463     gfp_only = gfp == 'only'
    464     if not gfp_only:

File ~/Projects/mne-python/mne/utils/check.py:571, in _check_if_nan(data, msg)
    569 """Raise if any of the values are NaN."""
    570 if not np.isfinite(data).all():
--> 571     raise ValueError("Some of the values {} are NaN.".format(msg))

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

Steps to reproduce

import mne

raw = mne.io.read_raw_fif("test.fif.gz")
raw.plot_psd()

Link to data

Unfortunately, the problematic file is ~240MB. It is available here:

https://drive.google.com/file/d/1q2B5KsS-TKFlBlULBUqswCeNMdn71a-a/view?usp=sharing

Expected results

Plotting the PSD works.

Actual results

Plotting the PSD throws an error.

Additional information

Note that setting reject_by_annotation=False works, but I would like to compute the PSD from good segments only (and therefore use the default reject_by_annotation=True).

This is on main:

Details
Platform:         macOS-11.7.1-x86_64-i386-64bit
Python:           3.10.9 (main, Dec 15 2022, 18:20:40) [Clang 13.0.0 (clang-1300.0.29.30)]
Executable:       /Users/clemens/.local/pipx/venvs/ipython/bin/python
CPU:              i386: 8 cores
Memory:           Unavailable (requires "psutil" package)
mne:              1.4.dev0
numpy:            1.24.1 {unknown linalg bindings (threadpoolctl module not found: No module named 'threadpoolctl')}
scipy:            1.10.0
matplotlib:       3.6.2 {backend=MacOSX}

sklearn:          Not found
numba:            Not found
nibabel:          Not found
nilearn:          Not found
dipy:             Not found
openmeeg:         Not found
cupy:             Not found
pandas:           1.5.2
pyvista:          Not found
pyvistaqt:        Not found
ipyvtklink:       Not found
vtk:              Not found
qtpy:             Not found
ipympl:           Not found
pyqtgraph:        Not found
pooch:            v1.6.0

mne_bids:         Not found
mne_nirs:         Not found
mne_features:     Not found
mne_qt_browser:   Not found
mne_connectivity: Not found
mne_icalabel:     Not found

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions