Skip to content

Add Yung+24 mass functions#317

Merged
steven-murray merged 5 commits into
mainfrom
add-yung24-mass-function-clean
Jul 6, 2026
Merged

Add Yung+24 mass functions#317
steven-murray merged 5 commits into
mainfrom
add-yung24-mass-function-clean

Conversation

@steven-murray

Copy link
Copy Markdown
Collaborator

Summary

Reopens #296 (originally by @christopherlovell) since that PR has gone unresponsive to review feedback and its branch can't be edited directly. This carries over Chris's original commit unchanged, plus the requested test improvements.

  • Adds the high-redshift HMF calibration from Yung et al. 2024 (MNRAS 527, 5929), calibrated on the GUREFT + MultiDark simulations across z = 6-19 down to log10(Mvir/Msun) ≈ 5.
  • New Yung24 class in src/hmf/mass_function/fitting_functions.py, modeled on Tinker08. units kwarg toggles between Table A1 ("h", default) and Table A2 ("physical").

Changes since #296

Addressing review feedback that the original two tests only exercised units-switching/error-raising behavior ("quirks of the fit") rather than actual correctness:

  • test_yung24_invalid_z_raises: covers the previously-untested z-range ValueError branch.
  • test_yung24_fsigma_matches_published_hmf: digitizes n-body data points directly from the vector graphics of Yung+24's Fig. A1, converts them to fsigma using the paper's own independent sigma(Mvir) fit (Eq. A4) and cosmology, and checks the code reproduces them to within the fit's own quoted accuracy (~30%). This is a genuine outcome-level check against the published simulation results, not a re-derivation of the same formula/coefficients the code implements.
  • Fixed a transcription slip in sim_definition: sigma_8=0.8230.829 (paper's Sec. 2 gives sigma_8 = 0.829). Documentation metadata only, doesn't affect any calculation.

Test plan

  • uv run pytest tests/ — 403 passed, 1 skipped
  • uv run ruff check / ruff format --check clean
  • Verified the new fsigma test fails when the implementation is deliberately mutated (swapped a/b exponents), confirming it actually catches bugs

Closes #296

🤖 Generated with Claude Code

christopherlovell and others added 3 commits July 5, 2026 20:42
Addresses review feedback on #296: the z-range ValueError branch was
untested, and the existing units tests only checked internal
self-consistency rather than correctness against real data.

Adds a z-range validation test, plus a test that digitizes n-body data
points from Fig. A1 of Yung+24 (arXiv:2309.14408) and checks that
fsigma, combined with the paper's own sigma(Mvir) fit (Eq. A4) and
cosmology, reproduces the published halo mass function to within the
fit's own quoted accuracy (~30%). This is an outcome-level check
against the actual published simulation results, rather than a
re-derivation of the same fitting formula the code implements.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The GUREFT simulations were run with sigma_8=0.829 (Yung+24 Sec. 2),
not 0.823 as previously recorded in sim_definition. This field is
documentation-only metadata and doesn't affect any fsigma calculation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.89%. Comparing base (09606bc) to head (f4d9dda).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #317      +/-   ##
==========================================
+ Coverage   97.86%   97.89%   +0.03%     
==========================================
  Files          26       26              
  Lines        2671     2710      +39     
==========================================
+ Hits         2614     2653      +39     
  Misses         57       57              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Steven Murray and others added 2 commits July 6, 2026 08:13
codecov flagged the cutmask property (both units branches and the
m=None fallback) as uncovered patch lines in #317.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Addresses further review feedback on the fsigma test added in b25c80b:

- Expand the (z, logM) grid instead of testing a single mass at 4
  redshifts: now covers logM=9 at all z, logM=11 for z<12, and logM=12
  for z<=8 (staying within each redshift's plotted mass range).
- Reuse hmf's own GrowthFactor instead of re-deriving the linear growth
  factor by hand.
- Compare against the *fitted* curve in Fig. A1, not the noisier n-body
  points, and clarify in the docstring that this specifically tests
  fsigma's functional form, not its propagation into dn/dm.
- Scale the tolerance by the local sensitivity d ln(fsigma)/d ln(sigma):
  fsigma ~ exp(-c/sigma^2) is exponentially sensitive to sigma at high z/
  mass, and Eq. A4's sigma(Mvir) fit is only an approximation (confirmed
  by cross-checking it against hmf's own transfer-function-based sigma),
  so a fixed tolerance is either too loose at low z or spuriously tight
  at high z.

Also adds test_yung24_dndlogm_matches_paper_fit, a separate end-to-end
check that MassFunction(hmf_model="Yung24") reproduces the same Fig. A1
points through the full pipeline (mass definitions, rho_m, real
sigma(M) from the EH transfer function) -- catching bugs the
fsigma-only test can't, using the same scaled-tolerance approach.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@steven-murray
steven-murray enabled auto-merge (squash) July 6, 2026 08:35
@steven-murray
steven-murray merged commit 3150f21 into main Jul 6, 2026
22 checks passed
@christopherlovell

Copy link
Copy Markdown
Contributor

Apologies for not getting to this earlier, busy few weeks. Glad it's in

@steven-murray

Copy link
Copy Markdown
Collaborator Author

Not a problem and thanks again for the PR!

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.

2 participants