mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-05-13 14:11:11 +00:00
Add better diagnostics & plotting (#67)
* Add caching functions * Add limts * Add new mass runs * Update .gitignore * Edit which CDFs are loaded * Stop saving cross hindxs * Change dist to half precision * New nearest path * Add neighbour counting * Add neighbour kwargs * Update work in progress * Add new counting * Add how dist is built * Collect dist to 1 file * Update reading routine * Delete Quijote files * Remove file * Back to float32 * Fix bugs * Rename utils * Remove neighbuor kwargs * Rename file * Fix bug * Rename plt utils * Change where nghb kwargs from * line length * Remove old notebooks * Move survey * Add white space * Update TODO * Update CDF calculation * Update temporarily plotting * Merge branch 'add_diagnostics' of github.com:Richard-Sti/csiborgtools into add_diagnostics * Start adding documentation to plotting * Remove comments * Better code documentation * Some work on tidal tensor * Better plotting * Add comment * Remove nb * Remove comment * Add documentation * Update plotting * Update submission * Update KL vs KS plots * Update the plotting routine * Update plotting * Update plotting routines
This commit is contained in:
parent
004d9629a2
commit
ccbbbd24b4
20 changed files with 1075 additions and 32121 deletions
|
@ -19,12 +19,14 @@ MPI parallelized over the reference simulations.
|
|||
from argparse import ArgumentParser
|
||||
from datetime import datetime
|
||||
from distutils.util import strtobool
|
||||
from os import remove
|
||||
|
||||
import numpy
|
||||
import yaml
|
||||
from mpi4py import MPI
|
||||
|
||||
from taskmaster import work_delegation
|
||||
from tqdm import trange
|
||||
|
||||
from utils import open_catalogues
|
||||
|
||||
try:
|
||||
|
@ -36,7 +38,7 @@ except ModuleNotFoundError:
|
|||
import csiborgtools
|
||||
|
||||
|
||||
def find_neighbour(args, nsim, cats, paths, comm):
|
||||
def find_neighbour(args, nsim, cats, paths, comm, save_kind):
|
||||
"""
|
||||
Find the nearest neighbour of each halo in the given catalogue.
|
||||
|
||||
|
@ -53,23 +55,78 @@ def find_neighbour(args, nsim, cats, paths, comm):
|
|||
Paths object.
|
||||
comm : mpi4py.MPI.Comm
|
||||
MPI communicator.
|
||||
save_kind : str
|
||||
Kind of data to save. Must be either `dist` or `bin_dist`.
|
||||
|
||||
Returns
|
||||
-------
|
||||
None
|
||||
"""
|
||||
assert save_kind in ["dist", "bin_dist"]
|
||||
ndist, cross_hindxs = csiborgtools.match.find_neighbour(nsim, cats)
|
||||
|
||||
mass_key = "totpartmass" if args.simname == "csiborg" else "group_mass"
|
||||
cat0 = cats[nsim]
|
||||
mass = cat0[mass_key]
|
||||
rdist = cat0.radial_distance(in_initial=False)
|
||||
|
||||
fout = paths.cross_nearest(args.simname, args.run, nsim)
|
||||
# Distance is saved optionally, whereas binned distance is always saved.
|
||||
if save_kind == "dist":
|
||||
out = {"ndist": ndist,
|
||||
"cross_hindxs": cross_hindxs,
|
||||
"mass": cat0[mass_key],
|
||||
"ref_hindxs": cat0["index"],
|
||||
"rdist": rdist}
|
||||
fout = paths.cross_nearest(args.simname, args.run, "dist", nsim)
|
||||
if args.verbose:
|
||||
print(f"Rank {comm.Get_rank()} writing to `{fout}`.", flush=True)
|
||||
numpy.savez(fout, **out)
|
||||
|
||||
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
||||
reader = csiborgtools.read.NearestNeighbourReader(
|
||||
paths=paths, **csiborgtools.neighbour_kwargs)
|
||||
counts = numpy.zeros((reader.nbins_radial, reader.nbins_neighbour),
|
||||
dtype=numpy.float32)
|
||||
counts = reader.count_neighbour(counts, ndist, rdist)
|
||||
out = {"counts": counts}
|
||||
fout = paths.cross_nearest(args.simname, args.run, "bin_dist", nsim)
|
||||
if args.verbose:
|
||||
print(f"Rank {comm.Get_rank()} writing to `{fout}`.", flush=True)
|
||||
numpy.savez(fout, ndist=ndist, cross_hindxs=cross_hindxs, mass=mass,
|
||||
ref_hindxs=cat0["index"], rdist=rdist)
|
||||
numpy.savez(fout, **out)
|
||||
|
||||
|
||||
def collect_dist(args, paths):
|
||||
"""
|
||||
Collect the binned nearest neighbour distances into a single file.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
args : argparse.Namespace
|
||||
Command line arguments.
|
||||
paths : csiborgtools.paths.Paths
|
||||
Paths object.
|
||||
|
||||
Returns
|
||||
-------
|
||||
"""
|
||||
fnames = paths.cross_nearest(args.simname, args.run, "bin_dist")
|
||||
|
||||
if args.verbose:
|
||||
print("Collecting counts into a single file.", flush=True)
|
||||
|
||||
for i in trange(len(fnames)) if args.verbose else range(len(fnames)):
|
||||
fname = fnames[i]
|
||||
data = numpy.load(fname)
|
||||
if i == 0:
|
||||
out = data["counts"]
|
||||
else:
|
||||
out += data["counts"]
|
||||
|
||||
remove(fname)
|
||||
|
||||
fout = paths.cross_nearest(args.simname, args.run, "tot_counts",
|
||||
nsim=0, nobs=0)
|
||||
if args.verbose:
|
||||
print(f"Writing the summed counts to `{fout}`.", flush=True)
|
||||
numpy.savez(fout, tot_counts=out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -87,16 +144,23 @@ if __name__ == "__main__":
|
|||
with open("./match_finsnap.yml", "r") as file:
|
||||
config = yaml.safe_load(file)
|
||||
|
||||
if args.simname == "csiborg":
|
||||
save_kind = "dist"
|
||||
else:
|
||||
save_kind = "bin_dist"
|
||||
|
||||
comm = MPI.COMM_WORLD
|
||||
rank = comm.Get_rank()
|
||||
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
||||
cats = open_catalogues(args, config, paths, comm)
|
||||
|
||||
def do_work(nsim):
|
||||
return find_neighbour(args, nsim, cats, paths, comm)
|
||||
return find_neighbour(args, nsim, cats, paths, comm, save_kind)
|
||||
|
||||
work_delegation(do_work, list(cats.keys()), comm,
|
||||
master_verbose=args.verbose)
|
||||
|
||||
comm.Barrier()
|
||||
if comm.Get_rank() == 0:
|
||||
if rank == 0:
|
||||
collect_dist(args, paths)
|
||||
print(f"{datetime.now()}: all finished. Quitting.")
|
||||
|
|
|
@ -18,20 +18,77 @@ nbins_marks: 10
|
|||
name:
|
||||
- totpartmass
|
||||
- group_mass
|
||||
min: 1.e+12
|
||||
max: 1.e+13
|
||||
min: 12.4
|
||||
max: 12.8
|
||||
islog: true
|
||||
|
||||
"mass002":
|
||||
primary:
|
||||
name:
|
||||
- totpartmass
|
||||
- group_mass
|
||||
min: 1.e+13
|
||||
max: 1.e+14
|
||||
min: 12.6
|
||||
max: 13.0
|
||||
islog: true
|
||||
|
||||
"mass003":
|
||||
primary:
|
||||
name:
|
||||
- totpartmass
|
||||
- group_mass
|
||||
min: 1.e+14
|
||||
min: 12.8
|
||||
max: 13.2
|
||||
islog: true
|
||||
|
||||
"mass004":
|
||||
primary:
|
||||
name:
|
||||
- totpartmass
|
||||
- group_mass
|
||||
min: 13.0
|
||||
max: 13.4
|
||||
islog: true
|
||||
|
||||
"mass005":
|
||||
primary:
|
||||
name:
|
||||
- totpartmass
|
||||
- group_mass
|
||||
min: 13.2
|
||||
max: 13.6
|
||||
islog: true
|
||||
|
||||
"mass006":
|
||||
primary:
|
||||
name:
|
||||
- totpartmass
|
||||
- group_mass
|
||||
min: 13.4
|
||||
max: 13.8
|
||||
islog: true
|
||||
|
||||
"mass007":
|
||||
primary:
|
||||
name:
|
||||
- totpartmass
|
||||
- group_mass
|
||||
min: 13.6
|
||||
max: 14.0
|
||||
islog: true
|
||||
|
||||
"mass008":
|
||||
primary:
|
||||
name:
|
||||
- totpartmass
|
||||
- group_mass
|
||||
min: 13.8
|
||||
max: 14.2
|
||||
islog: true
|
||||
|
||||
"mass009":
|
||||
primary:
|
||||
name:
|
||||
- totpartmass
|
||||
- group_mass
|
||||
min: 14.0
|
||||
islog: true
|
|
@ -106,8 +106,12 @@ def read_single_catalogue(args, config, nsim, run, rmax, paths, nobs=None):
|
|||
pname = _name
|
||||
if pname is None:
|
||||
raise KeyError(f"Invalid names `{sel['name']}`.")
|
||||
|
||||
cat.apply_bounds({pname: (sel.get("min", None), sel.get("max", None))})
|
||||
xmin = sel.get("min", None)
|
||||
xmax = sel.get("max", None)
|
||||
if sel.get("islog", False):
|
||||
xmin = 10**xmin if xmin is not None else None
|
||||
xmax = 10**xmax if xmax is not None else None
|
||||
cat.apply_bounds({pname: (xmin, xmax)})
|
||||
|
||||
# Now the secondary selection bounds. If needed transfrom the secondary
|
||||
# property before applying the bounds.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue