Add pytest test suite, CI workflow, and real-data validation - #16
Open
yash739 wants to merge 1 commit into
Open
Conversation
…60325A - Unit tests (test_poldata.py, test_polresponse.py, test_polarizationlike.py) against synthetic FITS fixtures in conftest.py. - Real-data tests (test_real_data_joint_fit.py) exercising the full TimeSeriesBuilder -> PolarizationLike -> joint likelihood pipeline against real POLAR event/response data. - Paper validation (test_paper_validation.py): PA-offset regression pins for real POLAR + 5 Daksha faces, a real local MultiNest recovery check against known injected values, and a parametrized comparison against Figure 6's quoted results (skips without analysis-server data access). - GitHub Actions CI workflow installing threeML's polpy branch (PyPI threeML doesn't have from_polarization/to_polarizationlike). - Removed broken/duplicate legacy test files; moved non-test analysis scripts from tests/ to examples/. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
sujaymate
self-requested a review
August 18, 2026 14:00
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.
Summary
Adds a working pytest suite for polpy (previously broken/incomplete — see below), a GitHub Actions CI workflow, and real-data regression/validation tests built from fitting/GRB160325A/joint_fit_daksha_polar.py in the paper repo.
Unit tests (test_poldata.py, test_polresponse.py, test_polarizationlike.py) — 13 tests against synthetic FITS fixtures in conftest.py, covering masking, PA-offset calculation, harmonic response fitting, angle wrapping, boundary polarization fractions, nuisance parameter toggles, and NaN-safety of the log-likelihood.
Real-data tests (test_real_data_joint_fit.py) — loads real POLAR event/response data for GRB160325A and checks the full pipeline (TimeSeriesBuilder.from_polarization → to_polarizationlike → joint likelihood) executes cleanly.
Paper validation (test_paper_validation.py):
get_pa_offset() pinned as a regression test (tight tolerance) against real POLAR data (2 files) and 5 real Daksha face files.
A real local MultiNest joint fit (POLAR + 5-face Daksha) verified against known injected values — recovered PF=52.3%(+2.4/−4.5) vs injected 50%, PA=115.8°(+3.4/−1.1) vs injected 117°, both within 1σ. Marked slow, skips automatically without a real MultiNest install.
A parametrized check against Figure 6's quoted POLAR/Daksha/joint recovery values — skips without access to the analysis-server data paths, since that data isn't (and shouldn't be) checked into the repo.
CI: .github/workflows/ci.yml runs the fast suite on python=3.12 (matching pyproject.toml's >=3.12 requirement), installing threeML from the polpy branch since TimeSeriesBuilder.from_polarization/to_polarizationlike aren't in the PyPI release.
Bugs found along the way
PolData can't load real POLAR files as-is — NCHANS/NSABINS are hardcoded as required header keys, but real POLAR .pevt files don't carry them. Worked around locally by patching the header on the copies in tests/data/; not fixed in poldata.py itself (see tests/data/README.md). Real fix needs a maintainer call on the right fallback (derive from data vs. from the paired .prsp).
Circular import between threeML.utils.data_builders.time_series_builder's PolPy-detection probe and polpy.polarizationlike's own from threeML import PluginPrototype — whichever imports first determines whether TimeSeriesBuilder.from_polarization silently becomes unavailable. Worked around in conftest.py (see comment there); real fix is probably a lazy import somewhere.
PyMultiNest/threeML crashes the whole Python process (sys.exit(1), not ImportError) on any machine without a compiled libmultinest (e.g. Windows, or plain-pip CI without conda-forge's multinest). Guarded in conftest.py since none of these tests exercise the sampler itself.
Known limitations
The Figure 6 comparison tests need the real analysis-server data paths (/home/polpy/...) to actually run; they're designed to be exercised there, not in ordinary CI.
cc @sujaymate