halogal Documentation

API Reference

Unified model classes for UVHMR and HOD calculations.

This module provides a class-based interface for all galaxy population modeling calculations, combining UV-halo mass relations with halo occupation distributions.

class halogal.model.HODModel(z, eps0=None, Mc=None, a=None, b=None, sigma_UV=None, Mcut=None, Msat=None, asat=None, add_dust=True)[source]

Bases: UVHMRModel

Halo Occupation Distribution model.

This class extends UVHMRModel to include central and satellite galaxy occupation functions.

Parameters:
  • z (float) – Redshift

  • eps0 (float, optional) – Star formation efficiency normalization. Default from config.

  • Mc (float, optional) – Characteristic halo mass in M_sun. Default from config.

  • a (float, optional) – Low-mass power-law slope. Default from config.

  • b (float, optional) – High-mass power-law slope. Default from config.

  • sigma_UV (float, optional) – UV magnitude scatter. Default from config.

  • Mcut (float, optional) – Satellite cutoff mass in M_sun. Default from config.

  • Msat (float, optional) – Satellite normalization mass in M_sun. Default from config.

  • asat (float, optional) – Satellite power-law slope. Default from config.

  • add_dust (bool, optional) – Whether to include dust attenuation. Default is True.

sigma_UV, Mcut, Msat, asat

HOD parameters

Type:

float

Examples

>>> # Use all defaults
>>> model = HODModel(z=6.0)
>>>
>>> # Compute occupation numbers
>>> import numpy as np
>>> Mh = np.logspace(10, 13, 100)
>>> N_cen = model.Ncen(Mh, MUV_thresh=-19.0)
>>> N_sat = model.Nsat(Mh, MUV_thresh=-19.0)
Ncen(Mh, MUV_thresh)[source]

Central galaxy occupation function.

Average number of central galaxies with M_UV < MUV_thresh.

Parameters:
  • Mh (float or array_like) – Halo mass in M_sun

  • MUV_thresh (float) – UV magnitude threshold (brighter than)

Returns:

N_cen – Average number of central galaxies

Return type:

float or ndarray

Ngal(Mh, MUV_thresh)[source]

Total galaxy occupation (central + satellite).

Parameters:
  • Mh (float or array_like) – Halo mass in M_sun

  • MUV_thresh (float) – UV magnitude threshold

Returns:

N_gal – Average total number of galaxies

Return type:

float or ndarray

Nsat(Mh, MUV_thresh)[source]

Satellite galaxy occupation function.

Average number of satellite galaxies with M_UV < MUV_thresh.

Parameters:
  • Mh (float or array_like) – Halo mass in M_sun

  • MUV_thresh (float) – UV magnitude threshold

Returns:

N_sat – Average number of satellite galaxies

Return type:

float or ndarray

update_parameters(**kwargs)[source]

Update model parameters.

Parameters:

**kwargs (dict) – Parameters to update: z, eps0, Mc, a, b, sigma_UV, Mcut, Msat, asat, add_dust

class halogal.model.HalomodHOD(z=None, MUV_thresh1=None, MUV_thresh2=None, eps0=None, Mc=None, a=None, b=None, sigma_UV=None, Mcut=None, Msat=None, asat=None, add_dust=None, h=None, M_min=None, **kwargs)[source]

Bases: HODPoisson

Halomod-compatible HOD class wrapping the HODModel.

This class bridges our HODModel with halomod’s expectations.

IMPORTANT: Handles unit conversions between halomod (M_sun/h) and HODModel (M_sun).

Parameters:
  • z (float) – Redshift

  • MUV_thresh1 (float, optional) – Bright-end UV magnitude threshold

  • MUV_thresh2 (float, optional) – Faint-end UV magnitude threshold

  • eps0 (optional) – HOD parameters. Default from config.

  • Mc (optional) – HOD parameters. Default from config.

  • a (optional) – HOD parameters. Default from config.

  • b (optional) – HOD parameters. Default from config.

  • sigma_UV (optional) – HOD parameters. Default from config.

  • Mcut (optional) – HOD parameters. Default from config.

  • Msat (optional) – HOD parameters. Default from config.

  • asat (optional) – HOD parameters. Default from config.

  • add_dust (optional) – HOD parameters. Default from config.

  • h (float, optional) – Hubble parameter H0/100

Examples

>>> hod = HalomodHOD(z=5.0, MUV_thresh1=-19.1, h=0.7)
class halogal.model.Observables(hod_model)[source]

Bases: object

Compute observables from an HOD model.

This class provides methods to compute various observables like luminosity functions, galaxy bias, and correlation functions from an HOD model.

All observable methods accept optional **params keyword arguments (eps0, Mc, a, b, sigma_UV, Mcut, Msat, asat) to update the underlying HOD model before computing. This enables efficient MCMC loops without recreating any objects.

For correlation functions specifically, use the initialize/update pattern: 1. Call initialize_correlation_model() once 2. Call update_correlation_model() in your MCMC loop

Parameters:

hod_model (HODModel) – The HOD model to use for computations

hod_model

The underlying HOD model

Type:

HODModel

Examples

>>> # Basic usage
>>> model = HODModel(z=6.0)
>>> obs = Observables(model)
>>> MUV = np.linspace(-22, -16, 20)
>>> phi = obs.luminosity_function(MUV)
>>> # MCMC fitting - all observables support inline parameter updates
>>> obs = Observables(HODModel(z=6.0))
>>> for eps0, sigma_UV in mcmc_samples:
...     phi = obs.luminosity_function(MUV, eps0=eps0, sigma_UV=sigma_UV)
...     bg = obs.galaxy_bias(MUV, eps0=eps0, sigma_UV=sigma_UV)
>>> # Correlation function MCMC (uses halomod caching)
>>> obs.initialize_correlation_model(MUV_thresh1=-19.1)
>>> for eps0, sigma_UV in mcmc_samples:
...     result = obs.update_correlation_model(eps0=eps0, sigma_UV=sigma_UV)
...     w_theta = result['correlation']
compute_correlation_function(MUV_thresh1, MUV_thresh2=0, **kwargs)[source]

Compute correlation function (convenience method).

This creates a new halomod model each time. For MCMC fitting, use initialize_correlation_model() + update_correlation_model() instead.

Parameters are the same as initialize_correlation_model().

Returns:

result – Dictionary with ‘model’, ‘separation’, ‘correlation’, ‘type’

Return type:

dict

galaxy_bias(MUV_arr, dMUV=0.05, **params)[source]

Compute galaxy bias as a function of UV magnitude.

Parameters:
  • MUV_arr (array_like) – Array of UV absolute magnitudes

  • dMUV (float, optional) – Magnitude bin width

  • **params (dict, optional) – HOD parameter overrides (eps0, Mc, a, b, sigma_UV, Mcut, Msat, asat, add_dust). Applied to the model before computing.

Returns:

bias – Galaxy bias

Return type:

ndarray

initialize_correlation_model(MUV_thresh1, MUV_thresh2=0, cosmo_model=None, correlation_type='angular', zmin=None, zmax=None, znum=150, p1=None, theta_min=1.0, theta_max=7200.0, theta_num=100, rmin=0.001, rmax=200.0, rnum=200, rp_min=0.1, rp_max=100.0, rp_num=100, pi_max=100.0, hmf_model='Watson', bias_model='Tinker10', concentration_model='Duffy08', halo_profile='NFW', exclusion_model='DblSphere_', sd_bias_model=None, **kwargs)[source]

Initialize halomod model for efficient parameter updates.

Call this once before MCMC fitting. Then use update_correlation_model() to efficiently update HOD parameters.

This creates and caches the halomod model, allowing fast parameter updates via halomod’s update() method.

Parameters are the same as compute_correlation_function().

Returns:

result – Dictionary with ‘model’, ‘separation’, ‘correlation’, ‘type’

Return type:

dict

Examples

>>> # Initialize once
>>> obs = Observables(model)
>>> result = obs.initialize_correlation_model(
...     MUV_thresh1=-19.1, correlation_type='angular'
... )
>>>
>>> # Update efficiently in MCMC loop
>>> for eps0 in mcmc_chain:
...     result = obs.update_correlation_model(eps0=eps0)
...     chi2 = compute_chi2(result['correlation'], data)
luminosity_function(MUV_arr, dMUV=0.05, **params)[source]

Compute UV luminosity function.

Parameters:
  • MUV_arr (array_like) – Array of UV absolute magnitudes

  • dMUV (float, optional) – Magnitude bin width. Default is 0.05.

  • **params (dict, optional) – HOD parameter overrides (eps0, Mc, a, b, sigma_UV, Mcut, Msat, asat, add_dust). Applied to the model before computing.

Returns:

phi – Luminosity function Φ(M_UV) in Mpc^-3 mag^-1

Return type:

ndarray

Examples

>>> obs.luminosity_function(MUV)                          # current params
>>> obs.luminosity_function(MUV, eps0=0.3, sigma_UV=0.5)  # override
mean_bias(MUV_thresh, **params)[source]

Compute mean galaxy bias for galaxies brighter than threshold.

Parameters:
  • MUV_thresh (float) – UV magnitude threshold

  • **params (dict, optional) – HOD parameter overrides.

Returns:

bias_mean – Mean galaxy bias

Return type:

float

mean_halo_mass(MUV_thresh, **params)[source]

Compute mean halo mass for galaxies brighter than threshold.

Parameters:
  • MUV_thresh (float) – UV magnitude threshold

  • **params (dict, optional) – HOD parameter overrides.

Returns:

log10_Mh_mean – Mean log10 halo mass

Return type:

float

number_density(MUV_thresh, **params)[source]

Compute cumulative galaxy number density brighter than threshold.

Parameters:
  • MUV_thresh (float) – UV magnitude threshold

  • **params (dict, optional) – HOD parameter overrides.

Returns:

n_gal – Galaxy number density in Mpc^-3

Return type:

float

update_correlation_model(z_center=None, p_of_z=None, MUV_thresh1=None, MUV_thresh2=None, eps0=None, Mc=None, a=None, b=None, sigma_UV=None, Mcut=None, Msat=None, asat=None)[source]

Update HOD parameters and recompute correlation function efficiently.

This uses halomod’s update() method to efficiently recompute the correlation function with new parameters, without recreating the entire model.

Must call initialize_correlation_model() first.

Parameters:
  • z_center (float, optional) – Update the redshift center

  • p_of_z (callable, optional) – Update the redshift distribution function

  • MUV_thresh1 (float, optional) – Update UV magnitude threshold

  • MUV_thresh2 (float, optional) – Update faint-end threshold

  • eps0 (float, optional) – Update star formation efficiency

  • Mc (float, optional) – Update characteristic mass

  • a (float, optional) – Update low-mass slope

  • b (float, optional) – Update high-mass slope

  • sigma_UV (float, optional) – Update UV scatter

  • Mcut (float, optional) – Update satellite cutoff mass

  • Msat (float, optional) – Update satellite normalization mass

  • asat (float, optional) – Update satellite slope

Returns:

result – Dictionary with ‘model’, ‘separation’, ‘correlation’, ‘type’

Return type:

dict

Examples

>>> # Initialize once
>>> result = obs.initialize_correlation_model(MUV_thresh1=-19.1)
>>>
>>> # Update in MCMC loop
>>> for eps0, sigma_UV in zip(eps0_chain, sigma_UV_chain):
...     result = obs.update_correlation_model(
...         eps0=eps0, sigma_UV=sigma_UV
...     )
...     likelihood = compute_likelihood(result['correlation'])
class halogal.model.UVHMRModel(z, eps0=None, Mc=None, a=None, b=None, add_dust=True)[source]

Bases: object

Base class for UV-Halo Mass Relation models.

This class handles the relationship between halo mass and UV luminosity through star formation. It serves as the foundation for more complex models that include occupation distributions.

Parameters:
  • z (float) – Redshift

  • eps0 (float, optional) – Star formation efficiency normalization. Default from config.

  • Mc (float, optional) – Characteristic halo mass in M_sun. Default from config.

  • a (float, optional) – Low-mass power-law slope. Default from config.

  • b (float, optional) – High-mass power-law slope. Default from config.

  • add_dust (bool, optional) – Whether to include dust attenuation. Default is True.

z, eps0, Mc, a, b

Model parameters

Type:

float

add_dust

Whether dust is included

Type:

bool

Examples

>>> # Use all defaults (fitted to Bouwens+2021)
>>> model = UVHMRModel(z=6.0)
>>>
>>> # Override specific parameters
>>> model = UVHMRModel(z=6.0, eps0=0.2, Mc=10**12)
MUV(Mh)[source]

UV absolute magnitude from halo mass.

Parameters:

Mh (float or array_like) – Halo mass in M_sun

Returns:

MUV – UV absolute magnitude

Return type:

float or ndarray

Mhalo(MUV, M_min=1000000.0, M_max=1e+16, num_points=1000)[source]

Inverse: halo mass from UV magnitude.

Parameters:
  • MUV (float or array_like) – UV absolute magnitude

  • M_min (float, optional) – Halo mass range for interpolation

  • M_max (float, optional) – Halo mass range for interpolation

  • num_points (int, optional) – Number of points for interpolation

Returns:

Mh – Halo mass in M_sun

Return type:

float or ndarray

halo_accretion_rate(Mh)[source]

Compute halo mass accretion rate.

Parameters:

Mh (float or array_like) – Halo mass in M_sun

Returns:

dMh_dt – Halo mass accretion rate in M_sun/yr

Return type:

float or ndarray

sfr(Mh)[source]

Star formation rate from halo mass.

Parameters:

Mh (float or array_like) – Halo mass in M_sun

Returns:

sfr – Star formation rate in M_sun/yr

Return type:

float or ndarray

star_formation_efficiency(Mh)[source]

Compute star formation efficiency.

Parameters:

Mh (float or array_like) – Halo mass in M_sun

Returns:

epsilon – Star formation efficiency

Return type:

float or ndarray

update_parameters(**kwargs)[source]

Update model parameters.

Parameters:

**kwargs (dict) – Parameters to update: z, eps0, Mc, a, b, add_dust

Cosmology-related functions for halo mass function and bias calculations.

class halogal.cosmology.HaloMassFunction(z, M_min=6, M_max=15, num_points=None, mdef='vir', model='watson13')[source]

Class for computing and caching halo mass functions.

This class provides a convenient interface for HMF calculations with optional caching of results.

z

Redshift

Type:

float

M_min

Minimum log10(M/M_sun)

Type:

float

M_max

Maximum log10(M/M_sun)

Type:

float

num_points

Number of mass bins

Type:

int

mdef

Mass definition

Type:

str

model

HMF model

Type:

str

property halo_bias

Get halo bias.

property hmf

Get halo mass function.

property log10_mass

Get log10 mass array.

property mass

Get linear mass array.

halogal.cosmology.get_halo_bias(M, z, mdef='vir', model='tinker10')[source]

Compute halo bias as a function of mass and redshift.

Parameters:
  • M (float or array_like) – Halo mass in M_sun (physical units)

  • z (float) – Redshift

  • mdef (str, optional) – Mass definition. Default is ‘vir’.

  • model (str, optional) – Bias model. Default is ‘tinker10’.

Returns:

b – Halo bias (dimensionless)

Return type:

float or ndarray

Notes

Colossus expects mass in M_sun/h. To factor out h: M [M_sun/h] = M [M_sun] * h

halogal.cosmology.get_halo_mass_function(z, M_min=6, M_max=15, num_points=None, mdef='vir', model='watson13')[source]

Compute the halo mass function at redshift z.

Parameters:
  • z (float) – Redshift

  • M_min (float, optional) – Minimum log10(M/M_sun) in physical units. Default is 6.

  • M_max (float, optional) – Maximum log10(M/M_sun) in physical units. Default is 15.

  • num_points (int, optional) – Number of mass bins. Default is from config.

  • mdef (str, optional) – Mass definition: ‘vir’, ‘fof’, ‘200m’, etc. Default is ‘vir’.

  • model (str, optional) – HMF model: ‘watson13’, ‘tinker08’, ‘reed07’, etc. Default is ‘watson13’.

Returns:

  • log10_mass (ndarray) – Array of log10(M/M_sun) in physical units

  • hmf (ndarray) – Halo mass function dn/dln(M) in physical units of Mpc^-3

Notes

Colossus expects mass in M_sun/h and returns dn/dlnM in (h/Mpc)^3. To convert between physical and comoving units: - Mass: M [M_sun/h] = M [M_sun] * h (factor out h by multiplying) - HMF: dn/dlnM [Mpc^-3] = dn/dlnM [(h/Mpc)^3] * h^3 (evaluate h)

UV luminosity and dust attenuation functions.

halogal.luminosity.MUV_from_SFR(sfr, z, add_dust=True, c_uv=None, convergence_threshold=0.02)[source]

Convert star formation rate to UV absolute magnitude.

Parameters:
  • sfr (float or array_like) – Star formation rate in M_sun/yr

  • z (float) – Redshift

  • add_dust (bool, optional) – Whether to add dust attenuation. Default is True.

  • c_uv (float, optional) – SFR to UV luminosity conversion factor. Default is Salpeter IMF value from config.

  • convergence_threshold (float, optional) – Convergence criterion for dust iteration. Default is 0.02 (2%).

Returns:

MUV_obs – Observed UV absolute magnitude (with dust if add_dust=True)

Return type:

float or ndarray

Notes

Dust attenuation is added iteratively until convergence because the MUV-beta relation is calibrated on observations.

halogal.luminosity.SFR_from_MUV(MUV, z, remove_dust=True, c_uv=None)[source]

Convert UV absolute magnitude to star formation rate.

Parameters:
  • MUV (float or array_like) – UV absolute magnitude

  • z (float) – Redshift

  • remove_dust (bool, optional) – Whether to remove dust attenuation. Default is True.

  • c_uv (float, optional) – SFR to UV luminosity conversion factor.

Returns:

sfr – Star formation rate in M_sun/yr

Return type:

float or ndarray

halogal.luminosity.beta_color(z, MUV)[source]

UV spectral slope (beta) as a function of redshift and magnitude.

Based on Bouwens+2013-14 data.

Parameters:
  • z (float or array_like) – Redshift

  • MUV (float or array_like) – UV absolute magnitude

Returns:

beta – UV spectral slope

Return type:

float or ndarray

References

Bouwens et al. 2013, 2014

halogal.luminosity.dust_attenuation(z, MUV, high_z_dust=True, C0=None, C1=None)[source]

UV dust attenuation as a function of redshift and magnitude.

Parameters:
  • z (float or array_like) – Redshift

  • MUV (float or array_like) – UV absolute magnitude (observed)

  • high_z_dust (bool, optional) – Whether to include dust at z > 8. Default is True.

  • C0 (float, optional) – Attenuation constant. Default from config.

  • C1 (float, optional) – Attenuation slope. Default from config.

Returns:

A_UV – UV dust attenuation in magnitudes

Return type:

float or ndarray

Notes

This should be applied iteratively since the MUV-beta relation is calibrated on observations, not intrinsic magnitudes.