legend-dataflow-scripts 0.1.4__py3-none-any.whl → 0.1.6__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.
@@ -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,37 +1,37 @@
1
1
  legenddataflowscripts/__init__.py,sha256=hlpvTxSBjOyXlZUyOyYx3VwT5LS6zNzhAZnTmfT3NjU,303
2
- legenddataflowscripts/_version.py,sha256=hcPkC9vIGgfrKK6ft7ysLT7iOCjpFmCBmyKLmXiaZ1g,511
2
+ legenddataflowscripts/_version.py,sha256=ESbJO0YD7TYfOUv_WDIJJgWELGepEWsoyhqVifEcXPA,511
3
3
  legenddataflowscripts/par/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  legenddataflowscripts/par/geds/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  legenddataflowscripts/par/geds/dsp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  legenddataflowscripts/par/geds/dsp/dplms.py,sha256=OOvnN_OcU046zhuyNTGxcmGYLCZ7YseK4rNyMDaRsC4,5314
7
- legenddataflowscripts/par/geds/dsp/eopt.py,sha256=UklMozVw57X8EhOVjOxwKSXtuHkX45iJ2YMLx69TQps,13680
7
+ legenddataflowscripts/par/geds/dsp/eopt.py,sha256=jmljkIPamz-L1lX8kEqSdmRuZJ-a9---9Qj-1ACghNQ,13792
8
8
  legenddataflowscripts/par/geds/dsp/evtsel.py,sha256=qheFqGezjRxW9UNf9DV1n8VuZjCLGZT-WaWyhrfgPJ4,16485
9
9
  legenddataflowscripts/par/geds/dsp/nopt.py,sha256=K7R4OBfO0wek03VvhBoYXDP7lURi_Xoph9Kb3iMkfx4,4263
10
10
  legenddataflowscripts/par/geds/dsp/pz.py,sha256=sucYUtsgWKYtR-GbmRh5b61EYHqNRMWGckD3DJdHUvs,8273
11
11
  legenddataflowscripts/par/geds/dsp/svm.py,sha256=eDneRB_PQZp8Q4n2VheTX3kbu4ufZQ-jnuCCjvtwFpk,826
12
12
  legenddataflowscripts/par/geds/dsp/svm_build.py,sha256=8K0NUpQqL2HUWRKjMpM5H-TienVPUzIuKED94ZZnIzA,2227
13
13
  legenddataflowscripts/par/geds/hit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- legenddataflowscripts/par/geds/hit/aoe.py,sha256=4sXRz6UaPD7phihAO3_C42l7fJT8UrhhOZswzO8rAqw,11387
15
- legenddataflowscripts/par/geds/hit/ecal.py,sha256=tsIL9FP-aXgM2B1K8ygjcsLeNZ9Yv7je84fT-K7m3vQ,26194
16
- legenddataflowscripts/par/geds/hit/lq.py,sha256=td0qVvVRwYbhiA-IhAZYLgTdW6xpTeeE3mrSoWeLw2U,11307
14
+ legenddataflowscripts/par/geds/hit/aoe.py,sha256=lkA7cgSRdyDt58AYOIuPoCBxiClVJU-6wwYSImpdVFg,11413
15
+ legenddataflowscripts/par/geds/hit/ecal.py,sha256=HogjtX-QUkwogh-jA9F0jTTvEjEfCUK5GY4cHGUBaAw,27854
16
+ legenddataflowscripts/par/geds/hit/lq.py,sha256=TW3vu0UFYgQz2-vrb_ic8ghIpe3ukKMF4Kt-iFP7VAQ,11346
17
17
  legenddataflowscripts/par/geds/hit/qc.py,sha256=16RWhybvnODv4dUuSkO6EDtPvJJJmeFwFaPTgS9N7cs,12746
18
18
  legenddataflowscripts/tier/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  legenddataflowscripts/tier/dsp.py,sha256=J_ABEqbQurZHJOg8LV2aporNjZQpPg2bDZG6DkmuAL4,8633
20
20
  legenddataflowscripts/tier/hit.py,sha256=-LCfsqYAYPAuN2OKbPuh4G2P5B4uA4YmQGcqUtbZxis,4989
21
21
  legenddataflowscripts/utils/__init__.py,sha256=NPpxqapio8CeQIbG8gYnz-OPoUbOlDT6tjXV-lJrKWc,426
22
- legenddataflowscripts/utils/alias_table.py,sha256=e0wRiDcpje8VVr_PlcbkA0kPz0qSGpGX4vJ3tfGefMA,742
22
+ legenddataflowscripts/utils/alias_table.py,sha256=OfET_-ZG6FfXL9JRqPJiSWUdDrDQlNnz5RsLkH2sk5Y,1605
23
23
  legenddataflowscripts/utils/cfgtools.py,sha256=_1yxw_eJ08AihONhJ9sWet5HQZpOagj8Yg8y9LS3zX4,381
24
- legenddataflowscripts/utils/convert_np.py,sha256=8q_K3w3jAREG-9CJlErP3Vca0OYTYAYJIK4g_TClvBU,819
24
+ legenddataflowscripts/utils/convert_np.py,sha256=qw-pX9345lhzLAwERLjEJtnikzAWWIeD9lyDre2n9P0,853
25
25
  legenddataflowscripts/utils/log.py,sha256=5v8J7PZJHHoSy12w9e9DkYmqdPvYXj6YfVaMbhvX614,2230
26
26
  legenddataflowscripts/utils/plot_dict.py,sha256=-wfJC5U9OTE1Asazz64kT5Ta008w6UJmDSsr3YAubRM,449
27
27
  legenddataflowscripts/utils/pulser_removal.py,sha256=kuARdp1jf-lsUWcb0_KRDp-ZXzkHNrDCXUc3h7TJm7Q,424
28
28
  legenddataflowscripts/workflow/__init__.py,sha256=JhudKYhBT8bXtX4LCqxQCHzUiITpugAtFxePWEtphC4,474
29
- legenddataflowscripts/workflow/execenv.py,sha256=O6Z6EH6Yp0JXnwX2wTzduHC9Q9gu-_d1RuuE2pQ5caE,9061
29
+ legenddataflowscripts/workflow/execenv.py,sha256=qTG4N9ovEPxA0QtqG0wWUIuK50BZIcYvpVlpy-XgxPw,9257
30
30
  legenddataflowscripts/workflow/filedb.py,sha256=rbvOcXUxLbHz177QuDIDAL3aysz-bZDjHOiMsRHssZo,3434
31
31
  legenddataflowscripts/workflow/pre_compile_catalog.py,sha256=cEK0KXh-ClSE2Bo9MK471o79XG22bMY5r-2tIihtCfk,790
32
32
  legenddataflowscripts/workflow/utils.py,sha256=eKE8KIG2ffynZt9fTbI1SVQV85i3aW9GFGh1Nio1iDo,3118
33
- legend_dataflow_scripts-0.1.4.dist-info/METADATA,sha256=kCV4uTOiqJBCGvMteN0O5b0YGwLCMrZR8DF3LytqCF4,3122
34
- legend_dataflow_scripts-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
- legend_dataflow_scripts-0.1.4.dist-info/entry_points.txt,sha256=B197waSm-orA_ZS-9rkxNDsmOHdCn8CbWodnlqXQKRg,1313
36
- legend_dataflow_scripts-0.1.4.dist-info/top_level.txt,sha256=s8E2chjJNYUbrN6whFG_VCsJKySFp1IOXLcUefA7DB0,22
37
- legend_dataflow_scripts-0.1.4.dist-info/RECORD,,
33
+ legend_dataflow_scripts-0.1.6.dist-info/METADATA,sha256=PTXbBwFCBHDbdxQamprkPrSTly1YVydK5y0HUb__9Bk,3122
34
+ legend_dataflow_scripts-0.1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
+ legend_dataflow_scripts-0.1.6.dist-info/entry_points.txt,sha256=B197waSm-orA_ZS-9rkxNDsmOHdCn8CbWodnlqXQKRg,1313
36
+ legend_dataflow_scripts-0.1.6.dist-info/top_level.txt,sha256=s8E2chjJNYUbrN6whFG_VCsJKySFp1IOXLcUefA7DB0,22
37
+ legend_dataflow_scripts-0.1.6.dist-info/RECORD,,
@@ -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)
@@ -1,11 +1,35 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import json
4
+ from pathlib import Path
4
5
 
5
6
  import h5py
6
7
 
7
8
 
8
- def alias_table(file, mapping):
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):
9
33
  """
10
34
  Create an alias table for the given file and mapping.
11
35
 
@@ -13,16 +37,19 @@ def alias_table(file, mapping):
13
37
  file (str): Path to the input file.
14
38
  mapping (dict): Mapping of current table name and alias table name.
15
39
 
16
- Returns:
17
- dict: A dictionary containing the alias table.
18
40
  """
19
41
  if isinstance(mapping, str):
20
42
  mapping = json.loads(mapping)
43
+ if isinstance(mapping, list):
44
+ for m in mapping:
45
+ alias_table(file, m)
21
46
  with h5py.File(file, "a") as f:
22
47
  for raw_id, alias in mapping.items():
23
48
  if raw_id in f:
24
49
  if isinstance(alias, list | tuple):
25
50
  for a in alias:
26
51
  f[a] = f[raw_id]
52
+ convert_parents_to_structs(f[a])
27
53
  else:
28
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)