diff --git a/km3io/offline.py b/km3io/offline.py index 9c2726d853a2000164f23dab1739b3f7724c8bca..800ff05ac6282869faa40e01e911a923d64643ec 100644 --- a/km3io/offline.py +++ b/km3io/offline.py @@ -179,7 +179,7 @@ class OfflineKeys: 'JSTART_NPE_MIP', 'JSTART_NPE_MIP_TOTAL', 'JSTART_LENGTH_METRES', 'JVETO_NPE', 'JVETO_NUMBER_OF_HITS', 'JENERGY_MUON_RANGE_METRES', 'JENERGY_NOISE_LIKELIHOOD', - 'JENERGY_NDF', 'JENERGY_NUMBER_OF_HITS'] # 'JCOPY_Z_M' not anymore in Jpp + 'JENERGY_NDF', 'JENERGY_NUMBER_OF_HITS', 'JCOPY_Z_M'] return self._fit_keys @property @@ -432,7 +432,7 @@ class OfflineReader: a recarray of the best track fit data (reconstruction data). """ if self._best_reco is None: - keys = ", ".join(self.keys.fit_keys) + keys = ", ".join(self.keys.fit_keys[:-1]) empty_fit_info = np.array([match for match in self._find_empty(self.tracks.fitinf)]) fit_info = [i for i,j in zip(self.tracks.fitinf, @@ -495,7 +495,7 @@ class OfflineReader: ValueError raised when the reconstruction stages of interest are not found in the file. """ - keys = ", ".join(self.keys.fit_keys) + keys = ", ".join(self.keys.fit_keys[:-1]) fit_info = self.tracks.fitinf rec_stages = np.array([match for match in self._find_rec_stages(stages)]) @@ -520,7 +520,7 @@ class OfflineReader: list of reconstruction stages of interest. for example [1, 2, 3, 4, 5]. - Yields + Yieldsma ------ generator the track id and the index of the reconstruction stages of @@ -544,7 +544,8 @@ class OfflineReader: Parameters ---------- chunk_arr : Chunked array - Chunked array or jagged array of data of interest. + Chunked array or jagged array of data of interest. For example: + km3io.OfflineReader(my_file).tracks.fitinf . Yields ------ diff --git a/tests/test_offline.py b/tests/test_offline.py index e2835181f91b3e5d5e0ad9801280058e946bc655..b4a6ee8b3d9c4ba45a9a063f6a21ac81a9c86543 100644 --- a/tests/test_offline.py +++ b/tests/test_offline.py @@ -1,4 +1,5 @@ import unittest +import numpy as np from pathlib import Path from km3io.offline import Reader, OfflineEvents, OfflineHits, OfflineTracks @@ -115,6 +116,7 @@ class TestReader(unittest.TestCase): class TestOfflineReader(unittest.TestCase): def setUp(self): self.r = OfflineReader(OFFLINE_FILE) + self.nu = OfflineReader(OFFLINE_NUMUCC) self.Nevents = 10 self.selected_data = OfflineReader(OFFLINE_FILE, data=self.r._data[0])._data @@ -132,6 +134,57 @@ class TestOfflineReader(unittest.TestCase): # check that there are 10 events self.assertEqual(Nevents, self.Nevents) + def test_find_empty(self): + fitinf = self.nu.tracks.fitinf + rec_stages = self.nu.tracks.rec_stages + + empty_fitinf = np.array([match for match in + self.nu._find_empty(fitinf)]) + empty_stages = np.array([match for match in + self.nu._find_empty(rec_stages)]) + + self.assertListEqual(empty_fitinf[:5, 1].tolist(), [23, 14, + 14, 4, None]) + self.assertListEqual(empty_stages[:5, 1].tolist(), [False, False, + False, False, + None]) + + def test_find_rec_stages(self): + stages = np.array([match for match in + self.nu._find_rec_stages([1, 2, 3, 4, 5])]) + + self.assertListEqual(stages[:5, 1].tolist(), [0, 0, 0, 0, None]) + + def test_get_reco_fit(self): + JGANDALF_BETA0_RAD = [0.0020367251782607574, + 0.003306725805622178, + 0.0057877124222254885, + 0.015581698352185896] + reco_fit = self.nu.get_reco_fit([1, 2, 3, 4, 5])['JGANDALF_BETA0_RAD'] + + self.assertListEqual(JGANDALF_BETA0_RAD, reco_fit[:4].tolist()) + with self.assertRaises(ValueError): + self.nu.get_reco_fit([1000, 4512, 5625]) + + def test_get_max_reco_stages(self): + rec_stages = self.nu.tracks.rec_stages + max_reco = self.nu._get_max_reco_stages(rec_stages) + + self.assertEqual(len(max_reco.tolist()), 9) + self.assertListEqual(max_reco[0].tolist(), [[1, 2, 3, 4, 5], + 5, 0]) + + def test_best_reco(self): + JGANDALF_BETA1_RAD = [0.0014177681261476852, + 0.002094094517471032, + 0.003923368624980349, + 0.009491461076780453] + best = self.nu.best_reco + + self.assertEqual(best.size, 9) + self.assertEqual(best['JGANDALF_BETA1_RAD'][:4].tolist(), JGANDALF_BETA1_RAD) + + class TestOfflineEvents(unittest.TestCase): def setUp(self): @@ -325,14 +378,6 @@ class TestOfflineTracks(unittest.TestCase): list(tracks[_slice].E[:,0]) ) - def test_reco_data(self): - reco = self.tracks.reco - self.assertEqual(10, reco.size) - E = reco['JENERGY_ENERGY'] - self.assertListEqual([99.10458562488608, 99.10458562488608, 99.10458562488608], - E[:3].tolist()) - - class TestOfflineTrack(unittest.TestCase): def setUp(self):