legend-dataflow-scripts 0.1.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.
Files changed (36) hide show
  1. legend_dataflow_scripts-0.1.0.dist-info/METADATA +57 -0
  2. legend_dataflow_scripts-0.1.0.dist-info/RECORD +36 -0
  3. legend_dataflow_scripts-0.1.0.dist-info/WHEEL +5 -0
  4. legend_dataflow_scripts-0.1.0.dist-info/entry_points.txt +18 -0
  5. legend_dataflow_scripts-0.1.0.dist-info/top_level.txt +1 -0
  6. legenddataflowscripts/__init__.py +17 -0
  7. legenddataflowscripts/_version.py +21 -0
  8. legenddataflowscripts/par/__init__.py +0 -0
  9. legenddataflowscripts/par/geds/__init__.py +0 -0
  10. legenddataflowscripts/par/geds/dsp/__init__.py +0 -0
  11. legenddataflowscripts/par/geds/dsp/dplms.py +145 -0
  12. legenddataflowscripts/par/geds/dsp/eopt.py +398 -0
  13. legenddataflowscripts/par/geds/dsp/evtsel.py +400 -0
  14. legenddataflowscripts/par/geds/dsp/nopt.py +120 -0
  15. legenddataflowscripts/par/geds/dsp/pz.py +217 -0
  16. legenddataflowscripts/par/geds/dsp/svm.py +28 -0
  17. legenddataflowscripts/par/geds/dsp/svm_build.py +69 -0
  18. legenddataflowscripts/par/geds/hit/__init__.py +0 -0
  19. legenddataflowscripts/par/geds/hit/aoe.py +245 -0
  20. legenddataflowscripts/par/geds/hit/ecal.py +778 -0
  21. legenddataflowscripts/par/geds/hit/lq.py +213 -0
  22. legenddataflowscripts/par/geds/hit/qc.py +326 -0
  23. legenddataflowscripts/tier/__init__.py +0 -0
  24. legenddataflowscripts/tier/dsp.py +263 -0
  25. legenddataflowscripts/tier/hit.py +148 -0
  26. legenddataflowscripts/utils/__init__.py +15 -0
  27. legenddataflowscripts/utils/alias_table.py +28 -0
  28. legenddataflowscripts/utils/cfgtools.py +14 -0
  29. legenddataflowscripts/utils/convert_np.py +31 -0
  30. legenddataflowscripts/utils/log.py +77 -0
  31. legenddataflowscripts/utils/pulser_removal.py +16 -0
  32. legenddataflowscripts/workflow/__init__.py +20 -0
  33. legenddataflowscripts/workflow/execenv.py +327 -0
  34. legenddataflowscripts/workflow/filedb.py +107 -0
  35. legenddataflowscripts/workflow/pre_compile_catalog.py +24 -0
  36. legenddataflowscripts/workflow/utils.py +113 -0
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: legend-dataflow-scripts
3
+ Version: 0.1.0
4
+ Summary: Python package for the processing scripts for LEGEND-200 data
5
+ Author-email: George Marshall <ggmarsh@uw.edu>, Luigi Pertoldi <gipert@pm.me>
6
+ Maintainer: The LEGEND Collaboration
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: POSIX
13
+ Classifier: Operating System :: Unix
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Scientific/Engineering
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ Requires-Dist: colorlog
21
+ Requires-Dist: dbetto>=1.2.3
22
+ Requires-Dist: pygama>=2.1.1a3
23
+ Requires-Dist: dspeed>=1.6.6a1
24
+ Requires-Dist: pylegendmeta>=1.2.5
25
+ Requires-Dist: legend-pydataobj>=1.12.0a4
26
+ Requires-Dist: legend-daq2lh5>=1.5.0
27
+ Requires-Dist: pip
28
+ Provides-Extra: test
29
+ Requires-Dist: legend-dataflow-scripts; extra == "test"
30
+ Requires-Dist: pytest>=6; extra == "test"
31
+ Requires-Dist: pytest-cov>=3; extra == "test"
32
+ Provides-Extra: dev
33
+ Requires-Dist: legend-dataflow-scripts[test]; extra == "dev"
34
+ Requires-Dist: pre-commit; extra == "dev"
35
+ Provides-Extra: docs
36
+ Requires-Dist: sphinx>=7.0; extra == "docs"
37
+ Requires-Dist: myst_parser>=0.13; extra == "docs"
38
+ Requires-Dist: sphinx_inline_tabs; extra == "docs"
39
+ Requires-Dist: sphinx_copybutton; extra == "docs"
40
+ Requires-Dist: sphinx_autodoc_typehints; extra == "docs"
41
+ Requires-Dist: furo>=2023.08.17; extra == "docs"
42
+
43
+ # LEGEND dataflow scripts
44
+
45
+ [![PyPI](https://img.shields.io/pypi/v/legend-dataflow-scripts?logo=pypi)](https://pypi.org/project/legend-dataflow-scripts/)
46
+ ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/legend-exp/legend-dataflow-scripts?logo=git)
47
+ [![GitHub Workflow Status](https://img.shields.io/github/checks-status/legend-exp/legend-dataflow-scripts/main?label=main%20branch&logo=github)](https://github.com/legend-exp/legend-dataflow-scripts/actions)
48
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
49
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
50
+ [![Codecov](https://img.shields.io/codecov/c/github/legend-exp/legend-dataflow-scripts?logo=codecov)](https://app.codecov.io/gh/legend-exp/legend-dataflow-scripts)
51
+ ![GitHub issues](https://img.shields.io/github/issues/legend-exp/legend-dataflow-scripts?logo=github)
52
+ ![GitHub pull requests](https://img.shields.io/github/issues-pr/legend-exp/legend-dataflow-scripts?logo=github)
53
+ ![License](https://img.shields.io/github/license/legend-exp/legend-dataflow-scripts)
54
+ [![Read the Docs](https://img.shields.io/readthedocs/legend-dataflow-scripts?logo=readthedocs)](https://legend-dataflow-scripts.readthedocs.io)
55
+
56
+ Scripts used in the LEGEND data processing. These scripts are general enough to be used in
57
+ test stand processings also.
@@ -0,0 +1,36 @@
1
+ legenddataflowscripts/__init__.py,sha256=hlpvTxSBjOyXlZUyOyYx3VwT5LS6zNzhAZnTmfT3NjU,303
2
+ legenddataflowscripts/_version.py,sha256=-LyU5F1uZDjn6Q8_Z6-_FJt_8RE4Kq9zcKdg1abSSps,511
3
+ legenddataflowscripts/par/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ legenddataflowscripts/par/geds/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ legenddataflowscripts/par/geds/dsp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ legenddataflowscripts/par/geds/dsp/dplms.py,sha256=OOvnN_OcU046zhuyNTGxcmGYLCZ7YseK4rNyMDaRsC4,5314
7
+ legenddataflowscripts/par/geds/dsp/eopt.py,sha256=UklMozVw57X8EhOVjOxwKSXtuHkX45iJ2YMLx69TQps,13680
8
+ legenddataflowscripts/par/geds/dsp/evtsel.py,sha256=qheFqGezjRxW9UNf9DV1n8VuZjCLGZT-WaWyhrfgPJ4,16485
9
+ legenddataflowscripts/par/geds/dsp/nopt.py,sha256=K7R4OBfO0wek03VvhBoYXDP7lURi_Xoph9Kb3iMkfx4,4263
10
+ legenddataflowscripts/par/geds/dsp/pz.py,sha256=6tkXvL1ND-j4ulxfsRJadiNXPWqqadT7k99eti9MK-k,8265
11
+ legenddataflowscripts/par/geds/dsp/svm.py,sha256=eDneRB_PQZp8Q4n2VheTX3kbu4ufZQ-jnuCCjvtwFpk,826
12
+ legenddataflowscripts/par/geds/dsp/svm_build.py,sha256=8K0NUpQqL2HUWRKjMpM5H-TienVPUzIuKED94ZZnIzA,2227
13
+ legenddataflowscripts/par/geds/hit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ legenddataflowscripts/par/geds/hit/aoe.py,sha256=0reLWzYxau09DKyu_KrywC56njSLOVGAT6QfDBSNfvM,8499
15
+ legenddataflowscripts/par/geds/hit/ecal.py,sha256=tsIL9FP-aXgM2B1K8ygjcsLeNZ9Yv7je84fT-K7m3vQ,26194
16
+ legenddataflowscripts/par/geds/hit/lq.py,sha256=CWasjmdaBNVk7AFNrV-RZ8UcvUzfww7wxvhrRdGSobc,7379
17
+ legenddataflowscripts/par/geds/hit/qc.py,sha256=yT922UcNdw9X0yQ-JqoABeDuT-NMpKE2dvKO7qUGLes,11821
18
+ legenddataflowscripts/tier/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ legenddataflowscripts/tier/dsp.py,sha256=J_ABEqbQurZHJOg8LV2aporNjZQpPg2bDZG6DkmuAL4,8633
20
+ legenddataflowscripts/tier/hit.py,sha256=-LCfsqYAYPAuN2OKbPuh4G2P5B4uA4YmQGcqUtbZxis,4989
21
+ legenddataflowscripts/utils/__init__.py,sha256=_eYTjqTMgjeQGO4HKmiqVAkyW9fh9FEz-_lQtcM-Lfg,366
22
+ legenddataflowscripts/utils/alias_table.py,sha256=e0wRiDcpje8VVr_PlcbkA0kPz0qSGpGX4vJ3tfGefMA,742
23
+ legenddataflowscripts/utils/cfgtools.py,sha256=_1yxw_eJ08AihONhJ9sWet5HQZpOagj8Yg8y9LS3zX4,381
24
+ legenddataflowscripts/utils/convert_np.py,sha256=8q_K3w3jAREG-9CJlErP3Vca0OYTYAYJIK4g_TClvBU,819
25
+ legenddataflowscripts/utils/log.py,sha256=5v8J7PZJHHoSy12w9e9DkYmqdPvYXj6YfVaMbhvX614,2230
26
+ legenddataflowscripts/utils/pulser_removal.py,sha256=kuARdp1jf-lsUWcb0_KRDp-ZXzkHNrDCXUc3h7TJm7Q,424
27
+ legenddataflowscripts/workflow/__init__.py,sha256=p-57OklNpVYqwMaLctLO8zMvhpXaTILkd3j4CaS_Juk,394
28
+ legenddataflowscripts/workflow/execenv.py,sha256=34V7euhKiTXDDBDuX4t2Oi_zPx6lAcCRYiHqVCz6Xps,9032
29
+ legenddataflowscripts/workflow/filedb.py,sha256=rbvOcXUxLbHz177QuDIDAL3aysz-bZDjHOiMsRHssZo,3434
30
+ legenddataflowscripts/workflow/pre_compile_catalog.py,sha256=cEK0KXh-ClSE2Bo9MK471o79XG22bMY5r-2tIihtCfk,790
31
+ legenddataflowscripts/workflow/utils.py,sha256=eKE8KIG2ffynZt9fTbI1SVQV85i3aW9GFGh1Nio1iDo,3118
32
+ legend_dataflow_scripts-0.1.0.dist-info/METADATA,sha256=fzaP59xzQtj2rxNOiq0K29b36LYQgtbo-I44z24-7ew,3134
33
+ legend_dataflow_scripts-0.1.0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
34
+ legend_dataflow_scripts-0.1.0.dist-info/entry_points.txt,sha256=B197waSm-orA_ZS-9rkxNDsmOHdCn8CbWodnlqXQKRg,1313
35
+ legend_dataflow_scripts-0.1.0.dist-info/top_level.txt,sha256=s8E2chjJNYUbrN6whFG_VCsJKySFp1IOXLcUefA7DB0,22
36
+ legend_dataflow_scripts-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.7.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,18 @@
1
+ [console_scripts]
2
+ build-filedb = legenddataflowscripts.workflow.filedb:build_filedb
3
+ build-tier-dsp = legenddataflowscripts.tier.dsp:build_tier_dsp
4
+ build-tier-dsp-single-channel = legenddataflowscripts.tier.dsp:build_tier_dsp_single_channel
5
+ build-tier-hit = legenddataflowscripts.tier.hit:build_tier_hit
6
+ build-tier-hit-single-channel = legenddataflowscripts.tier.hit:build_tier_hit_single_channel
7
+ dataflow = legenddataflowscripts.workflow.execenv:dataflow
8
+ par-geds-dsp-dplms = legenddataflowscripts.par.geds.dsp.dplms:par_geds_dsp_dplms
9
+ par-geds-dsp-eopt = legenddataflowscripts.par.geds.dsp.eopt:par_geds_dsp_eopt
10
+ par-geds-dsp-evtsel = legenddataflowscripts.par.geds.dsp.evtsel:par_geds_dsp_evtsel
11
+ par-geds-dsp-nopt = legenddataflowscripts.par.geds.dsp.nopt:par_geds_dsp_nopt
12
+ par-geds-dsp-pz = legenddataflowscripts.par.geds.dsp.pz:par_geds_dsp_pz
13
+ par-geds-dsp-svm = legenddataflowscripts.par.geds.dsp.svm:par_geds_dsp_svm
14
+ par-geds-dsp-svm-build = legenddataflowscripts.par.geds.dsp.svm_build:par_geds_dsp_svm_build
15
+ par-geds-hit-aoe = legenddataflowscripts.par.geds.hit.aoe:par_geds_hit_aoe
16
+ par-geds-hit-ecal = legenddataflowscripts.par.geds.hit.ecal:par_geds_hit_ecal
17
+ par-geds-hit-lq = legenddataflowscripts.par.geds.hit.lq:par_geds_hit_lq
18
+ par-geds-hit-qc = legenddataflowscripts.par.geds.hit.qc:par_geds_hit_qc
@@ -0,0 +1 @@
1
+ legenddataflowscripts
@@ -0,0 +1,17 @@
1
+ from __future__ import annotations
2
+
3
+ from .workflow import (
4
+ as_ro,
5
+ set_last_rule_name,
6
+ subst_vars,
7
+ subst_vars_impl,
8
+ subst_vars_in_snakemake_config,
9
+ )
10
+
11
+ __all__ = [
12
+ "as_ro",
13
+ "set_last_rule_name",
14
+ "subst_vars",
15
+ "subst_vars_impl",
16
+ "subst_vars_in_snakemake_config",
17
+ ]
@@ -0,0 +1,21 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
5
+
6
+ TYPE_CHECKING = False
7
+ if TYPE_CHECKING:
8
+ from typing import Tuple
9
+ from typing import Union
10
+
11
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
12
+ else:
13
+ VERSION_TUPLE = object
14
+
15
+ version: str
16
+ __version__: str
17
+ __version_tuple__: VERSION_TUPLE
18
+ version_tuple: VERSION_TUPLE
19
+
20
+ __version__ = version = '0.1.0'
21
+ __version_tuple__ = version_tuple = (0, 1, 0)
File without changes
File without changes
File without changes
@@ -0,0 +1,145 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import pickle as pkl
5
+ import time
6
+ from pathlib import Path
7
+
8
+ import numpy as np
9
+ from dbetto import TextDB
10
+ from dbetto.catalog import Props
11
+ from lgdo import Array, Table, lh5
12
+ from pygama.pargen.dplms_ge_dict import dplms_ge_dict
13
+
14
+ from ....utils import build_log, convert_dict_np_to_float
15
+
16
+
17
+ def par_geds_dsp_dplms() -> None:
18
+ argparser = argparse.ArgumentParser()
19
+ argparser.add_argument("--fft-raw-filelist", help="fft_raw_filelist", type=str)
20
+ argparser.add_argument("--peak-file", help="tcm_filelist", type=str, required=True)
21
+ argparser.add_argument("--inplots", help="in_plot_path", type=str)
22
+ argparser.add_argument("--database", help="database", type=str, required=True)
23
+
24
+ argparser.add_argument("--log", help="log_file", type=str)
25
+ argparser.add_argument("--configs", help="configs", type=str, required=True)
26
+
27
+ argparser.add_argument("--datatype", help="Datatype", type=str, required=True)
28
+ argparser.add_argument("--timestamp", help="Timestamp", type=str, required=True)
29
+ argparser.add_argument("--channel", help="Channel", type=str, required=True)
30
+ argparser.add_argument(
31
+ "--raw-table-name", help="raw table name", type=str, required=True
32
+ )
33
+
34
+ argparser.add_argument("--dsp-pars", help="dsp_pars", type=str, required=True)
35
+ argparser.add_argument("--lh5-path", help="lh5_path", type=str, required=True)
36
+ argparser.add_argument("--plot-path", help="plot_path", type=str)
37
+
38
+ args = argparser.parse_args()
39
+
40
+ configs = TextDB(args.configs, lazy=True).on(args.timestamp, system=args.datatype)
41
+ config_dict = configs["snakemake_rules"]["pars_dsp_dplms"]
42
+
43
+ log = build_log(config_dict, args.log)
44
+
45
+ configs = TextDB(args.configs).on(args.timestamp, system=args.datatype)
46
+ dsp_config = config_dict["inputs"]["proc_chain"][args.channel]
47
+
48
+ dplms_json = config_dict["inputs"]["dplms_pars"][args.channel]
49
+ dplms_dict = Props.read_from(dplms_json)
50
+
51
+ db_dict = Props.read_from(args.database)
52
+
53
+ if dplms_dict["run_dplms"] is True:
54
+ with Path(args.fft_raw_filelist).open() as f:
55
+ fft_files = sorted(f.read().splitlines())
56
+
57
+ t0 = time.time()
58
+ log.info("\nLoad fft data")
59
+ energies = lh5.read_as(
60
+ f"{args.raw_table_name}/daqenergy", fft_files, library="np"
61
+ )
62
+ idxs = np.where(energies == 0)[0]
63
+ raw_fft = lh5.read(
64
+ args.raw_table_name,
65
+ fft_files,
66
+ n_rows=dplms_dict["n_baselines"],
67
+ idx=idxs,
68
+ )
69
+ t1 = time.time()
70
+ msg = f"Time to load fft data {(t1 - t0):.2f} s, total events {len(raw_fft)}"
71
+ log.info(msg)
72
+
73
+ log.info("\nRunning event selection")
74
+ peaks_kev = np.array(dplms_dict["peaks_kev"])
75
+ # kev_widths = [tuple(kev_width) for kev_width in dplms_dict["kev_widths"]]
76
+
77
+ peaks_rounded = [int(peak) for peak in peaks_kev]
78
+ peaks = lh5.read_as(f"{args.raw_table_name}/peak", args.peak_file, library="np")
79
+ ids = np.isin(peaks, peaks_rounded)
80
+ peaks = peaks[ids]
81
+ # idx_list = [np.where(peaks == peak)[0] for peak in peaks_rounded]
82
+
83
+ raw_cal = lh5.read(args.raw_table_name, args.peak_file, idx=ids)
84
+ msg = f"Time to run event selection {(time.time() - t1):.2f} s, total events {len(raw_cal)}"
85
+ log.info(msg)
86
+
87
+ if isinstance(dsp_config, str | list):
88
+ dsp_config = Props.read_from(dsp_config)
89
+
90
+ if args.plot_path:
91
+ out_dict, plot_dict = dplms_ge_dict(
92
+ raw_fft,
93
+ raw_cal,
94
+ dsp_config,
95
+ db_dict,
96
+ dplms_dict,
97
+ display=1,
98
+ )
99
+ if args.inplots:
100
+ with Path(args.inplots).open("rb") as r:
101
+ inplot_dict = pkl.load(r)
102
+ inplot_dict.update({"dplms": plot_dict})
103
+
104
+ else:
105
+ out_dict = dplms_ge_dict(
106
+ raw_fft,
107
+ raw_cal,
108
+ dsp_config,
109
+ db_dict,
110
+ dplms_dict,
111
+ )
112
+
113
+ coeffs = out_dict["dplms"].pop("coefficients")
114
+ dplms_pars = Table(col_dict={"coefficients": Array(coeffs)})
115
+ out_dict["dplms"]["coefficients"] = (
116
+ f"loadlh5('{args.lh5_path}', '{args.channel}/dplms/coefficients')"
117
+ )
118
+ msg = f"DPLMS creation finished in {(time.time() - t0) / 60} minutes"
119
+ log.info(msg)
120
+ else:
121
+ out_dict = {}
122
+ dplms_pars = Table(col_dict={"coefficients": Array([])})
123
+ if args.inplots:
124
+ with Path(args.inplots).open("rb") as r:
125
+ inplot_dict = pkl.load(r)
126
+ else:
127
+ inplot_dict = {}
128
+
129
+ db_dict.update(out_dict)
130
+
131
+ Path(args.lh5_path).parent.mkdir(parents=True, exist_ok=True)
132
+ lh5.write(
133
+ Table(col_dict={"dplms": dplms_pars}),
134
+ name=args.channel,
135
+ lh5_file=args.lh5_path,
136
+ wo_mode="overwrite",
137
+ )
138
+
139
+ Path(args.dsp_pars).parent.mkdir(parents=True, exist_ok=True)
140
+ Props.write_to(args.dsp_pars, convert_dict_np_to_float(db_dict))
141
+
142
+ if args.plot_path:
143
+ Path(args.plot_path).parent.mkdir(parents=True, exist_ok=True)
144
+ with Path(args.plot_path).open("wb") as f:
145
+ pkl.dump(inplot_dict, f, protocol=pkl.HIGHEST_PROTOCOL)