-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaen_mapping.py
70 lines (70 loc) · 2.56 KB
/
caen_mapping.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
import numpy
from statistics import mean
class Map:
def __init__(self,mapFile,view=False):
with open(mapFile,'r') as f:
lines=f.read().split('\n')
mapping=[l.split(' ') for l in lines]
a=[len(l) for l in mapping]
averageColumn=sum(a)/len(a)
mapping=[m for m in mapping if len(m) >= averageColumn]
if view:
print(mapFile)
for i in mapping:
print(' '.join(i))
print("")
self.columns=max([len(l) for l in mapping])
self.rows=len(mapping)
self.mapping=mapping
def getBounds(*args):
all=[]
reduced=[]
for arr_arr in args:
for arr in arr_arr.mapping:
for a in arr:
try:
all.append(int(a))
except:
pass
for item in all:
if item in reduced:
print("There is an issue with the mapping.")
print("The channel, {} appeared twice.".format(item))
response=""
while not (response.lower() in ['yes','no','y','n']):
response=input("Continue (y/n)? ")
if response.lower() in ['yes','y']:
print("bad idea...")
return
else:
quit(-1)
reduced.append(item)
def pulseDiff(self,minimums,maximums,n=None):
img=[[-1 for i in range(self.columns)] for j in range(self.rows)]
for j in range(self.rows):
for i in range(self.columns):
try:
chan=int(self.mapping[j][i])
if n is None:
diff=[maximums[chan][i] - minimums[chan][i] for i in range(len(minimums[chan]))]
img[j][i]=mean(diff)
else:
img[j][i]=maximums[chan][n] - minimums[chan][n]
except Exception as e:
#print(e)
img[j][i]=numpy.nan
return img
pass
def shape(self,values,n=None):
img=[[-1 for i in range(self.columns)] for j in range(self.rows)]
for j in range(self.rows):
for i in range(self.columns):
try:
chan=int(self.mapping[j][i])
if n is None:
img[j][i]=mean(values[chan])
else:
img[j][i]=values[chan][n]
except:
img[j][i]=numpy.nan
return img