Newer
Older
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
from filePath import *
from interpolate import *
import cmd #cmd in small letters is the name of the module. do cmd.Cmd.any_function() to run a function from the class from the module
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import glob
# from plotRaman import *
import os
import numpy as np
from material import *
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
import re
import pyperclip3
def lineOrMap(fp):
with open(fp) as file:
lines=file.readlines()
if(lines[0][0]!="ï"):
print(fp," has been detected to be a map type file")
return 0
else:
print(fp," has been detected to be a line type file")
return 1
def polyParsAndCorrect():
print("\nThe Polytec Parse And Correct routine expects all files to either be raw line or map files from the polytec")
a=input("\nAre you sure all .txt files in the directory are from the polytec ? (y/n): ")
if(a.lower()=='y'):
print("\nStarting file parsing")
files=glob.glob("*.txt")
f_list=fileExtensionRemover(glob.glob("*.txt"))
newpath=os.getcwd()+"\clean_polytec"+"\\"
path_line=newpath+"\line\\"
if not os.path.exists(path_line):
os.makedirs(path_line)
path_map=newpath+"\map\\"
if not os.path.exists(path_map):
os.makedirs(path_map)
for i,fp in enumerate(files):
if(lineOrMap(fp)==1):
flag=0
with open(fp) as file:
x=[]
z=[]
for line in file:
try:
if(isinstance(int(line[6]),int)):
values=line.replace(' ','0').split('\t')
x.append(float(values[0].replace(',','.')))
z.append(float(values[1].replace(',','.')))
except:
flag=1
if(flag):
print("currently running on: ",fp)
with open (path_line+f_list[i]+"_line_data_cleaned.txt",'w') as new_file:
for k in range(len(x)):
new_file.write(str(x[k])+" "+str(z[k])+"\n")
# print("Cleaned line data saved to: ",path_line)
else:
print("currently running on: ",fp)
with open(fp) as file:
lines=file.readlines()
x=[]
y=[]
z=[]
for j in range(len(lines)):
values=lines[j].split()
x.append(float(values[0].replace(',','.')))
y.append(float(values[1].replace(',','.')))
z.append(float(values[2].replace(',','.')))
with open (path_map+f_list[i]+"_map_data_cleaned.txt",'w') as new_file:
for k in range(len(x)):
new_file.write(str(x[k])+" "+str(y[k])+" "+str(z[k])+"\n")
# print("Cleaned map data saved to: ",path_map)
print('\n---------------------------------------------------------------\n')
pyperclip3.copy("path "+newpath)
print("\nOperation successful! Created path and path command copied to clipboard. Paste to move DesCar to the created directory\n")
elif(a.lower()=='n'):
print("\nPlease remove non polytec files before proceeding. Exiting ...")
else:
print("\nCommand not recognised. Exiting ...")
def deflection():
print("\n!!Attention: The deflection routine will take the pressure information into the name of the polytec line measurement. File name should not contain numbers except the pressure info. For instance 0.5kpa, 0.5_kpa, my_measure_0.5kpa will all work but 20231127_0.5Kpa or 0.5Kpa(1) will not !!\n")
newpath=os.getcwd()+"\deflection_data"+"\\"
if not os.path.exists(newpath):
os.makedirs(newpath)
files=glob.glob("*.txt")
x_peak=[]
y_peak=[]
for i,fp in enumerate(files):
print("currently running on: ",files[i])
x_peak.append(float(re.findall(r'\d+',files[i])[0])) #re.findall allows to find letters in a string
with open(fp) as file:
x = []
y = []
for line in file:
values = line.split()
# x.append(float(values[0]))
y.append(float(values[1]))
y_peak.append(y[np.argmax(y)])
sort=np.argsort(x_peak)
x=[]
y=[]
for k in range(len(sort)):
x.append(x_peak[sort[k]])
y.append(y_peak[sort[k]])
with open (newpath+"deflection_data.txt",'w') as file:
for j in range(len(x)):
file.write(str(x[j])+" "+str(y[j])+"\n")
print('\n---------------------------------------------------------------\n')
pyperclip3.copy("path "+newpath)
print("\nOperation successful! Created path and path command copied to clipboard. Paste to move DesCar to the created directory\n")
def dCycle():
newpath=os.getcwd()+"\looped_data\\"
if not os.path.exists(newpath):
os.makedirs(newpath)
print("\n!!Attention: files should be named up1, down1, up2, ... for this routine to work!! Automating checking starting ...\n")
flag=0
try:
files=glob.glob("*.txt")
flag=0
for i in range(len(files)):
if((files[i][:2]=="up")):
if(isinstance(int(files[i][2]),int) and len(files[i])==7):
print(files[i]," detected. Format ok")
else:
print(files[i]," detected. !!Wrong format!! Starting auto correction attempt ... ")
os.rename(os.getcwd()+"\\"+str(files[i]),os.getcwd()+"\\"+str(files[i][:3]+".txt"))
elif(files[i][:4]=="down"):
if(isinstance(int(files[i][4]),int) and len(files[i])==9):
print(files[i]," detected. Format ok")
else:
print(files[i]," detected. !!Wrong format!! Starting auto correction attempt ... ")
os.rename(os.getcwd()+"\\"+str(files[i]),os.getcwd()+"\\"+str(files[i][:5]+".txt"))
except:
print("\nError in data interpretation loop. Exiting...")
flag=1
if(flag==0):
try:
shift_x=0
shift_y=0
with open("up1.txt") as file:
print("Working on up1")
x_temp=[]
y_temp=[]
for line in file:
values = line.split()
x_temp.append(float(values[0]))
y_temp.append(float(values[1]))
sort=np.argsort(x_temp)
x=[]
y=[]
for k in range(len(sort)):
x.append(x_temp[sort[k]])
y.append(y_temp[sort[k]])
# shift_x=x[-1]
shift_y=y[-1]
with open (newpath+"up1.txt",'w') as new_file:
for k in range(len(x)):
new_file.write(str(x[k])+" "+str(y[k])+"\n")
counter=1
for i in range(len(files)):
if(i==0):
print("Skipping up1 (already done)")
elif(i%2==0 and i!=0):
with open("up"+str(counter)+".txt") as file:
print("Working on: \"up"+str(counter)+".txt\".")
# print("Working on: \"up"+str(counter)+".txt\". (i="+str(i)+" and Counter="+str(counter)+")")
x_temp=[]
y_temp=[]
for line in file:
values = line.split()
x_temp.append(float(values[0]))
y_temp.append(float(values[1]))
sort=np.argsort(x_temp)
x=[]
y=[]
for k in range(len(sort)):
x.append(x_temp[sort[k]])
y.append(y_temp[sort[k]])
# shift_x=shift_x-x[0]
shift_y=shift_y-y[0]
for j in range(len(x)):
# x[j]=x[j]+shift_x
y[j]=y[j]+shift_y
# shift_x=x[-1]
shift_y=y[-1]
with open (newpath+"up"+str(counter)+".txt",'w') as new_file:
for k in range(len(x)):
new_file.write(str(x[k])+" "+str(y[k])+"\n")
elif(i%2==1):
with open("down"+str(counter)+".txt") as file:
print("Working on: \"down"+str(counter)+".txt\".")
# print("Working on: \"down"+str(counter)+".txt\". (i="+str(i)+" and Counter="+str(counter)+")")
x_temp=[]
y_temp=[]
for line in file:
values = line.split()
x_temp.append(float(values[0]))
y_temp.append(float(values[1]))
sort=np.argsort(x_temp)
x=[]
y=[]
for k in range(len(sort)):
x.append(x_temp[sort[k]])
y.append(y_temp[sort[k]])
# shift_x=shift_x-x[-1]
shift_y=shift_y-y[-1]
for j in range(len(x)):
# x[j]=x[j]+(shift_x)
y[j]=y[j]+(shift_y)
# shift_x=x[0]
shift_y=y[0]
with open (newpath+"down"+str(counter)+".txt",'w') as new_file:
for k in range(len(x)):
new_file.write(str(x[k])+" "+str(y[k])+"\n")
counter=counter+1
else:
print("Should not happen")
print('\n---------------------------------------------------------------\n')
pyperclip3.copy("path "+newpath)
print("\nOperation successful! Created path and path command copied to clipboard. Paste to move DesCar to the created directory\n")
except:
print("\nError in main loop. Name correction attempts might have failed if initial names were wrong or data format are wrong. Exiting...")