mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-05-14 06:31:11 +00:00
Fix overlap runs (#125)
* Update nb * Update script * Update script * Rename * Update script * Update script * Remove warning * Ignore minors when extracting MAH * Fix paths bug * Move notebooks * Move files * Rename and delete things * Rename file * Move file * Rename things * Remove old print statement * Add basic MAH plot * Add random MAH path * Output snapshot numbers * Add MAH random extraction * Fix redshift bug * Edit script * Add extracting random MAH * Little updates * Add CB2 redshift * Add some caching * Add diagnostic plots * Add caching * Minor updates * Update nb * Update notebook * Update script * Add Sorce randoms * Add CB2 varysmall * Update nb * Update nb * Update nb * Use catalogue HMF * Move definition of radec2galactic * Update nb * Update import * Update import * Add galatic coords to catalogues * Update nb
This commit is contained in:
parent
c71f5a8513
commit
ee222cd010
31 changed files with 1813 additions and 798 deletions
97
scripts/mah_random.py
Normal file
97
scripts/mah_random.py
Normal file
|
@ -0,0 +1,97 @@
|
|||
# Copyright (C) 2024 Richard Stiskalek
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 3 of the License, or (at your
|
||||
# option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
"""
|
||||
Script to extract the mass accretion histories in random simulations. Follows
|
||||
the main progenitor of FoF haloes.
|
||||
"""
|
||||
from argparse import ArgumentParser
|
||||
import csiborgtools
|
||||
import numpy as np
|
||||
from h5py import File
|
||||
from mpi4py import MPI
|
||||
from taskmaster import work_delegation # noqa
|
||||
from tqdm import trange
|
||||
from cache_to_disk import cache_to_disk
|
||||
|
||||
|
||||
@cache_to_disk(30)
|
||||
def load_data(nsim, simname, min_logmass):
|
||||
"""Load the data for a given simulation."""
|
||||
bnd = {"totmass": (10**min_logmass, None), "dist": (None, 135)}
|
||||
if "csiborg2_" in simname:
|
||||
kind = simname.split("_")[-1]
|
||||
cat = csiborgtools.read.CSiBORG2Catalogue(nsim, 99, kind, bounds=bnd)
|
||||
merger_reader = csiborgtools.read.CSiBORG2MergerTreeReader(nsim, kind)
|
||||
else:
|
||||
raise ValueError(f"Unknown simname: {simname}")
|
||||
|
||||
return cat, merger_reader
|
||||
|
||||
|
||||
def main_progenitor_mah(cat, merger_reader, simname, verbose=True):
|
||||
"""Follow the main progenitor of each `z = 0` FoF halo."""
|
||||
indxs = cat["index"]
|
||||
|
||||
# Main progenitor information as a function of time
|
||||
shape = (len(cat), cat.nsnap + 1)
|
||||
main_progenitor_mass = np.full(shape, np.nan, dtype=np.float32)
|
||||
group_mass = np.full(shape, np.nan, dtype=np.float32)
|
||||
|
||||
for i in trange(len(cat), disable=not verbose, desc="Haloes"):
|
||||
d = merger_reader.main_progenitor(indxs[i])
|
||||
|
||||
main_progenitor_mass[i, d["SnapNum"]] = d["MainProgenitorMass"]
|
||||
group_mass[i, d["SnapNum"]] = d["Group_M_Crit200"]
|
||||
|
||||
return {"Redshift": [csiborgtools.snap2redshift(i, simname) for i in range(cat.nsnap + 1)], # noqa
|
||||
"MainProgenitorMass": main_progenitor_mass,
|
||||
"GroupMass": group_mass,
|
||||
"FinalGroupMass": cat["totmass"],
|
||||
}
|
||||
|
||||
|
||||
def save_output(data, nsim, simname, verbose=True):
|
||||
"""Save the output to a file."""
|
||||
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
||||
|
||||
fname = paths.random_mah(simname, nsim)
|
||||
if verbose:
|
||||
print(f"Saving output to `{fname}`")
|
||||
|
||||
with File(fname, "w") as f:
|
||||
for key, value in data.items():
|
||||
f.create_dataset(key, data=value)
|
||||
|
||||
|
||||
if "__main__" == __name__:
|
||||
parser = ArgumentParser(description="Extract the mass accretion history in random simulations.") # noqa
|
||||
parser.add_argument("--simname", help="Name of the simulation.", type=str,
|
||||
choices=["csiborg2_random"])
|
||||
parser.add_argument("--min_logmass", type=float,
|
||||
help="Minimum log mass of the haloes.")
|
||||
args = parser.parse_args()
|
||||
COMM = MPI.COMM_WORLD
|
||||
|
||||
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
||||
nsims = paths.get_ics(args.simname)
|
||||
|
||||
def main(nsim):
|
||||
verbose = COMM.Get_size() == 1
|
||||
cat, merger_reader = load_data(nsim, args.simname, args.min_logmass)
|
||||
data = main_progenitor_mah(cat, merger_reader, args.simname,
|
||||
verbose=verbose)
|
||||
save_output(data, nsim, args.simname, verbose=verbose)
|
||||
|
||||
work_delegation(main, list(nsims), MPI.COMM_WORLD)
|
23
scripts/mah_random.sh
Executable file
23
scripts/mah_random.sh
Executable file
|
@ -0,0 +1,23 @@
|
|||
memory=4
|
||||
on_login=${1}
|
||||
nthreads=5
|
||||
|
||||
queue="berg"
|
||||
env="/mnt/users/rstiskalek/csiborgtools/venv_csiborg/bin/python"
|
||||
file="mah_random.py"
|
||||
|
||||
min_logmass=13.0
|
||||
simname="csiborg2_random"
|
||||
|
||||
|
||||
pythoncm="$env $file --simname $simname --min_logmass $min_logmass"
|
||||
if [ $on_login -eq 1 ]; then
|
||||
echo $pythoncm
|
||||
$pythoncm
|
||||
else
|
||||
cm="addqueue -q $queue -n $nthreads -m $memory $pythoncm"
|
||||
echo "Submitting:"
|
||||
echo $cm
|
||||
echo
|
||||
eval $cm
|
||||
fi
|
|
@ -56,7 +56,8 @@ if __name__ == "__main__":
|
|||
choices=["overlap", "max"], help="Kind of matching.")
|
||||
parser.add_argument("--simname", type=str, required=True,
|
||||
help="Simulation name.",
|
||||
choices=["csiborg", "quijote"])
|
||||
choices=["csiborg1", "quijote", "csiborg2_main",
|
||||
"csiborg2_random", "csiborg2_varysmall"])
|
||||
parser.add_argument("--nsim0", type=int, default=None,
|
||||
help="Reference IC for Max's matching method.")
|
||||
parser.add_argument("--min_logmass", type=float, required=True,
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#!/bin/bash
|
||||
nthreads=11
|
||||
memory=4
|
||||
queue="cmb"
|
||||
nthreads=41
|
||||
memory=12
|
||||
queue="berg"
|
||||
env="/mnt/zfsusers/rstiskalek/csiborgtools/venv_csiborg/bin/python"
|
||||
file="match_all.py"
|
||||
file="match_overlap_all.py"
|
||||
|
||||
simname="quijote"
|
||||
min_logmass=13.25
|
||||
nsim0=0
|
||||
kind="max"
|
||||
mult=10
|
||||
simname=${1}
|
||||
min_logmass=12.25
|
||||
sigma=1
|
||||
kind="overlap"
|
||||
mult=10 # Only for Max's method
|
||||
nsim0=0 # Only for Max's method
|
||||
verbose="false"
|
||||
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ file="match_overlap_single.py"
|
|||
|
||||
simname="csiborg2_main"
|
||||
kind="overlap"
|
||||
min_logmass=13.25
|
||||
mult=5
|
||||
min_logmass=12
|
||||
mult=5 # Only for Max's method
|
||||
sigma=1
|
||||
|
||||
# sims=(7444 7468)
|
||||
|
@ -37,14 +37,14 @@ do
|
|||
|
||||
pythoncm="$env $file --kind $kind --nsim0 $nsim0 --nsimx $nsimx --simname $simname --min_logmass $min_logmass --sigma $sigma --mult $mult --verbose $verbose"
|
||||
|
||||
# $pythoncm
|
||||
$pythoncm
|
||||
|
||||
cm="addqueue -q $queue -n 1x1 -m $memory $pythoncm"
|
||||
echo "Submitting:"
|
||||
echo $cm
|
||||
echo
|
||||
$cm
|
||||
sleep 0.05
|
||||
# cm="addqueue -q $queue -n 1x1 -m $memory $pythoncm"
|
||||
# echo "Submitting:"
|
||||
# echo $cm
|
||||
# echo
|
||||
# $cm
|
||||
# sleep 0.05
|
||||
|
||||
done
|
||||
done
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue