-
Notifications
You must be signed in to change notification settings - Fork 0
/
Curve.py
694 lines (611 loc) · 20.7 KB
/
Curve.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
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
import numpy as np
import matplotlib.pyplot as pyt
import os
from datetime import date
##
## # Curve.py #
## General purpose functions to read absorption spectrum file
## prepared: 05/02/2016 by Kak Wong
## last edit: 09/07/2016
##
## date of irradiation
dateN2 = date(2015,12,19)
dateN3 = date(2016,01,14)
dateN4 = date(2016,01,11)
dateN4new = date(2016,03,25)
dateCT = date(2015,11,3) # inaccurate
datecold = date(2016,04,01)
datewarm = date(2016,04,04)
def obsolete(f):
def _wrapper(*args, **kwargs):
print "## warning >> "+ f.__name__+"() >> this is an obsolete function"
return f(*args, **kwargs)
return _wrapper
class Curve:
""" Absorption Curve Class """
x= np.linspace(600,200,401)
# irradation date of batch array
dN = [0,0,dateN2,dateN3,dateN4,0,dateN4new,0,dateN4new,
0, datewarm,datecold]+[0]*2
# useful colors on matplotlib
farben = ['blue', 'green', 'red', 'magenta', 'blueviolet', 'darkcyan']
farben += ['hotpink', 'salmon','slategray','springgreen','chocolate', 'crimson']
irrdates = dict()
# verbose trigger
verbose = 0
## CONSTRUCTOR
def __init__(self, name, date, silent = False):
""" Curve class CONSTRUCTOR """
## note: castor table not given a batch num yet
## batch number:
## EJ200SP/EJ260 N1-4 : 1-4
## new irrad. 200SP : 5-8
## old EJ200 samples : 9
## cold/warm irrad. : 10-11
## new PVT/PS samples : 21-35
## variated width : 41-45
self.nametag = name
self.datetag = date
self.data = [0]*5
try:
i = self.nametag.index('-N')
self.batch = int(self.nametag[i+2])
except ValueError:
self.batch = 0
#### the following part needs revamp soon
# special line for new irradiation
if (self.batch in [2,4] and 'EJ200SP' in self.nametag
and self.datetag >= dateN4new):
self.batch +=4
# EJ200 irradiation
if (self.batch == 0 and self.hasKeyword(['EJ200','1X-'])):
self._coldsamples()
if ('EJ' in self.nametag) and ('PVT' in self.nametag):
if ('PVT-T' in self.nametag):
i = self.nametag.index('PVT-T')
self.batch = int(Curve._rstrip(i+7,self.nametag))+40
else:
i = self.nametag.index('P-N')
#self.batch = int(self.nametag[i+3:])+20
self.batch = int(Curve._rstrip(i+3,self.nametag))+20
if ('EJ' in self.nametag) and ('PS' in self.nametag):
if ('PS-T' in self.nametag):
i = self.nametag.index('PS-T')
self.batch = int(Curve._rstrip(i+6,self.nametag))+40
else:
i = self.nametag.index('P-')
#self.batch = int(self.nametag[i+2:])+20
self.batch = int(Curve._rstrip(i+2,self.nametag))+20
if Curve.verbose == 1 and not silent:
#print self.batch, ': ', self.nametag, self.cvage()
print "%-15s %s %s" %(self.nametag, self.batch, self.cvage())
@staticmethod
def _rstrip(i, name,sep = '_'):
return name[i:].split(sep)[0].rstrip('abcd ')
# subroutine for warm/cold samples
def _coldsamples(self):
i = self.nametag.index('X-')
try:
number = int(self.nametag[i+2:i+4])
except ValueError:
number = int(self.nametag[i+2:i+3])
if number == 10 or number == 11:
self.batch = number
else:
self.batch = 9
return
def __repr__(self):
return '<'+self.nametag+' '+''.join(['_' if d is 0 else 'o' for d in self.data[1:5]])+str(self.__len__())+'>'
## INPUT CURVE DATA
def add(self, number, dcurve):
# now assume that input is transmittance
if self.data[number] is not 0:
self.data.append(dcurve)
#print 'extra data curve!'
else: self.data[number] = dcurve
## BASIC FUNCTION
def __len__(self): return self.nonzerodata().__len__()
def len(self): return self.__len__()
def printType(self): return [type(d) for d in self.data]
def arraynzd(self): return np.array(self.nonzerodata())
def nonzerodata(self): return [x for x in self.data if x is not 0]
def view(self, number, t = True):
if self.data[number] is 0: return 0
if t: return self.data[number]
return Curve.absp(self.data[number])
def hasKeyword(self, keywords):
isTrue = True
if type(keywords) == str:
keywords = [keywords]
for keyword in keywords:
isTrue = isTrue and (keyword in self.nametag)
return isTrue
def label(self, nslice = slice(None), dslice = slice(5, None), hasDay=True):
lbl = self.nametag[nslice] + ' ' + str(self.datetag)[dslice]
if hasDay:
age = self.cvage()
if age != -1:
lbl = lbl +' Day '+str(age)
#if '-6' in self.nametag and self.batch == 6: # @obsolete
# lbl = 'CasT ' + lbl
return lbl
def cvage(self):
""" age of a sample from last irradiation """
try:
age = (self.datetag - Curve.dN[self.batch]).days
except (TypeError, IndexError):
age=-1
for piece in Curve.irrdates.keys():
if self.hasKeyword(piece):
age = (self.datetag - Curve.irrdates[piece]).days
return age
return age
def tvalueat(self, lbd, side = 0):
if side > 0:
t = self.data[side]
# exception: if side curve is missing. raise error code 0 so maketimegrpah can catch it
if type(t) is not np.ndarray:
raise ValueError(0,self.label()+'side '+' abcd'[side]+' is empty')
return t[600-lbd]
print 'lambda=', lbd,'nm: ', self.avgcurve()[600-lbd]
return self.avgtcurve()[600-lbd], self.errtcurve()[600-lbd]
## STATIC METHOD
@staticmethod
def trsm(absp): return np.power(10,(-1.*np.array(absp)))
@staticmethod
def absp(trsm): return -np.log10(np.array(trsm))
@staticmethod
def ctypename(t = None): return 'Transmission' if t else 'Absorption'
@staticmethod
def makeslice(a,b): return slice(600-b,600-a)
#slicing generator: converts 200-600nm to python index """
## SUBCLASS
class NoneIter:
""" Empty Iterater: always return None with each next() """
def __init__(self):
print "initiate None iterater"
def next(self):
return None
## PRODUCE CURVES
def avgcurve(self, t=None):
nonzero = self.arraynzd()
if t:
return np.average(nonzero,0)
return np.average(Curve.absp(np.array(nonzero)),0)
def errcurve(self, t=None):
# average error curve
if t:
return self.errtcurve()
nonzero = self.arraynzd()
#return np.ptp(np.array(nonzero),0)/2
return np.std(np.array(nonzero),0)
@obsolete
def viewt(self, number):
if self.data[number] is 0: return 0
#return Curve.trsm(self.data[number])
return self.data[number]
@obsolete
def avgtcurve(self):
# average transmission curve
nonzero = self.arraynzd()
#return np.max(self.trsm(nonzero),0)
return np.average(nonzero,0)
@obsolete
def mvavgtcurve(self, n=3):
nzd = self.nonzerodata()
for i in range(len(nzd)):
nzd[i]= Curve.moving_average(nzd[i], n=n)
return np.average(np.array(nzd),0)
@obsolete
def errtcurve(self):
# average transmission error
nonzero = self.arraynzd()
t= self.trsm(nonzero)
#t= np.power(10,(-1*np.array(nonzero)))
#return np.ptp(t,0)/2
return np.std(t,0)
@obsolete #
def diff(self,refl_reduction = False):
a = self.view(2)+self.view(4)
b = self.view(1)+self.view(3)
if refl_reduction:
a=a-a[20:80].sum()/60
b=b-b[20:80].sum()/60
return (a-b)/(a+b)
@staticmethod
def diffc(c1,c2):
a = c1.avgcurve()
b = c2.avgcurve()
return (a-b)/(a+b)
@staticmethod
def moving_average(a, n=3) :
ret = np.cumsum(a, dtype=float)
ret[n:] = ret[n:] - ret[:-n]
return ret[n - 1:] / n
# CURVE GENERATORS
def addCurve(self, c):
""" Combine two Curve objects """
self.data.extend(c.nonzerodata())
def copy(self):
c = Curve(self.nametag, self.datetag, True) # silent
c.data = [0]*len(self.data)
for i, e in enumerate(self.data):
if e is not 0:
c.data[i] = np.copy(e)
return c
def clone(self):
newc = Curve(self.nametag, self.datetag)
newc.data = [c.copy() if isinstance(c,np.ndarray) else c for c in self.data]
return newc
def __add__(self, other):
""" built-in add function """
c = self.copy()
c.addCurve(other)
return c
def __radd__(self, other):
""" built-in reverse add function """
if other == 0: return self.copy()
else: return self.__add__(other)
def shift(self, shift):
for i in range(5):
if not isinstance(self.data[i],int):
self.data[i] = Curve.shifter(self.data[i],shift)
return
@staticmethod
def shifter(ar, shift = 0.5):
""" return curve with shifted x axis
using linear extrapolation """
## left shift case
if shift > 0:
iShift = int(np.ceil(shift)-1) # integer shift
deci = shift - iShift # decimal part
## special case where deci = 0??? ##TODO!
newar = np.convolve(ar, [deci, 1- deci] + [0]*iShift, 'valid')
return np.append(newar, [np.nan]*(iShift+1)) # padding for x
# right shift
if shift <=0:
shift = -shift
iShift = int(np.ceil(shift) - 1)
deci = shift - iShift
newar = np.convolve(ar, [0]*iShift + [1- deci ,deci] , 'valid')
return np.append([np.nan]*(iShift+1), newar)
## PLOTTING FUNCTIONS
@staticmethod
def defaultplotting(title = None, xlabel='wavelength nm', axis = 0, ylabel=None, hasGrid = True, t=None, block = True, isShow = True):
""" default plot styling method """
if not axis: axis = pyt
else: axis.xlabel, axis.ylabel = axis.set_xlabel, axis.set_ylabel
if not ylabel: ## if ylabel not specified
ylabel = Curve.ctypename(t)
axis.grid(hasGrid)
#axis.legend(loc = 0)
axis.xlabel(xlabel)
axis.ylabel(ylabel)
if title: axis.title(title)
if isShow: axis.show(block = block)
return
@staticmethod
def compPlotter(ax_main, ax_ratio,xx, avg, ref, lw1 = 1, lw2 = 1, yexp = None, **kwargs):
""" Plotter defined for the Comparison graph """
ax_main.plot(xx,avg, linewidth = lw1, **kwargs)
if yexp:
y = eval(yexp)
else:
y = (avg/ref-1)
ax_ratio.plot(xx,y, linewidth = lw2, **kwargs)
@staticmethod
def compSidePlotter(ax_main, ax_ratio,xx, c, cref, lw1 = 1., lw2 = 1 , s=slice(None)):
""" Plot two pieces and compare their individual sides """
for i in range(1,5):
clr, lbr = Curve.farben[i-1], ' side '+ ' ABCD'[i]
if cref.viewt(i) is not 0:
ax_main.plot(xx[s], cref.viewt(i)[s], linewidth = lw1,
color = clr, label = cref.label() + lbr, linestyle = 'dashed')
if c.viewt(i)[s] is not 0:
ax_main.plot(xx[s], c.viewt(i)[s] , linewidth = lw1,
color = clr, label = c.label()+lbr)
if cref.viewt(i) is not 0 and c.viewt(i) is not 0:
y = c.viewt(i)/cref.viewt(i) -1
ax_ratio.plot(xx[s],y[s], linewidth = lw2,color = Curve.farben[i-1])
else:
print 'ref curve:curve Side', ' ABCD'[i],type(cref.viewt(i)), type(c.viewt(i))
Curve.defaultplotting(axis = ax_main ,isShow = False)
Curve.defaultplotting(axis = ax_ratio , ylabel = 'Ratio-1', isShow = False)
return
def plot(self, t=None):
pyt.plot(Curve.x,self.avgcurve(t))
print self.label()
Curve.defaultplotting(self.label(),t=t)
return
def plotallcurves(self, t=None, newfig = None, plotting = True):
# plot all member curves of a measured piece
i = 0
if newfig:
fig = pyt.figure()
for c in self.data:
if c is not 0:
if not t: c = self.absp(c)
pyt.plot(Curve.x, c, label = 'Side '+(' ABCD1234567890'[i]))
i+=1
print self.label()
if plotting:
Curve.defaultplotting(self.nametag + ' ' + str(self.datetag),t=t, block = not newfig)
return
def plotallcurvesComp(self, t=None, plotting = True, s = slice(None), shr = dict(height_ratios = [3,2]),ratioyrange=None, save = False, showDiff = False):
""" always creates newfigure due to subplots """
fig, (ax1, ax2) = pyt.subplots(2,1, sharex=True, gridspec_kw=shr,figsize = (8,8))
fig.suptitle(self.nametag + ' ' + str(self.datetag), y=.95, size=17)
for i,c in enumerate(self.data):
if c is not 0:
if not t: c = self.absp(c)
ax1.plot(Curve.x[s], c[s], label = 'Side '+(' ABCD1234567890'[i]))
if not t: ax2.plot(Curve.x[s],(c-self.avgcurve(t=t))[s])
else: ax2.plot(Curve.x[s],(c/self.avgcurve(t=t)-1)[s])
if showDiff:
kwarg_Diff = dict(color = 'darkred', linestyle = 'dashed')
ax1.plot([np.nan],[np.nan], label = 'Absp Diff', **kwarg_Diff)
ax2.plot(Curve.x[s],self.diff, **kwarg_Diff)
ax1.plot(Curve.x[s],self.errcurve(t=t)[s]*10, label = 'Error x10', color = 'cyan')
Curve.defaultplotting(axis = ax1, t=t, isShow = False)
ax1.legend(loc = 0)
Curve.defaultplotting(axis = ax2, ylabel = 'Diff' if (not t) else 'Ratio-1', isShow = False)
ax2.set_ylim(ratioyrange)
print self.label()
if plotting:
pyt.show(block= True)
if save:
filen_init = 'plots/SpecCompMem'+self.nametag+'_'+str(self.datetag)[5:]
Curve.saveFigHelper(filen_init,fig)
pyt.close()
return
### test of concept ###
@obsolete
def plotallcurvesDiff(self, plotting = True, s = slice(None), shr = [3,2], save = False,ratioyrange=None, t=None):
""" always creates newfigure due to subplots;
parameter t is ignored """
i = 0
shr = dict(height_ratios = shr)
fig, (ax1, ax2) = pyt.subplots(2,1, sharex=True, gridspec_kw=shr,figsize = (8,8))
fig.suptitle(self.nametag + ' ' + str(self.datetag), y=.95, size=17)
for i in range(1,5):
c=self.view(i)
if False: #c is not 0:
ax1.plot(Curve.x[s], c[s], label = 'Side '+(' ABCD1234567890'[i]))
ax2.plot(Curve.x[s],(c-self.avgcurve())[s],color =['gray','slategray'][i%2])
a = self.view(2)+self.view(4)
b = self.view(1)+self.view(3)
#a=a-a[20:60].sum()/40+.005
#b=b-b[20:60].sum()/40+.005
ax1.plot(Curve.x[s], a[s], label = 'side B+D')
#ax2.plot(Curve.x[s],(a-self.avgcurve())[s],color =['gray','slategray'][i%2])
ax1.plot(Curve.x[s], b[s], label = 'side A+C')
#ax2.plot(Curve.x[s],(b-self.avgcurve())[s],color =['gray','slategray'][i%2])
#ax2.plot(Curve.x[s],self.diff(refl_reduction = True)[s],linestyle='dashed',linewidth=3)
ax2.plot(Curve.x[s],((a-b)/(a+b))[s],linestyle='dashed',linewidth=3)
ax1.plot(Curve.x[s],self.errcurve()[s]*10, label = 'Error x10', color = 'cyan')
ax1.legend(loc = 0)
defaultplotting(pyt = ax1, ylabel = 'Absorption', isShow = False)
defaultplotting(pyt = ax2, ylabel = 'Diff', isShow = False)
ax2.set_ylim(ratioyrange)
print self.label()
if plotting:
pyt.show(block= True)
if save:
filen_init = 'plots/SpecCompMem'+self.nametag+'_'+str(self.datetag)[5:]
Curve.saveFigHelper(filen_init,fig)
pyt.close()
return
@staticmethod
def saveFigHelper(filen_init, fig):
""" takes file name and save fig in png extension"""
filen = filen_init + '.png'
i=1
while os.path.isfile(filen):
## wherein such filename exists, search for next available name
filen = filen_init +'_'+str(i)+'.png'
i+=1
print 'saved: ' + filen
fig.savefig(filen)
return
## remove spikes
def spikeRm(self, value = 10.):
d = [c for c in self.data if c is not 0]
for c in d:
while True:
index = (c == value).nonzero()[0]
if index.size < 1:
break
c[index] = c[index-1]
return
@staticmethod
def getAllCsv(path = 'data/'):
farray = os.listdir(path)
return [(path+f) for f in farray if f[-4:] == '.csv']
@staticmethod
def curveCreateAllCsv(path = 'data/'):
def _datemake(string):
ymd = (string[8:12],string[12:14],string[14:16])
return date(*map(int,ymd))
fnList = Curve.getAllCsv(path)
curves = []
for n in fnList:
try:
curves += curveCreation(_datemake(n),[n,],verbose=1, skips=2)
except ValueError:
print 'Warning: Date cannot be obtained:', n
return curves
@staticmethod
def _txtdateinput(s):
try: # first three items: date of measurement
cdate = date(*map(int,s[:3]))
except ValueError:
print 'error:',s
raise
return cdate
@staticmethod
def readIrrDate(logfile):
f = open(logfile)
Curve.irrdates = dict()
for line in f:
s = line.rstrip().split(',')
if '#' not in s[0] and s[0]:# skip comment lines
cdate = Curve._txtdateinput(s)
# follows: filenames
piecename = [piece.lstrip(" '").rstrip(" '\n") for piece in s[3:]]
Curve.irrdates.update([[p, cdate] for p in piecename])
for (n, d) in Curve.irrdates.iteritems():
print d, n
return
############## file opening pattern generalize ???? ###############
def fileopener(logfile,**kwargs):
f = open(logfile)
initfunct()
for line in f:
s = line.rstrip().split(',')
# skip comment lines
if '#' not in s[0] and s[0]:
function(**kwargs)
endfunct()
return
def readCurveFile(logfile, verbose = 1, skips = False, sepcurve =False):
f = open(logfile)
curves = []
for line in f:
s = line.rstrip().split(',')
# skip comment lines
if '#' not in s[0] and s[0]:
cdate = Curve._txtdateinput(s)
# follows: filenames
filenames = [fn.lstrip(" '").rstrip(" '\n") for fn in s[3:]]
curves+=curveCreation(cdate, filenames,
verbose = verbose, skips = skips, sepcurve = sepcurve)
return curves
def curveCreation(cdate, filenames, verbose = 1,
skips = False, sepcurve = False, abspmode = True):
# skips: ignore unexpected entries and move on
# default to False, which raises exceptions
# sepcurve: save entries into separate curves
# abspmode: if False, forces conversion to transmittances
## read file and create curve class
## return list of Curves
tempcurve = []
def _printer(c): print "%-25s %2s %2s " %(c, c.batch, c.cvage())
for fname in filenames:
isOldFile = False #so it won't print the last curve of the previous file again
f = open(fname)
if verbose:
print fname
Curve.verbose = 1
names = f.readline().split(',')[0::2]
modes = f.readline().rstrip('\n').rstrip('\r').split(',')[1::2]
f.close()
f2 = np.loadtxt(fname,skiprows = 2, delimiter = ',')
lastname = ''
for i, n in enumerate(names):
facenum = ord(n[-1])-96
truename = n[:-1]
importcurve = True
if facenum not in range(1,5):
importcurve = False
if not skips: # not skipping/ skips = 0
## expects that each curve is importable
## error is shown if that is not the case
raise Exception('weird names: %s %s' % (n, ord(n[-1])-96))
elif skips == 1: ## next input as new curve; not import curve
lastname = None
elif skips == 3: ## import curve. Assumes "face a"
truename = n
importcurve = True
facenum = 1
elif skips == 2: ## completely ignore input (seldom needed)
pass
else:
print '!exceptional case!', n, skips
print 'treated as case II: complete ignores'
if importcurve:
if truename != lastname or sepcurve:
if tempcurve and isOldFile: _printer(tempcurve[-1])
tempcurve.append(Curve(truename,cdate,silent=True))
lastname = truename
if abspmode and modes[i] == 'Abs':
# even in default abspmode if the code detects T% it converts the number to absp
tempcurve[-1].add(facenum,Curve.trsm(f2[:,i*2+1]))
else:
tempcurve[-1].add(facenum,f2[:,i*2+1]/100.)
isOldFile = True
if tempcurve: _printer(tempcurve[-1])
return tempcurve
## ACTION ON ARRAY OF CURVES
def curvesKeyword(icurves, name = None, char = None, batchn = None):
""" given sample name string, return all curves contains the keyword """
if name is None:
return icurves
if batchn is not None:
return [c for c in icurves if c.hasKeyword(name.split(char)) and c.batch == batchn]
return [c for c in icurves if c.hasKeyword(name.split(char))]
def curvesDate(icurves, date_measured):
# return curves with the date
# date can be date object or tuple
if not date_measured:
return icurves
if type(date_measured) is tuple:
date_measured = date(*date_measured)
return [c for c in icurves if c.datetag == date_measured]
def curvesRemoveRedundant(icurves):
temp = []
for c in icurves:
isNew = True
for tc in temp:
if tc.nametag == c.nametag:
isNew = False
if isNew:
temp.append(c)
return temp
def curvesAge(icurves, day = 0, rincl = False, dayrange = 0):
""" return curves with a specific age of irradiation """
ctemp = []
for c in icurves:
if c.batch <= 1 or c.batch == 9 :
# case 1: option to include reference samples
if rincl:
ctemp.append(c)
elif np.abs(c.cvage() - day) <= dayrange:
# case 2-4: check irradaition date and datetag
ctemp.append(c)
return ctemp
@obsolete
def curvesRef(icurves, rred = False):
# rred removes redundant options
temp = [c for c in icurves if c.batch in [1,9] ]
if rred:
temp = curvesRemoveRedundant(temp)
return temp
## obsolete probably
@obsolete
def keycGen(curves, cKeyword, keywords, batchnum=None, hasCastor = False):
""" Similar to curvesKeyword: return curves with sample string
Further selects for different batch numbers"""
keycurve = curvesKeyword(curves, name = cKeyword)
keycN = [0]*5
if not batchnum:
batchnum = [None] * 5
for i in range(5):
keycN[i] = curvesKeyword(keycurve, name = keywords[i],batchn = batchnum[i])
# Castor table samples are not of the same formula as the EJ200SP pieces
#if hasCastor:
# keycN[5] = curvesKeyword(keycurve, name = '-6')
#else:
# keycN[5] = []
return keycurve, keycN
@obsolete
def specPlotter(curves, title, xlabel='wavelength nm', ylabel='absorption',
target = pyt, xslice = (None,), t = 0):
# provided a set of curves, plot them with titles and legends
# as nametag of the curve
s = slice(*xslice)
for i in range(len(curves)):
y = curves[i].avgcurve(t=t)
target.plot(Curve.x[s],y[s],label = curves[i].nametag,
color = farben[i%len(farben)])
Curve.defaultplotting(title, xlabel, ylabel, hasGrid = True, t=t)
return