Cast hit-operation float parameters to float32 at load time - #43
Merged
Conversation
Calibration parameters load from the pars YAML as python (64-bit) floats, and Table.eval/numexpr promotes float32-array x float64-scalar to float64 - making every derived hit column (calibrated energies, PSD and QC classifiers, 83% of the pht tier's raw bytes, compressing at only 0.84-0.95) float64 even when the DSP inputs are float32. YAML cannot express float32, so the cast happens in build-tier-hit after loading the parameter dictionary, in both the multi-channel and single-channel entry points (covers the hit and pht tiers). Ops whose expressions reference genuine float64 columns (timestamp) still promote to float64, which is correct. Validated on production p16 pht pars over real data: 48/49 float ops become float32, all boolean cuts and NaN patterns identical, every difference <= 5e-5 of the column spread. The lone holdout is AoE_Classifier, whose generated expression embeds a 10**-99 literal - to be fixed in the A/E calibration generator upstream. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces HIT/PHT output size by preventing Table.eval/numexpr from promoting derived columns to float64 solely due to Python-float (float64) calibration parameters loaded from YAML. It introduces a load-time cast of per-operation float parameters to np.float32, and adds tests that exercise both the casting helper and the end-to-end CLI behavior.
Changes:
- Add
_cast_op_params_f32to cast operationparametersfloats (including floats inside lists) tonp.float32after config/pars merge. - Apply the cast in both
build-tier-hitentry points (multi-channel and single-channel). - Add unit + end-to-end tests asserting derived HIT outputs remain
float32when inputs arefloat32.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/legenddataflowscripts/tier/hit.py |
Adds and applies _cast_op_params_f32 to keep derived HIT/PHT columns float32 when possible. |
tests/test_build_tier_hit.py |
Adds targeted tests for type handling and an end-to-end run validating float32 output dtype and numerical agreement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #41 (
input-validation) — only the last commit is new here; retarget/rebase tomainonce #41 merges.Motivation
Profiling LEGEND production files showed the pht (hit) tier's float64 columns — 10 calibrated energies, 3 PSD classifiers, 8 QC cut classifiers — account for 83% of the tier's raw bytes and barely compress (gzip ratios 0.84–0.95, they are noise-like mantissas). They are float64 only because the calibration
parametersload from the pars YAML as python floats, andTable.eval/numexpr promotesfloat32-array × float64-scalarto float64. YAML cannot express float32, so the pars files cannot carry the dtype — the cast has to happen at load time.Change
build-tier-hitcasts python-float entries of each operation'sparameterstonp.float32after loading/merging the parameter dictionary (_cast_op_params_f32), in both the multi-channel and single-channel entry points. Sincebuild-tier-hit --tier phtis the same script, this covers the hit and pht tiers. Ints, bools and strings are untouched; floats inside lists are cast.Operations whose expressions reference genuine float64 columns (e.g.
timestamp) still promote to float64, which is correct and safe.Validation (production p16 pht pars for V05267A over real raw data)
AoE_Classifier: its generated expression embeds a10**-99division guard (a float64 literal, which also underflows to 0 in float32) — that needs a one-line fix in the A/E calibration generator (pygama), out of scope here.Tests
tests/test_build_tier_hit.py: unit test of the cast helper's type handling, plus an end-to-end run of thebuild-tier-hitconsole script over a synthetic float32 DSP file with a minimal rule-config tree, asserting the derived column comes out float32 with values matching a float64 reference at 5e-6.Disclosure
Per
AI_POLICY.md: developed with AI assistance (Claude) and reviewed by the submitter.🤖 Generated with Claude Code