griddata: QH6214 qhull input error: not enough points(2) to construct initial simplex
griddata: QH6214 qhull input error: not enough points(2) to construct initial simplex
我正在尝试创建相对稀疏的 EEG 数据(27 个电极)的头顶视图热图。我将 EEG 电极的 x,y 笛卡尔坐标转换为极坐标,并尝试将它们映射为极坐标。每个 x,y 坐标对应于一个给定值(如果您想知道:Hurst 指数),我希望该位置周围的颜色与之对应。
我从 this page 的工作代码开始,并尝试使其适应我的问题。不幸的是,我的改编不起作用。
这是我的代码:
from __future__ import division, print_function, absolute_import
from pylab import *
import numpy as np
from scipy.interpolate import griddata
# Setting the paremeters that define the circle
max_r = 1
max_theta = 2.0 * np.pi
###Cartesian coordinates of the 27 electrodes
###x axis goes from back of head to nose, with nose being the positive direction
###y axis goes from ear to ear, with toward right ear (from perspective of self) being the negative direction
# X coordinates
X = [0.95, 0.95, 0.673, 0.673, 0.000000000000000044, 0.000000000000000044,
-0.673, -0.673, -0.95, -0.95, 0.587, 0.587, 0.0000000000000000612, 0.0000000000000000612,
-0.587, -0.587, 0.719, 0.00000000000000000000000000000000375, -0.719,
0.375, 0.375, 0.999, -0.999, -0.375, -0.375, -0.9139, -0.9139,.5,.6,.7,.8]
# Y coordinates
Y = [0.309, -0.309, 0.545, -0.545, 0.719, -0.719, 0.545, -0.545,
0.309, -0.309, 0.809, -0.809, 0.999, -0.999, 0.809, -0.809, 0, -0.0000000000000000612,
-0.0000000000000000881, 0.375, -0.375, 0, -0.000000000000000122, 0.375, -0.375, 0.2063, -0.2063,.5,.6,.7,.8]
# Convert cartesian coordinates to polar
def convert_to_polar(x, y):
theta = np.arctan2(y, x)
r = np.sqrt(x ** 2 + y ** 2)
return theta, r
# Arrays that house the theta and radii from converted cartesian coordinates.
Thetas = []
Rs = []
# Converting cartesian coordinates to polar, for each electrode
for i in range(0, 31):
theta, r = convert_to_polar(X[i], Y[i])
Thetas.append(theta)
Rs.append(r)
# Making a two column list that contains the converted thetas and radii, so the appropriate shape is attained.
points = [Thetas,Rs]
values = [[.51,.71,.81,.91,.72,.87,.90,.67,.78,.89,.56,.45,.68,.96,.69,.63,.37,.85,.92,.70,.74,.97,.35,.76,.68,.46,.68,90,91,92,93],
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,30,78,56,90]]
# now we create a grid of values, interpolated from our random sample above
theta = np.linspace(0.0, max_theta, 100)
r = np.linspace(0, max_r, 200)
grid_r, grid_theta = np.meshgrid(r, theta)
data = griddata(points, values, (grid_r, grid_theta),fill_value=0)
# Create a polar projection
ax1 = plt.subplot(projection="polar")
ax1.pcolormesh(theta, r, data.T)
plt.show()
我收到一个错误:
Traceback (most recent call last):
File "/Users/mac/NIH/EEG/Python/Testing heat map", line 50, in <module>
data = griddata(points, values, (grid_r, grid_theta),fill_value=0)
File "/Users/mac/anaconda/lib/python2.7/site-packages/scipy/interpolate/ndgriddata.py", line 217, in griddata rescale=rescale)
File "scipy/interpolate/interpnd.pyx", line 246, in scipy.interpolate.interpnd.LinearNDInterpolator.__init__
(scipy/interpolate/interpnd.c:4980)
File "scipy/spatial/qhull.pyx", line 1747, in scipy.spatial.qhull.Delaunay.__init__
(scipy/spatial/qhull.c:15918)
File "scipy/spatial/qhull.pyx", line 415, in scipy.spatial.qhull._Qhull.__init__
(scipy/spatial/qhull.c:5108) scipy.spatial.qhull.**QhullError: QH6214 qhull input error: not enough points(2) to construct initial simplex (need 33)**
While executing: | qhull d Qbb Qt Q12 Qx Qz Qc Options selected for
Qhull 2015.2.r 2016/01/18: run-id 1980533833 delaunay Qbbound-last
Qtriangulate Q12-no-wide-dup Qxact-merge Qz-infinity-point
Qcoplanar-keep _zero-centrum Qinterior-keep
Q3-no-merge-vertices-dim-high
粗体部分是我想理解的。当我添加更多点时(即,当我将更多点添加到列表 X 和 Y 中成为极坐标时),错误声称需要的点数不断增加,总是比我输入的点数提前两步。
有谁知道如何处理这个问题吗?
griddata
的第一个参数必须具有形状 (n, D)
,其中 n
是点的数量,D
是这些点的维度。您传入了 points = [Thetas,Rs]
,其中 Thetas
和 Rs
是长度为 31 的列表。当该输入被转换为二维数组时,它将具有 (2, 31)
的形状。所以griddata
认为你只传入了两个31维的点。
要解决此问题,您可以使用 numpy.column_stack
创建 points
,使其成为形状为 (31, 2)
的数组,例如:
points = np.column_stack((Thetas, Rs))
我正在尝试创建相对稀疏的 EEG 数据(27 个电极)的头顶视图热图。我将 EEG 电极的 x,y 笛卡尔坐标转换为极坐标,并尝试将它们映射为极坐标。每个 x,y 坐标对应于一个给定值(如果您想知道:Hurst 指数),我希望该位置周围的颜色与之对应。
我从 this page 的工作代码开始,并尝试使其适应我的问题。不幸的是,我的改编不起作用。
这是我的代码:
from __future__ import division, print_function, absolute_import
from pylab import *
import numpy as np
from scipy.interpolate import griddata
# Setting the paremeters that define the circle
max_r = 1
max_theta = 2.0 * np.pi
###Cartesian coordinates of the 27 electrodes
###x axis goes from back of head to nose, with nose being the positive direction
###y axis goes from ear to ear, with toward right ear (from perspective of self) being the negative direction
# X coordinates
X = [0.95, 0.95, 0.673, 0.673, 0.000000000000000044, 0.000000000000000044,
-0.673, -0.673, -0.95, -0.95, 0.587, 0.587, 0.0000000000000000612, 0.0000000000000000612,
-0.587, -0.587, 0.719, 0.00000000000000000000000000000000375, -0.719,
0.375, 0.375, 0.999, -0.999, -0.375, -0.375, -0.9139, -0.9139,.5,.6,.7,.8]
# Y coordinates
Y = [0.309, -0.309, 0.545, -0.545, 0.719, -0.719, 0.545, -0.545,
0.309, -0.309, 0.809, -0.809, 0.999, -0.999, 0.809, -0.809, 0, -0.0000000000000000612,
-0.0000000000000000881, 0.375, -0.375, 0, -0.000000000000000122, 0.375, -0.375, 0.2063, -0.2063,.5,.6,.7,.8]
# Convert cartesian coordinates to polar
def convert_to_polar(x, y):
theta = np.arctan2(y, x)
r = np.sqrt(x ** 2 + y ** 2)
return theta, r
# Arrays that house the theta and radii from converted cartesian coordinates.
Thetas = []
Rs = []
# Converting cartesian coordinates to polar, for each electrode
for i in range(0, 31):
theta, r = convert_to_polar(X[i], Y[i])
Thetas.append(theta)
Rs.append(r)
# Making a two column list that contains the converted thetas and radii, so the appropriate shape is attained.
points = [Thetas,Rs]
values = [[.51,.71,.81,.91,.72,.87,.90,.67,.78,.89,.56,.45,.68,.96,.69,.63,.37,.85,.92,.70,.74,.97,.35,.76,.68,.46,.68,90,91,92,93],
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,30,78,56,90]]
# now we create a grid of values, interpolated from our random sample above
theta = np.linspace(0.0, max_theta, 100)
r = np.linspace(0, max_r, 200)
grid_r, grid_theta = np.meshgrid(r, theta)
data = griddata(points, values, (grid_r, grid_theta),fill_value=0)
# Create a polar projection
ax1 = plt.subplot(projection="polar")
ax1.pcolormesh(theta, r, data.T)
plt.show()
我收到一个错误:
Traceback (most recent call last):
File "/Users/mac/NIH/EEG/Python/Testing heat map", line 50, in <module>
data = griddata(points, values, (grid_r, grid_theta),fill_value=0)
File "/Users/mac/anaconda/lib/python2.7/site-packages/scipy/interpolate/ndgriddata.py", line 217, in griddata rescale=rescale)
File "scipy/interpolate/interpnd.pyx", line 246, in scipy.interpolate.interpnd.LinearNDInterpolator.__init__
(scipy/interpolate/interpnd.c:4980)
File "scipy/spatial/qhull.pyx", line 1747, in scipy.spatial.qhull.Delaunay.__init__
(scipy/spatial/qhull.c:15918)
File "scipy/spatial/qhull.pyx", line 415, in scipy.spatial.qhull._Qhull.__init__
(scipy/spatial/qhull.c:5108) scipy.spatial.qhull.**QhullError: QH6214 qhull input error: not enough points(2) to construct initial simplex (need 33)**
While executing: | qhull d Qbb Qt Q12 Qx Qz Qc Options selected for
Qhull 2015.2.r 2016/01/18: run-id 1980533833 delaunay Qbbound-last
Qtriangulate Q12-no-wide-dup Qxact-merge Qz-infinity-point
Qcoplanar-keep _zero-centrum Qinterior-keep
Q3-no-merge-vertices-dim-high
粗体部分是我想理解的。当我添加更多点时(即,当我将更多点添加到列表 X 和 Y 中成为极坐标时),错误声称需要的点数不断增加,总是比我输入的点数提前两步。
有谁知道如何处理这个问题吗?
griddata
的第一个参数必须具有形状 (n, D)
,其中 n
是点的数量,D
是这些点的维度。您传入了 points = [Thetas,Rs]
,其中 Thetas
和 Rs
是长度为 31 的列表。当该输入被转换为二维数组时,它将具有 (2, 31)
的形状。所以griddata
认为你只传入了两个31维的点。
要解决此问题,您可以使用 numpy.column_stack
创建 points
,使其成为形状为 (31, 2)
的数组,例如:
points = np.column_stack((Thetas, Rs))