From 858a153fad5dafb4a431af95301fe87e681551f3 Mon Sep 17 00:00:00 2001 From: rstiskalek Date: Fri, 18 Nov 2022 10:44:41 +0000 Subject: [PATCH] add box2cosmoredshift --- csiborgtools/units/box_units.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/csiborgtools/units/box_units.py b/csiborgtools/units/box_units.py index cff387a..a3c4bc9 100644 --- a/csiborgtools/units/box_units.py +++ b/csiborgtools/units/box_units.py @@ -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.