# Erp plot\_topomap NaN to integer error

**URL:** <https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317>\
**Category:** Support & Discussions\
**Tags:** eeg, visualization\
**Created:** [June 25, 2021, 12:58pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317 "2021-06-25T12:58:48Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![andraderenew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/andraderenew/32/606_2.png) [@andraderenew](https://mne.discourse.group/u/andraderenew)\
**Post date:** [June 25, 2021, 12:58pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/1 "2021-06-25T12:58:48Z")

</div>

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.

```python
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.

```python
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

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [June 28, 2021, 4:50pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/2 "2021-06-28T16:50:47Z")

</div>

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`).

---

<div class="post-metadata">

**Author:** ![andraderenew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/andraderenew/32/606_2.png) [@andraderenew](https://mne.discourse.group/u/andraderenew)\
**Post date:** [June 28, 2021, 7:06pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/3 "2021-06-28T19:06:57Z")

</div>

ten\_five=mne.channels.make\_standard\_montage(‘standard\_1005’)

this is my variable “ten\_five”.

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [June 28, 2021, 7:47pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/4 "2021-06-28T19:47:16Z")

</div>

> [@drammock](#):
>
> Hard to debug any further than that without the data file

can you provide a link to the data too?

---

<div class="post-metadata">

**Author:** ![andraderenew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/andraderenew/32/606_2.png) [@andraderenew](https://mne.discourse.group/u/andraderenew)\
**Post date:** [June 28, 2021, 8:31pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/5 "2021-06-28T20:31:32Z")

</div>

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

[https://www.dropbox.com/t/acogq0a1KppNhGsL](https://www.dropbox.com/l/AABzZrKRNcYbG7Z9m0OexH8WeBVSXRunqMc)

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [June 28, 2021, 9:06pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/6 "2021-06-28T21:06:16Z")

</div>

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:

> <https://github.com/mne-tools/mne-python/issues/9511>
>
> from the forum: https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-er…ror/3317
> 
> extrapolate = 'box' or 'local' both work, but the default ('head') fails (at some point in the code we call \`np.arcsin\` and its argument is out of the domain for that function, thus introducing a NaN)
> 
> \`\`\`py
> import numpy as np
> import mne
> 
> exp3 = mne.io.read\_raw\_edf('exp3.edf', preload=True)
> exp3.filter(1,30, method='iir')
> events\_exp3 = mne.make\_fixed\_length\_events(exp3, duration=1.0)
> 
> ten\_five = mne.channels.make\_standard\_montage('standard\_1005')
> exp3.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 = rest\_exp3.plot\_topomap()
> \`\`\`
> Traceback:
> \`\`\`
> \---------------------------------------------------------------------------
> ValueError Traceback (most recent call last)
> \<ipython-input-4-7729af823da6\> in \<module\>
> \----\> 1 fig = rest\_exp3.plot\_topomap()
> 
> /opt/mne/python/mne/evoked.py in plot\_topomap(self, times, ch\_type, vmin, vmax, cmap, sensors, colorbar, scalings, units, res, size, cbar\_fmt, time\_unit, time\_format, proj, show, show\_names, title, mask, mask\_params, outlines, contours, image\_interp, average, axes, extrapolate, sphere, border, nrows, ncols)
> 443 axes=None, extrapolate=\_EXTRAPOLATE\_DEFAULT, sphere=None,
> 444 border=\_BORDER\_DEFAULT, nrows=1, ncols='auto'):
> \--\> 445 return plot\_evoked\_topomap(
> 446 self, times=times, ch\_type=ch\_type, vmin=vmin,
> 447 vmax=vmax, cmap=cmap, sensors=sensors, colorbar=colorbar,
> 
> /opt/mne/python/mne/viz/topomap.py in plot\_evoked\_topomap(\*\*\*failed resolving arguments\*\*\*)
> 1714 adjust\_for\_cbar = colorbar and ncols is not None and idx \>= ncols - 1
> 1715 ax\_idx = idx + 1 if adjust\_for\_cbar else idx
> \-\> 1716 tp, cn, interp = \_plot\_topomap(
> 1717 data\[:, idx\], pos, axes=axes\[ax\_idx\],
> 1718 mask=mask\_\[:, idx\] if mask is not None else None, \*\*kwargs)
> 
> /opt/mne/python/mne/viz/topomap.py in \_plot\_topomap(data, pos, vmin, vmax, cmap, sensors, res, axes, names, show\_names, mask, mask\_params, outlines, contours, image\_interp, show, onselect, extrapolate, sphere, border, ch\_type, cnorm)
> 950 
> 951 # find mask limits
> \--\> 952 extent, Xi, Yi, interp = \_setup\_interp(
> 953 pos, res, extrapolate, sphere, outlines, border)
> 954 interp.set\_values(data)
> 
> /opt/mne/python/mne/viz/topomap.py in \_setup\_interp(pos, res, extrapolate, sphere, outlines, border)
> 837 yi = np.linspace(ymin, ymax, res)
> 838 Xi, Yi = np.meshgrid(xi, yi)
> \--\> 839 interp = \_GridData(pos, extrapolate, clip\_origin, clip\_radius, border)
> 840 extent = (xmin, xmax, ymin, ymax)
> 841 return extent, Xi, Yi, interp
> 
> /opt/mne/python/mne/viz/topomap.py in \_\_init\_\_(self, pos, extrapolate, origin, radii, border)
> 607 
> 608 # Adding points outside the extremes helps the interpolators
> \--\> 609 outer\_pts, mask\_pts, tri = \_get\_extra\_points(
> 610 pos, extrapolate, origin, radii)
> 611 self.n\_extra = outer\_pts.shape\[0\]
> 
> /opt/mne/python/mne/viz/topomap.py in \_get\_extra\_points(pos, extrapolate, origin, radii)
> 576 # return points on the head circle
> 577 angle = np.arcsin(distance / np.mean(radii))
> \--\> 578 n\_pnts = max(12, int(np.round(2 \* np.pi / angle)))
> 579 points\_l = np.linspace(0, 2 \* np.pi, n\_pnts, endpoint=False)
> 580 use\_radii = radii \* 1.1 + distance
> 
> ValueError: cannot convert float NaN to integer
> \> /opt/mne/python/mne/viz/topomap.py(578)\_get\_extra\_points()
> 576 # return points on the head circle
> 577 angle = np.arcsin(distance / np.mean(radii))
> \--\> 578 n\_pnts = max(12, int(np.round(2 \* np.pi / angle)))
> 579 points\_l = np.linspace(0, 2 \* np.pi, n\_pnts, endpoint=False)
> 580 use\_radii = radii \* 1.1 + distance
> \`\`\`
> cc @mmagnuski

---

<div class="post-metadata">

**Author:** ![andraderenew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/andraderenew/32/606_2.png) [@andraderenew](https://mne.discourse.group/u/andraderenew)\
**Post date:** [June 28, 2021, 9:17pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/7 "2021-06-28T21:17:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andraderenew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/andraderenew/32/606_2.png) [@andraderenew](https://mne.discourse.group/u/andraderenew)\
**Post date:** [June 28, 2021, 9:25pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/8 "2021-06-28T21:25:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [June 28, 2021, 9:44pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/9 "2021-06-28T21:44:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andraderenew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/andraderenew/32/606_2.png) [@andraderenew](https://mne.discourse.group/u/andraderenew)\
**Post date:** [July 3, 2021, 9:30pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/10 "2021-07-03T21:30:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [July 5, 2021, 9:59am UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/11 "2021-07-05T09:59:03Z")

</div>

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

Alex

---

<div class="post-metadata">

**Author:** ![andraderenew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/andraderenew/32/606_2.png) [@andraderenew](https://mne.discourse.group/u/andraderenew)\
**Post date:** [July 5, 2021, 1:27pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/12 "2021-07-05T13:27:54Z")

</div>

> **[René Andrade Rey sent you 2 items](https://www.dropbox.com/t/2liywsODETsQIM9q)**
>
> 50\_decoding.py + 1 more item

I hope this helps!!

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [July 5, 2021, 2:15pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/13 "2021-07-05T14:15:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [July 5, 2021, 2:19pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/14 "2021-07-05T14:19:59Z")

</div>

issue to follow up:

[https://github.com/mne-tools/mne-python/issues/9526](https://github.com/mne-tools/mne-python/issues/9526)

Alex

---

<div class="post-metadata">

**Author:** ![andraderenew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/andraderenew/32/606_2.png) [@andraderenew](https://mne.discourse.group/u/andraderenew)\
**Post date:** [July 6, 2021, 8:17pm UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/15 "2021-07-06T20:17:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bradmacer](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@bradmacer](https://mne.discourse.group/u/bradmacer)\
**Post date:** [November 14, 2022, 4:48am UTC](https://mne.discourse.group/t/erp-plot-topomap-nan-to-integer-error/3317/16 "2022-11-14T04:48:20Z")

</div>

> [@andraderenew](#):
>
> ValueError: cannot convert float NaN to integer

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:

```python
float('nan') == float('nan')      
False

```

The “ValueError: cannot convert [float NaN to integer](http://net-informations.com/ds/err/nan.htm)” 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.
