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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
from filePath 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 scipy.optimize import curve_fit
from scipy.interpolate import interp1d
import pyperclip3
def avg():
print("\nImportant remark: Might bug with polytec file\n")
newpath=os.getcwd()+"\\avg_data"+"\\"
if not os.path.exists(newpath):
os.makedirs(newpath)
files=glob.glob("*.txt")
a=len(files)
current_file=""
try:
x=np.zeros(file_length(files[1]))
y=np.zeros(file_length(files[1]))
print("Opening and averaging ",len(files)," files")
for i,fp in enumerate(files): #retourne l'index dans i et retourne le premiere element (T1.txt par exemple) dans fp
current_file=files[i]
if(((i+1)%a)==0):
# print("this is i ",i)
print(files[i])
with open(fp) as file:
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_temp1=[]
y_temp1=[]
for k in range(len(sort)):
x_temp1.append(x_temp[sort[k]])
y_temp1.append(y_temp[sort[k]])
x=np.array(x_temp1)
# print("this is Y before sum loop if",y)
y=y+np.array(y_temp1)
# print("this is y after sum: loop if",y)
# print("this is what will be plotted x",x)
y=y/a
# print("this is what will be plotted y/a",y)
# ax.plot(x,y/a)
else:
with open(fp) as file:
print(files[i],"is used with")
x1 = []
y1 = []
for line in file:
values = line.split()
x1.append(float(values[0]))
y1.append(float(values[1]))
sort1=np.argsort(x1)
x2=[]
y2=[]
for k in range(len(sort1)):
x2.append(x1[sort1[k]])
y2.append(y1[sort1[k]])
# print("this is y before sum loop else",y)
y=y+np.array(y2)
# print("this is y after loop else:",y)
fileName=input("\nPlease provide a file name without the extension:")
with open (newpath+fileName+".txt",'w') as new_file:
for k in range(len(x)):
new_file.write(str(x[k])+" "+str(y[k])+"\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")
except:
print('\n---------------------------------------------------------------')
print('\nError: Operation was halted. Files probably have different length. Please check your files before proceeding. Operation stopped while working on: ',current_file,'\n')
def colMult(coef):
try:
if(coef!=None and coef!=" " and coef!=""):
cstx,csty=coef.split(",")
cstx=float(cstx)
csty=float(csty)
flag=0
else:
cstx,csty=input("Please provide a coef (x,y): ").split(",")
cstx=float(cstx)
csty=float(csty)
flag=0
except:
flag=1
if(flag==0):
newpath=os.getcwd()+"\\multiplied_data"+"\\"
if not os.path.exists(newpath):
os.makedirs(newpath)
files=glob.glob("*.txt")
f_list=fileExtensionRemover(glob.glob("*.txt"))
for i,fp in enumerate(files):
print("Working on: ",files[i])
with open(fp) as file:
x = []
y = []
for line in file:
values = line.split()
x.append(float(values[0]))
y.append(float(values[1]))
for j in range(len(x)):
x[j]=x[j]*cstx
y[j]=y[j]*csty
with open (newpath+f_list[i]+".txt",'w') as new_file:
for k in range(len(x)):
new_file.write(str(x[k])+" "+str(y[k])+"\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")
else:
print("Improper input. Exiting ...")
def colAdd(shift):
try:
if(shift!=None and shift!=" " and shift!=""):
cstx,csty=shift.split(",")
cstx=float(cstx)
csty=float(csty)
flag=0
else:
cstx,csty=input("Please provide an offset (x,y): ").split(",")
cstx=float(cstx)
csty=float(csty)
flag=0
except:
flag=1
if(flag==0):
newpath=os.getcwd()+"\\shifted_data"+"\\"
if not os.path.exists(newpath):
os.makedirs(newpath)
files=glob.glob("*.txt")
f_list=fileExtensionRemover(glob.glob("*.txt"))
for i,fp in enumerate(files):
print("Working on: ",files[i])
with open(fp) as file:
x = []
y = []
for line in file:
values = line.split()
x.append(float(values[0]))
y.append(float(values[1]))
for j in range(len(x)):
x[j]=x[j]+cstx
y[j]=y[j]+csty
with open (newpath+f_list[i]+".txt",'w') as new_file:
for k in range(len(x)):
new_file.write(str(x[k])+" "+str(y[k])+"\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")
else:
print("Improper input. Exiting...")
def generic_data_cleaner():
print("\nThis routine allows to output clean dual column xy txt from generic input file. \nPlease describe your file:")
newpath=os.getcwd()+"\\"
files=glob.glob("*.txt")
f_list=fileExtensionRemover(glob.glob("*.txt"))
flag=0
try:
if(cleanset.skipRows==None):
row=int(input("\nHow many rows to skip: "))
else:
row=int(cleanset.skipRows)
column=[]
if(cleanset.colName==None):
column.append(input("\nPlease provide the name of the columns (coma separated): ").split(','))
else:
column.append(cleanset.colName.split(','))
temp=[]
if(cleanset.colExport==None):
temp.append(input("\nWhat column combination would you like to export (formating 0+1,0+2, ...): ").split(","))
else:
temp.append(cleanset.colExport.split(','))
export=[]
for i in range(len(temp[0])):
export.append(temp[0][i].split('+'))
except:
flag=1
print("\nError in input interpretation. Check input or your general gfClean settings. Exiting ...")
csv=0
if(flag==0):
try:
print("\nStarting procedure ...\n---------------------------------------------------\n")
for i,fp in enumerate(files):
print("Working on ",files[i])
try:
data_str=np.loadtxt(files[i],skiprows=row,comments="END_DB",dtype=str)
# data_str=np.loadtxt(files[i],skiprows=row,comments="END_DB",dtype=str,delimiter=',')
except:
print("\n!! Error with !!",files[i],"\n")
continue
for k in range(len(temp[0])):
path=newpath+"("+column[0][int(export[k][0])]+"_"+column[0][int(export[k][1])]+")"
if not os.path.exists(path):
os.makedirs(path)
# with open (newpath+f_list[i]+"_("+column[0][int(export[k][0])]+"_"+column[0][int(export[k][1])]+").txt",'w') as file:
with open (path+"\\"+f_list[i]+"_("+column[0][int(export[k][0])]+"_"+column[0][int(export[k][1])]+")"+".txt",'w') as file:
for j in range(len(data_str[:,0])):
file.write(data_str[j,int(export[k][0])].replace(',','.')+" "+data_str[j,int(export[k][1])].replace(',','.')+"\n")
except:
print("\n---------------------------------------\n")
print("\nError in main txt decoding loop. Trying csv decoding.\n")
csv=1
if(csv==1):
try:
print("\nStarting csv backup procedure ...\n---------------------------------------------------\n")
for i,fp in enumerate(files):
print("Working on ",files[i])
try:
# data_str=np.loadtxt(files[i],skiprows=row,comments="END_DB",dtype=str)
data_str=np.loadtxt(files[i],skiprows=row,comments="END_DB",dtype=str,delimiter=',')
except:
print("\n!! Error with !!",files[i],"\n")
continue
for k in range(len(temp[0])):
path=newpath+"("+column[0][int(export[k][0])]+"_"+column[0][int(export[k][1])]+")"
if not os.path.exists(path):
os.makedirs(path)
# with open (newpath+f_list[i]+"_("+column[0][int(export[k][0])]+"_"+column[0][int(export[k][1])]+").txt",'w') as file:
with open (path+"\\"+f_list[i]+"_("+column[0][int(export[k][0])]+"_"+column[0][int(export[k][1])]+")"+".txt",'w') as file:
for j in range(len(data_str[:,0])):
file.write(data_str[j,int(export[k][0])].replace(',','.')+" "+data_str[j,int(export[k][1])].replace(',','.')+"\n")
except:
print("\n---------------------------------------\n")
print("\nDecoding failed. Exiting ...\n")
flag=1
if(flag==0):
print('\n---------------------------------------------------------------\n')
print("\nOperation successful!\n")
class Clean:
def __init__(self):
self.skipRows=None
self.colExport=None
self.colName=None
def set_colName(self,colName):
self.colName=colName
def get_colName(self):
return self.colName
def set_colExport(self,colExport):
self.colExport=colExport
def get_colExport(self):
return self.colExport
def set_skipRows(self,skipRows):
self.skipRows=skipRows
def get_skipRows(self):
return self.skipRows
def clear(self):
self.skipRows=None
self.colExport=None
self.colName=None
cleanset=Clean()
def col_export(col_export):
if(col_export==''):
a=input("\nWhat column combination would you like to export (formating 0+1,0+2, ...): ")
cleanset.set_colExport(a)
print("Exported column set to: ",a,"\n")
else:
cleanset.set_colExport(col_export)
print("Exported column set to: ",col_export,"\n")
def col_name(col_name):
if(col_name==''):
a=input("\nPlease provide the name of the columns (coma separated): ")
cleanset.set_colName(a)
print("Col name set to: ",a,"\n")
else:
cleanset.set_colName(col_name)
print("Col names set to: ",col_name,"\n")
def skip_row(skip):
if(skip==''):
a=input("\nNumber of rows to skip: ")
cleanset.set_skipRows(a)
print("Skip set to: ",a,"\n")
else:
cleanset.set_skipRows(skip)
print("Skip set to: ",skip,"\n")
def gfClear():
cleanset.clear()
print("\nGeneral file clean settings cleared succesfully !\n")