diff --git a/examples/plot_offline_events.py b/examples/plot_offline_events.py index 4ae497d704952bf6e7afb31ef80ba0cba200cf95..35ac85d505a06334511e43a3d6bcf74b1d8c7821 100644 --- a/examples/plot_offline_events.py +++ b/examples/plot_offline_events.py @@ -9,12 +9,13 @@ Note: the offline file used here has MC offline data and was intentionaly reduce to 10 events. """ import km3io as ki +from km3net_testdata import data_path ##################################################### # First, pass a filename to the `OfflineReader` class to open the file. # Note that only some meta information is read into memory. -r = ki.OfflineReader("samples/numucc.root") +r = ki.OfflineReader(data_path("offline/numucc.root")) ##################################################### diff --git a/examples/plot_offline_hits.py b/examples/plot_offline_hits.py index a6f1c383393e7bbd6d01ee02f480ce1d9402828a..fab625d085692d82a121c28d32690b2d26f553e7 100644 --- a/examples/plot_offline_hits.py +++ b/examples/plot_offline_hits.py @@ -9,12 +9,13 @@ Note: the offline file used here has MC offline data and was intentionaly reduce to 10 events. """ import km3io as ki +from km3net_testdata import data_path ##################################################### # To access offline hits/mc_hits data: -mc_hits = ki.OfflineReader("samples/numucc.root").events.mc_hits -hits = ki.OfflineReader("samples/km3net_offline.root").events.hits +mc_hits = ki.OfflineReader(data_path("offline/numucc.root")).events.mc_hits +hits = ki.OfflineReader(data_path("offline/km3net_offline.root")).events.hits ##################################################### @@ -111,4 +112,4 @@ print(hits.channel_id[mask]) ##################################################### # or: -print(hits.dom_id[mask]) \ No newline at end of file +print(hits.dom_id[mask]) diff --git a/examples/plot_offline_tracks.py b/examples/plot_offline_tracks.py index d5bf65612c40a8fb2545fa8e1a89fb2163294013..42cf746ded71529f0eb43a4a3e8d6e2a14baf384 100644 --- a/examples/plot_offline_tracks.py +++ b/examples/plot_offline_tracks.py @@ -8,12 +8,13 @@ written by aanet software. Note: the offline files used here were intentionaly reduced to 10 events. """ import km3io as ki +from km3net_testdata import data_path ##################################################### # To access offline tracks/mc_tracks data: -mc_tracks = ki.OfflineReader("samples/numucc.root").events.mc_tracks -tracks = ki.OfflineReader("samples/km3net_offline.root").events.tracks +mc_tracks = ki.OfflineReader(data_path("offline/numucc.root")).events.mc_tracks +tracks = ki.OfflineReader(data_path("offline/km3net_offline.root")).events.tracks ##################################################### @@ -113,4 +114,4 @@ print(tracks.lik[mask]) ##################################################### # or: -print(tracks.dir_z[mask]) \ No newline at end of file +print(tracks.dir_z[mask]) diff --git a/examples/plot_offline_usr.py b/examples/plot_offline_usr.py index b74baa94c9e134310087201e2df1ec00bbf7d630..c335f49dfb0720adad356ceca7cd05eef9408561 100644 --- a/examples/plot_offline_usr.py +++ b/examples/plot_offline_usr.py @@ -8,12 +8,13 @@ interface. The available keys can be accessed either as attributes or via a dictionary lookup: """ import km3io as ki +from km3net_testdata import data_path ##################################################### # First, pass a filename to the `OfflineReader` class to open the file. # Note that only some meta information is read into memory. -r = ki.OfflineReader("samples/usr-sample.root") +r = ki.OfflineReader(data_path("offline/usr-sample.root")) ##################################################### diff --git a/examples/plot_online_example.py b/examples/plot_online_example.py index 2a1db9b276ec6513c8cde7953d061cffea100369..72a38ddfc9ccfefbe091d5a9632effa966c5c493 100644 --- a/examples/plot_online_example.py +++ b/examples/plot_online_example.py @@ -9,6 +9,7 @@ Such a file is usually called "KM3NET_00000001_00000002.root", where the first number is the detector ID and the second the run number. """ import km3io as ki +from km3net_testdata import data_path ##################################################### # Accessing the event tree @@ -17,7 +18,7 @@ import km3io as ki # with: -f = ki.OnlineReader("samples/km3net_online.root") +f = ki.OnlineReader(data_path("online/km3net_online.root")) ##################################################### # Note that only some meta information is read into memory. diff --git a/requirements-dev.txt b/requirements-dev.txt index 1194f7201631083dad1a65b976cfaed898dd468a..813d15aa1ea7686dc67509a88d2d8a37ed4fe294 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,4 @@ +km3net-testdata>=0.2.6 matplotlib memory_profiler numpydoc==0.9.2 diff --git a/tests/test_gseagen.py b/tests/test_gseagen.py index 9063c5f6009a6979d805a176359fe2a714fd93c0..842d006a17f5dfa003779ebfb8363475fadb986e 100644 --- a/tests/test_gseagen.py +++ b/tests/test_gseagen.py @@ -2,11 +2,11 @@ import os import re import unittest +from km3net_testdata import data_path + from km3io.gseagen import GSGReader -SAMPLES_DIR = os.path.join(os.path.dirname(__file__), "samples") -GSG_FILE = os.path.join(SAMPLES_DIR, "gseagen.root") -GSG_READER = GSGReader(GSG_FILE) +GSG_READER = GSGReader(data_path("gseagen/gseagen.root")) class TestGSGHeader(unittest.TestCase): @@ -56,7 +56,7 @@ class TestGSGHeader(unittest.TestCase): self.assertListEqual(self.header["NuList"].tolist(), [-14, 14]) def test_unsupported_header(self): - f = GSGReader(os.path.join(SAMPLES_DIR, "km3net_online.root")) + f = GSGReader(data_path("online/km3net_online.root")) with self.assertWarns(UserWarning): f.header diff --git a/tests/test_offline.py b/tests/test_offline.py index 4fb616b30f65c409f5af60fa92451b745b6ac221..f58e45adfe738a9cb449e37df040eb01f51e68b3 100644 --- a/tests/test_offline.py +++ b/tests/test_offline.py @@ -2,17 +2,15 @@ import unittest import numpy as np from pathlib import Path +from km3net_testdata import data_path + from km3io import OfflineReader from km3io.offline import _nested_mapper, Header -SAMPLES_DIR = Path(__file__).parent / 'samples' -OFFLINE_FILE = OfflineReader(SAMPLES_DIR / 'km3net_offline.root') -OFFLINE_USR = OfflineReader(SAMPLES_DIR / 'usr-sample.root') -OFFLINE_MC_TRACK_USR = OfflineReader( - SAMPLES_DIR / - 'mcv5.11r2.gsg_muonCChigherE-CC_50-5000GeV.km3_AAv1.jterbr00004695.jchain.aanet.498.root' -) -OFFLINE_NUMUCC = OfflineReader(SAMPLES_DIR / "numucc.root") # with mc data +OFFLINE_FILE = OfflineReader(data_path("offline/km3net_offline.root")) +OFFLINE_USR = OfflineReader(data_path("offline/usr-sample.root")) +OFFLINE_MC_TRACK_USR = OfflineReader(data_path('offline/mcv5.11r2.gsg_muonCChigherE-CC_50-5000GeV.km3_AAv1.jterbr00004695.jchain.aanet.498.root')) +OFFLINE_NUMUCC = OfflineReader(data_path("offline/numucc.root")) # with mc data class TestOfflineReader(unittest.TestCase): @@ -22,9 +20,9 @@ class TestOfflineReader(unittest.TestCase): self.n_events = 10 def test_context_manager(self): - filename = SAMPLES_DIR / 'km3net_offline.root' - with OfflineReader(filename) as r: - assert r._filename == filename + filename = OFFLINE_FILE + with OfflineReader(data_path("offline/km3net_offline.root")) as r: + assert r def test_number_events(self): assert self.n_events == len(self.r.events) diff --git a/tests/test_online.py b/tests/test_online.py index 45897b76a38f4f76a3bf068f1228d18eb80368b8..5cef172a24cd7fad5b225cb52f5bc489a2ab18f1 100644 --- a/tests/test_online.py +++ b/tests/test_online.py @@ -2,10 +2,11 @@ import os import re import unittest +from km3net_testdata import data_path + from km3io.online import OnlineReader, get_rate, has_udp_trailer, get_udp_max_sequence_number, get_channel_flags, get_number_udp_packets -SAMPLES_DIR = os.path.join(os.path.dirname(__file__), "samples") -ONLINE_FILE = os.path.join(SAMPLES_DIR, "km3net_online.root") +ONLINE_FILE = data_path("online/km3net_online.root") class TestOnlineReaderContextManager(unittest.TestCase): diff --git a/tests/test_tools.py b/tests/test_tools.py index b14f0aba6777c4f344fda81fc9a38146df31346a..ab6bbdb13e22be7af317fb838a348e6a0a261f92 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -3,16 +3,17 @@ import unittest import awkward1 as ak import numpy as np - from pathlib import Path + +from km3net_testdata import data_path + from km3io import OfflineReader from km3io.tools import (to_num, cached_property, unfold_indices, unique, uniquecount, fitinf, fitparams, count_nested, _find, mask, best_track, rec_types, get_w2list_param, get_multiplicity) -SAMPLES_DIR = Path(__file__).parent / 'samples' -OFFLINE_FILE = OfflineReader(SAMPLES_DIR / 'km3net_offline.root') +OFFLINE_FILE = OfflineReader(data_path("offline/km3net_offline.root")) # class TestGetw2listParam(unittest.TestCase): # def test_get_w2list_param(self):