CSiBORG FoF switch (#75)

* Add moving FoF membership files

* add FoF membership path

* Add notes where its PHEW

* Add FoF catalogue path

* Correct typo

* Add more functionalities

* Make work with halo IDs from FoF

* Edit print statement

* Fix copy bug

* copy

* Add FoF catalogue reading

* Clean up script

* Fix typo

* Little edits

* Fix naming convention

* Rename key

* Remove loading substructure particles

* Rename CSiBORG Cat

* Rename clumps cat

* Rename cat

* Remove misplaced import

* Switch to halos

* rm import

* structfit of only halos

* Add FoF halo reading

* Add a short comment

* Fix __getitem__ to work with int

* Fix problems

* Improve __getitem__

* Add more conversion

* Fix indexing

* Fix __getitem__ assertion

* Fix numbers

* Rename

* Fix verbosity flags

* Add full Quijote HMF option

* Add plot of Quijote only

* Add quijote full paths

* Fix the fit_init script

* Renam arg

* Update .gitignore

* add default argument name

* Change default verbosity flag

* Modernise script structure

* Fix dictionary

* Fix reading to include m200c

* Modernise script

* Add args
This commit is contained in:
Richard Stiskalek 2023-07-24 14:10:21 +02:00 committed by GitHub
parent fcd1a6b321
commit eb8d070fff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 659 additions and 466 deletions

View file

@ -46,11 +46,11 @@ def open_csiborg(nsim):
Returns
-------
cat : csiborgtools.read.HaloCatalogue
cat : csiborgtools.read.CSiBORGHaloCatalogue
"""
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
bounds = {"totpartmass": (None, None), "dist": (0, 155/0.705)}
return csiborgtools.read.HaloCatalogue(nsim, paths, bounds=bounds)
return csiborgtools.read.CSiBORGHaloCatalogue(nsim, paths, bounds=bounds)
def open_quijote(nsim, nobs=None):
@ -118,7 +118,7 @@ def plot_mass_vs_ncells(nsim, pdf=False):
def plot_hmf(pdf=False):
"""
Plot the (ultimate paretn) halo mass function of CSiBORG and Quijote.
Plot the FoF halo mass function of CSiBORG and Quijote.
Parameters
----------
@ -132,7 +132,8 @@ def plot_hmf(pdf=False):
print("Plotting the HMF...", flush=True)
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
csiborg_nsims = paths.get_ics("csiborg")
# csiborg_nsims = paths.get_ics("csiborg")
csiborg_nsims = [7444]
print("Loading CSiBORG halo counts.", flush=True)
for i, nsim in enumerate(tqdm(csiborg_nsims)):
data = numpy.load(paths.halo_counts("csiborg", nsim))
@ -141,6 +142,8 @@ def plot_hmf(pdf=False):
csiborg_counts = numpy.full((len(csiborg_nsims), len(bins) - 1),
numpy.nan, dtype=numpy.float32)
csiborg_counts[i, :] = data["counts"]
print(data["counts"])
print(csiborg_counts)
csiborg_counts /= numpy.diff(bins).reshape(1, -1)
print("Loading Quijote halo counts.", flush=True)
@ -211,6 +214,76 @@ def plot_hmf(pdf=False):
plt.close()
def plot_hmf_quijote_full(pdf=False):
"""
Plot the FoF halo mass function of Quijote full run.
Parameters
----------
pdf : bool, optional
Whether to save the figure as a PDF file.
Returns
-------
None
"""
print("Plotting the HMF...", flush=True)
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
print("Loading Quijote halo counts.", flush=True)
quijote_nsims = paths.get_ics("quijote")
for i, nsim in enumerate(tqdm(quijote_nsims)):
data = numpy.load(paths.halo_counts("quijote_full", nsim))
if i == 0:
bins = data["bins"]
counts = numpy.full((len(quijote_nsims), len(bins) - 1), numpy.nan,
dtype=numpy.float32)
counts[i, :] = data["counts"]
counts /= numpy.diff(bins).reshape(1, -1)
counts /= 1000**3
x = 10**(0.5 * (bins[1:] + bins[:-1]))
# Edit lower and upper limits
counts[:, x < 10**(12.4)] = numpy.nan
counts[:, x > 4e15] = numpy.nan
with plt.style.context(plt_utils.mplstyle):
cols = plt.rcParams["axes.prop_cycle"].by_key()["color"]
fig, ax = plt.subplots(nrows=2, sharex=True,
figsize=(3.5, 2.625 * 1.25),
gridspec_kw={"height_ratios": [1, 0.65]})
fig.subplots_adjust(hspace=0, wspace=0)
# Upper panel data
mean = numpy.mean(counts, axis=0)
std = numpy.std(counts, axis=0)
ax[0].plot(x, mean)
ax[0].fill_between(x, mean - std, mean + std, alpha=0.5)
# Lower panel data
for i in range(counts.shape[0]):
ax[1].plot(x, counts[i, :] / mean, c=cols[0])
# Labels and accesories
ax[1].axhline(1, color="k", ls=plt.rcParams["lines.linestyle"],
lw=0.5 * plt.rcParams["lines.linewidth"], zorder=0)
ax[0].set_ylabel(r"$\frac{\mathrm{d}^2 n}{\mathrm{d}\log M_{\rm h} \mathrm{d} V}~[\mathrm{dex}^{-1} (\mathrm{Mpc / h})^{-3}]$", # noqa
fontsize="small")
ax[1].set_xlabel(r"$M_{\rm h}$ [$M_\odot$]")
ax[1].set_ylabel(r"$\mathrm{HMF} / \langle \mathrm{HMF} \rangle$",
fontsize="small")
ax[0].set_xscale("log")
ax[0].set_yscale("log")
ax[0].legend()
fig.tight_layout(h_pad=0, w_pad=0)
for ext in ["png"] if pdf is False else ["png", "pdf"]:
fout = join(plt_utils.fout, f"hmf_quijote_full.{ext}")
print(f"Saving to `{fout}`.")
fig.savefig(fout, dpi=plt_utils.dpi, bbox_inches="tight")
plt.close()
def load_field(kind, nsim, grid, MAS, in_rsp=False, smooth_scale=None):
r"""
Load a single field.
@ -516,7 +589,8 @@ def plot_sky_distribution(field, nsim, grid, nside, smooth_scale=None,
if plot_halos is not None:
bounds = {"dist": (dmin, dmax),
"totpartmass": (plot_halos, None)}
cat = csiborgtools.read.HaloCatalogue(nsim, paths, bounds=bounds)
cat = csiborgtools.read.CSiBORGHaloCatalogue(nsim, paths,
bounds=bounds)
X = cat.position(cartesian=False)
healpy.projscatter(numpy.deg2rad(X[:, 2] + 90),
numpy.deg2rad(X[:, 1]),
@ -560,6 +634,9 @@ if __name__ == "__main__":
if False:
plot_hmf(pdf=False)
if True:
plot_hmf_quijote_full(pdf=False)
if False:
kind = "overdensity"
grid = 1024
@ -567,7 +644,7 @@ if __name__ == "__main__":
plot_groups=False, dmin=45, dmax=60,
plot_halos=5e13, volume_weight=True)
if True:
if False:
kind = "overdensity"
grid = 256
smooth_scale = 0
@ -589,4 +666,3 @@ if __name__ == "__main__":
plt.tight_layout()
plt.savefig("../plots/velocity_distribution.png", dpi=450,
bbox_inches="tight")

View file

@ -51,11 +51,11 @@ def open_cat(nsim):
Returns
-------
cat : csiborgtools.read.HaloCatalogue
cat : csiborgtools.read.CSiBORGHaloCatalogue
"""
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
bounds = {"totpartmass": (1e12, None)}
return csiborgtools.read.HaloCatalogue(nsim, paths, bounds=bounds)
return csiborgtools.read.CSiBORGHaloCatalogue(nsim, paths, bounds=bounds)
def plot_mass_vs_pairoverlap(nsim0, nsimx):