diff --git a/tests/hit/configs/aggregations-hit-config.json b/tests/hit/configs/aggregations-hit-config.json new file mode 100644 index 000000000..db5f5380d --- /dev/null +++ b/tests/hit/configs/aggregations-hit-config.json @@ -0,0 +1,34 @@ +{ + "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": {} + } + }, + "aggregations": { + "aggr1": { + "bit0": "is_valid_rt", + "bit1": "is_valid_t0", + "bit2": "is_valid_tmax" + }, + "aggr2": { + "bit0": "is_valid_t0", + "bit1": "is_valid_tmax" + } + } + } \ No newline at end of file diff --git a/tests/hit/test_build_hit.py b/tests/hit/test_build_hit.py index e497a1742..0c7cf3cf4 100644 --- a/tests/hit/test_build_hit.py +++ b/tests/hit/test_build_hit.py @@ -96,7 +96,32 @@ 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" + + build_hit( + dsp_test_file, + outfile=outfile, + hit_config=f"{config_dir}/aggregations-hit-config.json", + wo_mode="overwrite", + ) + sto = LH5Store() + obj, _ = sto.read_object("/geds/hit", outfile) + 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' + + # 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"