mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-05-20 17:41:13 +00:00
Simplify box units
This commit is contained in:
parent
5500fbd2b9
commit
162524e969
1 changed files with 6 additions and 73 deletions
|
@ -28,80 +28,39 @@ from .readsim import CSiBORGReader, QuijoteReader
|
||||||
|
|
||||||
|
|
||||||
class BaseBox(ABC):
|
class BaseBox(ABC):
|
||||||
"""
|
|
||||||
Base class for box units.
|
|
||||||
"""
|
|
||||||
_name = "box_units"
|
_name = "box_units"
|
||||||
_cosmo = None
|
_cosmo = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cosmo(self):
|
def cosmo(self):
|
||||||
"""
|
|
||||||
The box cosmology.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
cosmo : `astropy.cosmology.LambdaCDM`
|
|
||||||
"""
|
|
||||||
if self._cosmo is None:
|
if self._cosmo is None:
|
||||||
raise ValueError("Cosmology not set.")
|
raise ValueError("Cosmology not set.")
|
||||||
return self._cosmo
|
return self._cosmo
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def H0(self):
|
def H0(self):
|
||||||
r"""
|
r"""Present Hubble parameter in :math:`\mathrm{km} \mathrm{s}^{-1}`"""
|
||||||
The Hubble parameter at the time of the snapshot in units of
|
|
||||||
:math:`\mathrm{km} \mathrm{s}^{-1} \mathrm{Mpc}^{-1}`.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
H0 : float
|
|
||||||
"""
|
|
||||||
return self.cosmo.H0.value
|
return self.cosmo.H0.value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rho_crit0(self):
|
def rho_crit0(self):
|
||||||
r"""
|
"""Present-day critical density in M_sun h^2 / cMpc^3."""
|
||||||
Present-day critical density in :math:`M_\odot h^2 / \mathrm{cMpc}^3`.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
rho_crit0 : float
|
|
||||||
"""
|
|
||||||
rho_crit0 = self.cosmo.critical_density0
|
rho_crit0 = self.cosmo.critical_density0
|
||||||
return rho_crit0.to_value(units.solMass / units.Mpc**3)
|
return rho_crit0.to_value(units.solMass / units.Mpc**3)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def h(self):
|
def h(self):
|
||||||
r"""
|
"""The little 'h' parameter at the time of the snapshot."""
|
||||||
The little 'h' parameter at the time of the snapshot.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
h : float
|
|
||||||
"""
|
|
||||||
return self._h
|
return self._h
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def Om0(self):
|
def Om0(self):
|
||||||
r"""
|
"""The present time matter density parameter."""
|
||||||
The matter density parameter.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
Om0 : float
|
|
||||||
"""
|
|
||||||
return self.cosmo.Om0
|
return self.cosmo.Om0
|
||||||
|
|
||||||
@abstractproperty
|
@abstractproperty
|
||||||
def boxsize(self):
|
def boxsize(self):
|
||||||
"""
|
"""Box size in cMpc."""
|
||||||
Box size in cMpc.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
boxsize : float
|
|
||||||
"""
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -256,7 +215,7 @@ class CSiBORGBox(BaseBox):
|
||||||
|
|
||||||
class QuijoteBox(BaseBox):
|
class QuijoteBox(BaseBox):
|
||||||
"""
|
"""
|
||||||
Quijote fiducial cosmology box.
|
Quijote cosmology box.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -289,33 +248,7 @@ class QuijoteBox(BaseBox):
|
||||||
return length / self.boxsize
|
return length / self.boxsize
|
||||||
|
|
||||||
def solarmass2box(self, mass):
|
def solarmass2box(self, mass):
|
||||||
r"""
|
|
||||||
Convert mass from :math:`M_\odot / h` to box units.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
mass : float
|
|
||||||
Mass in :math:`M_\odot`.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
mass : float
|
|
||||||
Mass in box units.
|
|
||||||
"""
|
|
||||||
return mass / self._info["TotMass"]
|
return mass / self._info["TotMass"]
|
||||||
|
|
||||||
def box2solarmass(self, mass):
|
def box2solarmass(self, mass):
|
||||||
r"""
|
|
||||||
Convert mass from box units to :math:`M_\odot / h`.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
mass : float
|
|
||||||
Mass in box units.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
mass : float
|
|
||||||
Mass in :math:`M_\odot / h`.
|
|
||||||
"""
|
|
||||||
return mass * self._info["TotMass"]
|
return mass * self._info["TotMass"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue