-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pattern.py
90 lines (67 loc) · 2.27 KB
/
test_pattern.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
#/06/2017
#VELLEYEN Stephane
# 25/09/2017 OMH
import os
import time
import sys
import math
import numpy as np
import pylab as pl
boardid=sys.argv[1]
cas=sys.argv[2]
DATADIR=sys.argv[3]
siz = 2*90 # event size
off = 1 # Skip 1st sample for each channel
sizc = 4*(siz-(off+1))
def read():
file = DATADIR+'/last_run.txt'
rid = str(int(np.loadtxt(file)))
fichier=DATADIR+'/P'+str(rid)+'_b'+boardid+'.data.txt'
print 'Reading pattern data file',fichier
file = open(fichier,'r')
evts = file.read().split('-----------------') # Definition d'un evenements
nevts = len(evts)-1 # take last event
file.close()
j = 0; # Index of array filling (because date & data are "append")
for i in range(1,nevts+1):
if float(i)/100 == int(i/100):
print 'Event',i,'/',nevts
evt = evts[i]
evtsplit = evt.split('\n')
if np.size(evtsplit)>8: # Event is of normal size
# Data
raw=evtsplit[9:][:] #raw data
evts2 = raw[0].split(' ') # Cut raw data list into samples
ievts2 = [int(i) for i in evts2[0:np.size(evts2)-1]] #Skip first samples
index1st = [range(off+1),range(siz,siz+off+1),range(2*siz,2*siz+off+1),range(3*siz,3*siz+off+1)]
ievts2 = np.delete(ievts2,index1st)
test1 = np.mean(ievts2)
print 'Mean value for test=',test1
if np.size(ievts2) != sizc:
print '##########Error: event size !=',sizc,' ##########'
sys.exit(-1)
return ievts2 #renvoie les donnees
def main():
tab=read()
if cas=="0":
a=0*np.ones(sizc) #On declare un tableau de 720 valeurs
elif cas=="1":
a=4095*np.ones(sizc) #On declare un tableau de 720 valeur
elif cas=="2":
a=1365*np.ones(sizc) #On declare un tableau de 720 valeur
m = range(sizc)
m2 = (np.asarray(m)%2 != 0) # Start with 2730
a[m2] = 2730
elif cas=="3":
a=819*np.ones(sizc) #On declare un tableau de 720 valeur
elif cas=="4":
a=int(4032)*np.ones(sizc) #On declare un tableau de 720 valeur
print 'Value expected=',np.mean(a)
if np.array_equal(tab,a): #On teste la moyenne et le nombre donnees
print "Pattern ", cas, ": success."
return 1 #Renvoie la valeur de la variable cas
else:
print "Pattern ", cas, ": failed."
return 0 #renvoie 255
if __name__ == '__main__':
main()