Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Nov 21, 2023
1 parent 890bdfb commit e4f9ad9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 43 deletions.
9 changes: 7 additions & 2 deletions src/pygama/hit/build_hit.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ def build_hit(
for high_lvl_flag, flags in cfg["aggregations"].items():
flags_list = list(flags.values())
rev_flags = [
row[::-1] for row in outtbl_obj.get_dataframe(flags_list).values # "bit0" is the rightmost bit --> reverse columns
row[::-1]
for row in outtbl_obj.get_dataframe(
flags_list
).values # "bit0" is the rightmost bit --> reverse columns
]
int_vals = [
int("".join("1" if val else "0" for val in row), 2) # 2 for binary
int(
"".join("1" if val else "0" for val in row), 2
) # 2 for binary
for row in rev_flags
]
int_vals = Array(np.array(int_vals))
Expand Down
56 changes: 25 additions & 31 deletions tests/hit/configs/aggregations-hit-config.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
{
"outputs": [
"is_valid_rt",
"is_valid_t0",
"is_valid_tmax",
"aggr1",
"aggr2"
],
"operations": {
"is_valid_rt": {
"expression": "((tp_90-tp_10)>96) & ((tp_50-tp_10)>=16)",
"parameters": {}
},
"is_valid_t0": {
"expression": "(tp_0_est>47000) & (tp_0_est<55000)",
"parameters": {}
},
"is_valid_tmax": {
"expression": "(tp_max>47000) & (tp_max<120000)",
"parameters": {}
}
"outputs": ["is_valid_rt", "is_valid_t0", "is_valid_tmax", "aggr1", "aggr2"],
"operations": {
"is_valid_rt": {
"expression": "((tp_90-tp_10)>96) & ((tp_50-tp_10)>=16)",
"parameters": {}
},
"aggregations": {
"aggr1": {
"bit0": "is_valid_rt",
"bit1": "is_valid_t0",
"bit2": "is_valid_tmax"
},
"aggr2": {
"bit0": "is_valid_t0",
"bit1": "is_valid_tmax"
}
"is_valid_t0": {
"expression": "(tp_0_est>47000) & (tp_0_est<55000)",
"parameters": {}
},
"is_valid_tmax": {
"expression": "(tp_max>47000) & (tp_max<120000)",
"parameters": {}
}
},
"aggregations": {
"aggr1": {
"bit0": "is_valid_rt",
"bit1": "is_valid_t0",
"bit2": "is_valid_tmax"
},
"aggr2": {
"bit0": "is_valid_t0",
"bit1": "is_valid_tmax"
}
}
}
}
25 changes: 15 additions & 10 deletions tests/hit/test_build_hit.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def test_outputs_specification(dsp_test_file, tmptestdir):
store = LH5Store()
obj, _ = store.read_object("/geds/hit", outfile)
assert list(obj.keys()) == ["calE", "AoE", "A_max"]


def test_aggregation_outputs(dsp_test_file, tmptestdir):
outfile = f"{tmptestdir}/LDQTA_r117_20200110T105115Z_cal_geds_hit.lh5"

Expand All @@ -110,18 +110,23 @@ def test_aggregation_outputs(dsp_test_file, tmptestdir):

sto = LH5Store()
obj, _ = sto.read_object("/geds/hit", outfile)
assert list(obj.keys()) == ["is_valid_rt", "is_valid_t0", "is_valid_tmax", "aggr1", "aggr2"]

assert list(obj.keys()) == [
"is_valid_rt",
"is_valid_t0",
"is_valid_tmax",
"aggr1",
"aggr2",
]

df = store.load_dfs(outfile, ["aggr1", "aggr2"], "geds/hit/")
assert df["aggr1"].dtype == 'int'
assert df["aggr2"].dtype == 'int'

assert df["aggr1"].dtype == "int"
assert df["aggr2"].dtype == "int"

# aggr1 consists of 3 bits --> max number can be 7, aggr2 consists of 2 bits so max numer can be 3
assert (df["aggr1"] > 7).any() == False
assert (df["aggr2"] > 3).any() == False




def test_build_hit_spms_basic(dsp_test_file_spm, tmptestdir):
out_file = f"{tmptestdir}/L200-comm-20211130-phy-spms_hit.lh5"
Expand Down

0 comments on commit e4f9ad9

Please sign in to comment.