Erp plot_topomap NaN to integer error

Dear MNE experts:

I have one issue while computing an ERP topomap. I have tried plot_projs_topomap as well but always the same error. I thought it was an issue of the projections as 0 projections items are activated. I’m not sure.

Not setting metadata
Not setting metadata
307 matching events found
Setting baseline interval to [-0.30078125, 0.0] sec
Applying baseline correction (mode: mean)
0 projection items activated
Loading data for 307 events and 257 original time points ...
1 bad epochs dropped
/Users/andraderenew/opt/anaconda3/envs/mne/lib/python3.8/site-packages/mne/viz/topomap.py:570: RuntimeWarning: invalid value encountered in arcsin
angle = np.arcsin(distance / np.mean(radii))
Traceback (most recent call last):
File "/Users/andraderenew/Dropbox/Aplicaciones/Mind_Monitor/others/postprocessing/erp_mne.py", line 57, in <module>
fig = rest_exp3.plot_topomap(times, average=0.05)
File "/Users/andraderenew/opt/anaconda3/envs/mne/lib/python3.8/site-packages/mne/evoked.py", line 346, in plot_topomap
return plot_evoked_topomap(
File "/Users/andraderenew/opt/anaconda3/envs/mne/lib/python3.8/site-packages/mne/viz/topomap.py", line 1666, in plot_evoked_topomap
tp, cn, interp = _plot_topomap(
File "/Users/andraderenew/opt/anaconda3/envs/mne/lib/python3.8/site-packages/mne/viz/topomap.py", line 903, in _plot_topomap
extent, Xi, Yi, interp = _setup_interp(
File "/Users/andraderenew/opt/anaconda3/envs/mne/lib/python3.8/site-packages/mne/viz/topomap.py", line 791, in _setup_interp
interp = _GridData(pos, extrapolate, clip_origin, clip_radius, border)
File "/Users/andraderenew/opt/anaconda3/envs/mne/lib/python3.8/site-packages/mne/viz/topomap.py", line 602, in __init__
outer_pts, mask_pts, tri = _get_extra_points(
File "/Users/andraderenew/opt/anaconda3/envs/mne/lib/python3.8/site-packages/mne/viz/topomap.py", line 571, in _get_extra_points
n_pnts = max(12, int(np.round(2 * np.pi / angle)))
ValueError: cannot convert float NaN to integer

I use this code below.

exp3=mne.io.read_raw_edf('/Users/andraderenew/Dropbox/Aplicaciones/Mind_Monitor/others/postprocessing/exp3.edf', preload=True)

exp3.filter(1,30, method='iir')

events_exp3=mne.make_fixed_length_events(exp3, duration=1.0)

exp3=exp3.copy().set_montage(ten_five)

epochs_exp3 = mne.Epochs(exp3, events_exp3, event_id={'resting_state':1}, tmin=-0.3, tmax=0.7, preload=True)

rest_exp3=epochs_exp3['resting_state'].average()

fig_exp3=rest_exp3.plot(spatial_colors=True)

rest_exp3.plot(gfp=True, spatial_colors=True, ylim=dict(eeg=[-12, 12]))

times = np.linspace(0.05, 0.15, 5)

fig = rest_exp3.plot_topomap(times, average=0.05)

Thanks for all the help win advance!!

Best,

Rene Andrade

something is probably wrong with your montage, as it looks like you’re ending up with NaN angles (so either distance is NaN or radii is zero probably). Hard to debug any further than that without the data file and the code that generates your montage variable (ten_five).

ten_five=mne.channels.make_standard_montage(‘standard_1005’)

this is my variable “ten_five”.

can you provide a link to the data too?

sorry I didn’t know how to send the data file

https://www.dropbox.com/t/acogq0a1KppNhGsL

Thanks for sending the data. This appears to be a bug (or at least bug-ish) in MNE-Python arising from the fact that you have only 4 electrodes. A quick-and-dirty solution to at least let you see your plots is to pass extrapolate='local' or extrapolate='box' to the plot_topomap() method. I opened a bug report:

oh thank you very much!! I have checked and it works!!!

I have added to the previous code this lines

p10_minus_exp3 = mne.combine_evoked([rest_post10, rest_exp3], weights=[1, -1])
p10_minus_exp3.plot_joint()

so I get this error message

No projector specified for this dataset. Please consider the method self.add_proj.
/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py:570: RuntimeWarning: invalid value encountered in arcsin
angle = np.arcsin(distance / np.mean(radii))
Traceback (most recent call last):
File “/Users/andraderenew/Dropbox/Aplicaciones/Mind_Monitor/others/postprocessing/erp_mne.py”, line 76, in
p10_minus_exp3.plot_joint()
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/evoked.py”, line 377, in plot_joint
return plot_evoked_joint(self, times=times, title=title, picks=picks,
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/evoked.py”, line 1457, in plot_evoked_joint
evoked.plot_topomap(times=times_sec, axes=map_ax, show=False,
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/evoked.py”, line 346, in plot_topomap
return plot_evoked_topomap(
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py”, line 1666, in plot_evoked_topomap
tp, cn, interp = _plot_topomap(
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py”, line 903, in _plot_topomap
extent, Xi, Yi, interp = _setup_interp(
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py”, line 791, in _setup_interp
interp = _GridData(pos, extrapolate, clip_origin, clip_radius, border)
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py”, line 602, in init
outer_pts, mask_pts, tri = _get_extra_points(
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py”, line 571, in _get_extra_points
n_pnts = max(12, int(np.round(2 * np.pi / angle)))
ValueError: cannot convert float NaN to integer

I don’t know if it is related that’s why I post in this thread. Thanks for such a quick answer by the way

That is exactly the same error as before, because plot_joint calls plot_topomap to create its inset topomaps. Use the topomap_args parameter to change the extrapolate strategy.

thank you so much one more time!! I again have the similar issue in another topic MVPA. When plotting

csp.fit(X, y)

csp.plot_patterns(epochs.info)

csp.plot_filters(epochs.info, scalings=1e-9)

there seems to be an error when uisng topo_

/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py:570: RuntimeWarning: invalid value encountered in arcsin
angle = np.arcsin(distance / np.mean(radii))
Traceback (most recent call last):
File “/Users/andraderenew/Dropbox/Aplicaciones/Mind_Monitor/experiments/cathode vermis/50_decoding.py”, line 254, in
csp.plot_patterns(epochs.info)
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/decoding/csp.py”, line 353, in plot_patterns
return patterns.plot_topomap(
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/evoked.py”, line 346, in plot_topomap
return plot_evoked_topomap(
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py”, line 1666, in plot_evoked_topomap
tp, cn, interp = _plot_topomap(
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py”, line 903, in _plot_topomap
extent, Xi, Yi, interp = _setup_interp(
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py”, line 791, in _setup_interp
interp = _GridData(pos, extrapolate, clip_origin, clip_radius, border)
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py”, line 602, in init
outer_pts, mask_pts, tri = _get_extra_points(
File “/Users/andraderenew/opt/anaconda3/lib/python3.8/site-packages/mne/viz/topomap.py”, line 571, in _get_extra_points
n_pnts = max(12, int(np.round(2 * np.pi / angle)))
ValueError: cannot convert float NaN to integer

How do I pass the parameter here? I guess is with set_params but I’m not clear on how to.

can you share a folder with me so I can replicate?

Alex

I hope this helps!!

try with this:

joint_kwargs = dict(ts_args=dict(time_unit=“s”), topomap_args=dict(time_unit=“s”, sphere=0.136))

for some reason with only four electrodes the topomap code crashes with default sphere size.

I’ll open an issue.

Alex

issue to follow up:

https://github.com/mne-tools/mne-python/issues/9526

Alex

thanks for everything. I don’t know how to use joint_kwargs with CSP. I think that is further down the code. Also I tried to run the code but when doing temporal generalization I couldn’t get the plots. Python quits so there are no errors. Just that the previous plots gets unable to close and the rest won’t get plotted.

You can avoid this with a mask method. Note first that in python NaN is defined as the number which is not equal to itself:

float('nan') == float('nan')      
False

The “ValueError: cannot convert float NaN to integer” raised because of Pandas doesn’t have the ability to store NaN values for integers. From Pandas v0.24, introduces Nullable Integer Data Types which allows integers to coexist with NaNs. This does allow integer NaNs . This is the pandas integer, instead of the numpy integer. So, use Nullable Integer Data Types (e.g. Int64).

df['x'].astype('Int64')

NB: You have to go through numpy float first and then to nullable Int32, for some reason.

1 Like