New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OverFlowError when calling : SourceEstimate.plot(...)
#12606
Comments
Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴 |
SourceEstimate.plot(...)
Thanks for the report. It appears it's happening because the maximum value of your data is zero (which may indicate a mistake somewhere in your script; is data with no positive values plausible for you?) The error is happening here: mne-python/mne/viz/_brain/_brain.py Lines 4153 to 4171 in 1c5b39f
@wmvanvliet you wrote this code in your UI event system work (#11891), any chance you have time to take a look? |
Ah, the np.log10() call needs protection to prevent no.log10(0) of course. My bad :) PR incoming |
Description of the problem
Hello,
I'm trying to use the SourceEstimation.plot to get the 3D brain graph with the red activated areas.
When calling SourceEstimation.plot, i'm facing an Python Exception: `OverflowError: cannot convert float infinity to integer``
I'm sure the problem is from the SourceEstimate.data. Beacause after adding 1e-14 to all elements of this array, the exception is lo longer here.
My SourceEstimate.data matrix is a float64, it does not contains any INF or NAN :
Output :
I then supposed that this error was caused by the presence of "0" in the data.
So I tried with a matrix that contains multiple lines with 0, things goes well.
So I suppose this as an issue. Let me know if I'm doing something wrong.
Best
Steps to reproduce
Link to data
Matrix_data_cause_stc_plot_error.mat.zip
Expected results
Actual results
OverflowError Traceback (most recent call last)
Cell In[17], line 37
34 stc_recreate = mne.SourceEstimate(data=data_recreate, vertices=vertices_recreate, tmin=tmin_recreate, tstep=tstep_recreate, subject=subject_recreate)
36 initial_time = 0.1
---> 37 brain = stc_recreate.plot(
38 subjects_dir=subjects_dir,
39 initial_time=initial_time,
40 smoothing_steps=7,
41 hemi='both',
42 )
File c:\Users\Ilian\Documents\dev\best-python.venv\lib\site-packages\mne\source_estimate.py:793, in _BaseSourceEstimate.plot(self, subject, surface, hemi, colormap, time_label, smoothing_steps, transparent, alpha, time_viewer, subjects_dir, figure, views, colorbar, clim, cortex, size, background, foreground, initial_time, time_unit, backend, spacing, title, show_traces, src, volume_options, view_layout, add_data_kwargs, brain_kwargs, verbose)
759 @copy_function_doc_to_method_doc(plot_source_estimates)
760 def plot(
761 self,
(...)
791 verbose=None,
792 ):
--> 793 brain = plot_source_estimates(
794 self,
795 subject,
796 surface=surface,
797 hemi=hemi,
798 colormap=colormap,
799 time_label=time_label,
800 smoothing_steps=smoothing_steps,
801 transparent=transparent,
802 alpha=alpha,
803 time_viewer=time_viewer,
804 subjects_dir=subjects_dir,
805 figure=figure,
806 views=views,
807 colorbar=colorbar,
808 clim=clim,
809 cortex=cortex,
810 size=size,
811 background=background,
812 foreground=foreground,
813 initial_time=initial_time,
814 time_unit=time_unit,
815 backend=backend,
816 spacing=spacing,
817 title=title,
818 show_traces=show_traces,
819 src=src,
820 volume_options=volume_options,
821 view_layout=view_layout,
822 add_data_kwargs=add_data_kwargs,
823 brain_kwargs=brain_kwargs,
824 verbose=verbose,
825 )
826 return brain
File :12, in plot_source_estimates(stc, subject, surface, hemi, colormap, time_label, smoothing_steps, transparent, alpha, time_viewer, subjects_dir, figure, views, colorbar, clim, cortex, size, background, foreground, initial_time, time_unit, backend, spacing, title, show_traces, src, volume_options, view_layout, add_data_kwargs, brain_kwargs, verbose)
File c:\Users\Ilian\Documents\dev\best-python.venv\lib\site-packages\mne\viz_3d.py:2427, in plot_source_estimates(stc, subject, surface, hemi, colormap, time_label, smoothing_steps, transparent, alpha, time_viewer, subjects_dir, figure, views, colorbar, clim, cortex, size, background, foreground, initial_time, time_unit, backend, spacing, title, show_traces, src, volume_options, view_layout, add_data_kwargs, brain_kwargs, verbose)
2425 else:
2426 with use_3d_backend(backend):
-> 2427 return _plot_stc(
2428 stc,
2429 overlay_alpha=alpha,
2430 brain_alpha=alpha,
2431 vector_alpha=alpha,
2432 cortex=cortex,
2433 foreground=foreground,
2434 size=size,
2435 scale_factor=None,
2436 show_traces=show_traces,
2437 src=src,
2438 volume_options=volume_options,
2439 view_layout=view_layout,
2440 add_data_kwargs=add_data_kwargs,
2441 brain_kwargs=brain_kwargs,
2442 **kwargs,
2443 )
File c:\Users\Ilian\Documents\dev\best-python.venv\lib\site-packages\mne\viz_3d.py:2597, in _plot_stc(stc, subject, surface, hemi, colormap, time_label, smoothing_steps, subjects_dir, views, clim, figure, initial_time, time_unit, background, time_viewer, colorbar, transparent, brain_alpha, overlay_alpha, vector_alpha, cortex, foreground, size, scale_factor, show_traces, src, volume_options, view_layout, add_data_kwargs, brain_kwargs)
2594 del kwargs
2596 if time_viewer:
-> 2597 brain.setup_time_viewer(time_viewer=time_viewer, show_traces=show_traces)
2598 else:
2599 brain.show()
File c:\Users\Ilian\Documents\dev\best-python.venv\lib\site-packages\mne\viz_brain_brain.py:601, in Brain.setup_time_viewer(failed resolving arguments)
599 self._configure_shortcuts()
600 self._configure_picking()
--> 601 self._configure_dock()
602 self._configure_tool_bar()
603 self._configure_menu()
File c:\Users\Ilian\Documents\dev\best-python.venv\lib\site-packages\mne\viz_brain_brain.py:1027, in Brain._configure_dock(self)
1025 self._configure_dock_playback_widget(name="Playback")
1026 self._configure_dock_orientation_widget(name="Orientation")
-> 1027 self._configure_dock_colormap_widget(name="Color Limits")
1028 self._configure_dock_trace_widget(name="Trace")
1030 # Smoothing widget
File c:\Users\Ilian\Documents\dev\best-python.venv\lib\site-packages\mne\viz_brain_brain.py:867, in Brain._configure_dock_colormap_widget(self, name)
866 def _configure_dock_colormap_widget(self, name):
--> 867 fmin, fmax, fscale, fscale_power = _get_range(self)
868 rng = [fmin * fscale, fmax * fscale]
869 self._data["fscale"] = fscale
File c:\Users\Ilian\Documents\dev\best-python.venv\lib\site-packages\mne\viz_brain_brain.py:4181, in _get_range(brain)
4179 fscale_power = 0
4180 else:
-> 4181 fscale_power = int(np.log10(fmax))
4182 if fscale_power < 0:
4183 fscale_power -= 1
OverflowError: cannot convert float infinity to integer
Additional information
Platform Windows-10-10.0.22621-SP0
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
Executable c:\Users\Ilian\Documents\dev\best-python.venv\Scripts\python.exe
CPU Intel64 Family 6 Model 165 Stepping 2, GenuineIntel (8 cores)
Memory 31.8 GB
Core
├☑ mne 1.7.0 (latest release)
├☑ numpy 1.26.4 (OpenBLAS 0.3.23.dev with 8 threads)
├☑ scipy 1.13.0
└☑ matplotlib 3.8.4 (backend=module://matplotlib_inline.backend_inline)
Numerical (optional)
├☑ sklearn 1.4.2
├☑ nibabel 5.2.1
├☑ nilearn 0.10.4
├☑ pandas 2.2.2
└☐ unavailable numba, dipy, openmeeg, cupy, h5io, h5py
Visualization (optional)
├☑ pyvista 0.43.5 (OpenGL 4.5.0 NVIDIA 552.12 via NVIDIA GeForce GTX 1650 Ti/PCIe/SSE2)
├☑ pyvistaqt 0.11.0
├☑ vtk 9.3.0
├☑ qtpy 2.4.1 (PyQt6=6.6.1)
└☐ unavailable ipympl, pyqtgraph, mne-qt-browser, ipywidgets, trame_client, trame_server, trame_vtk, trame_vuetify
Ecosystem (optional)
└☐ unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline, neo, eeglabio, edfio, mffpy, pybv
The text was updated successfully, but these errors were encountered: