I create my data through apply_inverse(), from mne python, I want to write my data into a vtk file with a time series, however I can only get a static vtk file, don’t know where does wrong. Thanks for your help!
Here is my code:
stc_suf = apply_inverse(evoked, inv, lambda2, inv_method)
data=stc_suf.data
# Assuming you have already generated your data and visualized it
# using stc_suf.plot() and mlab.show()
# Define the output filename
filename = 'output_lh.vtk'
filename2 = 'output_rh.vtk'
polydata = vtk.vtkPolyData()
points = vtk.vtkPoints()
# Get the vertices and faces from the stc_suf object
vertices1, faces1 = read_surface('./test/surf/lh.pial')
vertices2, faces2 = read_surface('./test/surf/rh.pial')
for vertex in vertices1:
points.InsertNextPoint(vertex)
polydata.SetPoints(points)
triangles = vtk.vtkCellArray()
for face in faces1:
triangle = vtk.vtkTriangle()
triangle.GetPointIds().SetId(0, face[0])
triangle.GetPointIds().SetId(1, face[1])
triangle.GetPointIds().SetId(2, face[2])
triangles.InsertNextCell(triangle)
polydata.SetPolys(triangles)
scalars = vtk.vtkFloatArray()
scalars.SetNumberOfComponents(data.shape[1])
scalars.SetName('TimeSeriesData')
for i in range(data.shape[1]):
for j in range(data.shape[0]):
scalars.InsertNextValue(data[j, i])
polydata.GetPointData().SetScalars(scalars)
writer = vtk.vtkPolyDataWriter()
writer.SetFileName(filename)
writer.SetFileTypeToASCII()
writer.SetInputData(polydata)
writer.Write()