diff --git a/yt/frontends/ramses/fields.py b/yt/frontends/ramses/fields.py index 6937da007a4..65e4b36acfe 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 90dbe87b71b..0a2eb9d0ec7 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(