Skip to content

Commit

Permalink
pre-commit cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmarshall committed Feb 3, 2024
1 parent 26549c0 commit 15922b6
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions scripts/build_skm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import os
import pathlib

import lgdo.lh5 as lh5
import numpy as np
from legendmeta import LegendMetadata
from legendmeta.catalog import Props
from lgdo.types import Table
from pygama.skm.build_skm import build_skm
from util.FileKey import ProcessingFileKey
import lgdo.lh5 as lh5
from lgdo.types import Table


sto=lh5.LH5Store()
sto = lh5.LH5Store()


def group_files(fs_evt, fs_hit, fs_dsp, fs_tcm):
Expand Down Expand Up @@ -78,9 +77,11 @@ def group_files(fs_evt, fs_hit, fs_dsp, fs_tcm):
]["skm_config"]

if isinstance(skm_config_file, dict):
skm_config = {key:Props.read_from(config_file) for key, config_file in skm_config_file.items()}
skm_config = {
key: Props.read_from(config_file) for key, config_file in skm_config_file.items()
}
else:
skm_config = {"all":Props.read_from(skm_config_file)}
skm_config = {"all": Props.read_from(skm_config_file)}

if isinstance(args.hit_files, list) and args.hit_files[0].split(".")[-1] == "filelist":
hit_files = args.hit_files[0]
Expand Down Expand Up @@ -125,11 +126,10 @@ def group_files(fs_evt, fs_hit, fs_dsp, fs_tcm):
pathlib.Path(os.path.dirname(args.output)).mkdir(parents=True, exist_ok=True)

rng = np.random.default_rng()
rand_num = rng.integers(0,99999)
rand_num = rng.integers(0, 99999)
temp_output = f"{args.output}.{rand_num:05d}"

for f_evt, f_hit, f_dsp, f_tcm in input_files:

log_string = f"running files evt:{os.path.basename(f_evt)}, hit:{os.path.basename(f_hit)},"
log_string += f"\ndsp:{os.path.basename(f_dsp)}, tcm: {os.path.basename(f_tcm)}"
log.debug(log_string)
Expand All @@ -150,10 +150,11 @@ def group_files(fs_evt, fs_hit, fs_dsp, fs_tcm):
hit_group="hit",
tcm_id_table_pattern="ch{}",
)
tables[key] = sto.read(f"skm/{key}" if key != "all" else "skm", f"{args.output}.{rand_num+1:05d}")[0]
tbl = Table(col_dict = tables)
sto.write(obj=tbl, name="skm",
lh5_file=temp_output, wo_mode="a")
tables[key] = sto.read(
f"skm/{key}" if key != "all" else "skm", f"{args.output}.{rand_num+1:05d}"
)[0]
tbl = Table(col_dict=tables)
sto.write(obj=tbl, name="skm", lh5_file=temp_output, wo_mode="a")
os.remove(f"{args.output}.{rand_num+1:05d}")

os.rename(temp_output, args.output)

0 comments on commit 15922b6

Please sign in to comment.