mirror of
https://github.com/Richard-Sti/csiborgtools.git
synced 2024-12-22 17:08:03 +00:00
add mass and position conversions
This commit is contained in:
parent
0876716719
commit
c24842baf1
2 changed files with 53 additions and 1 deletions
|
@ -14,4 +14,5 @@
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
from .readsim import (get_sim_path, open_particle, open_unbinding,
|
from .readsim import (get_sim_path, open_particle, open_unbinding,
|
||||||
read_particle, read_clumpid, read_clumps)
|
read_particle, read_clumpid, read_clumps,
|
||||||
|
convert_mass_cols, convert_position_cols)
|
||||||
|
|
|
@ -11,6 +11,8 @@ F32 = numpy.float32
|
||||||
F64 = numpy.float64
|
F64 = numpy.float64
|
||||||
I32 = numpy.int32
|
I32 = numpy.int32
|
||||||
I64 = numpy.int64
|
I64 = numpy.int64
|
||||||
|
BOXSIZE = 677.7 # Mpc/h. Otherwise positions in [0, 1].
|
||||||
|
BOXMASS = 3.749e19 # Msun
|
||||||
|
|
||||||
|
|
||||||
def get_sim_path(n, fname="ramses_out_{}", srcdir="/mnt/extraspace/hdesmond"):
|
def get_sim_path(n, fname="ramses_out_{}", srcdir="/mnt/extraspace/hdesmond"):
|
||||||
|
@ -297,3 +299,52 @@ def read_clumps(n, simpath):
|
||||||
for i, name in enumerate(dtype["names"]):
|
for i, name in enumerate(dtype["names"]):
|
||||||
out[name] = arr[:, i]
|
out[name] = arr[:, i]
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def convert_mass_cols(arr, cols):
|
||||||
|
"""
|
||||||
|
Convert mass columns from box units to :math:`M_{odot}`. `arr` is passed by
|
||||||
|
reference and is not explicitly returned back.
|
||||||
|
|
||||||
|
TODO: check about little h
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
arr : structured array
|
||||||
|
The array whose columns are to be converted.
|
||||||
|
cols : str or list of str
|
||||||
|
The mass columns to be converted.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
cols = [cols] if isinstance(cols, str) else cols
|
||||||
|
for col in cols:
|
||||||
|
arr[col] *= BOXMASS
|
||||||
|
|
||||||
|
|
||||||
|
def convert_position_cols(arr, cols, zero_centered=False):
|
||||||
|
"""
|
||||||
|
Convert position columns from box units to :math:`Mpc / h`. `arr` is
|
||||||
|
passed by reference and is not explicitly returned back.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
arr : structured array
|
||||||
|
The array whose columns are to be converted.
|
||||||
|
cols : str or list of str
|
||||||
|
The mass columns to be converted.
|
||||||
|
zero_centered : bool, optional
|
||||||
|
Whether to translate the well-resolved origin in the centre of the
|
||||||
|
simulation to the :math:`(0, 0 , 0)` point.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
cols = [cols] if isinstance(cols, str) else cols
|
||||||
|
for col in cols:
|
||||||
|
arr[col] *= BOXSIZE
|
||||||
|
if zero_centered:
|
||||||
|
arr[col] -= BOXSIZE / 2
|
||||||
|
|
Loading…
Reference in a new issue