Skip to content

Commit a06eaea

Browse files
committed
more pre-commit formatting fixes, fixed snakefile imports and init file
1 parent efb6fc1 commit a06eaea

File tree

7 files changed

+69
-37
lines changed

7 files changed

+69
-37
lines changed

Snakefile

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ This includes:
1111
"""
1212

1313
import pathlib, os, json, sys
14-
import scripts as ds
14+
import scripts.util as ds
1515
from scripts.util.pars_loading import pars_catalog
1616
from scripts.util.patterns import *
17+
from scripts.util.utils import (
18+
subst_vars_in_snakemake_config,
19+
config_path,
20+
chan_map_path,
21+
pars_path,
22+
filelist_path,
23+
log_path,
24+
runcmd,
25+
)
1726
from datetime import datetime
1827
from collections import OrderedDict
1928

scripts/pars_hit_aoe.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import pickle as pkl
77

88
import numpy as np
9-
import pygama.pargen.AoE_cal as aoe
109
from legendmeta import LegendMetadata
10+
from pygama.pargen.AoE_cal import * # noqa: F403
11+
from pygama.pargen.AoE_cal import aoe_calibration, pol1, sigma_fit, standard_aoe
1112

1213
argparser = argparse.ArgumentParser()
1314
argparser.add_argument("files", help="files", nargs="*", type=str)
@@ -53,13 +54,11 @@
5354
if kwarg_dict["run_aoe"] is True:
5455
kwarg_dict.pop("run_aoe")
5556

56-
pdf = eval(kwarg_dict.pop("pdf")) if "pdf" in kwarg_dict else aoe.standard_aoe
57+
pdf = eval(kwarg_dict.pop("pdf")) if "pdf" in kwarg_dict else standard_aoe
5758

58-
sigma_func = (
59-
eval(kwarg_dict.pop("sigma_func")) if "sigma_func" in kwarg_dict else aoe.sigma_fit
60-
)
59+
sigma_func = eval(kwarg_dict.pop("sigma_func")) if "sigma_func" in kwarg_dict else sigma_fit
6160

62-
mean_func = eval(kwarg_dict.pop("mean_func")) if "mean_func" in kwarg_dict else aoe.pol1
61+
mean_func = eval(kwarg_dict.pop("mean_func")) if "mean_func" in kwarg_dict else pol1
6362

6463
if "plot_options" in kwarg_dict:
6564
for field, item in kwarg_dict["plot_options"].items():
@@ -80,7 +79,7 @@ def eres_func(x):
8079
def eres_func(x):
8180
return x * np.nan
8281

83-
cal_dict, out_dict, plot_dict, obj = aoe.aoe_calibration(
82+
cal_dict, out_dict, plot_dict, obj = aoe_calibration(
8483
files,
8584
lh5_path=f"{args.channel}/dsp",
8685
cal_dicts=cal_dict,

scripts/pars_hit_ecal.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
import matplotlib.pyplot as plt
1111
import numpy as np
1212
import pygama.math.histogram as pgh
13-
import pygama.pargen.ecal_th as ect
1413
from legendmeta import LegendMetadata
1514
from legendmeta.catalog import Props
1615
from matplotlib.colors import LogNorm
16+
from pygama.pargen.ecal_th import * # noqa: F403
17+
from pygama.pargen.ecal_th import energy_cal_th
1718
from scipy.stats import binned_statistic
1819

1920
log = logging.getLogger(__name__)
@@ -164,7 +165,7 @@ def baseline_tracking_plots(files, lh5_path, plot_options=None):
164165
common_plots = kwarg_dict.pop("common_plots")
165166

166167
if args.plot_path:
167-
out_dict, result_dict, plot_dict, ecal_object = ect.energy_cal_th(
168+
out_dict, result_dict, plot_dict, ecal_object = energy_cal_th(
168169
sorted(args.files),
169170
lh5_path=f"{args.channel}/dsp",
170171
hit_dict=hit_dict,
@@ -194,7 +195,7 @@ def baseline_tracking_plots(files, lh5_path, plot_options=None):
194195
with open(args.plot_path, "wb") as f:
195196
pkl.dump(plot_dict, f, protocol=pkl.HIGHEST_PROTOCOL)
196197
else:
197-
out_dict, result_dict, _ = ect.energy_cal_th(
198+
out_dict, result_dict, _ = energy_cal_th(
198199
sorted(args.files),
199200
lh5_path=f"{args.channel}/dsp",
200201
hit_dict=hit_dict,

scripts/pars_pht.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import pickle as pkl
77

88
import numpy as np
9-
import pygama.pargen.AoE_cal as aoe
10-
import pygama.pargen.ecal_th as ect
119
from legendmeta import LegendMetadata
10+
from pygama.pargen.AoE_cal import * # noqa: F403
11+
from pygama.pargen.AoE_cal import aoe_calibration, pol1, sigma_fit, standard_aoe
12+
from pygama.pargen.ecal_th import * # noqa: F403
13+
from pygama.pargen.ecal_th import partition_energy_cal_th
1214
from util.FileKey import ChannelProcKey, ProcessingFileKey
1315

1416
argparser = argparse.ArgumentParser()
@@ -143,23 +145,23 @@ def run_splitter(files):
143145
final_dict[timestamp] = sorted(filelist)
144146

145147
# run energy supercal
146-
ecal_results, ecal_plots, ecal_obj = ect.partition_energy_cal_th(
148+
ecal_results, ecal_plots, ecal_obj = partition_energy_cal_th(
147149
final_dict, lh5_path=f"{args.channel}/dsp", hit_dict=cal_dict, **ecal_options
148150
)
149151

150152
# run aoe cal
151153
if aoe_options.pop("run_aoe") is True:
152-
pdf = eval(aoe_options.pop("pdf")) if "pdf" in aoe_options else aoe.standard_aoe
154+
pdf = eval(aoe_options.pop("pdf")) if "pdf" in aoe_options else standard_aoe
153155

154156
if "mean_func" in aoe_options:
155157
mean_func = eval(aoe_options.pop("mean_func"))
156158
else:
157-
mean_func = aoe.pol1
159+
mean_func = pol1
158160

159161
if "sigma_func" in aoe_options:
160162
sigma_func = eval(aoe_options.pop("sigma_func"))
161163
else:
162-
sigma_func = aoe.sigma_fit
164+
sigma_func = sigma_fit
163165

164166
try:
165167
eres = ecal_results[aoe_options["cal_energy_param"]]["eres_linear"].copy()
@@ -183,7 +185,7 @@ def eres_func(x):
183185
def eres_func(x):
184186
return x * np.nan
185187

186-
cal_dict, out_dict, plot_dict, aoe_obj = aoe.aoe_calibration(
188+
cal_dict, out_dict, plot_dict, aoe_obj = aoe_calibration(
187189
final_dict,
188190
lh5_path=f"{args.channel}/dsp",
189191
cal_dicts=cal_dict,

scripts/util/__init__.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1-
from .CalibCatalog import Props, PropsStream, CalibCatalog
1+
from .CalibCatalog import CalibCatalog, Props, PropsStream
22
from .create_pars_keylist import pars_key_resolve
33
from .dataset_cal import dataset_file
4-
from .FileKey import FileKey, ProcessingFileKey, ChannelProcKey
4+
from .FileKey import ChannelProcKey, FileKey, ProcessingFileKey
55
from .pars_loading import pars_catalog
6-
from .utils import unix_time, subst_vars, subst_vars_in_snakemake_config, subst_vars_impl, runcmd
6+
from .utils import (
7+
runcmd,
8+
subst_vars,
9+
subst_vars_impl,
10+
subst_vars_in_snakemake_config,
11+
unix_time,
12+
)
13+
14+
__all__ = [
15+
"Props",
16+
"PropsStream",
17+
"CalibCatalog",
18+
"pars_key_resolve",
19+
"dataset_file",
20+
"FileKey",
21+
"ProcessingFileKey",
22+
"ChannelProcKey",
23+
"pars_catalog",
24+
"unix_time",
25+
"runcmd",
26+
"subst_vars_impl",
27+
"subst_vars",
28+
"subst_vars_in_snakemake_config",
29+
]
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{"valid_from": "20230101T123456Z", "category": "all", "apply": ["cal/p00/r000/l200-p00-r000-cal-20230101T123456Z-par_dsp.json"]}
22
{"valid_from": "20230110T123456Z", "category": "all", "apply": ["lar/p00/r000/l200-p00-r000-lar-20230110T123456Z-par_dsp.json", "cal/p00/r000/l200-p00-r000-cal-20230101T123456Z-par_dsp.json"]}
3-
{"valid_from": "20230202T004321Z", "category": "all", "apply": ["cal/p00/r001/l200-p00-r001-cal-20230202T004321Z-par_dsp.json","lar/p00/r000/l200-p00-r000-lar-20230110T123456Z-par_dsp.json"]}
3+
{"valid_from": "20230202T004321Z", "category": "all", "apply": ["cal/p00/r001/l200-p00-r001-cal-20230202T004321Z-par_dsp.json","lar/p00/r000/l200-p00-r000-lar-20230110T123456Z-par_dsp.json"]}

tests/test_util.py

+13-15
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
)
1313
from scripts.util.patterns import get_pattern_tier_daq, get_pattern_tier_dsp
1414
from scripts.util.utils import (
15-
tier_path,
1615
par_dsp_path,
17-
par_hit_path,
1816
par_overwrite_path,
19-
pars_path,
2017
tier_dsp_path,
18+
tier_path,
2119
)
2220

2321
testprod = Path(__file__).parent / "dummy_cycle"
@@ -59,7 +57,9 @@ def test_filekey():
5957

6058
def test_create_pars_keylist():
6159
key1 = FileKey("l200", "p00", "r000", "cal", "20230101T123456Z")
62-
assert pars_key_resolve.from_filekey(key1, {"cal": ["par_dsp"]}).valid_from == "20230101T123456Z"
60+
assert (
61+
pars_key_resolve.from_filekey(key1, {"cal": ["par_dsp"]}).valid_from == "20230101T123456Z"
62+
)
6363
key2 = FileKey("l200", "p00", "r000", "cal", "20230102T123456Z")
6464
assert pars_key_resolve.match_keys(key1, key2) == key1
6565
key3 = FileKey("l200", "p00", "r000", "cal", "20230101T000000Z")
@@ -69,9 +69,7 @@ def test_create_pars_keylist():
6969
pkey2 = pars_key_resolve.from_filekey(
7070
FileKey("l200", "p00", "r000", "lar", "20230102T123456Z"), {"lar": ["par_dsp"]}
7171
)
72-
assert pkey2.apply == [
73-
"lar/p00/r000/l200-p00-r000-lar-20230102T123456Z-par_dsp.json"
74-
]
72+
assert pkey2.apply == ["lar/p00/r000/l200-p00-r000-lar-20230102T123456Z-par_dsp.json"]
7573
pars_key_resolve.match_entries(pkey1, pkey2)
7674
assert set(pkey2.apply) == {
7775
"cal/p00/r000/l200-p00-r000-cal-20230101T123456Z-par_dsp.json",
@@ -97,7 +95,11 @@ def test_create_pars_keylist():
9795

9896
pkeylist = pars_key_resolve.generate_par_keylist(keylist)
9997
assert pkeylist == keylist
100-
assert set(pars_key_resolve.match_all_entries(pkeylist, {"cal": ["par_dsp"], "lar": ["par_dsp"]})[1].apply) == {
98+
assert set(
99+
pars_key_resolve.match_all_entries(pkeylist, {"cal": ["par_dsp"], "lar": ["par_dsp"]})[
100+
1
101+
].apply
102+
) == {
101103
"cal/p00/r000/l200-p00-r000-cal-20230101T123456Z-par_dsp.json",
102104
"lar/p00/r000/l200-p00-r000-lar-20230110T123456Z-par_dsp.json",
103105
}
@@ -107,9 +109,7 @@ def test_pars_loading():
107109
pars_files = CalibCatalog.get_calib_files(
108110
os.path.join(par_dsp_path(setup), "validity.jsonl"), "20230101T123456Z"
109111
)
110-
assert pars_files == [
111-
"cal/p00/r000/l200-p00-r000-cal-20230101T123456Z-par_dsp.json"
112-
]
112+
assert pars_files == ["cal/p00/r000/l200-p00-r000-cal-20230101T123456Z-par_dsp.json"]
113113

114114
par_override_files = CalibCatalog.get_calib_files(
115115
os.path.join(par_overwrite_path(setup), "dsp", "validity.jsonl"), "20230101T123456Z"
@@ -119,10 +119,8 @@ def test_pars_loading():
119119
pars_files, par_override_files
120120
)
121121

122-
assert pars_files == [
123-
"cal/p00/r000/l200-p00-r000-cal-20230101T123456Z-par_dsp.json"
124-
]
125-
122+
assert pars_files == ["cal/p00/r000/l200-p00-r000-cal-20230101T123456Z-par_dsp.json"]
123+
126124
assert set(pars_catalog.get_par_file(setup, "20230101T123456Z", "dsp")) == {
127125
os.path.join(
128126
par_dsp_path(setup),

0 commit comments

Comments
 (0)