Skip to content

Add pytest test suite, CI workflow, and real-data validation - #16

Open
yash739 wants to merge 1 commit into
masterfrom
add-pytest-test-suite
Open

Add pytest test suite, CI workflow, and real-data validation#16
yash739 wants to merge 1 commit into
masterfrom
add-pytest-test-suite

Conversation

@yash739

@yash739 yash739 commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

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

…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
sujaymate self-requested a review August 18, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant