2

I have a 1d array (voltage of EEG) for 26 EEG channels, I also have the 3d coordinates of the EEG channels.

x = np.array([  84.06,   83.74,   41.69,   51.87,   57.01,   51.84,    
    41.16, 21.02,   24.63,   21.16,  -16.52,  -13.25,  -11.28,    
   -12.8 , -16.65,  -48.48,  -48.77,  -48.35,  -75.17,  -80.11,     
   -82.23, -80.13,  -75.17, -114.52, -117.79, -114.68])                                                                                                                           

y = np.array([-26.81,  29.41, -66.99, -48.05,   0.9 ,  50.38,      
    68.71, -58.83, 0.57,  60.29, -83.36, -65.57,   0.23,  66.5 ,   
   -65.51, -0.42,  65.03, -71.46, -55.07,  -0.87,  53.51,  71.1 , 
   -28.98, -1.41,  26.89])

z = np.array([-10.56, -10.04, -15.96,  39.87,  66.36,  41.33, -15.31, 
    54.82, 87.63,  55.58, -12.65,  64.98,  99.81,  65.11, -11.79,     
    68.57, 98.37,  68.57,  -3.7 ,  59.44,  82.43,  59.4 ,  -3.69,      
    9.67, 15.84, 9.45])

data = [  884007.64101968,   997175.31684776,   853520.29922077,
    1146032.72839618,  1280654.00515894,  1136783.42927035,
     781802.02852187,  1165581.44354253,  1474539.74412991,
    1074018.46853295,   578909.21492644,  1067652.55432892,
    1508963.49572301,  1012764.69535714,   533385.60827991,
    1058268.82537597,  1392128.01175867,  1043996.55697014,
     675548.3896822 ,  1022400.8910867 ,  1360502.28709052,
    1108773.44991746,   780841.92929488,   986799.48807626,
     947189.96382125,   994734.32179115])

Now I would like to project the 1d array (data) onto a 3d interpolated surface, based on the channel-locations (x,y and z).

My problem is that I don't know how to shape the 1d vector into a 3d array reflecting both the positions and the values of the points, and then interpolate them to make a more interpretable plot. Also, I could also use some help in plotting it.

I am using > python 3, for plotting I mostly use matplotlib.

2d interpolation works (to eventually make a 2d topoplot) using scipy.interpolate.griddata.

N=300
xy_center = [np.min(x)+((np.max(x)-np.min(x))/2),np.min(y)+((np.max(y)-    
np.min(y))/2)]   # center of the plot
radius = ((np.max(x)-np.min(x))/2)        # radius

z = data

xi = numpy.linspace(np.min(x), np.max(x), N)
yi = numpy.linspace(np.min(y), np.max(y), N)
zi = scipy.interpolate.griddata((x, y), z, (xi[None,:], yi[:,None]),     
method='cubic')

Trying to do a similar 3d interpolation the data.shape and the coordinates don't add up.

d = data

xi = numpy.linspace(np.min(x), np.max(x), N)
yi = numpy.linspace(np.min(y), np.max(y), N)
zi = numpy.linspace(np.min(z), np.max(z), N)

int = scipy.interpolate.griddata((x, y, z), z, (xi[None,:],     
      yi[:,None],zi[:, None]), method='cubic')

I am aware that choosing the min/max values on the axis here is also not the correct thing to do, but I am not sure what else to do.

I did figure out how to make a 3d scatterplot of the x,y,z coordinates of the channels.

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ax.scatter(x, y, z)
plt.show()

I am sorry about not being very precise, but I am completely in the dark....

Hannekevd
  • 46
  • 3
  • You do not have to reshape the 1D data, they belong to an extra dimension (time). To plot with a 3D model you either have to reduce the 3D to a 2D model and use the 3rd dimension for your EEG sensors or you have to reduce the EEG sensor data (e.g. the mean value etc.). Alternatively, you could also create a movie. – norok2 Jul 01 '19 at 12:58
  • I think the problem with your 3D approach is that you are interpolating `data` values in a cube whereas you want to interpolate them on a curved surface that is given by the shape of the skull. So you want to first define a surface, for example using Delaunay triangulation in `scipy.spatial`, and then interpolate on that. `CloughTocher2DInterpolator` in `scipy.interpolate` might fit the bill (but I have never used it). Personally, however, I would first check if somebody else hasn't solved this problem already. For stuff like this, [visbrain](http://visbrain.org/index.html) comes to mind. – Paul Brodersen Jul 02 '19 at 09:45

0 Answers0