reboost 0.6.1__py3-none-any.whl → 0.7.0__py3-none-any.whl

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.
reboost/utils.py CHANGED
@@ -9,6 +9,7 @@ from collections.abc import Iterable, Mapping
9
9
  from contextlib import contextmanager
10
10
  from pathlib import Path
11
11
 
12
+ import h5py
12
13
  from dbetto import AttrsDict
13
14
  from lgdo import lh5
14
15
  from lgdo.types import Struct, Table, VectorOfVectors
@@ -51,7 +52,9 @@ def get_wo_mode(
51
52
  chunk
52
53
  the chunk index
53
54
  new_hit_file
54
- a flag of whether we are writing a new hit file
55
+ a flag of whether we are writing a new hit file. This does not indicate whether
56
+ the file already exists on disk, but whether the file name is different from the
57
+ last written chunk for this detector.
55
58
  overwrite
56
59
  a flag of whether to overwrite the old file.
57
60
 
@@ -75,6 +78,49 @@ def get_wo_mode(
75
78
  return "append"
76
79
 
77
80
 
81
+ def get_wo_mode_forwarded(
82
+ written_tables: set[str], new_hit_file: bool, overwrite: bool = False
83
+ ) -> str:
84
+ """Get the mode for lh5 file writing for forwarded tables tahat will be copied without chunking.
85
+
86
+ If we are writing a new output file and no other tables had been written yet, then
87
+ the mode "overwrite_file" is used if the overwrite flag is set, otherwise the mode
88
+ "write_safe" is used.
89
+
90
+ Otherwise "append" is used.
91
+
92
+ Parameters
93
+ ----------
94
+ written_tables
95
+ a set of already written table names, also including other table names of
96
+ non-forwarded (i.e. processed) tables.
97
+ new_hit_file
98
+ a flag of whether we are writing a new hit file. This does not indicate whether
99
+ the file already exists on disk, but whether the file name is different from the
100
+ last written chunk for this forwarded table.
101
+ overwrite
102
+ a flag of whether to overwrite the old file.
103
+
104
+ Returns
105
+ -------
106
+ the mode for IO
107
+ """
108
+ if not new_hit_file:
109
+ return "append"
110
+ if overwrite and len(written_tables) == 0:
111
+ return "overwrite_file"
112
+ return "write_safe"
113
+
114
+
115
+ def is_new_hit_file(files: AttrsDict, file_idx: int) -> bool:
116
+ """Return whether the hit file with the given index is a "new" hit file.
117
+
118
+ A new file is either the first file written, or when the previous file index has a
119
+ different file name.
120
+ """
121
+ return (file_idx == 0) or (files.hit[file_idx] != files.hit[file_idx - 1])
122
+
123
+
78
124
  def get_file_dict(
79
125
  stp_files: list[str] | str,
80
126
  glm_files: list[str] | str | None,
@@ -119,7 +165,7 @@ def get_file_dict(
119
165
  files = {}
120
166
 
121
167
  for file_type, file_list in zip(
122
- ["stp", "glm", "hit"], [stp_files, glm_files_list, hit_files_list]
168
+ ["stp", "glm", "hit"], [stp_files, glm_files_list, hit_files_list], strict=True
123
169
  ):
124
170
  if isinstance(file_list, str):
125
171
  files[file_type] = [file_list]
@@ -258,7 +304,10 @@ def get_function_string(expr: str, aliases: dict | None = None) -> tuple[str, di
258
304
  globs = globs | {
259
305
  package: importlib.import_module(package_import),
260
306
  }
261
- except Exception:
307
+ except Exception as e:
308
+ # for imports of our own package, raise the error back to the user
309
+ if package_import == "reboost":
310
+ raise e
262
311
  msg = f"Function {package_import} cannot be imported"
263
312
  log.debug(msg)
264
313
  continue
@@ -394,3 +443,61 @@ def write_lh5(
394
443
  )
395
444
  if time_dict is not None:
396
445
  time_dict.update_field("write", start_time)
446
+
447
+
448
+ def get_remage_detector_uids(h5file: str | Path) -> dict:
449
+ """Get mapping of detector names to UIDs from a remage output file.
450
+
451
+ The remage LH5 output files contain a link structure that lets the user
452
+ access detector tables by UID. For example:
453
+
454
+ .. code-block:: text
455
+
456
+ ├── stp · struct{det1,det2,optdet1,optdet2,scint1,scint2}
457
+ └── __by_uid__ · struct{det001,det002,det011,det012,det101,det102}
458
+ ├── det001 -> /stp/scint1
459
+ ├── det002 -> /stp/scint2
460
+ ├── det011 -> /stp/det1
461
+ ├── det012 -> /stp/det2
462
+ ├── det101 -> /stp/optdet1
463
+ └── det102 -> /stp/optdet2
464
+
465
+ This function analyzes this structure and returns:
466
+
467
+ .. code-block:: text
468
+
469
+ {1: 'scint1',
470
+ 2: 'scint2',
471
+ 11: 'det1',
472
+ 12: 'det2',
473
+ 101: 'optdet1',
474
+ 102: 'optdet2'g
475
+
476
+ Parameters
477
+ ----------
478
+ h5file
479
+ path to remage output file.
480
+ """
481
+ if isinstance(h5file, Path):
482
+ h5file = h5file.as_posix()
483
+
484
+ out = {}
485
+ with h5py.File(h5file, "r") as f:
486
+ g = f["/stp/__by_uid__"]
487
+ # loop over links
488
+ for key in g:
489
+ # is this a link?
490
+ link = g.get(key, getlink=True)
491
+ if isinstance(link, h5py.SoftLink):
492
+ m = re.fullmatch(r"det(\d+)", key)
493
+ if m is None:
494
+ msg = rf"'{key}' is not formatted as expected, i.e. 'det(\d+)', skipping"
495
+ log.warning(msg)
496
+ continue
497
+
498
+ # get the name of the link target without trailing groups (to
499
+ # i.e. remove /stp)
500
+ name = link.path.split("/")[-1]
501
+
502
+ out[int(m.group(1))] = name
503
+ return out
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reboost
3
- Version: 0.6.1
3
+ Version: 0.7.0
4
4
  Summary: New LEGEND Monte-Carlo simulation post-processing
5
5
  Author-email: Manuel Huber <info@manuelhu.de>, Toby Dixon <toby.dixon.23@ucl.ac.uk>, Luigi Pertoldi <gipert@pm.me>
6
6
  Maintainer: The LEGEND Collaboration
@@ -693,7 +693,7 @@ Classifier: Programming Language :: Python
693
693
  Classifier: Programming Language :: Python :: 3
694
694
  Classifier: Programming Language :: Python :: 3 :: Only
695
695
  Classifier: Topic :: Scientific/Engineering
696
- Requires-Python: >=3.9
696
+ Requires-Python: >=3.10
697
697
  Description-Content-Type: text/markdown
698
698
  License-File: LICENSE
699
699
  Requires-Dist: hdf5plugin
@@ -701,8 +701,8 @@ Requires-Dist: colorlog
701
701
  Requires-Dist: numpy
702
702
  Requires-Dist: scipy
703
703
  Requires-Dist: numba
704
- Requires-Dist: legend-pydataobj>=1.14
705
- Requires-Dist: legend-pygeom-optics>=0.9.2
704
+ Requires-Dist: legend-pydataobj>=1.15.1
705
+ Requires-Dist: legend-pygeom-optics>=0.12.0
706
706
  Requires-Dist: legend-pygeom-tools>=0.0.11
707
707
  Requires-Dist: hist
708
708
  Requires-Dist: dbetto
@@ -0,0 +1,42 @@
1
+ reboost/__init__.py,sha256=VZz9uo7i2jgAx8Zi15SptLZnE_qcnGuNWwqkD3rYHFA,278
2
+ reboost/_version.py,sha256=uLbRjFSUZAgfl7V7O8zKV5Db36k7tz87ZIVq3l2SWs0,704
3
+ reboost/build_evt.py,sha256=VXIfK_pfe_Cgym6gI8dESwONZi-v_4fll0Pn09vePQY,3767
4
+ reboost/build_glm.py,sha256=IerSLQfe51ZO7CQP2kmfPnOIVaDtcfw3byOM02Vaz6o,9472
5
+ reboost/build_hit.py,sha256=pjEaiPW63Q3MfpjI29uJXx9gtwfiOIgOcADRDrDpRrA,17409
6
+ reboost/cli.py,sha256=68EzKiWTHJ2u1RILUv7IX9HaVq6nTTM80_W_MUnWRe4,6382
7
+ reboost/core.py,sha256=wIIDxaPzEaozZOeKabz4l-29_IyY47RbNy6qS8Bai1Y,15297
8
+ reboost/iterator.py,sha256=qlEqRv5qOh8eIs-dyVOLYTvH-ZpQDx9fLckpcAdtWjs,6975
9
+ reboost/log_utils.py,sha256=VqS_9OC5NeNU3jcowVOBB0NJ6ssYvNWnirEY-JVduEA,766
10
+ reboost/profile.py,sha256=EOTmjmS8Rm_nYgBWNh6Rntl2XDsxdyed7yEdWtsZEeg,2598
11
+ reboost/units.py,sha256=LUwl6swLQoG09Rt9wcDdu6DTrwDsy-C751BNGzX4sz8,3651
12
+ reboost/utils.py,sha256=SfrqWdQZPNXw0x0DVucxHC5OwFXewM43tO-PNnIwjKI,14562
13
+ reboost/daq/__init__.py,sha256=rNPhxx1Yawt3tENYhmOYSum9_TdV57ZU5kjxlWFAGuo,107
14
+ reboost/daq/core.py,sha256=Rs6Q-17fzEod2iX_2WqEmnqKnNRFoWTYURl3wYhFihU,9915
15
+ reboost/daq/utils.py,sha256=KcH6zvlInmD2YiF6V--DSYBTYudJw3G-hp2JGOcES2o,1042
16
+ reboost/hpge/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ reboost/hpge/psd.py,sha256=P9lxji4njwFwPBR0vfh6gkvt7GQx2BRajvCsUUmtEqU,24407
18
+ reboost/hpge/surface.py,sha256=ROewOsSoq8zRAaiamWdMDl-UR7ZfsimgH2Lv9k0flKg,8494
19
+ reboost/hpge/utils.py,sha256=AcMS86v8s0SbeC4YA3CfH73GBZcC7Sb_RR3pRPjWAwU,2857
20
+ reboost/math/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
+ reboost/math/functions.py,sha256=OymiYTcA0NXxxm-MBDw5kqyNwHoLCmuv4J48AwnSrbU,5633
22
+ reboost/math/stats.py,sha256=Rq4Wdzv-3aoSK7EsPZCuOEHfnOz3w0moIzCEHbC07xw,3173
23
+ reboost/optmap/__init__.py,sha256=imvuyld-GLw8qdwqW-lXCg2feptcTyQo3wIzPvDHwmY,93
24
+ reboost/optmap/cli.py,sha256=CoH0P_WLEek1T9zxmlsM2TuxxzqobP-W-ym72uhxrO4,10252
25
+ reboost/optmap/convolve.py,sha256=9fM5zVKkwp03a3kqBwWppe1UOGdVm1Q6yF4P0v2I8VQ,22936
26
+ reboost/optmap/create.py,sha256=qwUvYiUotmLCrB6RsfwxRMGI4EYRn7Q4XlwppUTVZTE,18166
27
+ reboost/optmap/evt.py,sha256=UrjjNNeS7Uie4Ah9y_f5PyroFutLGo5aOFcwReOEy7o,5556
28
+ reboost/optmap/mapview.py,sha256=73kpe0_SKDj9bIhEx1ybX1sBP8TyvufiLfps84A_ijA,6798
29
+ reboost/optmap/numba_pdg.py,sha256=y8cXR5PWE2Liprp4ou7vl9do76dl84vXU52ZJD9_I7A,731
30
+ reboost/optmap/optmap.py,sha256=f8Y0zLmXZyOz4-GDUPViIY_vf_shY3ZQG9lSD31J8gc,12820
31
+ reboost/shape/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
+ reboost/shape/cluster.py,sha256=nwR1Dnf00SDICGPqpXeM1Q7_DwTtO9uP3wmuML45c3g,8195
33
+ reboost/shape/group.py,sha256=gOCYgir2gZqmW1JXtbNRPlQqP0gmUcbe7RVb9CbY1pU,5540
34
+ reboost/shape/reduction.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
+ reboost/spms/__init__.py,sha256=ffi0rH-ZFGmpURbFt-HY1ZAHCdady0mLXNsblRNh-JY,207
36
+ reboost/spms/pe.py,sha256=9KWmc4fGW5_bx4imsguLm-xp6rokt89iZcM-WD62Tj4,3090
37
+ reboost-0.7.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
38
+ reboost-0.7.0.dist-info/METADATA,sha256=-CFo2D7zHSJXcSsfMQtXIv8T4nx3qoR4OMD6EbaKLU0,44226
39
+ reboost-0.7.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
40
+ reboost-0.7.0.dist-info/entry_points.txt,sha256=DxhD6BidSWNot9BrejHJjQ7RRLmrMaBIl52T75oWTwM,93
41
+ reboost-0.7.0.dist-info/top_level.txt,sha256=q-IBsDepaY_AbzbRmQoW8EZrITXRVawVnNrB-_zyXZs,8
42
+ reboost-0.7.0.dist-info/RECORD,,
@@ -1,37 +0,0 @@
1
- reboost/__init__.py,sha256=VZz9uo7i2jgAx8Zi15SptLZnE_qcnGuNWwqkD3rYHFA,278
2
- reboost/_version.py,sha256=a3_WODLDfpmAw3pMw7qGqmRuXHTCC3STyQd2R1iEOgA,511
3
- reboost/build_evt.py,sha256=VXIfK_pfe_Cgym6gI8dESwONZi-v_4fll0Pn09vePQY,3767
4
- reboost/build_glm.py,sha256=IerSLQfe51ZO7CQP2kmfPnOIVaDtcfw3byOM02Vaz6o,9472
5
- reboost/build_hit.py,sha256=23JL5B7qThdHZqAK_HWoytqcEOWDhGsk4n5UMtojJ1c,15513
6
- reboost/cli.py,sha256=HZgqUZK0tSmnlGqoXjrbmLitW_i001TzibxvDrRxLLg,6324
7
- reboost/core.py,sha256=WGbWe2rcfMDEaehVyw7peqAHoTFWoCu5J6CdWHC5aWA,14974
8
- reboost/iterator.py,sha256=fATFDxu2PUc0e48OdJJujZo2kwykfRLH1oBtcB-s5pM,6905
9
- reboost/log_utils.py,sha256=VqS_9OC5NeNU3jcowVOBB0NJ6ssYvNWnirEY-JVduEA,766
10
- reboost/profile.py,sha256=EOTmjmS8Rm_nYgBWNh6Rntl2XDsxdyed7yEdWtsZEeg,2598
11
- reboost/units.py,sha256=3EH8XlpbsObdu5vLgxhm1600L6UNYD5jng4SjJT_1QE,2202
12
- reboost/utils.py,sha256=WT2jlyRT3LEMBEBRJtYIat3KIIZKocv4rHlTViBbhYM,10938
13
- reboost/hpge/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- reboost/hpge/psd.py,sha256=jAUAoQ_PMz76wyA1NXYHNKtOwoCnRT3My8_LCFrKi-U,13860
15
- reboost/hpge/surface.py,sha256=lbWcFnFFWKxtFKs755GyM9US_IfyxaoM6MpOIZgIMM0,7478
16
- reboost/hpge/utils.py,sha256=0Rx4HubCOm8JMECjWcAJXfAch9OkSlRpUkdsSlzwZ2E,2830
17
- reboost/math/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- reboost/math/functions.py,sha256=OymiYTcA0NXxxm-MBDw5kqyNwHoLCmuv4J48AwnSrbU,5633
19
- reboost/math/stats.py,sha256=cG-6mQx33Dzpv3ABkHLEwC104WJ_PMgbWtmjg37SBj4,3164
20
- reboost/optmap/__init__.py,sha256=imvuyld-GLw8qdwqW-lXCg2feptcTyQo3wIzPvDHwmY,93
21
- reboost/optmap/cli.py,sha256=N8J2Hd8m_csYU9CtpAp7Rc3LHy6eNzZ26gWZgHCiUso,10250
22
- reboost/optmap/convolve.py,sha256=x7boLDcBJIsontoB0yemvzHSE2hlRpUomlDXc3jqdr4,14668
23
- reboost/optmap/create.py,sha256=_6GZbdRvmjDFs6DDbWC-THZxaNPUiLAOIDNaigMKJSQ,18139
24
- reboost/optmap/evt.py,sha256=UrjjNNeS7Uie4Ah9y_f5PyroFutLGo5aOFcwReOEy7o,5556
25
- reboost/optmap/mapview.py,sha256=73kpe0_SKDj9bIhEx1ybX1sBP8TyvufiLfps84A_ijA,6798
26
- reboost/optmap/numba_pdg.py,sha256=y8cXR5PWE2Liprp4ou7vl9do76dl84vXU52ZJD9_I7A,731
27
- reboost/optmap/optmap.py,sha256=j4rfbQ84PYSpE-BvP4Rdt96ZjPdwy8P4e4eZz1mATys,12817
28
- reboost/shape/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
- reboost/shape/cluster.py,sha256=RIvBlhHzp88aaUZGofp5SD9bimnoiqIOddhQ84jiwoM,8135
30
- reboost/shape/group.py,sha256=gOCYgir2gZqmW1JXtbNRPlQqP0gmUcbe7RVb9CbY1pU,5540
31
- reboost/shape/reduction.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
- reboost-0.6.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
33
- reboost-0.6.1.dist-info/METADATA,sha256=T1TyULoQ01tNoZcuF1tfWdmG2WsV53DQuKCldpPEHRw,44222
34
- reboost-0.6.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
- reboost-0.6.1.dist-info/entry_points.txt,sha256=DxhD6BidSWNot9BrejHJjQ7RRLmrMaBIl52T75oWTwM,93
36
- reboost-0.6.1.dist-info/top_level.txt,sha256=q-IBsDepaY_AbzbRmQoW8EZrITXRVawVnNrB-_zyXZs,8
37
- reboost-0.6.1.dist-info/RECORD,,