Created
June 13, 2019 13:05
-
-
Save gdlmx/13cf4b4cb7ccb25c3f0aa18fecb6e4d6 to your computer and use it in GitHub Desktop.
Preprocessing scripts for MICRESS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import re, sys | |
def reindex_micress_vtk(vtkfilename): | |
pLUT = re.compile('\s*LOOKUP_TABLE\s+', flags=re.I) | |
headers=[] | |
with open(vtkfilename) as f: | |
for l in f: | |
headers.append(l.strip()) | |
if pLUT.match(l): | |
break | |
A= np.loadtxt(vtkfilename, skiprows=len(headers)) | |
a=set() | |
for i in A.reshape([A.size,]): | |
a.add(i) | |
a=sorted(list(a)) | |
B = np.zeros(A.shape) | |
for i in range(len(a)): | |
B[A==a[i]]=i+1 | |
B = B.astype('int') | |
assert np.all(B>0) | |
return B, headers | |
if __name__ == "__main__": | |
vtkfname = sys.argv[1] | |
Tab, Hdrs = reindex_micress_vtk(vtkfname) | |
np.savetxt('out_'+vtkfname, Tab, header='\n'.join(Hdrs) , fmt='%d', comments='') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment