mirror of
https://github.com/Richard-Sti/csiborgtools.git
synced 2024-12-23 01:08:02 +00:00
779f2e76ac
* Update redshift reading * Add helio to CMB redshift * Update imports * Update nb * Run for Quijote * Add script * Update * Update .gitignore * Update imports * Add Peery estimator * Add bulk flow scripts * Update typs * Add comment * Add blank space * Update submission script * Update description * Add barriers * Update nb * Update nb * Rename script * Move to old * Update imports * Add nb * Update script * Fix catalogue key * Update script * Update submit * Update comment * Update .gitignore * Update nb * Update for stationary obsrevers * Update submission * Add nb * Add better verbose control * Update nb * Update submit * Update nb * Add SN errors * Add draft of the script * Update verbosity flags * Add submission script * Debug script * Quickfix * Remove comment * Update nb * Update submission * Update nb * Processed UPGLADE
12 KiB
12 KiB
Constraining MAH in $\texttt{BORG}$¶
In [1]:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cm import ScalarMappable
from matplotlib.colors import Normalize
from cache_to_disk import delete_disk_caches_for_function
from scipy.stats import norm
from scipy.signal import savgol_filter
from mah import *
%load_ext autoreload
%autoreload 2
%matplotlib inline
$\texttt{MDPL2}$ to $\texttt{CB2}$ MAH comparison¶
In [11]:
min_age = 2.8
pmin, pmax = 5, 95
bounds = [14.5, 14.7]
mass_norm = 10**np.mean(bounds)
alphas = {3: 0.25, 2: 0.5, 1: 0.75}
xrange_cb2, random_mah_cb2 = extract_mah("csiborg2_random", bounds, "MainProgenitorMass", min_age=2.8)
xrange_mdpl2, random_mah_mdpl2 = extract_mah_mdpl2(bounds, min_age=2.8)
random_mah_cb2 /= random_mah_cb2[:, -1].reshape(-1, 1)
random_mah_mdpl2 /= random_mah_mdpl2[:, -1].reshape(-1, 1)
# random_mah_cb2 /= mass_norm
# random_mah_mdpl2 /= mass_norm
plt.figure()
cols = plt.rcParams["axes.prop_cycle"].by_key()["color"]
for n in [3, 2, 1]:
pmin, pmax = norm.cdf(-n) * 100 , norm.cdf(n) * 100
ylow, yhigh = np.percentile(random_mah_mdpl2, [pmin, pmax], axis=0)
plt.fill_between(xrange_mdpl2, ylow, yhigh, alpha=alphas[n], color=cols[0],
facecolor=cols[0], label=f"MDPL2 Random ({len(random_mah_mdpl2)})" if n == 1 else None)
pmin, pmax = norm.cdf(-1) * 100 , norm.cdf(1) * 100
ylow, yhigh = np.percentile(random_mah_cb2, [pmin, pmax], axis=0)
plt.plot(xrange_cb2, ylow, c=cols[1], ls="--", label=rf"$1\sigma$ CB2 Random ({len(random_mah_cb2)})", zorder=1)
plt.plot(xrange_cb2, yhigh, c=cols[1], ls="--", zorder=1)
pmin, pmax = norm.cdf(-2) * 100 , norm.cdf(2) * 100
ylow, yhigh = np.percentile(random_mah_cb2, [pmin, pmax], axis=0)
plt.plot(xrange_cb2, ylow, c=cols[1], ls="dotted", label=rf"$2\sigma$ CB2 Random ({len(random_mah_cb2)})", zorder=1)
plt.plot(xrange_cb2, yhigh, c=cols[1], ls="dotted", zorder=1)
# plt.fill_between(xrange_mdpl2,
# np.ones_like(xrange_mdpl2) * 10**bounds[0] / mass_norm,
# np.ones_like(xrange_mdpl2) * 10**bounds[1] / mass_norm, alpha=0.25,
# label=r"$z = 0$ selection", color="gray", zorder=0,
# hatch="///")
# They appear to be plotting the min-max
plt.plot(RANDOM_MAH_Sorce_Virgo_UPPER[:, 0],
RANDOM_MAH_Sorce_Virgo_UPPER[:, 1], c="red", ls="--", label="Sorce+2016 Virgo randoms")
plt.plot(RANDOM_MAH_SORCE_Virgo_LOWER[:, 0],
RANDOM_MAH_SORCE_Virgo_LOWER[:, 1], c="red", ls="--")
plt.yscale("log")
plt.legend(loc="lower right")
plt.xlabel(r"$\mathrm{Age} ~ [\mathrm{Gyr}]$")
plt.ylabel(r"$M_{\rm main}(t) / M_{\rm main}(z = 0)$")
plt.xlim(xrange_mdpl2.min(), xrange_mdpl2.max())
plt.ylim(1e-2, 1.01)
plt.tight_layout()
plt.savefig("../../plots/MAH_MDPL2_CB2_comparison_VIRGO.png", dpi=450)
plt.show()
In [2]:
nsim0 = 17417
simname = "csiborg2_main"
min_logmass = 12.25
delete_cache = False
if delete_cache:
delete_disk_caches_for_function("load_data")
cat0, catxs, merger_trees, overlaps = load_data(nsim0, simname, min_logmass)
nsimxs = [cat.nsim for cat in catxs]
In [32]:
catx = cat0
In [35]:
pos = catx["spherical_pos"]
ra, dec = pos[:, 1], pos[:, 2]
l, b = csiborgtools.flow.radec_to_galactic(pos[:, 1], pos[:, 2])
In [36]:
50 / 0.705
Out[36]:
In [45]:
113 * 0.705
Out[45]:
In [61]:
mask = (pos[:, 0] > 83.5) & (catx["totmass"] > 1e14) & (pos[:, 0] < 84) & (catx["totmass"] < 4e14)
plt.figure()
plt.scatter(ra[mask], dec[mask], s=20, c=np.log10(catx["totmass"][mask]))
plt.axvline(csiborgtools.hms_to_degrees(11, 44), zorder=0, ls="--", color="red", alpha=0.5)
plt.axhline(csiborgtools.dms_to_degrees(19, 45), zorder=0, ls="--", color="red", alpha=0.5)
# plt.axvline(285, zorder=0)
# plt.axhline(74, zorder=0)
plt.xlim(0, 360,)
plt.ylim(-90, 90)
plt.show()
In [62]:
cat0["totmass"][mask], cat0["dist"][mask], pos[:, 1][mask], cat0["index"][mask]
Out[62]:
In [120]:
mask = (cat0["dist"] < 100) & (cat0["totmass"] > 2e14)
mask.sum()
Out[120]:
In [121]:
cat0["totmass"][mask], cat0["index"][mask]
Out[121]:
In [133]:
overlaps.max_overlap(0, True)[108]
Out[133]:
In [135]:
data = extract_main_progenitor_maxoverlap(108, overlaps, merger_trees)
In [136]:
logmp = np.log10(np.array([data[nsim]["MainProgenitorMass"][0] for nsim in data.keys()]))
mean, std = np.mean(logmp), np.std(logmp)
print(f"mean = {mean:.4f}, std = {std:.4f}")
bounds = [mean - 1 * std, mean + 1 * std]
xrange_cb2, random_mah_cb2 = extract_mah("csiborg2_random", bounds, "MainProgenitorMass", min_age=2.8)
xrange_mdpl2, random_mah_mdpl2 = extract_mah_mdpl2(bounds, min_age=2.8)
print(f"Found {len(random_mah_cb2)} haloes in CB2 random.")
print(f"Found {len(random_mah_mdpl2)} haloes in MDPL2.")
age, mah = summarize_extracted_mah(simname, data, nsim0, nsimxs, "MainProgenitorMass", min_age=2.8)
random_mah_cb2 /= random_mah_cb2[:, -1].reshape(-1, 1)
random_mah_mdpl2 /= random_mah_mdpl2[:, -1].reshape(-1, 1)
mah /= mah[:, -1].reshape(-1, 1)
In [137]:
plt.figure()
# plt.hist(logmp, bins="auto")
plt.scatter(np.arange(len(logmp)), logmp)
plt.xlabel("Simulation index")
plt.ylabel(r"$\log M ~ [M_\odot / h]$")
# plt.axhline(mean, c="red", ls="--")
plt.tight_layout()
plt.savefig("../../plots/COMA_MASS.png", dpi=450)
plt.show()
In [138]:
pmin, pmax = 0.15, 100 - 0.15
# norm_mass = 10**np.nanmean(np.log10(mah[:, -1]))
norm_mass = 1
alphas = {3: 0.25, 2: 0.5, 1: 0.75}
plt.figure(figsize=(6, 4))
cols = plt.rcParams["axes.prop_cycle"].by_key()["color"]
lw = plt.rcParams["lines.linewidth"]
for n in [3, 2, 1]:
pmin, pmax = norm.cdf(-n) * 100 , norm.cdf(n) * 100
ylow, yhigh = np.percentile(random_mah_mdpl2 / norm_mass, [pmin, pmax], axis=0)
ylow = savgol_filter(ylow, 5, 1, mode="interp")
yhigh = savgol_filter(yhigh, 5, 1, mode="interp")
plt.fill_between(xrange_mdpl2, ylow, yhigh, alpha=alphas[n], color=cols[0],
facecolor=cols[0], zorder=0, edgecolor="blue",
label=f"MDPL2 Random ({len(random_mah_mdpl2)})" if n == 1 else None)
# pmin, pmax = norm.cdf(-n) * 100 , norm.cdf(n) * 100
# ylow, yhigh = np.percentile(random_mah_cb2 / norm_mass, [pmin, pmax], axis=0)
# ylow = savgol_filter(ylow, 5, 1, mode="interp")
# yhigh = savgol_filter(yhigh, 5, 1, mode="interp")
# plt.fill_between(xrange_cb2, ylow, yhigh, alpha=alphas[n], color=cols[0],
# facecolor=cols[0], zorder=0, edgecolor="blue",
# label=f"CB2 Random ({len(random_mah_cb2)})" if n == 1 else None)
if n == 3:
continue
ylow, yhigh = np.percentile(mah / norm_mass, [pmin, pmax], axis=0)
ylow = savgol_filter(ylow, 5, 1, mode="interp")
yhigh = savgol_filter(yhigh, 5, 1, mode="interp")
plt.fill_between(age, ylow, yhigh, alpha=alphas[n] / 2,
label="Coma" if n == 1 else None, zorder=1,
color=cols[1], edgecolor="red")
# pmin, pmax = norm.cdf(-1) * 100 , norm.cdf(1) * 100
# ylow, yhigh = np.percentile(random_mah_cb2 / norm_mass, [pmin, pmax], axis=0)
# plt.plot(xrange_cb2, ylow, c=cols[2], ls="--", lw=1.5 * lw,
# label=rf"$1\sigma$ CB2 Random ({len(random_mah_cb2)})")
# plt.plot(xrange_cb2, yhigh, c=cols[2], ls="--", lw=1.5 * lw)
# for i in range(len(mah)):
# plt.plot(age, mah[i] / norm_mass, c="black", lw=lw/4, alpha=0.5, zorder=4)
# plt.plot(RANDOM_MAH_Sorce_Virgo_UPPER[:, 0],
# RANDOM_MAH_Sorce_Virgo_UPPER[:, 1], c="red", ls="--", label="Sorce+2016 Virgo randoms")
# plt.plot(RANDOM_MAH_SORCE_Virgo_LOWER[:, 0],
# RANDOM_MAH_SORCE_Virgo_LOWER[:, 1], c="red", ls="--")
plt.yscale("log")
plt.legend(loc="lower right")
plt.xlabel(r"$\mathrm{Age} ~ [\mathrm{Gyr}]$")
plt.ylabel(r"$M_{\rm main}(t) / M_{\rm main}(z = 0)$")
plt.xlim(xrange_mdpl2.min(), xrange_mdpl2.max())
plt.ylim(0.01, 1)
plt.tight_layout()
# plt.savefig("../../plots/coma_MAIN.png")
plt.show()
In [ ]:
In [79]:
cmap = plt.cm.viridis
x = np.asarray([data[nsimx]["Overlap"] for nsimx in nsimxs if nsimx in data])
w = x - x.min()
w /= w.max()
norm = Normalize(vmin=x.min(), vmax=x.max())
sm = ScalarMappable(cmap=cmap, norm=norm)
sm.set_array(x)
fig, ax = plt.subplots()
lw = plt.rcParams["lines.linewidth"] / 2
d = data[nsim0]
ax.plot(d["Age"], d["MainProgenitorMass"], color="red", lw=1.5*lw,
label="Reference halo", zorder=1)
i = 0
for nsimx in nsimxs:
try:
d = data[nsimx]
except KeyError:
continue
ax.plot(d["Age"], d["MainProgenitorMass"], color=cmap(norm(x[i])),
zorder=0, lw=lw * (x[i] / x.max()))
i += 1
mu = np.nanmedian(random_mah, axis=0)
ymin = np.nanpercentile(random_mah, 16, axis=0)
ymax = np.nanpercentile(random_mah, 84, axis=0)
ax.plot(xrange, mu, color="black", label="Random")
ax.fill_between(xrange, ymin, ymax, color="black", alpha=0.5, zorder=-1)
cbar = fig.colorbar(sm, ax=ax, orientation='vertical')
cbar.set_label('Overlap')
ax.legend()
ax.set_yscale("log")
ax.set_xlabel(r"$t ~ [\mathrm{Gyr}]$")
ax.set_ylabel(r"$M_{\rm main} ~ [M_{\odot}]$")
ax.set_xlim(0)
plt.tight_layout()
# plt.savefig("../../plots/example_mah.png")
fig.show()
In [136]:
nsim0 = 1
simname = "csiborg2_random"
kind = simname.split("_")[-1]
min_logmass = 12.25
# NOTE: These can possibly be pickled to avoid doing this long process every
# single time.
cat = csiborgtools.read.CSiBORG2Catalogue(
nsim0, 99, kind, bounds={"totmass": (1e13, None), "dist": (0, 135)})
# merger_reader = csiborgtools.read.CSiBORG2MergerTreeReader(nsim0, kind)
In [149]:
a = np.array([0.01428571, 0.02424242, 0.03419913, 0.04415584, 0.05411255,
0.06406926, 0.07402597, 0.08398268, 0.09393939, 0.1038961 ,
0.11385281, 0.12380952, 0.13376623, 0.14372294, 0.15367965,
0.16363636, 0.17359307, 0.18354978, 0.19350649, 0.2034632 ,
0.21341991, 0.22337662, 0.23333333, 0.24329004, 0.25324675,
0.26320346, 0.27316017, 0.28311688, 0.29307359, 0.3030303 ,
0.31298701, 0.32294372, 0.33290043, 0.34285714, 0.35281385,
0.36277056, 0.37272727, 0.38268398, 0.39264069, 0.4025974 ,
0.41255411, 0.42251082, 0.43246753, 0.44242424, 0.45238095,
0.46233766, 0.47229437, 0.48225108, 0.49220779, 0.5021645 ,
0.51212121, 0.52207792, 0.53203463, 0.54199134, 0.55194805,
0.56190476, 0.57186147, 0.58181818, 0.59177489, 0.6017316 ,
0.61168831, 0.62164502, 0.63160173, 0.64155844, 0.65151515,
0.66147186, 0.67142857, 0.68138528, 0.69134199, 0.7012987 ,
0.71125541, 0.72121212, 0.73116883, 0.74112554, 0.75108225,
0.76103896, 0.77099567, 0.78095238, 0.79090909, 0.8008658 ,
0.81082251, 0.82077922, 0.83073593, 0.84069264, 0.85064935,
0.86060606, 0.87056277, 0.88051948, 0.89047619, 0.9004329 ,
0.91038961, 0.92034632, 0.93030303, 0.94025974, 0.95021645,
0.96017316, 0.97012987, 0.98008658, 0.99004329, 1. ])
In [155]:
from h5py import File
In [156]:
f = File("/mnt/extraspace/rstiskalek/csiborg_postprocessing/random_mah/random_mah_csiborg2_random_1.hdf5")
In [168]:
f["MainProgenitorMass"][0]
Out[168]:
In [ ]:
In [154]:
print(list(1 / a - 1))
In [142]:
np.sum(cat["totmass"] > 5e14)
Out[142]:
In [130]:
d1 = merger_reader.main_progenitor(10000)
In [132]:
d1["SnapNum"]
Out[132]:
In [127]:
np.sum(cat["totmass"] > 1e13)
Out[127]:
In [128]:
250e-3 * 8000 / 60
Out[128]:
In [ ]:
In [116]:
plt.figure()
plt.plot(d1["Age"], d1["MainProgenitorMass"])
plt.plot(d2["Age"], d2["MainProgenitorMass"])
plt.plot(d3["Age"], d3["MainProgenitorMass"])
plt.yscale("log")
plt.show()
In [110]:
cat["totmass"]
Out[110]:
In [ ]: