Commit 68dd4a91 authored by Remy Moll's avatar Remy Moll
Browse files

This is going to break a few things

parent 1e469036
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is stored in LFS. You can view the blob instead.
......@@ -9,7 +9,7 @@ based on decode.C by Dmitry Hits
"""
import sys, os
from numpy import array, uint32, cumsum, roll, zeros, float32, save, load
from numpy import array, mat, uint32, cumsum, roll, zeros, float32, save, load
from struct import unpack
......@@ -189,27 +189,40 @@ class ArrayLoader:
"""
def __init__(self, base_path) -> None:
self.converter = BinaryConverter()
self.converted_path_base = base_path + "data_converted/data{}.npy"
self.binary_path_base = base_path + "data{}.dat"
self.voltage_placeholder = "_v{}"
self.events_placeholder = "_e{}"
self.delay_placeholder = "_d{}"
self.base_path = base_path
self.fuzzy_base = "data"
def get_data(self, voltage, events=0, delay=0):
f_extension = self.voltage_placeholder.format(voltage)
fname_fuzzy = ""
fname_fuzzy += self.fuzzy_base + "_v{}".format(voltage)
if events != 0:
f_extension += self.events_placeholder.format(events)
if delay != 0:
f_extension += self.delay_placeholder.format(delay)
fname_fuzzy += "e_{}".format(events)
if delay != 0:
fname_fuzzy += "d_{}".format(delay)
fname_converted = self.converted_path_base.format(f_extension)
fname_binary = self.binary_path_base.format(f_extension)
if not os.path.exists(fname_converted):
# If the file was never converted before, do it once and save it to the data_converted directory. Only then proceed to the loading
converted = self.converter.convert(fname_binary)
return load(fname_converted)
files = os.listdir(self.base_path)
matches = []
for f in files:
if fname_fuzzy in f:
matches.append(f)
if len(matches) > 1:
print("Warning: The measurement file was not unambiguous. Please specify more arguments")
return
elif len(matches) == 0:
print("Warning: No data found.")
return
else:
fname = self.base_path + matches[0]
fname_converted = fname.replace(self.base_path, self.base_path + "data_converted/").replace(".dat", ".npy")
# change /data/... to /data/data_converted and change .dat to .npy
if not os.path.exists(fname_converted):
# If the file was never converted before, do it once and save it to the data_converted directory. Only then proceed to the loading
converted = self.converter.convert(fname)
return load(fname_converted), voltage, events, delay
......
......@@ -73,12 +73,13 @@ class Event:
class Measurement:
def __init__(self, cathode_voltage, n_events, delay, nbins, min_good_channels) -> None:
def __init__(self, cathode_voltage, n_events=0, delay=0, nbins=0, min_good_channels=6) -> None:
loaded, cathode_voltage, n_events, delay = DECODER.get_data(cathode_voltage, events=n_events, delay=delay)
self.cathode_voltage = cathode_voltage
self.delay = delay
self.events = []
loaded = DECODER.get_data(self.cathode_voltage, events=n_events, delay=self.delay)
for i in range(loaded.shape[0]): # no. of events:
self.events.append(Event(loaded[i,...], nbins, min_good_channels))
del loaded
......@@ -88,7 +89,9 @@ class Measurement:
def filter_events(self):
keep = [e for e in self.events if e.is_usable]
self.events = keep
old_len = self.n_events
self.n_events = len(keep)
print("Kept {}/{} elements.".format(self.n_events, old_len))
def get_peak_timings(self):
......
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment