mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-05-12 13:41:13 +00:00
CDF for nearest neighbour (#63)
* Updat ebounds * fix mistake * add plot script * fix which sims * Add Poisson * Just docs * Hide things to __main__ * Rename paths * Move old script * Remove radpos * Paths renaming * Paths renaming * Remove trunk stuff * Add import * Add nearest neighbour search * Add Quijote fiducial indices * Add final snapshot matching * Add fiducial observer selection * add boxsizes * Add reading functions * Little stuff * Bring back the fiducial observer * Add arguments * Add quijote paths * Add notes * Get this running * Add yaml * Remove Poisson stuff * Get the 2PCF script running * Add not finished htings * Remove comment * Verbosity only on 0th rank! * Update plotting style * Add nearest neighbour CDF * Save radial distance too * Add centres * Add basic plotting
This commit is contained in:
parent
369438f881
commit
2185846e90
34 changed files with 1254 additions and 351 deletions
103
scripts_plots/plot_knn.py
Normal file
103
scripts_plots/plot_knn.py
Normal file
|
@ -0,0 +1,103 @@
|
|||
# Copyright (C) 2023 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.
|
||||
|
||||
from os.path import join
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy
|
||||
|
||||
import scienceplots # noqa
|
||||
import utils
|
||||
|
||||
try:
|
||||
import csiborgtools
|
||||
except ModuleNotFoundError:
|
||||
import sys
|
||||
sys.path.append("../")
|
||||
import csiborgtools
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Probability of matching a reference simulation halo #
|
||||
###############################################################################
|
||||
|
||||
|
||||
def plot_knn(runname):
|
||||
print(f"Plotting kNN CDF for {runname}.")
|
||||
cols = plt.rcParams["axes.prop_cycle"].by_key()["color"]
|
||||
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
||||
reader = csiborgtools.read.kNNCDFReader(paths)
|
||||
|
||||
with plt.style.context(utils.mplstyle):
|
||||
plt.figure()
|
||||
|
||||
# Quijote kNN
|
||||
rs, cdf, ndensity = reader.read("quijote", runname, kind="auto")
|
||||
pk = reader.prob_k(cdf)
|
||||
pk_poisson = reader.poisson_prob_k(rs, numpy.arange(pk.shape[1]),
|
||||
ndensity)
|
||||
|
||||
for k in range(3):
|
||||
mu = numpy.mean(pk[:, k, :], axis=0)
|
||||
std = numpy.std(pk[:, k, :], axis=0)
|
||||
plt.plot(rs, mu, label=r"$k = {}$, Quijote".format(k + 1),
|
||||
c=cols[k % len(cols)])
|
||||
# plt.fill_between(rs, mu - std, mu + std, alpha=0.15,
|
||||
# color=cols[k % len(cols)], zorder=0)
|
||||
|
||||
mu = numpy.mean(pk_poisson[:, k, :], axis=0)
|
||||
std = numpy.std(pk_poisson[:, k, :], axis=0)
|
||||
plt.plot(rs, mu, c=cols[k % len(cols)], ls="dashed",
|
||||
label=r"$k = {}$, Poisson analytical".format(k + 1))
|
||||
# plt.fill_between(rs, mu - std, mu + std, alpha=0.15,
|
||||
# color=cols[k % len(cols)], zorder=0, hatch="\\")
|
||||
|
||||
# Quijote poisson kNN
|
||||
rs, cdf, ndensity = reader.read("quijote", "mass003_poisson",
|
||||
kind="auto")
|
||||
pk = reader.prob_k(cdf)
|
||||
|
||||
for k in range(3):
|
||||
mu = numpy.mean(pk[:, k, :], axis=0)
|
||||
std = numpy.std(pk[:, k, :], axis=0)
|
||||
plt.plot(rs, mu, label=r"$k = {}$, Poisson Quijote".format(k + 1),
|
||||
c=cols[k % len(cols)], ls="dotted")
|
||||
# plt.fill_between(rs, mu - std, mu + std, alpha=0.15,
|
||||
# color=cols[k % len(cols)], zorder=0)
|
||||
|
||||
# # CSiBORG kNN
|
||||
# rs, cdf, ndensity = reader.read("csiborg", runname, kind="auto")
|
||||
# pk = reader.mean_prob_k(cdf)
|
||||
# for k in range(2):
|
||||
# mu = pk[k, :, 0]
|
||||
# std = pk[k, :, 1]
|
||||
# plt.plot(rs, mu, ls="--", c=cols[k % len(cols)])
|
||||
# plt.fill_between(rs, mu - std, mu + std, alpha=0.15, hatch="\\",
|
||||
# color=cols[k % len(cols)], zorder=0)
|
||||
|
||||
plt.legend()
|
||||
plt.xlabel(r"$r~[\mathrm{Mpc}]$")
|
||||
plt.ylabel(r"$P(k | V = 4 \pi r^3 / 3)$")
|
||||
|
||||
for ext in ["png"]:
|
||||
fout = join(utils.fout, f"knn_{runname}.{ext}")
|
||||
print("Saving to `{fout}`.".format(fout=fout))
|
||||
plt.savefig(fout, dpi=utils.dpi, bbox_inches="tight")
|
||||
plt.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
plot_knn("mass003")
|
91
scripts_plots/plot_nearest.py
Normal file
91
scripts_plots/plot_nearest.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
# Copyright (C) 2023 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.
|
||||
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy
|
||||
import scienceplots # noqa
|
||||
from cache_to_disk import cache_to_disk, delete_disk_caches_for_function
|
||||
|
||||
import utils
|
||||
|
||||
try:
|
||||
import csiborgtools
|
||||
except ModuleNotFoundError:
|
||||
import sys
|
||||
sys.path.append("../")
|
||||
import csiborgtools
|
||||
|
||||
|
||||
@cache_to_disk(7)
|
||||
def read_cdf(simname, run, kwargs):
|
||||
paths = csiborgtools.read.Paths(**kwargs["paths_kind"])
|
||||
reader = csiborgtools.read.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
return reader.build_cdf(simname, run, verbose=True)
|
||||
|
||||
|
||||
def plot_cdf(kwargs):
|
||||
print("Plotting the CDFs.", flush=True)
|
||||
paths = csiborgtools.read.Paths(**kwargs["paths_kind"])
|
||||
reader = csiborgtools.read.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
x = reader.bin_centres("neighbour")
|
||||
|
||||
y_quijote = read_cdf("quijote", "mass003", kwargs)
|
||||
y_csiborg = read_cdf("csiborg", "mass003", kwargs)
|
||||
ncdf = y_quijote.shape[0]
|
||||
|
||||
with plt.style.context(utils.mplstyle):
|
||||
plt.figure()
|
||||
for i in range(ncdf):
|
||||
if i == 0:
|
||||
label1 = "Quijote"
|
||||
label2 = "CSiBORG"
|
||||
else:
|
||||
label1 = None
|
||||
label2 = None
|
||||
plt.plot(x, y_quijote[i], c="C0", label=label1)
|
||||
plt.plot(x, y_csiborg[i], c="C1", label=label2)
|
||||
plt.xlim(0, 75)
|
||||
plt.ylim(0, 1)
|
||||
plt.xlabel(r"$r_{\rm neighbour}~[\mathrm{Mpc}]$")
|
||||
plt.ylabel(r"$\mathrm{CDF}(r_{\rm neighbour})$")
|
||||
plt.legend()
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig("../plots/nearest_neighbour_cdf.png", dpi=450,
|
||||
bbox_inches="tight")
|
||||
plt.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('-c', '--clean', action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
kwargs = {"rmax_radial": 155 / 0.705,
|
||||
"nbins_radial": 20,
|
||||
"rmax_neighbour": 100.,
|
||||
"nbins_neighbour": 150,
|
||||
"paths_kind": csiborgtools.paths_glamdring}
|
||||
|
||||
cached_funcs = ["read_cdf"]
|
||||
if args.clean:
|
||||
for func in cached_funcs:
|
||||
print(f"Cleaning cache for function {func}.")
|
||||
delete_disk_caches_for_function(func)
|
||||
|
||||
|
||||
plot_cdf(kwargs)
|
|
@ -15,4 +15,4 @@
|
|||
|
||||
dpi = 450
|
||||
fout = "../plots/"
|
||||
mplstyle = ["notebook"]
|
||||
mplstyle = ["science", "notebook"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue