From bf62f557fbc73e5670893cde0195ae79285a2c7c Mon Sep 17 00:00:00 2001 From: Corentin Cadiou Date: Thu, 2 Nov 2023 17:28:23 +0000 Subject: [PATCH] Also work for non-conformal simulations --- yt/frontends/ramses/fields.py | 11 +++++------ yt/utilities/lib/cosmology_time.pyx | 5 ++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/yt/frontends/ramses/fields.py b/yt/frontends/ramses/fields.py index 6937da007a..65e4b36acf 100644 --- a/yt/frontends/ramses/fields.py +++ b/yt/frontends/ramses/fields.py @@ -189,12 +189,11 @@ def star_age_from_physical_cosmo(field, data): H0 = float( data.ds.quan(data.ds.hubble_constant * 100, "km/s/Mpc").to("1/Gyr") ) - times = data[ptype, "particle_birth_time"].value - time_tot = t_frw(data.ds, 0) * H0 - birth_time = ((time_tot + times) / H0,) - return data.ds.apply_units( - data.ds.current_time.to("Gyr") - birth_time, "Gyr" - ) + times = data[ptype, "conformal_birth_time"].value + time_tot = float(t_frw(data.ds, 0) * H0) + birth_time = (time_tot + times) / H0 + t_out = float(data.ds.current_time.to("Gyr")) + return data.apply_units(t_out - birth_time, "Gyr") def star_age(field, data): formation_time = data[ptype, "particle_birth_time"] diff --git a/yt/utilities/lib/cosmology_time.pyx b/yt/utilities/lib/cosmology_time.pyx index 90dbe87b71..0a2eb9d0ec 100644 --- a/yt/utilities/lib/cosmology_time.pyx +++ b/yt/utilities/lib/cosmology_time.pyx @@ -49,13 +49,12 @@ def t_frw(ds, z): om_l = ds.omega_lambda conv = ds.quan(0.01, "Mpc/km*s").to("Gyr") - if isinstance(z, float): + if isinstance(z, (int, float)): return ds.quan( quad(_a_dot_recip, 0, aexp, args=(h0, om_m, om_l))[0], units=conv, ) - return ds.arr( [quad(_a_dot_recip, 0, a, args=(h0, om_m, om_l))[0] for a in aexp], units=conv, @@ -69,7 +68,7 @@ def tau_frw(ds, z): om_m = ds.omega_matter om_l = ds.omega_lambda - if isinstance(z, float): + if isinstance(z, (int, float)): return quad(_da_dtau_recip, 1, aexp, args=(h0, om_m, om_l))[0] return np.asarray(