# Comoving distance between two points [(RA1, Dec1, z1) and (RA2, Dec2, z2)]

I have Redshift (z), RA and Dec positions for two points in a galaxy catalogue (say P1 = [z1=4, RA1=140, Dec1=2] and P2 = [z2=6, RA2=150, Dec2=5], where RA and Dec are given in degrees). How can I find the comoving distance between these two points using any package in python (like AstroPy, CosmoloPy etc)?

I am assuming a Flat-LCDM model with the cosmology H0=70, Om0=0.3, Ob0=0.05.

Presently, I am using this:

import cosmolopy.distance as cd
cosmo = {'omega_M_0' : 0.3, 'omega_lambda_0' : 0.7, 'h' : 0.70}
cosmo = cd.set_omega_k_0(cosmo)
z1 = 4.0
z2 = 6.0
d_co = cd.comoving_distance(z2, **cosmo)


Specifically, my questions are these:

(i) In the said example, how do I use information of the starting redshift z1?

(ii) Do I need to use information of [RA1, Dec1] and [RA2, Dec2] for an accurate calculation of the comoving separation between P1 and P2 (I need to find the comoving distance to a great degree of accuracy)?

As per my understanding one can get the distance between two object using astropy function. like this

# using astropy function the 3d separation
c1 = SkyCoord(ra1  *u.deg, dec1 *u.deg, distance=d_co1*u.Mpc, frame='icrs')
c2 = SkyCoord(ra2*u.deg, dec2 *u.deg, distance=d_co2*u.Mpc, frame='icrs')
# the commoving distance between any two galaxies
sep = c1.separation_3d(c2)


meanwhile for long distance we do consider the effect of expansion of the universe in that case we use this method as follows

# Comoving distance
D = cosmo.comoving_distance(z_cl)
D_C=cosmo.comoving_distance(z_halo)

# for member galaxies

# for cluster
ra_clus = ra_cl* np.pi / 180.0 # in radian
dec_clus = dec_cl * np.pi / 180.0 # in radian

x_cl = D * np.cos(dec_clus) * np.cos(ra_clus)
y_cl = D * np.cos(dec_clus) * np.sin(ra_clus)
z_cl = D * np.sin(dec_clus)

# commoving 3d distance between any two object in space-time
distance=np.sqrt((x_cl-x)**2+(y_cl-y)**2+(z_cl-z)**2)

# the physical distance can be calculated as follow:
# D_AB Physical distance to the galaxy B as seen from the galaxy A (ie distance between A and B)
D_AB = np.array(sep)/(1+np.array(zg))

#similarly the physical distance D_BA the distance of the galaxy A as seen from B
D_BA = np.array(sep)/(1+z_cl)
$$$$
`
• Are you sure this function can be used for cosmological distances? I think it's made for local distances that don't take into account the expansion of the Universe.
– pela
Feb 12 at 11:08
• Dear i admit that one is for local distances therefore i have written the one which take accounf for the expansion of the universe. please do correct me if possible
– Atul
Mar 28 at 20:49
• In comoving coordinates, SkyCoords should work as intended. To convert a comoving distance $d_\mathrm{com}$ to a physical distance $d_\mathrm{phy} = a\,d_\mathrm{com} = d_\mathrm{com}/(1+z)$, you then just need to specify in whose reference frame you want to calculate it, i.e. whose $z$ to use.
– pela
Apr 20 at 13:13
• Dear Pela thank you for the feedback its really helpful. i did the required changes. Best
– Atul
Apr 22 at 1:12

The general algorithm for the calculation is as follows:

First object Right Ascension, Declination and Redshift: $$\quad \alpha_1, \ \delta_1, \ z_1$$

Second object Right Ascension, Declination and Redshift: $$\alpha_2, \ \delta_2, \ z_2$$

Applying spherical trigonometry, the cosine of the angle $$\theta$$ between both objects is:

$$\cos \theta = \sin \delta_1 \sin \delta_2+\cos \delta_1 \cos \delta_2 \cos(\alpha_2-\alpha_1)$$

For a flat universe, as ours appears to be: $$\Omega_{K_0}=0$$.

For $$z_i < 100$$ we can neglect $$\Omega_{R_0}$$. Then, the distances to us now can be calculated using:

$$d_1=\frac{c}{H_0} \int_0^{z_1} \dfrac{dx}{\sqrt{\Omega_{M_0}(1+x)^3+\Omega_{\Lambda_0}}}$$

$$d_2=\frac{c}{H_0} \int_0^{z_2} \dfrac{dx}{\sqrt{\Omega_{M_0}(1+x)^3+\Omega_{\Lambda_0}}}$$

$$c=299 \ 792 \ 458 \ m/s$$

According to the results-2018 of the Planck Mission, the best values of the cosmological parameters are:

$$H_0=67.66 \ (km/s)/Mpc$$

$$\Omega_{M_0}=0.3111$$

$$\Omega_{\Lambda_0}=0.6889$$

This integral has no elementary primitive, but can be easily calculated by numerical methods.

Finally, to calculate the distance "$$d$$" between both objects now, use the law of cosines:

$$d=\sqrt{d_1^2+d_2^2-2 \ d_1 d_2 \cos \theta \, \, }$$

Regards