def event_setup(data_directory): if data_directory is None: return None Event_Setup = namedtuple( "Event_Setup", [ "data_directory", "event_file_path", "event_list", "fpos", "f", "t", "y", "x", ], ) event_file_path = os.path.join( data_directory, "reduce", "DAQ_2012-01-20T21-50-32", "DATASET_0", "EOS.bin", ) with open(event_file_path, "rb") as f: event_list, fpos = _cevent._cevents(f) f, t, y, x = event_list stp = Event_Setup(data_directory, event_file_path, event_list, fpos, f, t, y, x) return stp
def test_open_with_path(self, event_setup): # give the event reader a file path event_list, fpos = _cevent._cevents(event_setup.event_file_path, max_frames=10) f, t, y, x = event_list max_f = np.max(f) assert_equal(9, max_f)
def events(f, end_last_event=127, max_frames=None): """ Unpacks event data from packedbinary format for the ANSTO Platypus instrument Parameters ---------- f : file-like or str The file to read the data from. If `f` is not file-like then f is assumed to be a path pointing to the event file. end_last_event : uint The reading of event data starts from `end_last_event + 1`. The default of 127 corresponds to a file header that is 128 bytes long. max_frames : None, int Stop reading the event file when have read this many frames. If `None` then read all frames Returns ------- (f_events, t_events, y_events, x_events), end_events: x_events, y_events, t_events and f_events are numpy arrays containing the events. end_events is an array containing the byte offset to the end of the last successful event read from the file. Use this value to extract more events from the same file at a future date. """ if HAVE_CEVENTS: return _cevents(f, end_last_event=end_last_event, max_frames=max_frames) else: raise RuntimeError("Event streaming code not available")
def events(f, end_last_event=127, max_frames=np.inf): """ Unpacks event data from packedbinary format for the ANSTO Platypus instrument Parameters ---------- f : file-like or str The file to read the data from. If `f` is not file-like then f is assumed to be a path pointing to the event file. end_last_event : uint The reading of event data starts from `end_last_event + 1`. The default of 127 corresponds to a file header that is 128 bytes long. max_frames : int Stop reading the event file when have read this many frames. Returns ------- (f_events, t_events, y_events, x_events), end_last_event: x_events, y_events, t_events and f_events are numpy arrays containing the events. end_last_event is a byte offset to the end of the last successful event read from the file. Use this value to extract more events from the same file at a future date. """ if HAVE_CEVENTS: return _cevents(f, end_last_event=end_last_event, max_frames=max_frames) else: return _events(f, end_last_event=end_last_event, max_frames=max_frames)
def test_max_frames(self, event_setup): # test reading only a certain number of frames if HAVE_CEVENTS: with open(event_setup.event_file_path, "rb") as g: event_list, fpos = _cevent._cevents(g, max_frames=10) cyf, cyt, cyy, cyx = event_list max_f = np.max(cyf) assert_equal(9, max_f) event_list, fpos = _cevent._cevents(event_setup.event_file_path, max_frames=10) cyf, cyt, cyy, cyx = event_list max_f = np.max(cyf) assert_equal(9, max_f)
def test_cevents(self): # check that the cython cevents reader also reads the event file # accurately. if HAVE_CEVENTS: with open(self.event_file_path, 'rb') as f: event_list, fpos = _cevent._cevents(f) f, t, y, x = event_list assert_equal(self.t, t) assert_equal(self.f, f) assert_equal(self.y, y) assert_equal(self.x, x)
def setup_class(cls): path = os.path.dirname(os.path.realpath(__file__)) cls.event_file_path = os.path.join(path, 'DAQ_2012-01-20T21-50-32', 'DATASET_0', 'EOS.bin') with open(cls.event_file_path, 'rb') as f: if HAVE_CEVENTS: event_list, fpos = _cevent._cevents(f) else: event_list, fpos = event._events(f) cls.event_list = event_list cls.fpos = fpos cls.f, cls.t, cls.y, cls.x = event_list
def test_max_frames(self): # test reading only a certain number of frames # also use this test to compare pure python read of events with open(self.event_file_path, 'rb') as g: event_list, fpos = event._events(g, max_frames=10) f, t, y, x = event_list max_f = np.max(f) assert_equal(9, max_f) if HAVE_CEVENTS: with open(self.event_file_path, 'rb') as g: event_list, fpos = _cevent._cevents(g, max_frames=10) cyf, cyt, cyy, cyx = event_list max_f = np.max(cyf) assert_equal(9, max_f) assert_equal(cyf, f) assert_equal(cyt, t) assert_equal(cyy, y) assert_equal(cyx, x)