forked from mthalves/cm_plot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlot2d.py
More file actions
452 lines (284 loc) · 9.79 KB
/
Plot2d.py
File metadata and controls
452 lines (284 loc) · 9.79 KB
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# Protocol, Plots and utils imports
import MyGUICommons, Novonix_Protocol, Defs, myProgressBar, utils, re, csv, numpy, matplotlib.pyplot, scipy.interpolate, math, pandas, scipy.signal
from MyGUICommons import exit
from Novonix_Protocol import *
from Defs import *
from myProgressBar import *
from scipy.interpolate import spline
from utils import *
# Run Method
def run(info):
# 1. Plotting
if(info.Plot_Protocol == Plot_Protocol_Novonix):
for n_file in range(0,len(info.Plot_Files)):
newfilename = standard_formated_name(info.Plot_Files[n_file])
Plot2d().plotNovonix(newfilename,info.Plot_Destination,info.Plot_XData+4,info.Plot_YData+4,info.Plot_Cycle_Type,info.Plot_Cycle_Number,
info.Plot_Title,Novonix_Table[info.Plot_XData],Novonix_Table[info.Plot_YData])
#else:
# Plot2d().plot2y()
elif(info.Plot_Protocol == Plot_Protocol_BaSyTec):
print("BaSyTec")
elif(info.Plot_Protocol == Plot_Protocol_Xanes):
print("Xanes")
# 2. That's all folks :) ...
exit()
class Plot2d():
def __plotColumbic__(self,file,dest,col,plottitle,plotx,ploty):
print('Columbic')
# 1. Setting plot labels and retrieving the csv information
print('3: ',end="")
matplotlib.pyplot.title(plottitle)
print('|||',end="")
matplotlib.pyplot.xlabel(plotx)
print('||||',end="")
matplotlib.pyplot.ylabel(ploty)
print('||| 100%')
charge, discharge = [], []
information = []
cycle = 1
# 5. Plotting
print('4: Plotting... total estimate time: 15s')
line = file.readline()
matplotlib.interactive(True)
while(re.match('^$', line ) is None):
# a. tokenizing line
tokens = line.split(',')
while(re.match('^$', line ) is None and cycle == -int(tokens[1])):
# b. storing the information
value = float(tokens[col])
if(int(tokens[1]) < 0 and value != 0):
discharge.append(value)
# c. reading the new line
line = file.readline()
tokens = line.split(',')
cycle = cycle + 1
while(re.match('^$', line ) is None and cycle == int(tokens[1])):
# b. storing the information
value = float(tokens[col])
if(int(tokens[1]) > 0):
charge.append(value)
# c. reading the new line
line = file.readline()
tokens = line.split(',')
# d. incrementing the cycle
if(len(discharge) > 1 and len(charge) > 1 and (max(discharge)-min(discharge)) != 0):
information.append(((max(charge)-min(charge))/(max(discharge)-min(discharge)))*100)
charge, discharge = [], []
print(dest + '/' + plottitle + '.png')
matplotlib.pyplot.plot(information,'-')
# 6 . Closing the opened file
matplotlib.pyplot.show()
print('5: |||||||||| 100%')
file.close()
# 7. Thats all folks :) ...
print('6: |||||||||| 100%')
def __average__(self, V, window):
return sum(V)/window
def __delta__(self, V, cond, window):
if cond == 'f':
return self.__average__(V[window+1:], window)-self.__average__(V[window-math.ceil(window/2):window+math.ceil(window/2)], window)
elif cond == 'b':
return self.__average__(V[window-math.ceil(window/2):window+math.ceil(window/2)], window) - self.__average__(V[:window-1], window)
def __differentiate__(self, V, Q):
dVdQ = []
plotx = []
V = pandas.Series(V)
Q = pandas.Series(Q)
# Applies a moving average filter
V_smooth = pandas.Series.rolling(V, 1).mean()
Q_smooth = pandas.Series.rolling(Q, 1).mean()
#differentiting
dV = numpy.diff(V)
dQ = numpy.diff(Q)
dVdQ = dV/dQ
#applies a gaussian filter and a convolution
g = scipy.signal.gaussian(min(40, len(Q)-1), 2.5)
g = g/sum(g)
dVdQ_gaus = numpy.convolve(dVdQ, g, mode='same')
return dVdQ_gaus
def __plotDVA__(self,file,dest,plottitle,plotx_title,ploty_title,cycles):
print('DVA')
cycle_test = 1
# 1. Setting plot labels and retrieving the csv information
print('3: ',end="")
matplotlib.pyplot.title(plottitle)
print('|||',end="")
matplotlib.pyplot.xlabel(plotx_title)
print('||||',end="")
matplotlib.pyplot.ylabel(ploty_title)
print('||| 100%')
Q = []
V = []
dQdV = []
cycle, cur_file = 1, 1
# 2. Plotting
print('4: Plotting... total estimate time: 15s')
line = file.readline()
matplotlib.interactive(True)
matplotlib.pyplot.figure(cur_file)
while(re.match('^$', line ) is None):
# a. tokenizing line
tokens = line.split(',')
#print('while de fora')
while(re.match('^$', line ) is None and cycle == abs(int(tokens[1]))):
# b. storing the information
#print('while de dentro')
valueQ = float(tokens[7]) #capacitancia
valueV = float(tokens[6]) #potencial
if(int(tokens[1]) > 0 and valueQ != 0 and valueV != 0):
Q.append(valueQ)
V.append(valueV)
# c. reading the new line
line = file.readline()
tokens = line.split(',')
# d. incrementing the cycle
cycle = cycle + 1
#Test if the vector Q and V are not empty
if(len(Q) > 3 and len(V) > 3 and any([t != Q[0] for t in Q]) ):
# e. Differentiating dQ/dV
plotx = []
window_size= max([3, round(len(V)/50) if round(len(V)/50) % 2 != 0 else round(len(V)/50)+1])
dVdQ = self.__differentiate__(V, Q)
# f. plot
#if(abs(cycle) / 10 > cur_file):
if(cycle-2 in cycles):
# e. plotting
matplotlib.pyplot.figure(cur_file)
matplotlib.pyplot.title(plottitle)
matplotlib.pyplot.xlabel(plotx_title)
matplotlib.pyplot.ylabel(ploty_title)
matplotlib.pyplot.plot(Q[1:len(Q)], dVdQ,'-o',label = 'Cycle ' + str(cycle-1))
matplotlib.pyplot.legend(loc = 'upper right')
cur_file = cur_file + 1
V, Q, plotx, dVdQ = [], [], [], []
# 6 . Closing the opened file
matplotlib.pyplot.show()
print('5: |||||||||| 100%')
file.close()
# 7. Thats all folks :) ...
print('6: |||||||||| 100%')
def __plotVsTime__(self,file,dest,col,mode,cycles,plottitle,plotx,ploty,pb):
# 1. Setting plot labels and retrieving the csv information
cycle, cur_file = 1, 1
matplotlib.interactive(True)
matplotlib.pyplot.figure(cur_file)
pb.update(20)
matplotlib.pyplot.title(plottitle)
pb.update(40)
matplotlib.pyplot.xlabel(plotx)
pb.update(60)
matplotlib.pyplot.ylabel(ploty)
pb.update(80)
information = []
pb.update(100)
# 2. Plotting
line = file.readline()
pb.update(20)
while(re.match('^$', line ) is None):
# a. tokenizing line
tokens = line.split(',')
while(re.match('^$', line ) is None and cycle == abs(int(tokens[1]))):
# b. storing the information
value = float(tokens[col])
if(mode*int(tokens[1]) > 0):
information.append(value)
elif(mode == FULL_CYCLE):
information.append(value)
# c. reading the new line
line = file.readline()
tokens = line.split(',')
# d. incrementing the cycle
cycle = cycle + 1
if(cycle-2 in cycles):
matplotlib.pyplot.figure(cur_file)
matplotlib.pyplot.title(plottitle)
matplotlib.pyplot.xlabel(plotx)
matplotlib.pyplot.ylabel(ploty)
matplotlib.pyplot.plot(information,'-',label = 'Cycle ' + str(cycle-1))
# e. plotting
matplotlib.pyplot.legend(loc = 'upper right')
# f. updating the figure
cur_file = cur_file + 1
information = []
def __plotXY__(self,file,dest,xcol,ycol,mode,cycles,plottitle,plotx,ploty, pb):
# 1. Setting plot labels and retrieving the csv information
cycle, cur_file = 1, 1
matplotlib.interactive(True)
matplotlib.pyplot.figure(cur_file)
pb.update(20)
matplotlib.pyplot.title(plottitle)
pb.update(40)
matplotlib.pyplot.xlabel(plotx)
pb.update(60)
matplotlib.pyplot.ylabel(ploty)
pb.update(80)
xinformation, yinformation = [], []
pb.update(100)
# 2. Plotting
line = file.readline()
pb.update(20)
while(re.match('^$', line ) is None):
# a. tokenizing line
tokens = line.split(',')
while(re.match('^$', line ) is None and cycle == abs(int(tokens[1]))):
# b. storing the information
xvalue = float(tokens[xcol])
yvalue = float(tokens[ycol])
if(mode*int(tokens[1]) > 0):
xinformation.append(xvalue)
yinformation.append(yvalue)
elif(mode == FULL_CYCLE):
xinformation.append(xvalue)
yinformation.append(yvalue)
# c. reading the new line
line = file.readline()
tokens = line.split(',')
# d. incrementing the cycle
cycle = cycle + 1
if(cycle-2 in cycles):
# e. plotting
matplotlib.pyplot.figure(cur_file)
matplotlib.pyplot.title(plottitle)
matplotlib.pyplot.xlabel(plotx)
matplotlib.pyplot.ylabel(ploty)
matplotlib.pyplot.plot(xinformation,yinformation,'s',label = 'Cycle ' + str(cycle-1))
matplotlib.pyplot.legend(loc = 'upper right')
cur_file = cur_file + 1
xinformation, yinformation = [], []
def plotNovonix(self,filename,dest,xcol,ycol,mode,cycles,plottitle,plotx,ploty):
pb = myProgressBar('Plotting',['Opening File','Header Getting','Plot Type','Setting Labels and Information','Plot','Finishing'],40)
# 1. Opening the file
pb.start()
file = fopen(filename,'r')
pb.update(100)
# 2. Ignoring the header
file.readline()
pb.update(100)
# 3. Verifying the plot type
if(COULUMBIC in [xcol,ycol]):
pb.update(100)
self.__plotColumbic__(file,dest,7,plottitle,'Cycle Number','Coulombic Efficiency (%)')
return(None)
elif(DVA in [xcol,ycol]):
pb.update(100)
self.__plotDVA__(file,dest,plottitle,'Capacity (A)','dQ/dV',cycles)
return(None)
elif(xcol == 4):
pb.update(100)
self.__plotVsTime__(file,dest,ycol,mode,cycles,plottitle,plotx,ploty,pb)
pb.update(80)
elif(ycol == 4):
pb.update(100)
self.__plotVsTime__(file,dest,xcol,mode,cycles,plottitle,ploty,plotx,pb)
pb.update(80)
else:
pb.update(100)
self.__plotXY__(file,dest,xcol,ycol,mode,cycles,plottitle,plotx,ploty,pb)
pb.update(80)
# 6 . Closing the opened file
pb.update(100)
matplotlib.pyplot.show()
pb.update(50)
file.close()
pb.update(100)
# 7. Thats all folks :) ...