legend-pydataobj 1.0.0__tar.gz → 1.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/PKG-INFO +1 -1
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/setup.cfg +6 -1
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/legend_pydataobj.egg-info/PKG-INFO +1 -1
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/legend_pydataobj.egg-info/SOURCES.txt +3 -0
- legend_pydataobj-1.1.1/src/legend_pydataobj.egg-info/entry_points.txt +2 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/legend_pydataobj.egg-info/requires.txt +2 -1
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/__init__.py +2 -1
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/_version.py +2 -2
- legend_pydataobj-1.1.1/src/lgdo/cli.py +68 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/lh5_store.py +12 -5
- legend_pydataobj-1.1.1/src/lgdo/logging.py +40 -0
- legend_pydataobj-1.1.1/tests/conftest.py +28 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/test_lh5_store.py +94 -61
- legend_pydataobj-1.0.0/tests/conftest.py +0 -54
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/LICENSE +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/README.md +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/pyproject.toml +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/setup.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/legend_pydataobj.egg-info/dependency_links.txt +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/legend_pydataobj.egg-info/not-zip-safe +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/legend_pydataobj.egg-info/top_level.txt +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/compression/__init__.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/compression/base.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/compression/generic.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/compression/radware.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/compression/utils.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/compression/varlen.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/lgdo_utils.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/__init__.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/array.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/arrayofequalsizedarrays.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/encoded.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/fixedsizearray.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/lgdo.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/scalar.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/struct.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/table.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/vectorofvectors.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/lgdo/types/waveform_table.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/compression/conftest.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/compression/sigcompress/LDQTA_r117_20200110T105115Z_cal_geds_raw-0.dat +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/compression/sigcompress/special-wf-clipped.dat +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/compression/test_compression.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/compression/test_radware_sigcompress.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/compression/test_str2wfcodec.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/compression/test_uleb128_zigzag_diff.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/test_lgdo_utils.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/test_lh5_iterator.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_array.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_arrayofequalsizedarrays.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_encoded.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_fixedsizearray.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_representations.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_scalar.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_struct.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_table.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_table_eval.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_vectorofvectors.py +0 -0
- {legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_waveform_table.py +0 -0
@@ -31,7 +31,8 @@ classifiers =
|
|
31
31
|
[options]
|
32
32
|
packages = find:
|
33
33
|
install_requires =
|
34
|
-
|
34
|
+
colorlog
|
35
|
+
h5py>=3.2
|
35
36
|
hdf5plugin
|
36
37
|
numba!=0.53.*,!=0.54.*
|
37
38
|
numexpr
|
@@ -48,6 +49,10 @@ zip_safe = False
|
|
48
49
|
[options.packages.find]
|
49
50
|
where = src
|
50
51
|
|
52
|
+
[options.entry_points]
|
53
|
+
console_scripts =
|
54
|
+
lh5ls = lgdo.cli:lh5ls
|
55
|
+
|
51
56
|
[options.extras_require]
|
52
57
|
all =
|
53
58
|
legend-pydataobj[docs,test]
|
@@ -6,13 +6,16 @@ setup.py
|
|
6
6
|
src/legend_pydataobj.egg-info/PKG-INFO
|
7
7
|
src/legend_pydataobj.egg-info/SOURCES.txt
|
8
8
|
src/legend_pydataobj.egg-info/dependency_links.txt
|
9
|
+
src/legend_pydataobj.egg-info/entry_points.txt
|
9
10
|
src/legend_pydataobj.egg-info/not-zip-safe
|
10
11
|
src/legend_pydataobj.egg-info/requires.txt
|
11
12
|
src/legend_pydataobj.egg-info/top_level.txt
|
12
13
|
src/lgdo/__init__.py
|
13
14
|
src/lgdo/_version.py
|
15
|
+
src/lgdo/cli.py
|
14
16
|
src/lgdo/lgdo_utils.py
|
15
17
|
src/lgdo/lh5_store.py
|
18
|
+
src/lgdo/logging.py
|
16
19
|
src/lgdo/compression/__init__.py
|
17
20
|
src/lgdo/compression/base.py
|
18
21
|
src/lgdo/compression/generic.py
|
@@ -38,6 +38,7 @@ browsed easily in python like any `HDF5 <https://www.hdfgroup.org>`_ file using
|
|
38
38
|
`h5py <https://www.h5py.org>`_.
|
39
39
|
"""
|
40
40
|
|
41
|
+
from ._version import version as __version__
|
41
42
|
from .lh5_store import LH5Iterator, LH5Store, load_dfs, load_nda, ls, show
|
42
43
|
from .types import (
|
43
44
|
LGDO,
|
@@ -71,5 +72,5 @@ __all__ = [
|
|
71
72
|
"load_nda",
|
72
73
|
"ls",
|
73
74
|
"show",
|
74
|
-
"
|
75
|
+
"__version__",
|
75
76
|
]
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"""Command line interface utilities."""
|
2
|
+
from __future__ import annotations
|
3
|
+
|
4
|
+
import argparse
|
5
|
+
import sys
|
6
|
+
|
7
|
+
from . import __version__, logging, show
|
8
|
+
|
9
|
+
|
10
|
+
def lh5ls():
|
11
|
+
"""``lh5ls`` console command.
|
12
|
+
|
13
|
+
To learn more, have a look at the help section:
|
14
|
+
|
15
|
+
.. code-block:: console
|
16
|
+
|
17
|
+
$ lh5ls --help
|
18
|
+
"""
|
19
|
+
|
20
|
+
parser = argparse.ArgumentParser(
|
21
|
+
prog="lh5ls", description="Inspect LEGEND HDF5 (LH5) file contents"
|
22
|
+
)
|
23
|
+
|
24
|
+
# global options
|
25
|
+
parser.add_argument(
|
26
|
+
"--version", action="store_true", help="""Print the program version and exit"""
|
27
|
+
)
|
28
|
+
parser.add_argument(
|
29
|
+
"--verbose",
|
30
|
+
"-v",
|
31
|
+
action="store_true",
|
32
|
+
help="""Increase the program verbosity""",
|
33
|
+
)
|
34
|
+
parser.add_argument(
|
35
|
+
"--debug",
|
36
|
+
"-d",
|
37
|
+
action="store_true",
|
38
|
+
help="""Increase the program verbosity to maximum""",
|
39
|
+
)
|
40
|
+
|
41
|
+
# show options
|
42
|
+
parser.add_argument(
|
43
|
+
"lh5_file",
|
44
|
+
help="""Input LH5 file.""",
|
45
|
+
)
|
46
|
+
parser.add_argument("lh5_group", nargs="?", help="""LH5 group.""", default="/")
|
47
|
+
parser.add_argument(
|
48
|
+
"--attributes",
|
49
|
+
"-a",
|
50
|
+
action="store_true",
|
51
|
+
default=False,
|
52
|
+
help="""Print HDF5 attributes too""",
|
53
|
+
)
|
54
|
+
|
55
|
+
args = parser.parse_args()
|
56
|
+
|
57
|
+
if args.verbose:
|
58
|
+
logging.setup(logging.DEBUG)
|
59
|
+
elif args.debug:
|
60
|
+
logging.setup(logging.DEBUG, logging.root)
|
61
|
+
else:
|
62
|
+
logging.setup()
|
63
|
+
|
64
|
+
if args.version:
|
65
|
+
print(__version__) # noqa: T201
|
66
|
+
sys.exit()
|
67
|
+
|
68
|
+
show(args.lh5_file, args.lh5_group, attrs=args.attributes)
|
@@ -1287,9 +1287,11 @@ def show(
|
|
1287
1287
|
if dtype == "no datatype" and isinstance(val, h5py.Group):
|
1288
1288
|
dtype = "HDF5 group"
|
1289
1289
|
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1290
|
+
_attrs = ""
|
1291
|
+
if attrs:
|
1292
|
+
attrs_d = dict(val.attrs)
|
1293
|
+
attrs_d.pop("datatype", "")
|
1294
|
+
_attrs = "── " + str(attrs_d) if attrs_d else ""
|
1293
1295
|
|
1294
1296
|
# is this the last key?
|
1295
1297
|
killme = False
|
@@ -1301,11 +1303,16 @@ def show(
|
|
1301
1303
|
else:
|
1302
1304
|
char = "├──"
|
1303
1305
|
|
1304
|
-
print(f"{indent}{char} \033[1m{key}\033[0m · {dtype} {
|
1306
|
+
print(f"{indent}{char} \033[1m{key}\033[0m · {dtype} {_attrs}") # noqa: T201
|
1305
1307
|
|
1306
1308
|
# if it's a group, call this function recursively
|
1307
1309
|
if isinstance(val, h5py.Group):
|
1308
|
-
show(
|
1310
|
+
show(
|
1311
|
+
val,
|
1312
|
+
indent=indent + (" " if killme else "│ "),
|
1313
|
+
header=False,
|
1314
|
+
attrs=attrs,
|
1315
|
+
)
|
1309
1316
|
|
1310
1317
|
# break or move to next key
|
1311
1318
|
if killme:
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"""This module implements some helpers for setting up logging."""
|
2
|
+
import logging
|
3
|
+
|
4
|
+
import colorlog
|
5
|
+
|
6
|
+
DEBUG = logging.DEBUG
|
7
|
+
INFO = logging.INFO
|
8
|
+
WARNING = logging.WARNING
|
9
|
+
ERROR = logging.ERROR
|
10
|
+
FATAL = logging.FATAL
|
11
|
+
CRITICAL = logging.CRITICAL
|
12
|
+
|
13
|
+
|
14
|
+
def setup(level: int = logging.INFO, logger: logging.Logger = None) -> None:
|
15
|
+
"""Setup a colorful logging output.
|
16
|
+
|
17
|
+
If `logger` is None, sets up only the ``pygama`` logger.
|
18
|
+
|
19
|
+
Parameters
|
20
|
+
----------
|
21
|
+
level
|
22
|
+
logging level (see :mod:`logging` module).
|
23
|
+
logger
|
24
|
+
if not `None`, setup this logger.
|
25
|
+
|
26
|
+
Examples
|
27
|
+
--------
|
28
|
+
>>> from pygama import logging
|
29
|
+
>>> logging.setup(level=logging.DEBUG)
|
30
|
+
"""
|
31
|
+
handler = colorlog.StreamHandler()
|
32
|
+
handler.setFormatter(
|
33
|
+
colorlog.ColoredFormatter("%(log_color)s%(name)s [%(levelname)s] %(message)s")
|
34
|
+
)
|
35
|
+
|
36
|
+
if logger is None:
|
37
|
+
logger = colorlog.getLogger("pygama")
|
38
|
+
|
39
|
+
logger.setLevel(level)
|
40
|
+
logger.addHandler(handler)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import os
|
2
|
+
import shutil
|
3
|
+
import uuid
|
4
|
+
from getpass import getuser
|
5
|
+
from tempfile import gettempdir
|
6
|
+
|
7
|
+
import pytest
|
8
|
+
from legendtestdata import LegendTestData
|
9
|
+
|
10
|
+
_tmptestdir = os.path.join(gettempdir(), f"lgdo-tests-{getuser()}-{str(uuid.uuid4())}")
|
11
|
+
|
12
|
+
|
13
|
+
@pytest.fixture(scope="session")
|
14
|
+
def tmptestdir():
|
15
|
+
os.mkdir(_tmptestdir)
|
16
|
+
return _tmptestdir
|
17
|
+
|
18
|
+
|
19
|
+
def pytest_sessionfinish(session, exitstatus):
|
20
|
+
if exitstatus == 0:
|
21
|
+
shutil.rmtree(_tmptestdir)
|
22
|
+
|
23
|
+
|
24
|
+
@pytest.fixture(scope="session")
|
25
|
+
def lgnd_test_data():
|
26
|
+
ldata = LegendTestData()
|
27
|
+
ldata.checkout("c089a59")
|
28
|
+
return ldata
|
@@ -33,13 +33,13 @@ def test_gimme_file(lgnd_file):
|
|
33
33
|
store.gimme_file("non-existent-file")
|
34
34
|
|
35
35
|
|
36
|
-
def test_gimme_group(lgnd_file):
|
36
|
+
def test_gimme_group(lgnd_file, tmptestdir):
|
37
37
|
f = h5py.File(lgnd_file)
|
38
38
|
store = LH5Store()
|
39
39
|
g = store.gimme_group("/geds", f)
|
40
40
|
assert isinstance(g, h5py.Group)
|
41
41
|
|
42
|
-
f = h5py.File("/
|
42
|
+
f = h5py.File(f"{tmptestdir}/testfile.lh5", mode="w")
|
43
43
|
g = store.gimme_group("/geds", f, grp_attrs={"attr1": 1}, overwrite=True)
|
44
44
|
assert isinstance(g, h5py.Group)
|
45
45
|
|
@@ -95,7 +95,7 @@ def test_load_dfs(lgnd_file):
|
|
95
95
|
|
96
96
|
|
97
97
|
@pytest.fixture(scope="module")
|
98
|
-
def lh5_file():
|
98
|
+
def lh5_file(tmptestdir):
|
99
99
|
store = LH5Store()
|
100
100
|
|
101
101
|
struct = lgdo.Struct()
|
@@ -161,7 +161,7 @@ def lh5_file():
|
|
161
161
|
store.write_object(
|
162
162
|
struct,
|
163
163
|
"struct",
|
164
|
-
"/tmp
|
164
|
+
f"{tmptestdir}/tmp-pygama-lgdo-types.lh5",
|
165
165
|
group="/data",
|
166
166
|
start_row=1,
|
167
167
|
n_rows=3,
|
@@ -171,12 +171,12 @@ def lh5_file():
|
|
171
171
|
store.write_object(
|
172
172
|
struct,
|
173
173
|
"struct_full",
|
174
|
-
"/tmp
|
174
|
+
f"{tmptestdir}/tmp-pygama-lgdo-types.lh5",
|
175
175
|
group="/data",
|
176
176
|
wo_mode="append",
|
177
177
|
)
|
178
178
|
|
179
|
-
return "/tmp
|
179
|
+
return f"{tmptestdir}/tmp-pygama-lgdo-types.lh5"
|
180
180
|
|
181
181
|
|
182
182
|
def test_write_objects(lh5_file):
|
@@ -477,17 +477,17 @@ def test_read_lgnd_waveform_table_fancy_idx(lgnd_file):
|
|
477
477
|
|
478
478
|
|
479
479
|
@pytest.fixture(scope="module")
|
480
|
-
def enc_lgnd_file(lgnd_file):
|
480
|
+
def enc_lgnd_file(lgnd_file, tmptestdir):
|
481
481
|
store = LH5Store()
|
482
482
|
wft, n_rows = store.read_object("/geds/raw/waveform", lgnd_file)
|
483
483
|
wft.values.attrs["compression"] = RadwareSigcompress(codec_shift=-32768)
|
484
484
|
store.write_object(
|
485
485
|
wft,
|
486
486
|
"/geds/raw/waveform",
|
487
|
-
"/tmp
|
487
|
+
f"{tmptestdir}/tmp-pygama-compressed-wfs.lh5",
|
488
488
|
wo_mode="overwrite_file",
|
489
489
|
)
|
490
|
-
return "/tmp
|
490
|
+
return f"{tmptestdir}/tmp-pygama-compressed-wfs.lh5"
|
491
491
|
|
492
492
|
|
493
493
|
def test_write_compressed_lgnd_waveform_table(enc_lgnd_file):
|
@@ -502,21 +502,24 @@ def test_read_compressed_lgnd_waveform_table(lgnd_file, enc_lgnd_file):
|
|
502
502
|
|
503
503
|
|
504
504
|
# First test that we can overwrite a table with the same name without deleting the original field
|
505
|
-
def test_write_object_overwrite_table_no_deletion(caplog):
|
505
|
+
def test_write_object_overwrite_table_no_deletion(caplog, tmptestdir):
|
506
506
|
caplog.set_level(logging.DEBUG)
|
507
507
|
caplog.clear()
|
508
508
|
|
509
|
-
if os.path.exists("/
|
510
|
-
os.remove("/
|
509
|
+
if os.path.exists(f"{tmptestdir}/write_object_overwrite_test.lh5"):
|
510
|
+
os.remove(f"{tmptestdir}/write_object_overwrite_test.lh5")
|
511
511
|
|
512
512
|
tb1 = lh5.Table(col_dict={"dset1": lh5.Array(np.zeros(10))})
|
513
513
|
tb2 = lh5.Table(
|
514
514
|
col_dict={"dset1": lh5.Array(np.ones(10))}
|
515
515
|
) # Same field name, different values
|
516
516
|
store = LH5Store()
|
517
|
-
store.write_object(tb1, "my_group", "/
|
517
|
+
store.write_object(tb1, "my_group", f"{tmptestdir}/write_object_overwrite_test.lh5")
|
518
518
|
store.write_object(
|
519
|
-
tb2,
|
519
|
+
tb2,
|
520
|
+
"my_group",
|
521
|
+
f"{tmptestdir}/write_object_overwrite_test.lh5",
|
522
|
+
wo_mode="overwrite",
|
520
523
|
) # Now, try to overwrite the same field
|
521
524
|
|
522
525
|
# If the old field is deleted from the file before writing the new field, then we would get an extra debug statement
|
@@ -525,39 +528,46 @@ def test_write_object_overwrite_table_no_deletion(caplog):
|
|
525
528
|
]
|
526
529
|
|
527
530
|
# Now, check that the data were overwritten
|
528
|
-
tb_dat, _ = store.read_object(
|
531
|
+
tb_dat, _ = store.read_object(
|
532
|
+
"my_group", f"{tmptestdir}/write_object_overwrite_test.lh5"
|
533
|
+
)
|
529
534
|
assert np.array_equal(tb_dat["dset1"].nda, np.ones(10))
|
530
535
|
|
531
536
|
|
532
537
|
# Second: test that when we overwrite a table with fields with a different name, we delete the original field
|
533
|
-
def test_write_object_overwrite_table_with_deletion(caplog):
|
538
|
+
def test_write_object_overwrite_table_with_deletion(caplog, tmptestdir):
|
534
539
|
caplog.set_level(logging.DEBUG)
|
535
540
|
caplog.clear()
|
536
541
|
|
537
|
-
if os.path.exists("/
|
538
|
-
os.remove("/
|
542
|
+
if os.path.exists(f"{tmptestdir}/write_object_overwrite_test.lh5"):
|
543
|
+
os.remove(f"{tmptestdir}/write_object_overwrite_test.lh5")
|
539
544
|
|
540
545
|
tb1 = lh5.Table(col_dict={"dset1": lh5.Array(np.zeros(10))})
|
541
546
|
tb2 = lh5.Table(
|
542
547
|
col_dict={"dset2": lh5.Array(np.ones(10))}
|
543
548
|
) # Same field name, different values
|
544
549
|
store = LH5Store()
|
545
|
-
store.write_object(tb1, "my_group", "/
|
550
|
+
store.write_object(tb1, "my_group", f"{tmptestdir}/write_object_overwrite_test.lh5")
|
546
551
|
store.write_object(
|
547
|
-
tb2,
|
552
|
+
tb2,
|
553
|
+
"my_group",
|
554
|
+
f"{tmptestdir}/write_object_overwrite_test.lh5",
|
555
|
+
wo_mode="overwrite",
|
548
556
|
) # Now, try to overwrite with a different field
|
549
557
|
|
550
558
|
# Now, check that the data were overwritten
|
551
|
-
tb_dat, _ = store.read_object(
|
559
|
+
tb_dat, _ = store.read_object(
|
560
|
+
"my_group", f"{tmptestdir}/write_object_overwrite_test.lh5"
|
561
|
+
)
|
552
562
|
assert np.array_equal(tb_dat["dset2"].nda, np.ones(10))
|
553
563
|
|
554
564
|
# Also make sure that the first table's fields aren't lurking around the lh5 file!
|
555
|
-
with h5py.File("/
|
565
|
+
with h5py.File(f"{tmptestdir}/write_object_overwrite_test.lh5", "r") as lh5file:
|
556
566
|
assert "dset1" not in list(lh5file["my_group"].keys())
|
557
567
|
|
558
568
|
# Make sure the same behavior happens when we nest the table in a group
|
559
|
-
if os.path.exists("/
|
560
|
-
os.remove("/
|
569
|
+
if os.path.exists(f"{tmptestdir}/write_object_overwrite_test.lh5"):
|
570
|
+
os.remove(f"{tmptestdir}/write_object_overwrite_test.lh5")
|
561
571
|
|
562
572
|
tb1 = lh5.Table(col_dict={"dset1": lh5.Array(np.zeros(10))})
|
563
573
|
tb2 = lh5.Table(
|
@@ -565,35 +575,38 @@ def test_write_object_overwrite_table_with_deletion(caplog):
|
|
565
575
|
) # Same field name, different values
|
566
576
|
store = LH5Store()
|
567
577
|
store.write_object(
|
568
|
-
tb1,
|
578
|
+
tb1,
|
579
|
+
"my_table",
|
580
|
+
f"{tmptestdir}/write_object_overwrite_test.lh5",
|
581
|
+
group="my_group",
|
569
582
|
)
|
570
583
|
store.write_object(
|
571
584
|
tb2,
|
572
585
|
"my_table",
|
573
|
-
"/
|
586
|
+
f"{tmptestdir}/write_object_overwrite_test.lh5",
|
574
587
|
group="my_group",
|
575
588
|
wo_mode="overwrite",
|
576
589
|
) # Now, try to overwrite with a different field
|
577
590
|
|
578
591
|
# Now, check that the data were overwritten
|
579
592
|
tb_dat, _ = store.read_object(
|
580
|
-
"my_group/my_table", "/
|
593
|
+
"my_group/my_table", f"{tmptestdir}/write_object_overwrite_test.lh5"
|
581
594
|
)
|
582
595
|
assert np.array_equal(tb_dat["dset2"].nda, np.ones(10))
|
583
596
|
|
584
597
|
# Also make sure that the first table's fields aren't lurking around the lh5 file!
|
585
|
-
with h5py.File("/
|
598
|
+
with h5py.File(f"{tmptestdir}/write_object_overwrite_test.lh5", "r") as lh5file:
|
586
599
|
assert "dset1" not in list(lh5file["my_group/my_table"].keys())
|
587
600
|
|
588
601
|
|
589
602
|
# Third: test that when we overwrite other LGDO classes
|
590
|
-
def test_write_object_overwrite_lgdo(caplog):
|
603
|
+
def test_write_object_overwrite_lgdo(caplog, tmptestdir):
|
591
604
|
caplog.set_level(logging.DEBUG)
|
592
605
|
caplog.clear()
|
593
606
|
|
594
607
|
# Start with an lgdo.WaveformTable
|
595
|
-
if os.path.exists("/
|
596
|
-
os.remove("/
|
608
|
+
if os.path.exists(f"{tmptestdir}/write_object_overwrite_test.lh5"):
|
609
|
+
os.remove(f"{tmptestdir}/write_object_overwrite_test.lh5")
|
597
610
|
|
598
611
|
tb1 = lh5.WaveformTable(
|
599
612
|
t0=np.zeros(10),
|
@@ -613,12 +626,15 @@ def test_write_object_overwrite_lgdo(caplog):
|
|
613
626
|
) # Same field name, different values
|
614
627
|
store = LH5Store()
|
615
628
|
store.write_object(
|
616
|
-
tb1,
|
629
|
+
tb1,
|
630
|
+
"my_table",
|
631
|
+
f"{tmptestdir}/write_object_overwrite_test.lh5",
|
632
|
+
group="my_group",
|
617
633
|
)
|
618
634
|
store.write_object(
|
619
635
|
tb2,
|
620
636
|
"my_table",
|
621
|
-
"/
|
637
|
+
f"{tmptestdir}/write_object_overwrite_test.lh5",
|
622
638
|
wo_mode="overwrite",
|
623
639
|
group="my_group",
|
624
640
|
)
|
@@ -630,7 +646,7 @@ def test_write_object_overwrite_lgdo(caplog):
|
|
630
646
|
|
631
647
|
# Now, check that the data were overwritten
|
632
648
|
tb_dat, _ = store.read_object(
|
633
|
-
"my_group/my_table", "/
|
649
|
+
"my_group/my_table", f"{tmptestdir}/write_object_overwrite_test.lh5"
|
634
650
|
)
|
635
651
|
assert np.array_equal(tb_dat["values"].nda, np.ones((10, 10)))
|
636
652
|
|
@@ -638,17 +654,21 @@ def test_write_object_overwrite_lgdo(caplog):
|
|
638
654
|
array1 = lh5.Array(nda=np.zeros(10))
|
639
655
|
array2 = lh5.Array(nda=np.ones(20))
|
640
656
|
store = LH5Store()
|
641
|
-
store.write_object(
|
657
|
+
store.write_object(
|
658
|
+
array1, "my_array", f"{tmptestdir}/write_object_overwrite_test.lh5"
|
659
|
+
)
|
642
660
|
store.write_object(
|
643
661
|
array2,
|
644
662
|
"my_array",
|
645
|
-
"/
|
663
|
+
f"{tmptestdir}/write_object_overwrite_test.lh5",
|
646
664
|
wo_mode="overwrite",
|
647
665
|
write_start=5,
|
648
666
|
)
|
649
667
|
|
650
668
|
# Now, check that the data were overwritten
|
651
|
-
array_dat, _ = store.read_object(
|
669
|
+
array_dat, _ = store.read_object(
|
670
|
+
"my_array", f"{tmptestdir}/write_object_overwrite_test.lh5"
|
671
|
+
)
|
652
672
|
expected_out_array = np.append(np.zeros(5), np.ones(20))
|
653
673
|
|
654
674
|
assert np.array_equal(array_dat.nda, expected_out_array)
|
@@ -657,17 +677,19 @@ def test_write_object_overwrite_lgdo(caplog):
|
|
657
677
|
scalar1 = lh5.Scalar(0)
|
658
678
|
scalar2 = lh5.Scalar(1)
|
659
679
|
store = LH5Store()
|
660
|
-
store.write_object(
|
680
|
+
store.write_object(
|
681
|
+
scalar1, "my_scalar", f"{tmptestdir}/write_object_overwrite_test.lh5"
|
682
|
+
)
|
661
683
|
store.write_object(
|
662
684
|
scalar2,
|
663
685
|
"my_scalar",
|
664
|
-
"/
|
686
|
+
f"{tmptestdir}/write_object_overwrite_test.lh5",
|
665
687
|
wo_mode="overwrite",
|
666
688
|
)
|
667
689
|
|
668
690
|
# Now, check that the data were overwritten
|
669
691
|
scalar_dat, _ = store.read_object(
|
670
|
-
"my_scalar", "/
|
692
|
+
"my_scalar", f"{tmptestdir}/write_object_overwrite_test.lh5"
|
671
693
|
)
|
672
694
|
|
673
695
|
assert scalar_dat.value == 1
|
@@ -676,17 +698,19 @@ def test_write_object_overwrite_lgdo(caplog):
|
|
676
698
|
vov1 = lh5.VectorOfVectors(listoflists=[np.zeros(1), np.ones(2), np.zeros(3)])
|
677
699
|
vov2 = lh5.VectorOfVectors(listoflists=[np.ones(1), np.zeros(2), np.ones(3)])
|
678
700
|
store = LH5Store()
|
679
|
-
store.write_object(
|
701
|
+
store.write_object(
|
702
|
+
vov1, "my_vector", f"{tmptestdir}/write_object_overwrite_test.lh5"
|
703
|
+
)
|
680
704
|
store.write_object(
|
681
705
|
vov2,
|
682
706
|
"my_vector",
|
683
|
-
"/
|
707
|
+
f"{tmptestdir}/write_object_overwrite_test.lh5",
|
684
708
|
wo_mode="overwrite",
|
685
709
|
write_start=1,
|
686
710
|
) # start overwriting the second list of lists
|
687
711
|
|
688
712
|
vector_dat, _ = store.read_object(
|
689
|
-
"my_vector", "/
|
713
|
+
"my_vector", f"{tmptestdir}/write_object_overwrite_test.lh5"
|
690
714
|
)
|
691
715
|
|
692
716
|
assert np.array_equal(vector_dat.cumulative_length.nda, [1, 2, 4, 7])
|
@@ -694,20 +718,22 @@ def test_write_object_overwrite_lgdo(caplog):
|
|
694
718
|
|
695
719
|
|
696
720
|
# Test that when we try to overwrite an existing column in a table we fail
|
697
|
-
def test_write_object_append_column():
|
721
|
+
def test_write_object_append_column(tmptestdir):
|
698
722
|
# Try to append an array to a table
|
699
|
-
if os.path.exists("/
|
700
|
-
os.remove("/
|
723
|
+
if os.path.exists(f"{tmptestdir}/write_object_append_column_test.lh5"):
|
724
|
+
os.remove(f"{tmptestdir}/write_object_append_column_test.lh5")
|
701
725
|
|
702
726
|
array1 = lh5.Array(np.zeros(10))
|
703
727
|
tb1 = lh5.Table(col_dict={"dset1`": lh5.Array(np.ones(10))})
|
704
728
|
store = LH5Store()
|
705
|
-
store.write_object(
|
729
|
+
store.write_object(
|
730
|
+
array1, "my_table", f"{tmptestdir}/write_object_append_column_test.lh5"
|
731
|
+
)
|
706
732
|
with pytest.raises(RuntimeError) as exc_info:
|
707
733
|
store.write_object(
|
708
734
|
tb1,
|
709
735
|
"my_table",
|
710
|
-
"/
|
736
|
+
f"{tmptestdir}/write_object_append_column_test.lh5",
|
711
737
|
wo_mode="append_column",
|
712
738
|
) # Now, try to append a column to an array
|
713
739
|
|
@@ -717,8 +743,8 @@ def test_write_object_append_column():
|
|
717
743
|
)
|
718
744
|
|
719
745
|
# Try to append a table that has a same key as the old table
|
720
|
-
if os.path.exists("/
|
721
|
-
os.remove("/
|
746
|
+
if os.path.exists(f"{tmptestdir}/write_object_append_column_test.lh5"):
|
747
|
+
os.remove(f"{tmptestdir}/write_object_append_column_test.lh5")
|
722
748
|
|
723
749
|
tb1 = lh5.Table(
|
724
750
|
col_dict={"dset1": lh5.Array(np.zeros(10)), "dset2": lh5.Array(np.zeros(10))}
|
@@ -727,12 +753,14 @@ def test_write_object_append_column():
|
|
727
753
|
col_dict={"dset2": lh5.Array(np.ones(10))}
|
728
754
|
) # Same field name, different values
|
729
755
|
store = LH5Store()
|
730
|
-
store.write_object(
|
756
|
+
store.write_object(
|
757
|
+
tb1, "my_table", f"{tmptestdir}/write_object_append_column_test.lh5"
|
758
|
+
)
|
731
759
|
with pytest.raises(ValueError) as exc_info:
|
732
760
|
store.write_object(
|
733
761
|
tb2,
|
734
762
|
"my_table",
|
735
|
-
"/
|
763
|
+
f"{tmptestdir}/write_object_append_column_test.lh5",
|
736
764
|
wo_mode="append_column",
|
737
765
|
) # Now, try to append a column with a same field
|
738
766
|
|
@@ -743,20 +771,22 @@ def test_write_object_append_column():
|
|
743
771
|
)
|
744
772
|
|
745
773
|
# try appending a column that is larger than one that exists
|
746
|
-
if os.path.exists("/
|
747
|
-
os.remove("/
|
774
|
+
if os.path.exists(f"{tmptestdir}/write_object_append_column_test.lh5"):
|
775
|
+
os.remove(f"{tmptestdir}/write_object_append_column_test.lh5")
|
748
776
|
|
749
777
|
tb1 = lh5.Table(col_dict={"dset1": lh5.Array(np.zeros(10))})
|
750
778
|
tb2 = lh5.Table(
|
751
779
|
col_dict={"dset2": lh5.Array(np.ones(20))}
|
752
780
|
) # different field name, different size
|
753
781
|
store = LH5Store()
|
754
|
-
store.write_object(
|
782
|
+
store.write_object(
|
783
|
+
tb1, "my_table", f"{tmptestdir}/write_object_append_column_test.lh5"
|
784
|
+
)
|
755
785
|
with pytest.raises(ValueError) as exc_info:
|
756
786
|
store.write_object(
|
757
787
|
tb2,
|
758
788
|
"my_table",
|
759
|
-
"/
|
789
|
+
f"{tmptestdir}/write_object_append_column_test.lh5",
|
760
790
|
wo_mode="append_column",
|
761
791
|
) # Now, try to append a column with a different field size
|
762
792
|
|
@@ -767,8 +797,8 @@ def test_write_object_append_column():
|
|
767
797
|
)
|
768
798
|
|
769
799
|
# Finally successfully append a column
|
770
|
-
if os.path.exists("/
|
771
|
-
os.remove("/
|
800
|
+
if os.path.exists(f"{tmptestdir}/write_object_append_column_test.lh5"):
|
801
|
+
os.remove(f"{tmptestdir}/write_object_append_column_test.lh5")
|
772
802
|
|
773
803
|
tb1 = lh5.Table(col_dict={"dset1": lh5.Array(np.zeros(10))})
|
774
804
|
tb2 = lh5.Table(
|
@@ -776,19 +806,22 @@ def test_write_object_append_column():
|
|
776
806
|
) # different field name, different size
|
777
807
|
store = LH5Store()
|
778
808
|
store.write_object(
|
779
|
-
tb1,
|
809
|
+
tb1,
|
810
|
+
"my_table",
|
811
|
+
f"{tmptestdir}/write_object_append_column_test.lh5",
|
812
|
+
group="my_group",
|
780
813
|
)
|
781
814
|
store.write_object(
|
782
815
|
tb2,
|
783
816
|
"my_table",
|
784
|
-
"/
|
817
|
+
f"{tmptestdir}/write_object_append_column_test.lh5",
|
785
818
|
group="my_group",
|
786
819
|
wo_mode="append_column",
|
787
820
|
)
|
788
821
|
|
789
822
|
# Now, check that the data were appended
|
790
823
|
tb_dat, _ = store.read_object(
|
791
|
-
"my_group/my_table", "/
|
824
|
+
"my_group/my_table", f"{tmptestdir}/write_object_append_column_test.lh5"
|
792
825
|
)
|
793
826
|
assert isinstance(tb_dat, lgdo.Table)
|
794
827
|
assert np.array_equal(tb_dat["dset1"].nda, np.zeros(10))
|
@@ -1,54 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import shutil
|
3
|
-
import uuid
|
4
|
-
from getpass import getuser
|
5
|
-
from tempfile import gettempdir
|
6
|
-
|
7
|
-
import pytest
|
8
|
-
from legendtestdata import LegendTestData
|
9
|
-
|
10
|
-
_tmptestdir = os.path.join(
|
11
|
-
gettempdir(), "pygama-tests-" + getuser() + str(uuid.uuid4())
|
12
|
-
)
|
13
|
-
|
14
|
-
|
15
|
-
@pytest.fixture(scope="session")
|
16
|
-
def tmptestdir():
|
17
|
-
os.mkdir(_tmptestdir)
|
18
|
-
yield _tmptestdir
|
19
|
-
shutil.rmtree(_tmptestdir)
|
20
|
-
|
21
|
-
|
22
|
-
def pytest_sessionfinish(session, exitstatus):
|
23
|
-
if exitstatus is True:
|
24
|
-
os.rmdir(_tmptestdir)
|
25
|
-
|
26
|
-
|
27
|
-
@pytest.fixture(scope="session")
|
28
|
-
def lgnd_test_data():
|
29
|
-
ldata = LegendTestData()
|
30
|
-
ldata.checkout("c089a59")
|
31
|
-
return ldata
|
32
|
-
|
33
|
-
|
34
|
-
# @pytest.fixture(scope="session")
|
35
|
-
# def multich_raw_file(lgnd_test_data):
|
36
|
-
# out_file = "/tmp/L200-comm-20211130-phy-spms.lh5"
|
37
|
-
# out_spec = {
|
38
|
-
# "FCEventDecoder": {
|
39
|
-
# "ch{key}": {
|
40
|
-
# "key_list": [[0, 6]],
|
41
|
-
# "out_stream": out_file + ":{name}",
|
42
|
-
# "out_name": "raw",
|
43
|
-
# }
|
44
|
-
# }
|
45
|
-
# }
|
46
|
-
|
47
|
-
# build_raw(
|
48
|
-
# in_stream=lgnd_test_data.get_path("fcio/L200-comm-20211130-phy-spms.fcio"),
|
49
|
-
# out_spec=out_spec,
|
50
|
-
# overwrite=True,
|
51
|
-
# )
|
52
|
-
# assert os.path.exists(out_file)
|
53
|
-
|
54
|
-
# return out_file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/legend_pydataobj.egg-info/dependency_links.txt
RENAMED
File without changes
|
{legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/legend_pydataobj.egg-info/not-zip-safe
RENAMED
File without changes
|
{legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/src/legend_pydataobj.egg-info/top_level.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/compression/test_radware_sigcompress.py
RENAMED
File without changes
|
File without changes
|
{legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/compression/test_uleb128_zigzag_diff.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{legend_pydataobj-1.0.0 → legend_pydataobj-1.1.1}/tests/types/test_arrayofequalsizedarrays.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|