Coverage for src/km3dq_grl/__init__.py: 36%
39 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-18 16:16 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-18 16:16 +0000
1import atexit
2import sys
4try:
5 from importlib.metadata import version as get_version
6 version = get_version(__name__)
7except ImportError:
8 from pkg_resources import get_distribution
9 version = get_distribution(__name__).version
11from .calc import Calculator
14if sys.version_info < (3, 9):
15 import importlib_resources
17 try:
18 from importlib_resources import as_file
19 except ImportError:
20 from importlib_resources.trees import as_file
21else:
22 import importlib.resources as importlib_resources
23 from importlib.resources import as_file
25try:
26 from contextlib import ExitStack
27except ImportError:
28 from contextlib2 import ExitStack
31###############################################################################
32def get_site(det):
33 """Return the site of a detector"""
34 if "ARCA" in det:
35 return "ARCA"
37 return "ORCA"
40###############################################################################
41def defect_path(defect_type, defect_descr, det, defect_tag):
42 """Return the absolute filepath for a given defect"""
43 rel_path = (
44 f"{get_site(det)}/{det}/Defects/"
45 f"{defect_type}_{defect_descr}_{defect_tag}.txt"
46 )
47 ref = importlib_resources.files("km3dq_grl") / rel_path
49 file_manager = ExitStack()
50 atexit.register(file_manager.close)
51 file_path = file_manager.enter_context(as_file(ref))
52 return str(file_path)
55###############################################################################
56def fact_path(fact_type, det):
57 """Return the absolute filepath for a given defect"""
58 rel_path = f"{get_site(det)}/{det}/Facts/{fact_type}.txt"
59 ref = importlib_resources.files("km3dq_grl") / rel_path
61 file_manager = ExitStack()
62 atexit.register(file_manager.close)
63 file_path = file_manager.enter_context(as_file(ref))
64 return str(file_path)