-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in background.radial_comoving_distance
?
#128
Comments
See also: import jax.numpy as jnp
import numpy as np
import jax_cosmo as jcosmo
import matplotlib.pyplot as plt
from astropy.cosmology import Planck15 as astropy_planck15
jc_planck15 = jcosmo.Planck15()
z = jnp.linspace(0.001, 1.5, 100).astype("float32")
fig, ax = plt.subplots()
dist_mpch = jcosmo.background.radial_comoving_distance(jc_planck15, a=jcosmo.utils.z2a(z)) # in Mpc/h (??) or Mpc*h (!!)
ax.plot(z, dist_mpch / jc_planck15.h, label="dist_mpch / jref_cosmo.h", ls=":", lw=5)
ax.plot(z, dist_mpch * jc_planck15.h, label="dist_mpch * jref_cosmo.h", ls="--", )
ax.plot(z, astropy_planck15.comoving_distance(np.asarray(z)).value, label="astropy comoving_distance", ls="-")
ax.legend()
ax.set_ylabel("dist [Mpc]")
ax.set_xlabel("redshift") |
Hello had you a look at this notebook which is accompanying the Jax-Cosmo paper? import pyccl as ccl
from jax_cosmo import Cosmology, background
ccl.spline_params.A_SPLINE_NLOG=4*1024
ccl.physical_constants['T_CMB'] = 2.726 # as jax-cosmo
cosmo_ccl= ccl.Cosmology(
Omega_c=0.3, Omega_b=0.05, h=0.7, sigma8 = 0.8, n_s=0.96,
Neff=0,Omega_g=0,
transfer_function='eisenstein_hu', matter_power_spectrum='halofit')
cosmo_jax = Cosmology(Omega_c=0.3, Omega_b=0.05, h=0.7, sigma8 = 0.8, n_s=0.96,
Omega_k=0., w0=-1., wa=0.)
...
# Test array of scale factors
a_min = 0.01
a = np.linspace(a_min, 1.,100)
chi_ccl = ccl.comoving_radial_distance(cosmo_ccl, a)
chi_jax = background.radial_comoving_distance(cosmo_jax, a, log10_amin=np.log10(a_min),steps=5*1024)/cosmo_jax.h |
But So, to get distances in Mpc you should *multiply by In your example (as in mine actually) indeed you find the good chi_jax by dividing which means that your So my bug report |
Hello, Correct me if I am wrong, but if Exactly the same way that Then if |
You mean that “cosmo_jax.h" is in unit of h^-1 ? Though: import jax_cosmo as jcosmo
jc_planck15 = jcosmo.Planck15()
jc_planck15.h
So h= H0/100, then... h is not in h^-1 unit, right ? It's very confusing... |
Sorry for not being clear. It always has been the case (not specifically in jax-cosmo) that to get from Mpc to Mpc/h, we have to multiply by h, not divide by it. For instance, That's not a weird convention, the conversion from kilometers to meters works the same. To convert a distance in km into km/1000 = m, we have to multiply its value by 1000, not divide by it. To state things formally, we can see that a conversion constant c is always implicitly in unit Hope it helps still. |
Hello guys,
I'm sorry but I have a stupid question. I have the feeling that there is an issue of
h
in the functionbackground.radial_comoving_distance
: The doc says it is returning distances inMpc/h
while I think it returns it inMpc * h
.Here is an example comparing to
astropy.cosmology
astropy: [1945.56126208 5971.73020615] expected dist_mpch * jc_planck15.h: [ 893.26105 2744.334 ] dist_mpch / jc_planck15.h: [1946.6506 5980.625 ]
The text was updated successfully, but these errors were encountered: