2022-10-18 18:41:20 +00:00
|
|
|
# Copyright (C) 2022 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.
|
2022-10-20 22:28:44 +00:00
|
|
|
"""
|
|
|
|
Notebook utility functions.
|
|
|
|
"""
|
2022-10-18 18:41:20 +00:00
|
|
|
|
2022-10-20 22:28:44 +00:00
|
|
|
|
|
|
|
import numpy
|
2022-11-06 10:26:24 +00:00
|
|
|
from os.path import join
|
2022-10-20 22:28:44 +00:00
|
|
|
from tqdm import trange
|
|
|
|
from astropy.cosmology import FlatLambdaCDM
|
2022-10-18 18:41:20 +00:00
|
|
|
|
|
|
|
try:
|
2022-10-20 22:37:33 +00:00
|
|
|
import csiborgtools
|
2022-10-18 18:41:20 +00:00
|
|
|
except ModuleNotFoundError:
|
|
|
|
import sys
|
|
|
|
sys.path.append("../")
|
|
|
|
|
|
|
|
|
2022-10-30 20:16:56 +00:00
|
|
|
Nsplits = 200
|
|
|
|
dumpdir = "/mnt/extraspace/rstiskalek/csiborg/"
|
|
|
|
|
|
|
|
|
2022-10-18 18:41:20 +00:00
|
|
|
def load_mmain_convert(n):
|
|
|
|
srcdir = "/users/hdesmond/Mmain"
|
2022-10-20 22:37:33 +00:00
|
|
|
arr = csiborgtools.io.read_mmain(n, srcdir)
|
2022-10-18 18:41:20 +00:00
|
|
|
|
2022-10-20 22:37:33 +00:00
|
|
|
csiborgtools.utils.convert_mass_cols(arr, "mass_cl")
|
|
|
|
csiborgtools.utils.convert_position_cols(
|
|
|
|
arr, ["peak_x", "peak_y", "peak_z"])
|
|
|
|
csiborgtools.utils.flip_cols(arr, "peak_x", "peak_z")
|
2022-10-18 18:41:20 +00:00
|
|
|
|
2022-10-20 22:37:33 +00:00
|
|
|
d, ra, dec = csiborgtools.utils.cartesian_to_radec(arr)
|
|
|
|
arr = csiborgtools.utils.add_columns(
|
|
|
|
arr, [d, ra, dec], ["dist", "ra", "dec"])
|
2022-10-18 18:41:20 +00:00
|
|
|
return arr
|
|
|
|
|
|
|
|
|
|
|
|
def load_mmains(N=None, verbose=True):
|
2022-10-20 22:37:33 +00:00
|
|
|
ids = csiborgtools.io.get_csiborg_ids("/mnt/extraspace/hdesmond")
|
2022-10-18 18:41:20 +00:00
|
|
|
N = ids.size if N is None else N
|
|
|
|
if N > ids.size:
|
|
|
|
raise ValueError("`N` cannot be larger than 101.")
|
2022-10-20 22:28:44 +00:00
|
|
|
# If N less than num of CSiBORG, then radomly choose
|
|
|
|
if N == ids.size:
|
|
|
|
choices = numpy.arange(N)
|
|
|
|
else:
|
|
|
|
choices = numpy.random.choice(ids.size, N, replace=False)
|
|
|
|
|
2022-10-18 18:41:20 +00:00
|
|
|
out = [None] * N
|
2022-10-20 22:28:44 +00:00
|
|
|
iters = trange(N) if verbose else range(N)
|
2022-10-18 18:41:20 +00:00
|
|
|
for i in iters:
|
2022-10-20 22:28:44 +00:00
|
|
|
j = choices[i]
|
|
|
|
out[i] = load_mmain_convert(ids[j])
|
2022-10-18 18:41:20 +00:00
|
|
|
return out
|
|
|
|
|
|
|
|
|
2022-11-06 10:26:24 +00:00
|
|
|
def load_processed(Nsim, Nsnap):
|
|
|
|
simpath = csiborgtools.io.get_sim_path(Nsim)
|
|
|
|
outfname = join(
|
|
|
|
dumpdir, "ramses_out_{}_{}.npy".format(str(Nsim).zfill(5),
|
|
|
|
str(Nsnap).zfill(5)))
|
|
|
|
data = numpy.load(outfname)
|
|
|
|
# Add mmain
|
|
|
|
mmain = csiborgtools.io.read_mmain(Nsim, "/mnt/zfsusers/hdesmond/Mmain")
|
|
|
|
data = csiborgtools.io.merge_mmain_to_clumps(data, mmain)
|
|
|
|
# Cut on numbre of particles and finite m200
|
|
|
|
data = data[(data["npart"] > 100) & numpy.isfinite(data["m200"])]
|
|
|
|
|
|
|
|
# Do unit conversion
|
|
|
|
boxunits = csiborgtools.units.BoxUnits(Nsnap, simpath)
|
|
|
|
convert_cols = ["m200", "m500", "totpartmass", "mass_mmain",
|
|
|
|
"r200", "r500", "Rs", "rho0", "peak_x", "peak_y", "peak_z"]
|
|
|
|
data = csiborgtools.units.convert_from_boxunits(
|
|
|
|
data, convert_cols, boxunits)
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2022-10-18 18:41:20 +00:00
|
|
|
def load_planck2015(max_comdist=214):
|
|
|
|
cosmo = FlatLambdaCDM(H0=70.5, Om0=0.307, Tcmb0=2.728)
|
2022-10-20 22:37:33 +00:00
|
|
|
fpath = ("/mnt/zfsusers/rstiskalek/csiborgtools/"
|
2022-10-18 18:41:20 +00:00
|
|
|
+ "data/HFI_PCCS_SZ-union_R2.08.fits")
|
2022-10-20 22:37:33 +00:00
|
|
|
return csiborgtools.io.read_planck2015(fpath, cosmo, max_comdist)
|
2022-10-18 18:41:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def load_2mpp():
|
2022-10-20 22:28:44 +00:00
|
|
|
cosmo = FlatLambdaCDM(H0=70.5, Om0=0.307, Tcmb0=2.728)
|
2022-10-20 22:37:33 +00:00
|
|
|
return csiborgtools.io.read_2mpp("../data/2M++_galaxy_catalog.dat", cosmo)
|