-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimpleanalysis.py
More file actions
59 lines (42 loc) · 1.43 KB
/
simpleanalysis.py
File metadata and controls
59 lines (42 loc) · 1.43 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
""" An example "analysis". """
import eventfile
import numpy as np
import matplotlib.pyplot as plt
# this line allows us to access the Django database:
from modulejournal import wsgi
from journal import models
from django.core.files import File
def main():
module = models.Module.objects.get(pk=2)
runs = models.RunEntry.objects.filter(module=module)
for inputrun in runs:
perform_analysis(inputrun)
def perform_analysis(inputrun: models.RunEntry):
filename = inputrun.data.path
with open(filename, 'rb') as f:
header, data = eventfile.read_event_file(f)
eventsize = 96
length = len(data)
summed = None
nevents = int(length/eventsize)
print(nevents)
summed = np.zeros((48,16))
for i in range(nevents):
thebytes = data[i*eventsize:i*eventsize+eventsize]
frame = np.frombuffer(thebytes, dtype=np.uint8)
hits = np.reshape(np.unpackbits(frame), newshape=(48, 16))
summed += hits
plt.imshow(summed)
plt.savefig("temp.png")
# plt.show()
with open("temp.png", 'rb') as f:
df = File(f)
tool = models.AnalysisTool.objects.get(name="SimpleAnalysis")
toolrun = models.ToolRun(tool=tool)
toolrun.save()
toolrun.inputRuns=[inputrun]
toolrun.save()
outputimage = models.OutputImage(image=df, toolrun=toolrun)
outputimage.save()
if __name__ == '__main__':
main()