def _read(self, file, det_file=None): if det_file is not None: cal = modules.DetApplier(det_file=det_file) else: cal = None if self.center_time or self.add_t0: time_pp = modules.TimePreproc( add_t0=self.add_t0, center_time=self.center_time, subtract_t0_mchits=self.subtract_t0_mchits, ) else: time_pp = None pump = kp.io.hdf5.HDF5Pump(filename=file) for i, blob in enumerate(pump): if i % 1000 == 0: print("Blob {}".format(i)) if cal is not None: blob = cal.process(blob) if time_pp is not None: blob = time_pp.process(blob) self.data = np.concatenate( [self.data, self._get_data_one_event(blob)]) pump.close()
def test_time_preproc_center(self): module = modules.TimePreproc(add_t0=False, center_time=True) target = { "Hits": kp.Table({ "time": [-1.0, 0.0, 1.0], "t0": [0.1, 0.2, 0.3], "triggered": [0, 1, 1], }) } out_blob = module.process(self.in_blob) self.assertSetEqual(set(out_blob.keys()), set(target.keys())) np.testing.assert_array_equal(np.array(out_blob["Hits"]), np.array(target["Hits"]))
def test_time_preproc_t0_and_center(self): module = modules.TimePreproc(add_t0=True, center_time=True) target = { "Hits": kp.Table({ 'time': [-1.1, 0., 1.1], "t0": [0.1, 0.2, 0.3], "triggered": [0, 1, 1], }) } out_blob = module.process(self.in_blob) self.assertSetEqual(set(out_blob.keys()), set(target.keys())) np.testing.assert_array_almost_equal( np.array(out_blob["Hits"].view("<f8")), np.array(target["Hits"].view("<f8")))