mirror of
https://github.com/Richard-Sti/csiborgtools.git
synced 2024-12-22 22:28:03 +00:00
9e4b34f579
* Update README * Update density field reader * Update name of SDSSxALFAFA * Fix quick bug * Add little fixes * Update README * Put back fit_init * Add paths to initial snapshots * Add export * Remove some choices * Edit README * Add Jens' comments * Organize imports * Rename snapshot * Add additional print statement * Add paths to initial snapshots * Add masses to the initial files * Add normalization * Edit README * Update README * Fix bug in CSiBORG1 so that does not read fof_00001 * Edit README * Edit README * Overwrite comments * Add paths to init lag * Fix Quijote path * Add lagpatch * Edit submits * Update README * Fix numpy int problem * Update README * Add a flag to keep the snapshots open when fitting * Add a flag to keep snapshots open * Comment out some path issue * Keep snapshots open * Access directly snasphot * Add lagpatch for CSiBORG2 * Add treatment of x-z coordinates flipping * Add radial velocity field loader * Update README * Add lagpatch to Quijote * Fix typo * Add setter * Fix typo * Update README * Add output halo cat as ASCII * Add import * Add halo plot * Update README * Add evaluating field at radial distanfe * Add field shell evaluation * Add enclosed mass computation * Add BORG2 import * Add BORG boxsize * Add BORG paths * Edit run * Add BORG2 overdensity field * Add bulk flow clauclation * Update README * Add new plots * Add nbs * Edit paper * Update plotting * Fix overlap paths to contain simname * Add normalization of positions * Add default paths to CSiBORG1 * Add overlap path simname * Fix little things * Add CSiBORG2 catalogue * Update README * Add import * Add TNG density field constructor * Add TNG density * Add draft of calculating BORG ACL * Fix bug * Add ACL of enclosed density * Add nmean acl * Add galaxy bias calculation * Add BORG acl notebook * Add enclosed mass calculation * Add TNG300-1 dir * Add TNG300 and BORG1 dir * Update nb
829 KiB
829 KiB
In [4]:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from sklearn.neighbors import NearestNeighbors
import joblib
from tqdm import tqdm
try:
import csiborgtools
except ModuleNotFoundError:
print("not found")
import sys
sys.path.append("../")
import csiborgtools
%matplotlib notebook
%load_ext autoreload
%autoreload 2
In [5]:
cat = csiborgtools.read.HaloCatalogue(7444, min_mass=1e13, max_dist=155 / 0.705)
In [11]:
knn = NearestNeighbors()
knn.fit(cat.positions)
knncdf = csiborgtools.match.kNN_CDF()
rs, cdfs_high = knncdf(knn, nneighbours=3, Rmax=155 / 0.705, rmin=0.05, rmax=40,
nsamples=int(1e6), neval=int(1e4), random_state=42)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
m1 = (rs > 1) & (rs < 35)
fig, axs = plt.subplots(ncols=3, figsize=(6.4 * 1.5, 4.8), sharey=True)
fig.subplots_adjust(wspace=0)
for k in range(3):
for n in range(len(ics)):
m = m1 & (cdfs[n, k, :] > 1e-3)
axs[k].plot(rs[m], cdfs[n, k, m], c="black", lw=0.05)
axs[k].set_xscale("log")
axs[k].set_yscale("log")
axs[k].set_title(r"$k = {}$".format(k))
axs[k].set_xlabel(r"$r~\left[\mathrm{Mpc}\right]$")
axs[0].set_ylabel(r"Peaked CDF")
plt.tight_layout(w_pad=0)
fig.savefig("../plots/peaked_cdf.png", dpi=450)
fig.show()
In [ ]:
m = (rs > 0.5) & (rs < 35)
fig, axs = plt.subplots(ncols=3, figsize=(6.4 * 1.5, 4.8), sharey=True)
fig.subplots_adjust(wspace=0)
for k in range(3):
mu = np.nanmean(cdfs[:, k, :], axis=0)
for n in range(len(ics)):
axs[k].plot(rs[m], (cdfs[n, k, :] / mu)[m], c="black", lw=0.1)
axs[k].set_ylim(0.5, 1.5)
axs[k].axhline(1, ls="--", c="red", zorder=0)
axs[k].axvline(2.65 / 0.705, ls="--", c="red", zorder=0)
axs[k].set_xscale("log")
axs[k].set_xlabel(r"$r~\left[\mathrm{Mpc}\right]$")
axs[k].set_title(r"$k = {}$".format(k))
axs[0].set_ylabel(r"Relative peaked CDF")
plt.tight_layout(w_pad=0)
fig.savefig("../plots/peaked_cdf_ratios.png", dpi=450)
fig.show()
In [ ]:
plt.figure()
k = 2
mu = np.nanmean(cdfs[:, k, :], axis=0)
# plt.plot(rs, mu, c="black")
for i in range(len(ics)):
plt.plot(rs, cdfs[i, k, :] / mu)
plt.ylim(0.75, 1.25)
plt.axhline(1, ls="--", c="black")
plt.xscale("log")
# plt.yscale("log")
plt.show()
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
x.shape
In [ ]:
In [ ]:
In [ ]:
dist0, __ = knn0.kneighbors(X, 3)
distx, __ = knnx.kneighbors(X, 3)
In [ ]:
x0, y0 = knncdf.peaked_cdf_from_samples(dist0[:, 0], 0.5, 20, neval=10000)
xx, yx = knncdf.peaked_cdf_from_samples(distx[:, 0], 0.5, 20, neval=10000)
In [ ]:
distx[:, 0].min()
In [ ]:
plt.figure()
plt.plot(x0, y0)
plt.plot(xx, yx)
plt.yscale("log")
plt.xscale("log")
plt.show()
In [ ]:
In [ ]:
plt.figure()
for i in range(3):
plt.plot(*knncdf.cdf_from_samples(dist0[:, i], 1, 25))
plt.plot(*knncdf.cdf_from_samples(distx[:, i], 1, 25))
# plt.xlim(0.5, 25)
plt.yscale("log")
plt.xscale("log")
plt.xlabel(r"$r~\left[\mathrm{Mpc}\right]$")
plt.show()
In [ ]:
In [ ]:
x = dist[:, 0]
q = np.linspace(0, 100, int(x.size / 5))
p = np.percentile(x, q)
In [ ]:
y = np.sort(x)
yy = np.arange(y.size) / y.size
In [ ]:
plt.figure()
plt.plot(p, q / 100)
plt.plot(y, yy)
# plt.yscale("log")
plt.show()
In [ ]:
In [ ]:
plt.figure()
plt.hist(dist[:, 0], bins="auto", histtype="step")
plt.hist(dist[:, 1], bins="auto", histtype="step")
plt.hist(dist[:, 2], bins="auto", histtype="step")
plt.show()
In [ ]:
In [ ]:
In [ ]:
plt.figure()
plt.hist(cat0["dec"], bins="auto")
plt.show()
In [ ]:
gen = np.random.default_rng(22)
In [ ]:
gen.normal()
In [ ]:
In [ ]:
theta = np.linspace( t, np.pi, 100)
plt.figure()
plt.plot(theta, np.sin(theta))
plt.show()
In [ ]:
In [ ]:
In [ ]:
X = np.array([-3.9514747, -0.6966991, 2.97158]).reshape(1, -1)
X
In [ ]:
dist, indxs = knn0.kneighbors(X, n_neighbors=1)
dist, indxs
In [ ]:
cat0.positions[indxs]
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: