Halo mass function¶
The HMF is the differential number density of haloes per unit
log10(M):
\[
\frac{\mathrm{d}n}{\mathrm{d}\log_{10}M}\;[(\mathrm{Mpc}/h)^{-3}]
\]
Each hmf.hdf5 file stores the mass binning, raw counts, the
differential HMF, and the cumulative n(>M).
Default binning¶
The defaults live in halocat.config:
| Constant | Default |
|---|---|
LOG10M_MIN |
12.5 |
LOG10M_MAX |
15.5 |
NBIN_HMF |
30 bins of 0.1 dex (derived from above) |
Loading or measuring¶
HMFLoader is load-or-measure: pass
overwrite=True to force a re-measurement.
from halocat import HMFLoader
loader = HMFLoader()
hmf = loader.get("LCDM", 0.25, imodel=1, ibox=1)
print(hmf.dndlog10M.shape) # (NBIN_HMF,)
print(hmf.log10M_bin_centre[[0, -1]])
print(hmf.box_size, "Mpc/h")
The returned HMFRecord carries:
log10M_bin_edges,log10M_bin_left,log10M_bin_centre— the binningcounts— raw histogram of haloes per bindndlog10M— the differential HMFn_gt_M— the cumulativen(>M)derived fromcounts/box_size**3attrs— the file-level HDF5 attributes (gravity,redshift,imodel,ibox,box_size,snapnum, ...)
Plotting¶
import matplotlib.pyplot as plt
M = 10 ** hmf.log10M_bin_centre
plt.loglog(M, hmf.dndlog10M, "o-")
plt.xlabel(r"$M\;[M_\odot/h]$")
plt.ylabel(r"$\mathrm{d}n/\mathrm{d}\log_{10}M\;[(\mathrm{Mpc}/h)^{-3}]$")
Stacking across iboxes¶
HMFLoader.get_grid loads (or
measures on demand) a sub-grid and stacks it:
import numpy as np
grid = loader.get_grid(
gravities=["LCDM"], redshifts=[0.25],
imodels=[1], iboxes=[1, 2, 3, 4, 5],
)
mean = np.nanmean(grid["dndlog10M"], axis=3) # axis=3 is `ibox`
std = np.nanstd(grid["dndlog10M"], axis=3)
The output array has shape (G, Z, M, B, K) for (gravities, redshifts,
imodels, iboxes, log10M bins). A boolean present mask of shape
(G, Z, M, B) marks which realisations contributed.
Pass skip_missing=True to leave gaps as NaN instead of triggering
on-demand measurements.
Driver scripts¶
| Script | Purpose |
|---|---|
scripts/measure_hmf.py |
Batch measurement loop (load-or-measure) |
scripts/load_hmf.py |
Inspect single records or a sub-grid summary |
scripts/plot_hmf.py |
One-panel plot, one line per imodel, mean over boxes |
See scripts/bookkeeping.md for the full driver index and flag list.