mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-06-08 18:01:11 +00:00
Add new ICs (#59)
* edit IC paths * Remove import * Edit path * Change naming * Add __main__ * Script to match everything * Edit docs * Remove test statement * Move import * Update nb
This commit is contained in:
parent
ab8199be2c
commit
b710b8e89c
18 changed files with 9536 additions and 134 deletions
|
@ -16,5 +16,5 @@ from csiborgtools import clustering, field, fits, match, read # noqa
|
|||
|
||||
# Arguments to csiborgtools.read.CSiBORGPaths.
|
||||
paths_glamdring = {"srcdir": "/mnt/extraspace/hdesmond/",
|
||||
"postdir": "/mnt/extraspace/rstiskalek/csiborg/",
|
||||
"postdir": "/mnt/extraspace/rstiskalek/CSiBORG/",
|
||||
}
|
||||
|
|
|
@ -258,22 +258,22 @@ class PairOverlap:
|
|||
in_initial : bool
|
||||
Whether to calculate separation in the initial or final snapshot.
|
||||
norm_kind : str, optional
|
||||
The kind of normalisation to apply to the distances. Can be `r200`,
|
||||
`ref_patch` or `sum_patch`.
|
||||
The kind of normalisation to apply to the distances.
|
||||
Can be `r200c`, `ref_patch` or `sum_patch`.
|
||||
|
||||
Returns
|
||||
-------
|
||||
dist : array of 1-dimensional arrays of shape `(nhalos, )`
|
||||
"""
|
||||
assert (norm_kind is None
|
||||
or norm_kind in ("r200", "ref_patch", "sum_patch"))
|
||||
or norm_kind in ("r200c", "ref_patch", "sum_patch"))
|
||||
# Get positions either in the initial or final snapshot
|
||||
pos0 = self.cat0().position(in_initial)
|
||||
posx = self.catx().position(in_initial)
|
||||
|
||||
# Get the normalisation array if applicable
|
||||
if norm_kind == "r200":
|
||||
norm = self.cat0("r200")
|
||||
if norm_kind == "r200c":
|
||||
norm = self.cat0("r200c")
|
||||
if norm_kind == "ref_patch":
|
||||
norm = self.cat0("lagpatch")
|
||||
if norm_kind == "sum_patch":
|
||||
|
|
|
@ -146,34 +146,25 @@ class CSiBORGPaths:
|
|||
warn(f"Created directory `{fdir}`.", UserWarning, stacklevel=1)
|
||||
return join(fdir, f"{kind}_{str(nsim).zfill(5)}.{ftype}")
|
||||
|
||||
def get_ics(self, tonew):
|
||||
def get_ics(self):
|
||||
"""
|
||||
Get CSiBORG IC realisation IDs from the list of folders in
|
||||
`self.srcdir`.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
tonew : bool
|
||||
If `True`, path to the '_new' ICs is returned.
|
||||
|
||||
Returns
|
||||
-------
|
||||
ids : 1-dimensional array
|
||||
"""
|
||||
files = glob(join(self.srcdir, "ramses_out*"))
|
||||
files = [f.split("/")[-1] for f in files] # Select only file names
|
||||
if tonew:
|
||||
files = [f for f in files if "_new" in f]
|
||||
ids = [int(f.split("_")[2]) for f in files] # Take the IC IDs
|
||||
else:
|
||||
files = [f for f in files if "_inv" not in f] # Remove inv. ICs
|
||||
files = [f for f in files if "_new" not in f] # Remove _new
|
||||
files = [f for f in files if "OLD" not in f] # Remove _old
|
||||
ids = [int(f.split("_")[-1]) for f in files]
|
||||
try:
|
||||
ids.remove(5511)
|
||||
except ValueError:
|
||||
pass
|
||||
files = [f.split("/")[-1] for f in files] # Select only file names
|
||||
files = [f for f in files if "_inv" not in f] # Remove inv. ICs
|
||||
files = [f for f in files if "_new" not in f] # Remove _new
|
||||
files = [f for f in files if "OLD" not in f] # Remove _old
|
||||
ids = [int(f.split("_")[-1]) for f in files]
|
||||
try:
|
||||
ids.remove(5511)
|
||||
except ValueError:
|
||||
pass
|
||||
return numpy.sort(ids)
|
||||
|
||||
def ic_path(self, nsim, tonew=False):
|
||||
|
@ -194,6 +185,8 @@ class CSiBORGPaths:
|
|||
fname = "ramses_out_{}"
|
||||
if tonew:
|
||||
fname += "_new"
|
||||
return join(self.postdir, "output", fname.format(nsim))
|
||||
|
||||
return join(self.srcdir, fname.format(nsim))
|
||||
|
||||
def get_snapshots(self, nsim):
|
||||
|
|
|
@ -24,7 +24,7 @@ class PKReader:
|
|||
|
||||
Parameters
|
||||
----------
|
||||
get_ics : list of int
|
||||
ics : list of int
|
||||
IC IDs to be read.
|
||||
hw : float
|
||||
Box half-width.
|
||||
|
@ -35,8 +35,8 @@ class PKReader:
|
|||
dtype : dtype, optional
|
||||
Output precision. By default `numpy.float32`.
|
||||
"""
|
||||
def __init__(self, get_ics, hw, fskel=None, dtype=numpy.float32):
|
||||
self.get_ics = get_ics
|
||||
def __init__(self, ics, hw, fskel=None, dtype=numpy.float32):
|
||||
self.ics= ics
|
||||
self.hw = hw
|
||||
if fskel is None:
|
||||
fskel = "/mnt/extraspace/rstiskalek/csiborg/crosspk/out_{}_{}_{}.p"
|
||||
|
@ -69,19 +69,19 @@ class PKReader:
|
|||
-------
|
||||
ks : 1-dimensional array
|
||||
Array of wavenumbers.
|
||||
pks : 2-dimensional array of shape `(len(self.get_ics), ks.size)`
|
||||
pks : 2-dimensional array of shape `(len(self.ics), ks.size)`
|
||||
Autocorrelation of each simulation.
|
||||
"""
|
||||
kmin, kmax = self._set_klim(kmin, kmax)
|
||||
ks, pks, sel = None, None, None
|
||||
for i, nsim in enumerate(self.get_ics):
|
||||
for i, nsim in enumerate(self.ics):
|
||||
pk = joblib.load(self.fskel.format(nsim, nsim, self.hw))
|
||||
# Get cuts and pre-allocate arrays
|
||||
if i == 0:
|
||||
x = pk.k3D
|
||||
sel = (kmin < x) & (x < kmax)
|
||||
ks = x[sel].astype(self.dtype)
|
||||
pks = numpy.full((len(self.get_ics), numpy.sum(sel)),
|
||||
pks = numpy.full((len(self.ics), numpy.sum(sel)),
|
||||
numpy.nan, dtype=self.dtype)
|
||||
pks[i, :] = pk.Pk[sel, 0, 0]
|
||||
|
||||
|
@ -144,12 +144,12 @@ class PKReader:
|
|||
Cross-correlations. The first column is the the IC and is being
|
||||
cross-correlated with the remaining ICs, in the second column.
|
||||
"""
|
||||
nics = len(self.get_ics)
|
||||
nics = len(self.ics)
|
||||
|
||||
ks, xpks = None, None
|
||||
for i, ic0 in enumerate(tqdm(self.get_ics)):
|
||||
for i, ic0 in enumerate(tqdm(self.ics)):
|
||||
k = 0
|
||||
for ic1 in self.get_ics:
|
||||
for ic1 in self.ics:
|
||||
# We don't want cross-correlation
|
||||
if ic0 == ic1:
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue