Skip to content

Commit

Permalink
Also work for non-conformal simulations
Browse files Browse the repository at this point in the history
  • Loading branch information
cphyc committed Nov 2, 2023
1 parent 5f4efb2 commit bf62f55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 5 additions & 6 deletions yt/frontends/ramses/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
5 changes: 2 additions & 3 deletions yt/utilities/lib/cosmology_time.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit bf62f55

Please sign in to comment.