Compare commits
2 commits
13536ea628
...
3a9ffadb86
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a9ffadb86 | ||
|
|
2415ecedcc |
2 changed files with 54 additions and 5 deletions
10
bananas.py
10
bananas.py
|
|
@ -1,15 +1,17 @@
|
|||
#! /usr/bin/python3
|
||||
|
||||
from seth_classes import Banana
|
||||
from seth_classes import ReadSeth
|
||||
import argparse
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
parser = argparse.ArgumentParser(prog='bananas.py')
|
||||
parser.add_argument('filepath')
|
||||
parser.add_argument( '-v', '--verbose', action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
fp = args.filepath
|
||||
v = args.verbose
|
||||
|
||||
def make_hist(dataframe, binsize = 100):
|
||||
mask_slice0 = dataframe['sl'] == '0'
|
||||
|
|
@ -19,6 +21,6 @@ def make_hist(dataframe, binsize = 100):
|
|||
print(slice0)
|
||||
|
||||
|
||||
test = Banana()
|
||||
make_hist(test.read_from_file(fp))
|
||||
|
||||
test = ReadSeth(fp, v)
|
||||
for event in test:
|
||||
print(event)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import numpy as np
|
|||
import pandas as pd
|
||||
|
||||
|
||||
class Banana():
|
||||
class Banana:
|
||||
|
||||
def read_from_file(self, filepath):
|
||||
d={'clock':[], 'sl':[], 'channel':[], 'dtime':[], 'lost':[], 'a':[], 'b':[], 'phase':[], 'banana':[], 'pha':[]} # slice (sl) is called det in ahepamfile.c
|
||||
|
|
@ -17,3 +17,50 @@ class Banana():
|
|||
d[keys[i]].append(contents[i+1])
|
||||
return pd.DataFrame(d)
|
||||
|
||||
|
||||
class ReadSeth:
|
||||
|
||||
def __init__(self, filename, verbose = False):
|
||||
self.verbose = verbose
|
||||
self.filename = filename
|
||||
self.file = open(filename, 'r')
|
||||
self.partial=[]
|
||||
self.complete=[]
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
e = self.read_more()
|
||||
while not self.complete:
|
||||
if not self.partial:
|
||||
raise StopIteration
|
||||
e = self.complete[0]
|
||||
self.complete[0:1]=[]
|
||||
return e
|
||||
|
||||
|
||||
time_old=100
|
||||
|
||||
def read_more(self):
|
||||
time_window = 5
|
||||
l = self.file.readline()
|
||||
if self.verbose:
|
||||
print(l, l[0])
|
||||
if l[0] == ' E':
|
||||
line = [float(num) for num in l.split(r'\s+')[1:]]
|
||||
print(line)
|
||||
if not self.partial or line[0] + time_window <= self.partial[0][0]:
|
||||
self.partial.append(line)
|
||||
self.read_more()
|
||||
self.complete.append(self.partial)
|
||||
self.partial = []
|
||||
|
||||
|
||||
class SethEvent:
|
||||
|
||||
def __init__(self):
|
||||
self.eventlines = []
|
||||
|
||||
def append_line(self, line: list):
|
||||
self.eventlines.append(line)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue