Skip to content

gh-216: move bias to spectra#417

Merged
JaimeRZP merged 3 commits into
mainfrom
216-jrz
Jul 1, 2026
Merged

gh-216: move bias to spectra#417
JaimeRZP merged 3 commits into
mainfrom
216-jrz

Conversation

@JaimeRZP

@JaimeRZP JaimeRZP commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

fixes: #216

@JaimeRZP JaimeRZP changed the title gh-219: move bias to spectra gh-216: move bias to spectra Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
py3.10 83.35% <100.00%> (-0.05%) ⬇️
py3.11 83.35% <100.00%> (-0.05%) ⬇️
py3.12 83.31% <100.00%> (-0.05%) ⬇️
py3.13 82.88% <100.00%> (-0.05%) ⬇️
py3.9 83.55% <100.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
heracles/fields.py 96.40% <100.00%> (-0.06%) ⬇️
heracles/twopoint.py 95.00% <100.00%> (-0.36%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements issue #216 by shifting additive bias handling from field-map creation to angular power spectrum computation, using bias “ingredients” stored in dtype metadata to compute (and optionally subtract) the bias at spectrum time.

Changes:

  • Compute and attach bias metadata inside angular_power_spectra() for auto-spectra using fsky, musq, and dens.
  • Stop writing precomputed bias into mapped field metadata; retain only the ingredients needed for later bias computation.
  • Update/extend tests to reflect the new bias flow and expected metadata.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
heracles/twopoint.py Computes auto-spectrum bias from stored ingredients and debiases spectra when requested.
heracles/fields.py Removes precomputed bias from field metadata; stores bias ingredients only.
tests/test_twopoint.py Adds coverage for bias metadata behavior in angular_power_spectra().
tests/test_fields.py Updates expected mapped-field metadata to no longer include bias.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread heracles/twopoint.py
Comment on lines +259 to +267
# compute bias for auto-spectra from ingredients stored during field mapping
bias = None
if k1 == k2 and i1 == i2:
_fsky = md1.get("fsky")
_musq = md1.get("musq")
_dens = md1.get("dens")
if _fsky is not None and _musq is not None and _dens is not None:
factor = 0.5 if s1 == s2 == 2 else 1.0
bias = factor * _fsky * _musq / _dens
Comment thread tests/test_twopoint.py
Comment on lines +166 to +181
alms = {("F", 0): a}
cls = angular_power_spectra(alms, debias=False)
assert cls["F", "F", 0, 0].dtype.metadata["bias"] == pytest.approx(
fsky * musq / dens
)

# spin-2 auto: bias = 0.5 * fsky * musq / dens
b = np.zeros((2, size), dtype=complex)
b.dtype = np.dtype(
b.dtype, metadata={"spin": 2, "fsky": fsky, "musq": musq, "dens": dens}
)
alms2 = {("G", 0): b}
cls2 = angular_power_spectra(alms2, debias=False)
assert cls2["G", "G", 0, 0].dtype.metadata["bias"] == pytest.approx(
0.5 * fsky * musq / dens
)
@JaimeRZP JaimeRZP merged commit f82af30 into main Jul 1, 2026
11 checks passed
@JaimeRZP JaimeRZP deleted the 216-jrz branch July 1, 2026 12:40
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.

Move bias computation to spectrum computation

2 participants