def plotHead(chanNames=('F3','F4','C3','C4','P3','P4','O1','O2'),
radius=0.01, fillColor='black', lineColor='black',
drawLabels=True, clip=True, fontSize=12, ax=None, **kwargs):
# plot head outline and save result dict
result = plotHeadOutline(ax)
ax = result['ax']
# get chanNames that we have a location for
chanNames = [chanName for chanName in chanNames if chanName.lower() in chanLocs3d.keys()]
chanNamesLower = [chanName.lower() for chanName in chanNames] # lower case
# if no valid chanNames then just draw the outline
if len(chanNames) == 0:
return result
# get 3d cartesian coordinates for each channel
xyz = np.asarray([chanLocs3d[chanName] for chanName in chanNamesLower])
# make sure coordinates have unit magnitude
xyz = xyz / np.sqrt(np.sum(xyz**2, axis=1))[:,None]
# rotate by pi/2 around z axis
cos90 = np.cos(np.pi/2.0)
rot = np.asarray(((cos90,-1.0,0.0),(1.0,cos90,0.0),(0.0,0.0,1.0))).T
xyz = xyz.dot(rot)
# stereographic projection
x = xyz[:,0]
y = xyz[:,1]
z = xyz[:,2]
xy = np.vstack((x/(1.0+z), y/(1.0+z))).T
# list of circles and chan labels to store in result
circles = []
chanLabels = []
# for each channel
for chanName, coord in zip(chanNames, xy):
x, y = coord
c = pltPatches.Circle((x,y), radius, edgecolor=lineColor,
facecolor=fillColor, linewidth=1, fill=True, zorder=100)
ax.add_patch(c)
circles.append(c)
# draw channel labels
if drawLabels:
if fontSize is not None:
txt = ax.text(x,y+0.081, chanName, size=fontSize,
horizontalalignment='center', verticalalignment='center', zorder=100)
chanLabels.append(txt)
# save labels and circles in result
result['chanLabels'] = chanLabels
result['circles'] = circles
return result
评论列表
文章目录