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.iscosmological — Function
iscosmological(info::InfoType) -> BoolReturn 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) # trueMera.cosmology — Function
cosmology(info::InfoType) -> NamedTupleReturn 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:
| field | meaning |
|---|---|
iscosmological | Bool, see iscosmological |
redshift | z = 1/aexp - 1 |
aexp | scale factor a of the snapshot |
H0 | Hubble constant [km/s/Mpc] |
omega_m | matter density parameter Ωm |
omega_l | dark-energy density parameter ΩΛ |
omega_k | curvature density parameter Ωk |
omega_b | baryon density parameter Ωb |
hubble_time_Gyr | Hubble time 1/H0 [Gyr] |
age_Gyr | age of the universe at this snapshot [Gyr] |
lookback_Gyr | lookback time from z=0 to this snapshot [Gyr] |
rho_crit_cgs | critical 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.9Mera.redshift — Function
redshift(info::InfoType) -> Float64Cosmological redshift of the snapshot, z = 1/aexp - 1. Returns 0.0 for a non-cosmological run (where aexp = 1).
Mera.formation_time — Function
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_redshift — Function
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_length — Function
comoving_to_proper_length(info, length_comoving) -> Float64Convert a comoving length to the proper length at the snapshot's aexp (proper = comoving * aexp). Identity for non-cosmological runs.
Mera.proper_to_comoving_length — Function
proper_to_comoving_length(info, length_proper) -> Float64Convert a proper length at the snapshot to comoving (comoving = proper / aexp). Identity for non-cosmological runs.
Mera.comoving_to_proper_density — Function
comoving_to_proper_density(info, density_comoving) -> Float64Convert a comoving mass density to proper density (proper = comoving / aexp^3). Identity for non-cosmological runs.
Mera.proper_to_comoving_density — Function
proper_to_comoving_density(info, density_proper) -> Float64Convert 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_density — Function
critical_density(info::InfoType; unit=:g_cm3, z=redshift(info)) -> Float64Critical 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_density — Function
mean_matter_density(info::InfoType; unit=:g_cm3, z=redshift(info)) -> Float64Mean (proper) matter mass density at the snapshot redshift, ρ̄_m = Ωm · ρ_crit,0 · (1+z)³ [g/cm³].
Mera.mean_baryon_density — Function
mean_baryon_density(info::InfoType; unit=:g_cm3, z=redshift(info)) -> Float64Mean (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).