Velocity observer (#86)

* Continue if r200c not defined

* Remove smooth scale

* Remove smooth scale

* Edit Max Matching plot

* Add peculiar velocity

* Add Vobs calculation

* Edit docs

* Add Vobs plot

* Improve plotting

* Edit naming convention

* Make a note

* Add new cat options

* Update density field RSP calculation

* Update field 2 rsp

* Move functions and shorten documentation

* Improve transforms and comments

* Update docs

* Update imports

* Edit calculation

* Add docs

* Remove imports

* Add Quijote flags

* Edit documentation

* Shorten documentation

* Edit func calls

* Shorten

* Docs edits

* Edit docs

* Shorten docs

* Short docs edits

* Simplify docs a little bit

* Save plotting

* Update env
This commit is contained in:
Richard Stiskalek 2023-08-30 23:27:20 +01:00 committed by GitHub
parent 8e3127f4d9
commit ae92fd9b72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 761 additions and 788 deletions

View file

@ -191,7 +191,7 @@ def get_mtot_vs_maxpairoverlap(nsim0, simname, mass_kind, min_logmass,
def get_max(y_):
if len(y_) == 0:
return 0
return numpy.max(y_)
return numpy.nanmax(y_)
reader = csiborgtools.read.NPairsOverlap(cat0, catxs, paths, min_logmass)
@ -218,7 +218,6 @@ def mtot_vs_maxpairoverlap(nsim0, simname, mass_kind, min_logmass, smoothed,
x, y, xbins = get_mtot_vs_maxpairoverlap(nsim0, simname, mass_kind,
min_logmass, smoothed, nbins)
plt.close("all")
with plt.style.context(plt_utils.mplstyle):
plt.figure()
plt.hexbin(x, y, mincnt=1, gridsize=50, bins="log")
@ -252,6 +251,87 @@ def mtot_vs_maxpairoverlap(nsim0, simname, mass_kind, min_logmass, smoothed,
plt.close()
# --------------------------------------------------------------------------- #
###############################################################################
# Total DM halo mass vs maximum pair overlap consistency #
###############################################################################
# --------------------------------------------------------------------------- #
@cache_to_disk(120)
def get_mtot_vs_maxpairoverlap_consistency(nsim0, simname, mass_kind,
min_logmass, smoothed):
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
nsimxs = csiborgtools.read.get_cross_sims(simname, nsim0, paths,
min_logmass, smoothed=smoothed)
cat0 = open_cat(nsim0, simname)
catxs = open_cats(nsimxs, simname)
reader = csiborgtools.read.NPairsOverlap(cat0, catxs, paths, min_logmass)
x = numpy.log10(cat0[mass_kind])
mask = x > min_logmass
x = x[mask]
nhalos = len(x)
y = numpy.full((len(catxs), nhalos), numpy.nan)
for i in trange(len(catxs), desc="Stacking catalogues"):
overlaps = reader[i].overlap(smoothed)
for j in range(nhalos):
# if len(overlaps[j]) > 0:
y[i, j] = numpy.sum(overlaps[j])
return x, y
def mtot_vs_maxpairoverlap_consistency(nsim0, simname, mass_kind, min_logmass,
smoothed, ext="png"):
left_edges = numpy.arange(min_logmass, 15, 0.1)
# delete_disk_caches_for_function("get_mtot_vs_maxpairoverlap_consistency")
x, y0 = get_mtot_vs_maxpairoverlap_consistency(nsim0, simname, mass_kind,
min_logmass, smoothed)
nsims, nhalos = y0.shape
x_2, y0_2 = get_mtot_vs_maxpairoverlap_consistency(
0, "quijote", "group_mass", min_logmass, smoothed)
nsims2, nhalos = y0_2.shape
with plt.style.context(plt_utils.mplstyle):
plt.figure()
yplot = numpy.full(len(left_edges), numpy.nan)
yplot_2 = numpy.full(len(left_edges), numpy.nan)
for ymin in [0.3]:
y = numpy.sum(y0 > ymin, axis=0) / nsims
y_2 = numpy.sum(y0_2 > ymin, axis=0) / nsims2
for i, left_edge in enumerate(left_edges):
mask = x > left_edge
yplot[i] = numpy.mean(y[mask]) #/ nsims
mask = x_2 > left_edge
yplot_2[i] = numpy.mean(y_2[mask]) #/ nsims
plt.plot(left_edges, yplot, label="CSiBORG")
plt.plot(left_edges, yplot_2, label="Quijote")
plt.legend()
# y2 = numpy.concatenate(y0)
# y2 = y2[y2 > 0]
# m = y0 > 0
# plt.hist(y0[m], bins=30, density=True, histtype="step")
# m = y0_2 > 0
# plt.hist(y0_2[m], bins=30, density=True, histtype="step")
# plt.yscale("log")
plt.tight_layout()
fout = join(
plt_utils.fout,
f"mass_vs_max_pair_overlap_consistency_{simname}_{nsim0}.{ext}")
print(f"Saving to `{fout}`.")
plt.savefig(fout, dpi=plt_utils.dpi, bbox_inches="tight")
plt.close()
# --------------------------------------------------------------------------- #
###############################################################################
# Total DM halo mass vs summed pair overlaps #
@ -876,8 +956,7 @@ def get_matching_max_vs_overlap(simname, nsim0, min_logmass, mult):
def matching_max_vs_overlap(simname, nsim0, min_logmass):
left_edges = numpy.arange(min_logmass, 15, 0.1)
delete_disk_caches_for_function("get_matching_max_vs_overlap")
nsims = 100 if simname == "csiborg" else 9
with plt.style.context("science"):
fig, axs = plt.subplots(ncols=2, figsize=(3.5 * 2, 2.625))
@ -891,34 +970,36 @@ def matching_max_vs_overlap(simname, nsim0, min_logmass):
success = x["success"]
nbins = len(left_edges)
y = numpy.full((nbins, 100), numpy.nan)
y2 = numpy.full((nbins, 100), numpy.nan)
y = numpy.full((nbins, nsims), numpy.nan)
y2 = numpy.full(nbins, numpy.nan)
y2err = numpy.full(nbins, numpy.nan)
for i in range(nbins):
m = mass0 > left_edges[i]
for j in range(100):
for j in range(nsims):
y[i, j] = numpy.sum(
max_overlap[m, j] == match_overlap[m, j])
y[i, j] /= numpy.sum(success[m, j])
y2[i, j] = numpy.sum(success[m, j]) / numpy.sum(m)
offset = numpy.random.normal(0, 0.01)
y2[i] = numpy.mean(numpy.sum(success[m, :], axis=1) / nsims)
y2err[i] = numpy.std(numpy.sum(success[m, :], axis=1) / nsims)
offset = numpy.random.normal(0, 0.015)
ysummary = numpy.percentile(y, [16, 50, 84], axis=1)
axs[0].errorbar(
left_edges + offset, ysummary[1],
yerr=[ysummary[1] - ysummary[0], ysummary[2] - ysummary[1]],
capsize=3, c=cols[n],
capsize=4, c=cols[n], ls="dashed",
label=r"$\leq {}~R_{{\rm 200c}}$".format(mult), errorevery=2)
ysummary = numpy.percentile(y2, [16, 50, 84], axis=1)
axs[1].errorbar(
left_edges + offset, ysummary[1], ls="--",
yerr=[ysummary[1] - ysummary[0], ysummary[2] - ysummary[1]],
capsize=3, c=cols[n], errorevery=2)
axs[1].errorbar(left_edges + offset, y2, yerr=y2err,
capsize=4, errorevery=2, c=cols[n], ls="dashed")
axs[0].legend(ncols=2, fontsize="small")
for i in range(2):
axs[i].set_xlabel(r"$\log M_{\rm tot, min} ~ [M_\odot / h]$")
axs[1].set_ylim(0)
axs[0].set_ylabel(r"$f_{\rm agreement}$")
axs[1].set_ylabel(r"$f_{\rm match}$")
@ -1048,7 +1129,7 @@ if __name__ == "__main__":
smoothed = True
nbins = 10
ext = "png"
plot_quijote = False
plot_quijote = True
min_maxoverlap = 0.
funcs = [
@ -1128,5 +1209,19 @@ if __name__ == "__main__":
mtot_vs_maxoverlap_property(0, "quijote", min_logmass, key,
min_maxoverlap, smoothed)
if False:
matching_max_vs_overlap("csiborg", 7444, min_logmass)
if plot_quijote:
matching_max_vs_overlap("quijote", 0, min_logmass)
if True:
matching_max_vs_overlap(7444, min_logmass)
mtot_vs_maxpairoverlap_consistency(
7444, "csiborg", "fof_totpartmass", min_logmass, smoothed,
ext="png")
# if plot_quijote:
# mtot_vs_maxpairoverlap_consistency(
# 0, "quijote", "group_mass", min_logmass, smoothed,
# ext="png")