legend-dataflow-scripts 0.1.4__tar.gz → 0.1.6__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.
Files changed (45) hide show
  1. {legend_dataflow_scripts-0.1.4/src/legend_dataflow_scripts.egg-info → legend_dataflow_scripts-0.1.6}/PKG-INFO +1 -1
  2. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6/src/legend_dataflow_scripts.egg-info}/PKG-INFO +1 -1
  3. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/_version.py +2 -2
  4. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/dsp/eopt.py +4 -1
  5. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/hit/aoe.py +1 -0
  6. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/hit/ecal.py +62 -23
  7. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/hit/lq.py +4 -3
  8. legend_dataflow_scripts-0.1.6/src/legenddataflowscripts/utils/alias_table.py +55 -0
  9. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/utils/convert_np.py +1 -1
  10. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/workflow/execenv.py +7 -1
  11. legend_dataflow_scripts-0.1.4/src/legenddataflowscripts/utils/alias_table.py +0 -28
  12. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/LICENSE +0 -0
  13. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/README.md +0 -0
  14. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/pyproject.toml +0 -0
  15. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/setup.cfg +0 -0
  16. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legend_dataflow_scripts.egg-info/SOURCES.txt +0 -0
  17. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legend_dataflow_scripts.egg-info/dependency_links.txt +0 -0
  18. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legend_dataflow_scripts.egg-info/entry_points.txt +0 -0
  19. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legend_dataflow_scripts.egg-info/not-zip-safe +0 -0
  20. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legend_dataflow_scripts.egg-info/requires.txt +0 -0
  21. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legend_dataflow_scripts.egg-info/top_level.txt +0 -0
  22. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/__init__.py +0 -0
  23. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/__init__.py +0 -0
  24. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/__init__.py +0 -0
  25. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/dsp/__init__.py +0 -0
  26. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/dsp/dplms.py +0 -0
  27. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/dsp/evtsel.py +0 -0
  28. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/dsp/nopt.py +0 -0
  29. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/dsp/pz.py +0 -0
  30. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/dsp/svm.py +0 -0
  31. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/dsp/svm_build.py +0 -0
  32. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/hit/__init__.py +0 -0
  33. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/par/geds/hit/qc.py +0 -0
  34. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/tier/__init__.py +0 -0
  35. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/tier/dsp.py +0 -0
  36. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/tier/hit.py +0 -0
  37. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/utils/__init__.py +0 -0
  38. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/utils/cfgtools.py +0 -0
  39. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/utils/log.py +0 -0
  40. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/utils/plot_dict.py +0 -0
  41. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/utils/pulser_removal.py +0 -0
  42. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/workflow/__init__.py +0 -0
  43. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/workflow/filedb.py +0 -0
  44. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/workflow/pre_compile_catalog.py +0 -0
  45. {legend_dataflow_scripts-0.1.4 → legend_dataflow_scripts-0.1.6}/src/legenddataflowscripts/workflow/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: legend-dataflow-scripts
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Python package for the processing scripts for LEGEND-200 data
5
5
  Author-email: George Marshall <ggmarsh@uw.edu>, Luigi Pertoldi <gipert@pm.me>
6
6
  Maintainer: The LEGEND Collaboration
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: legend-dataflow-scripts
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Python package for the processing scripts for LEGEND-200 data
5
5
  Author-email: George Marshall <ggmarsh@uw.edu>, Luigi Pertoldi <gipert@pm.me>
6
6
  Maintainer: The LEGEND Collaboration
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.1.4'
21
- __version_tuple__ = version_tuple = (0, 1, 4)
20
+ __version__ = version = '0.1.6'
21
+ __version_tuple__ = version_tuple = (0, 1, 6)
@@ -23,7 +23,10 @@ from pygama.pargen.dsp_optimize import (
23
23
  from ....utils import build_log
24
24
 
25
25
  warnings.filterwarnings(action="ignore", category=RuntimeWarning)
26
- warnings.filterwarnings(action="ignore", category=np.exceptions.RankWarning)
26
+ try:
27
+ warnings.filterwarnings(action="ignore", category=np.exceptions.RankWarning)
28
+ except AttributeError: # np < 2
29
+ warnings.filterwarnings(action="ignore", category=np.RankWarning)
27
30
 
28
31
 
29
32
  def par_geds_dsp_eopt() -> None:
@@ -297,6 +297,7 @@ def par_geds_hit_aoe() -> None:
297
297
  else:
298
298
  aoe = None
299
299
  plot_dict = out_plot_dict
300
+ results_dict = {}
300
301
 
301
302
  if args.plot_file:
302
303
  common_dict = plot_dict.pop("common") if "common" in list(plot_dict) else None
@@ -33,7 +33,10 @@ mpl.use("agg")
33
33
  sto = lh5.LH5Store()
34
34
 
35
35
  warnings.filterwarnings(action="ignore", category=RuntimeWarning)
36
- warnings.filterwarnings(action="ignore", category=np.exceptions.RankWarning)
36
+ try:
37
+ warnings.filterwarnings(action="ignore", category=np.exceptions.RankWarning)
38
+ except AttributeError: # np < 2
39
+ warnings.filterwarnings(action="ignore", category=np.RankWarning)
37
40
 
38
41
 
39
42
  def plot_2614_timemap(
@@ -485,7 +488,7 @@ def par_geds_hit_ecal() -> None:
485
488
  msg = "invalid tier"
486
489
  raise ValueError(msg)
487
490
 
488
- build_log(config_dict, args.log)
491
+ log = build_log(config_dict, args.log)
489
492
 
490
493
  chmap = LegendMetadata(args.metadata).channelmap(
491
494
  args.timestamp, system=args.datatype
@@ -575,14 +578,23 @@ def par_geds_hit_ecal() -> None:
575
578
  ):
576
579
  e_uncal = data.query(selection_string)[energy_param].to_numpy()
577
580
 
578
- hist, bins, bar = pgh.get_hist(
579
- e_uncal[
580
- (e_uncal > np.nanpercentile(e_uncal, 95))
581
- & (e_uncal < np.nanpercentile(e_uncal, 99.9))
582
- ],
583
- dx=1,
584
- range=[np.nanpercentile(e_uncal, 95), np.nanpercentile(e_uncal, 99.9)],
585
- )
581
+ if len(e_uncal) > 0:
582
+ if isinstance(e_uncal[0], np.ndarray | list):
583
+ e_uncal = np.concatenate([arr for arr in e_uncal if len(arr) > 0])
584
+ hist, bins, _ = pgh.get_hist(
585
+ e_uncal[
586
+ (e_uncal > np.nanpercentile(e_uncal, 95))
587
+ & (e_uncal < np.nanpercentile(e_uncal, 99.9))
588
+ ],
589
+ dx=1,
590
+ range=[
591
+ np.nanpercentile(e_uncal, 95),
592
+ np.nanpercentile(e_uncal, 99.9),
593
+ ],
594
+ )
595
+ else:
596
+ msg = f"e_uncal should not be empty! energy_param: {energy_param}"
597
+ raise ValueError(msg)
586
598
 
587
599
  guess = 2614.511 / bins[np.nanargmax(hist)]
588
600
  full_object_dict[cal_energy_param] = HPGeCalibration(
@@ -644,8 +656,21 @@ def par_geds_hit_ecal() -> None:
644
656
  interp_energy_kev={"Qbb": 2039.0},
645
657
  )
646
658
 
659
+ energy = data[energy_param].to_numpy()
660
+ if isinstance(energy[0], np.ndarray | list):
661
+ energy = np.concatenate(energy)
662
+
663
+ if len(energy) < len(data):
664
+ log.warning("len(energy) and len(data) are not the same")
665
+ energy = np.pad(
666
+ energy, (0, len(data) - len(energy)), constant_values=np.nan
667
+ )
668
+
669
+ if len(data) < len(energy):
670
+ energy = energy[: len(data)]
671
+
647
672
  data[cal_energy_param] = nb_poly(
648
- data[energy_param].to_numpy(), full_object_dict[cal_energy_param].pars
673
+ energy, full_object_dict[cal_energy_param].pars
649
674
  )
650
675
 
651
676
  results_dict[cal_energy_param] = get_results_dict(
@@ -655,18 +680,32 @@ def par_geds_hit_ecal() -> None:
655
680
  hit_dict.update(
656
681
  {cal_energy_param: full_object_dict[cal_energy_param].gen_pars_dict()}
657
682
  )
658
- if "ctc" in cal_energy_param:
659
- no_ctc_dict = full_object_dict[cal_energy_param].gen_pars_dict()
660
- no_ctc_dict["expression"] = no_ctc_dict["expression"].replace("_ctc", "")
661
- hit_dict.update({cal_energy_param.replace("ctc", "noctc"): no_ctc_dict})
662
- hit_dict.update(
663
- {
664
- cal_energy_param.replace("_ctc", ""): {
665
- "expression": f"where({cal_energy_param.replace('ctc', 'noctc')}>{kwarg_dict.get('dt_theshold_kev', 100)}, {cal_energy_param}, {cal_energy_param.replace('ctc', 'noctc')})",
666
- "parameters": {},
667
- }
668
- }
669
- )
683
+ if "copy_calibration" in kwarg_dict:
684
+ for copy_cal_param, _copy_to_cal_param in kwarg_dict[
685
+ "copy_calibration"
686
+ ].items():
687
+ if copy_cal_param not in full_object_dict:
688
+ msg = f"copy_calibration parameter {copy_cal_param} not found in full_object_dict"
689
+ raise ValueError(msg)
690
+ if isinstance(_copy_to_cal_param, str):
691
+ copy_to_cal_param = [_copy_to_cal_param]
692
+ else:
693
+ copy_to_cal_param = _copy_to_cal_param
694
+ for cal_par in copy_to_cal_param:
695
+ if cal_par in full_object_dict:
696
+ msg = f"copy_calibration parameter {cal_par} already exists in full_object_dict"
697
+ raise ValueError(msg)
698
+ copy_dict = {cal_par: full_object_dict[cal_par].gen_pars_dict()}
699
+ copy_dict["expression"] = copy_dict[cal_par]["expression"].replace(
700
+ copy_cal_param, cal_par
701
+ )
702
+ hit_dict.update({cal_par: copy_dict[cal_par]})
703
+ if "extra_blocks" in kwarg_dict:
704
+ if isinstance(kwarg_dict["extra_blocks"], dict):
705
+ kwarg_dict["extra_blocks"] = [kwarg_dict["extra_blocks"]]
706
+ for extra_block in kwarg_dict["extra_blocks"]:
707
+ hit_dict.update(extra_block)
708
+
670
709
  if args.plot_path:
671
710
  param_plot_dict = {}
672
711
  if ~np.isnan(full_object_dict[cal_energy_param].pars).all():
@@ -295,7 +295,7 @@ def par_geds_hit_lq() -> None:
295
295
 
296
296
  data["run_timestamp"] = args.timestamp
297
297
 
298
- out_dicts, eres_dicts, plot_dicts, lq_dict = run_lq_calibration(
298
+ out_dicts, results_dicts, plot_dicts, lq_dict = run_lq_calibration(
299
299
  data,
300
300
  cal_dicts={args.timestamp: cal_dict},
301
301
  results_dicts={args.timestamp: eres_dict},
@@ -305,12 +305,13 @@ def par_geds_hit_lq() -> None:
305
305
  debug_mode=args.debug,
306
306
  )
307
307
  cal_dict = out_dicts[args.timestamp]
308
- eres_dict = eres_dicts[args.timestamp]
308
+ results_dict = results_dicts[args.timestamp]
309
309
  plot_dict = plot_dicts[args.timestamp]
310
310
  lq = lq_dict[args.timestamp]
311
311
 
312
312
  else:
313
313
  lq = None
314
+ results_dict = {}
314
315
 
315
316
  if args.plot_file:
316
317
  Path(args.plot_file).parent.mkdir(parents=True, exist_ok=True)
@@ -320,7 +321,7 @@ def par_geds_hit_lq() -> None:
320
321
  final_hit_dict = convert_dict_np_to_float(
321
322
  {
322
323
  "pars": {"operations": cal_dict},
323
- "results": dict(**ecal_dict["results"], lq=eres_dict),
324
+ "results": dict(**ecal_dict["results"], lq=results_dict),
324
325
  }
325
326
  )
326
327
  Path(args.hit_pars).parent.mkdir(parents=True, exist_ok=True)
@@ -0,0 +1,55 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+ import h5py
7
+
8
+
9
+ def convert_parents_to_structs(h5group):
10
+ if h5group.parent.name != "/" and len(h5group.parent.attrs) == 0:
11
+ h5group.parent.attrs.update(
12
+ {"datatype": "struct{" + h5group.name.split("/")[-1] + "}"}
13
+ )
14
+ elif (
15
+ len(h5group.parent.attrs) > 0
16
+ and h5group.name.split("/")[-1] not in h5group.parent.attrs["datatype"]
17
+ ):
18
+ h5group.parent.attrs.update(
19
+ {
20
+ "datatype": h5group.parent.attrs["datatype"][:-1]
21
+ + ","
22
+ + h5group.name.split("/")[-1]
23
+ + "}"
24
+ }
25
+ )
26
+ else:
27
+ return
28
+ convert_parents_to_structs(h5group.parent)
29
+ return
30
+
31
+
32
+ def alias_table(file: str | Path, mapping: str):
33
+ """
34
+ Create an alias table for the given file and mapping.
35
+
36
+ Args:
37
+ file (str): Path to the input file.
38
+ mapping (dict): Mapping of current table name and alias table name.
39
+
40
+ """
41
+ if isinstance(mapping, str):
42
+ mapping = json.loads(mapping)
43
+ if isinstance(mapping, list):
44
+ for m in mapping:
45
+ alias_table(file, m)
46
+ with h5py.File(file, "a") as f:
47
+ for raw_id, alias in mapping.items():
48
+ if raw_id in f:
49
+ if isinstance(alias, list | tuple):
50
+ for a in alias:
51
+ f[a] = f[raw_id]
52
+ convert_parents_to_structs(f[a])
53
+ else:
54
+ f[alias] = f[raw_id]
55
+ convert_parents_to_structs(f[alias])
@@ -24,7 +24,7 @@ def convert_dict_np_to_float(dic: dict) -> dict:
24
24
  convert_dict_np_to_float(value)
25
25
  elif isinstance(value, np.float32 | np.float64):
26
26
  dic[key] = float(value)
27
- elif isinstance(dic[key], Sequence):
27
+ elif isinstance(dic[key], Sequence) and not isinstance(dic[key], str):
28
28
  dic[key] = [
29
29
  float(x) if isinstance(x, np.float32 | np.float64) else x for x in value
30
30
  ]
@@ -316,10 +316,16 @@ def cmdexec(args) -> None:
316
316
  )
317
317
  config_dict["execenv"] = config_dict["execenv"][args.system]
318
318
 
319
+ exe_path = Path(config_dict.paths.install).resolve() / "bin"
320
+
319
321
  cmd_prefix, cmd_env = execenv_prefix(config_dict, as_string=False)
320
322
  cmd_expr = [*cmd_prefix, *args.command]
321
323
 
322
324
  msg = "running: " + _execenv2str(cmd_expr, cmd_env)
323
325
  log.debug(msg)
324
326
 
325
- subprocess.run(cmd_expr, env=os.environ | cmd_env, check=True)
327
+ env_dict = os.environ | cmd_env
328
+ env_dict["PATH"] = (
329
+ f"{exe_path}:{env_dict['PATH']}" # prepend the virtualenv bin dir
330
+ )
331
+ subprocess.run(cmd_expr, env=env_dict, check=True)
@@ -1,28 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import json
4
-
5
- import h5py
6
-
7
-
8
- def alias_table(file, mapping):
9
- """
10
- Create an alias table for the given file and mapping.
11
-
12
- Args:
13
- file (str): Path to the input file.
14
- mapping (dict): Mapping of current table name and alias table name.
15
-
16
- Returns:
17
- dict: A dictionary containing the alias table.
18
- """
19
- if isinstance(mapping, str):
20
- mapping = json.loads(mapping)
21
- with h5py.File(file, "a") as f:
22
- for raw_id, alias in mapping.items():
23
- if raw_id in f:
24
- if isinstance(alias, list | tuple):
25
- for a in alias:
26
- f[a] = f[raw_id]
27
- else:
28
- f[alias] = f[raw_id]