-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumpy2vtk.py
More file actions
26 lines (24 loc) · 736 Bytes
/
Copy pathnumpy2vtk.py
File metadata and controls
26 lines (24 loc) · 736 Bytes
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
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 12 15:55:50 2018
@author: zhe ren
"""
def numpy2vtk(a,filename,dx=1.0,dy=1.0,dz=1.0,x0=0.0,y0=0.0,z0=0.0):
# http://www.vtk.org/pdf/file-formats.pdf
f=open(filename,'w')
nx,ny,nz=a.shape
f.write("# vtk DataFile Version 2.0\n")
f.write("Test data\n")
f.write("ASCII\n")
f.write("DATASET STRUCTURED_POINTS\n")
f.write("DIMENSIONS %u %u %u\n"%(nz,ny,nx))
f.write("SPACING %f %f %f\n"%(dx,dy,dz))
f.write("ORIGIN %f %f %f\n"%(x0,y0,z0))
f.write("POINT_DATA %u\n"%len(a.flat))
f.write("SCALARS volume_scalars float 1\n")
f.write("LOOKUP_TABLE default\n")
for i in a.flat:
f.write("%f "%i)
f.close()
print 'function was called'
return ()