-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimestep_posi.py
executable file
·72 lines (55 loc) · 2.6 KB
/
timestep_posi.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'''
Created on Jan 29, 2015
@author: wange
This file is taking a exactly position particle information from a sort of timestepemittance.tbl file
to use this code. Run phase scan code first and got the timestep from parmela followed by various phase.
This code will generate a jitter.dat file
Copy phase vs phase jitter of three jitter.dat files into a spreadsheet file which including str, phase, amp. Jitter study could base on these data.
In jit_phase mode TIMESTEPEMITTANCE???.TBL--->TIMESTEPEMITTANCE??????.TBL
'''
import os
import fnmatch
path="C:\\cygwin64\\home\\wange\\UED\\1.5eleb\\par\\final\\sta\\fullrange\\str"
os.chdir(path)
if os.path.isfile('jitter.dat'):
os.remove('jitter.dat')
target=100.0000
print os.listdir(path)
for root, dirs, files in os.walk(path):
timestep=[elem for elem in files if fnmatch.fnmatch(elem,'TIMESTEPEMITTANCE???.TBL')]
print timestep
step=int(filter(str.isdigit,timestep[1]))-int(filter(str.isdigit,timestep[0]))
lengthts=len(timestep)
starts=int(filter(str.isdigit,timestep[0]))
print step, lengthts,starts
for name in timestep:
testfile=open(name,'r')
lines=testfile.readlines()
testfile.close()
steps=len(lines)-85
print name, ' ',len(lines)
jitterfile=open('jitter.dat','a')
for i in range(86,len(lines)+1):
lines[i]=lines[i].split()
#print i,' ', lines[i]
if float(lines[i][1])-target==0:
print str(filter(str.isdigit,name)),lines[i]
newline=map(float,lines[i])
newline=map("{:.10f}".format,newline) #newline=map(lambda x:"{:.10f}".format(float(x)),newline) or newline=["{:.10f}".format(float(i)) for i in lines]
# newline=map(str,newline)
jitterfile.write(str(filter(str.isdigit,name))+' '+' '.join(newline)+'\n')
#jitterfile.close()
break
elif float(lines[i-1][1])-target<0 and float(lines[i][1])-target>0:
#jitterfile=open('jitter.dat','w')
liness=map(float,lines[i-1])
linesl=map(float,lines[i])
#print liness, '\n',linesl
newline=[]
for n in range(20):
newline.append(str("{:.10f}".format(((target-liness[1])/(linesl[1]-liness[1]))*(linesl[n]-liness[n])+liness[n])))
n+=1
jitterfile.write(str(filter(str.isdigit,name))+' '+' '.join(newline)+'\n')
break
i+=1
jitterfile.close()