Cosmology API Reference

Functions for cosmological simulations: converting between comoving and proper frames, reading the expansion history of an output, and evaluating the background densities that set the context for a structure.

Every function takes an InfoType (or a data object carrying one), so the cosmological parameters come from the simulation itself rather than being supplied by hand. On a non-cosmological run, iscosmological returns false and the conversions are identities.

Expansion History

Reading where an output sits in cosmic history, and when an object formed.

Mera.iscosmologicalFunction
iscosmological(info::InfoType) -> Bool

Return true if the simulation is a cosmological RAMSES run, false for a non-cosmological ("idealised") run.

The decision uses the physical cosmology fields RAMSES writes into the info file. A non-cosmological run carries the sentinels aexp = 1 and omega_l = 0; any deviation (a dark-energy density, or a scale factor ≠ 1) marks a cosmological run.

info = getinfo(80, "…/yt_cosmo")
iscosmological(info)   # true
Mera.cosmologyFunction
cosmology(info::InfoType) -> NamedTuple

Return the cosmological state of the snapshot as a NamedTuple. All quantities are derived from the stored info fields, so this works on freshly read simulations and on Mera files of any age.

Fields:

fieldmeaning
iscosmologicalBool, see iscosmological
redshiftz = 1/aexp - 1
aexpscale factor a of the snapshot
H0Hubble constant [km/s/Mpc]
omega_mmatter density parameter Ωm
omega_ldark-energy density parameter ΩΛ
omega_kcurvature density parameter Ωk
omega_bbaryon density parameter Ωb
hubble_time_GyrHubble time 1/H0 [Gyr]
age_Gyrage of the universe at this snapshot [Gyr]
lookback_Gyrlookback time from z=0 to this snapshot [Gyr]
rho_crit_cgscritical density 3H(z)²/8πG at this snapshot [g/cm³]

For a non-cosmological run iscosmological is false, redshift is 0, and the cosmology-derived times/densities are returned as NaN (the sentinel info values are not physical).

c = cosmology(getinfo(80, "…/yt_cosmo"))
c.redshift        # ≈ 0.143
c.age_Gyr         # ≈ 11.9
Mera.redshiftFunction
redshift(info::InfoType) -> Float64

Cosmological redshift of the snapshot, z = 1/aexp - 1. Returns 0.0 for a non-cosmological run (where aexp = 1).

Mera.formation_timeFunction
formation_time(info::InfoType, birth; unit::Symbol=:Gyr)

Cosmic time (age of the universe) at which each star particle formed, for a cosmological RAMSES run, from its super-conformal :birth time(s). unit: :Gyr (default), :Myr, :yr, :s. Non-star sentinels return NaN. Equivalently formation_time = age_of_universe(snapshot) − stellar_age.

Mera.formation_redshiftFunction
formation_redshift(info::InfoType, birth)

Redshift z_form = 1/a_birth − 1 at which each star particle formed, for a cosmological RAMSES run, from its super-conformal :birth time(s) (scalar or array). Non-star sentinels (birth = 0) and birth times after the snapshot return NaN, so filter with birth .< 0 (or isfinite). See also formation_time.

(Note: via getvar(particles, :zform) these NaNs become 0 — getvar maps all NaNs to 0 — so there too, select stars with birth .< 0.)

zf = formation_redshift(info, getvar(part, :birth))

Comoving and Proper Frames

RAMSES stores lengths and densities in comoving units on a cosmological run. These convert in both directions.

Mera.comoving_to_proper_lengthFunction
comoving_to_proper_length(info, length_comoving) -> Float64

Convert a comoving length to the proper length at the snapshot's aexp (proper = comoving * aexp). Identity for non-cosmological runs.

Mera.proper_to_comoving_lengthFunction
proper_to_comoving_length(info, length_proper) -> Float64

Convert a proper length at the snapshot to comoving (comoving = proper / aexp). Identity for non-cosmological runs.

Mera.comoving_to_proper_densityFunction
comoving_to_proper_density(info, density_comoving) -> Float64

Convert a comoving mass density to proper density (proper = comoving / aexp^3). Identity for non-cosmological runs.

Mera.proper_to_comoving_densityFunction
proper_to_comoving_density(info, density_proper) -> Float64

Convert a proper mass density at the snapshot to comoving (comoving = proper * aexp^3). Identity for non-cosmological runs.

Background Densities

Reference densities at the redshift of the output, useful as thresholds for overdensity criteria.

Mera.critical_densityFunction
critical_density(info::InfoType; unit=:g_cm3, z=redshift(info)) -> Float64

Critical density at redshift z, ρ_crit(z) = 3H(z)²/8πG, with H(z) = H0·E(a) and the full Friedmann E(a) = √(Ωm a⁻³ + Ωk a⁻² + ΩΛ) — the same value cosmology(info).rho_crit_cgs reports at the snapshot redshift.

Note this is not ρ̄_m/Ωm. The mean matter density scales exactly as (1+z)³ whatever ΩΛ does, so mean_matter_density uses Ωm·ρ_crit,0·(1+z)³; the critical density follows E(a), which adds the ΩΛ term. At z ≈ 3.4 with Planck-like parameters the two differ by a couple of percent, so they are not interchangeable.

Code-agnostic: it needs only H0, the density parameters and the constants, so it works for RAMSES, GADGET and AREPO alike. Pass z for another redshift, or unit for something other than g/cm³ (any density unit getunit accepts, e.g. :Msol_pc3).

Mera.mean_matter_densityFunction
mean_matter_density(info::InfoType; unit=:g_cm3, z=redshift(info)) -> Float64

Mean (proper) matter mass density at the snapshot redshift, ρ̄_m = Ωm · ρ_crit,0 · (1+z)³ [g/cm³].

Mera.mean_baryon_densityFunction
mean_baryon_density(info::InfoType; unit=:g_cm3, z=redshift(info)) -> Float64

Mean (proper) baryon mass density at the snapshot redshift, ρ̄_b = Ωb · ρ_crit,0 · (1+z)³ [g/cm³]. This is the reference density for the gas overdensity getvar(hydro, :overdensity).