add box2cosmoredshift

This commit is contained in:
rstiskalek 2022-11-18 10:44:41 +00:00
parent 06d3fede95
commit 858a153fad

View file

@ -17,10 +17,11 @@ Simulation box unit transformations.
"""
import numpy
from astropy.cosmology import LambdaCDM
from astropy.cosmology import (LambdaCDM, z_at_value)
from astropy import (constants, units)
from ..io import read_info
# Map of unit conversions
CONV_NAME = {
"length": ["peak_x", "peak_y", "peak_z", "Rs", "rmin", "rmax", "r200",
@ -198,6 +199,23 @@ class BoxUnits:
"""
return self.box2kpc(length) * 1e-3
def box2cosmoredshift(self, length):
r"""
Convert the box comoving distance to cosmological redshift.
Parameters
----------
length : float
Length in box units.
Returns
-------
cosmo_redshift : foat
The cosmological redshift.
"""
dist = self.box2mpc(length) * units.Mpc
return z_at_value(self._cosmo.comoving_distance, dist)
def solarmass2box(self, mass):
r"""
Convert mass from :math:`M_\odot` (with :math:`h=0.705`) to box units.