mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-05-12 13:41:13 +00:00
Add galaxy sampling (#88)
* Improve calculations * Improve flags * Add smoothed options * Remove some old comments * Edit little things * Save smoothed * Move files * Edit imports * Edit imports * Renaming imports * Renaming imports * Sort imports * Sort files * Sorting * Optionally make copies of the field * Add quijote backup check * Add direct field smoothing * Shorten stupid documentation * Shorten stupid docs * Update conversion * Add particles to ASCII conversion * Add a short comment * Add SDSS uncorrected distance * Adjust comment * Add FITS index to galaxies * Remove spare space * Remove a stupid line * Remove blank line * Make space separated * Add interpolated field path * Add field sampling * Sort imports * Return density in cells * Clear out observer velocity * Add 170817 sampling * Fix normalization * Update plot
This commit is contained in:
parent
0af925e26a
commit
eccd8e3507
26 changed files with 610 additions and 365 deletions
|
@ -62,7 +62,7 @@ def open_cats(nsims, simname):
|
|||
|
||||
def read_dist(simname, run, kind, kwargs):
|
||||
paths = csiborgtools.read.Paths(**kwargs["paths_kind"])
|
||||
reader = csiborgtools.read.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
reader = csiborgtools.summary.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
|
||||
fpath = paths.cross_nearest(simname, run, "tot_counts", nsim=0, nobs=0)
|
||||
counts = numpy.load(fpath)["tot_counts"]
|
||||
|
@ -102,7 +102,7 @@ def plot_dist(run, kind, kwargs, runs_to_mass, pulled_cdf=False, r200=None):
|
|||
"""
|
||||
assert kind in ["pdf", "cdf"]
|
||||
print(f"Plotting the {kind} for {run}...", flush=True)
|
||||
reader = csiborgtools.read.NearestNeighbourReader(
|
||||
reader = csiborgtools.summary.NearestNeighbourReader(
|
||||
**kwargs, paths=csiborgtools.read.Paths(**kwargs["paths_kind"]))
|
||||
raddist = reader.bin_centres("radial")
|
||||
r = reader.bin_centres("neighbour")
|
||||
|
@ -241,7 +241,7 @@ def plot_cdf_diff(runs, kwargs, pulled_cdf, runs_to_mass):
|
|||
"""
|
||||
print("Plotting the CDF difference...", flush=True)
|
||||
paths = csiborgtools.read.Paths(**kwargs["paths_kind"])
|
||||
reader = csiborgtools.read.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
reader = csiborgtools.summary.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
r = reader.bin_centres("neighbour")
|
||||
runs_to_mass = [numpy.mean(runs_to_mass[run]) for run in runs]
|
||||
|
||||
|
@ -320,7 +320,7 @@ def make_kl(simname, run, nsim, nobs, kwargs):
|
|||
of each halo in the reference simulation.
|
||||
"""
|
||||
paths = csiborgtools.read.Paths(**kwargs["paths_kind"])
|
||||
reader = csiborgtools.read.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
reader = csiborgtools.summary.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
# This is the reference PDF. Must be Quijote!
|
||||
pdf = read_dist("quijote", run, "pdf", kwargs)
|
||||
return reader.kl_divergence(simname, run, nsim, pdf, nobs=nobs)
|
||||
|
@ -352,7 +352,7 @@ def make_ks(simname, run, nsim, nobs, kwargs):
|
|||
each halo in the reference simulation.
|
||||
"""
|
||||
paths = csiborgtools.read.Paths(**kwargs["paths_kind"])
|
||||
reader = csiborgtools.read.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
reader = csiborgtools.summary.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
# This is the reference CDF. Must be Quijote!
|
||||
cdf = read_dist("quijote", run, "cdf", kwargs)
|
||||
return reader.ks_significance(simname, run, nsim, cdf, nobs=nobs)
|
||||
|
@ -551,7 +551,7 @@ def plot_significance_vs_mass(simname, runs, nsim, nobs, kind, kwargs,
|
|||
print(f"Plotting {kind} significance vs mass.")
|
||||
assert kind in ["kl", "ks"]
|
||||
paths = csiborgtools.read.Paths(**kwargs["paths_kind"])
|
||||
reader = csiborgtools.read.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
reader = csiborgtools.summary.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
|
||||
with plt.style.context(plt_utils.mplstyle):
|
||||
plt.figure()
|
||||
|
@ -627,7 +627,7 @@ def plot_kl_vs_ks(simname, runs, nsim, nobs, kwargs, runs_to_mass,
|
|||
None
|
||||
"""
|
||||
paths = csiborgtools.read.Paths(**kwargs["paths_kind"])
|
||||
reader = csiborgtools.read.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
reader = csiborgtools.summary.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
|
||||
xs, ys, cs = [], [], []
|
||||
for run in runs:
|
||||
|
@ -697,7 +697,7 @@ def plot_kl_vs_overlap(runs, nsim, kwargs, runs_to_mass, plot_std=True,
|
|||
None
|
||||
"""
|
||||
paths = csiborgtools.read.Paths(**kwargs["paths_kind"])
|
||||
nn_reader = csiborgtools.read.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
nn_reader = csiborgtools.summary.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
|
||||
xs, ys1, ys2, cs = [], [], [], []
|
||||
for run in runs:
|
||||
|
|
|
@ -38,15 +38,6 @@ except ModuleNotFoundError:
|
|||
def open_csiborg(nsim):
|
||||
"""
|
||||
Open a CSiBORG halo catalogue. Applies mass and distance selection.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
nsim : int
|
||||
Simulation index.
|
||||
|
||||
Returns
|
||||
-------
|
||||
cat : csiborgtools.read.CSiBORGHaloCatalogue
|
||||
"""
|
||||
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
||||
bounds = {"totpartmass": (None, None), "dist": (0, 155)}
|
||||
|
@ -58,17 +49,6 @@ def open_csiborg(nsim):
|
|||
def open_quijote(nsim, nobs=None):
|
||||
"""
|
||||
Open a Quijote halo catalogue. Applies mass and distance selection.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
nsim : int
|
||||
Simulation index.
|
||||
nobs : int, optional
|
||||
Fiducial observer index.
|
||||
|
||||
Returns
|
||||
-------
|
||||
cat : csiborgtools.read.QuijoteHaloCatalogue
|
||||
"""
|
||||
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
||||
cat = csiborgtools.read.QuijoteHaloCatalogue(
|
||||
|
@ -82,17 +62,6 @@ def open_quijote(nsim, nobs=None):
|
|||
def plot_mass_vs_ncells(nsim, pdf=False):
|
||||
"""
|
||||
Plot the halo mass vs. number of occupied cells in the initial snapshot.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
nsim : int
|
||||
Simulation index.
|
||||
pdf : bool, optional
|
||||
Whether to save the figure as a PDF file.
|
||||
|
||||
Returns
|
||||
-------
|
||||
None
|
||||
"""
|
||||
cat = open_csiborg(nsim)
|
||||
mpart = 4.38304044e+09
|
||||
|
@ -123,15 +92,6 @@ def plot_mass_vs_ncells(nsim, pdf=False):
|
|||
def plot_hmf(pdf=False):
|
||||
"""
|
||||
Plot the FoF halo mass function of CSiBORG and Quijote.
|
||||
|
||||
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)
|
||||
|
@ -189,13 +149,15 @@ def plot_hmf(pdf=False):
|
|||
std_csiborg = numpy.std(csiborg_counts, axis=0)
|
||||
ax[0].plot(x, mean_csiborg, label="CSiBORG", c=cols[0])
|
||||
ax[0].fill_between(x, mean_csiborg - std_csiborg,
|
||||
mean_csiborg + std_csiborg, alpha=0.5, color=cols[0])
|
||||
mean_csiborg + std_csiborg,
|
||||
alpha=0.5, color=cols[0])
|
||||
|
||||
mean_quijote = numpy.mean(quijote_counts, axis=0)
|
||||
std_quijote = numpy.std(quijote_counts, axis=0)
|
||||
ax[0].plot(x, mean_quijote, label="Quijote", c=cols[1])
|
||||
ax[0].fill_between(x, mean_quijote - std_quijote,
|
||||
mean_quijote + std_quijote, alpha=0.5, color=cols[1])
|
||||
mean_quijote + std_quijote, alpha=0.5,
|
||||
color=cols[1])
|
||||
|
||||
ax[0].plot(x, csiborg5511, label="CSiBORG 5511", c="k", ls="--")
|
||||
std5511 = numpy.sqrt(csiborg5511)
|
||||
|
@ -207,7 +169,7 @@ def plot_hmf(pdf=False):
|
|||
+ (std_quijote / mean_quijote / numpy.log(10))**2)
|
||||
ax[1].plot(x, 10**log_y, c=cols[0])
|
||||
ax[1].fill_between(x, 10**(log_y - err), 10**(log_y + err), alpha=0.5,
|
||||
color=col[0])
|
||||
color=cols[0])
|
||||
|
||||
ax[1].plot(x, csiborg5511 / mean_quijote, c="k", ls="--")
|
||||
|
||||
|
@ -239,11 +201,6 @@ 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
|
||||
|
@ -305,29 +262,13 @@ def plot_hmf_quijote_full(pdf=False):
|
|||
plt.close()
|
||||
|
||||
|
||||
def load_field(kind, nsim, grid, MAS, in_rsp=False):
|
||||
def load_field(kind, nsim, grid, MAS, in_rsp=False, smooth_scale=None):
|
||||
r"""
|
||||
Load a single field.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
kind : str
|
||||
Field kind.
|
||||
nsim : int
|
||||
Simulation index.
|
||||
grid : int
|
||||
Grid size.
|
||||
MAS : str
|
||||
Mass assignment scheme.
|
||||
in_rsp : bool, optional
|
||||
Whether to load the field in redshift space.
|
||||
|
||||
Returns
|
||||
-------
|
||||
field : n-dimensional array
|
||||
"""
|
||||
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
||||
return numpy.load(paths.field(kind, MAS, grid, nsim, in_rsp=in_rsp))
|
||||
return numpy.load(paths.field(kind, MAS, grid, nsim, in_rsp=in_rsp,
|
||||
smooth_scale=smooth_scale))
|
||||
|
||||
|
||||
###############################################################################
|
||||
|
@ -338,35 +279,8 @@ def load_field(kind, nsim, grid, MAS, in_rsp=False):
|
|||
def plot_projected_field(kind, nsim, grid, in_rsp, smooth_scale, MAS="PCS",
|
||||
vel_component=0, highres_only=True, slice_find=None,
|
||||
pdf=False):
|
||||
r"""
|
||||
"""
|
||||
Plot the mean projected field, however can also plot a single slice.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
kind : str
|
||||
Field kind.
|
||||
nsim : int
|
||||
Simulation index.
|
||||
grid : int
|
||||
Grid size.
|
||||
in_rsp : bool
|
||||
Whether to load the field in redshift space.
|
||||
smooth_scale : float
|
||||
Smoothing scale in :math:`\mathrm{Mpc} / h`.
|
||||
MAS : str, optional
|
||||
Mass assignment scheme.
|
||||
vel_component : int, optional
|
||||
Which velocity field component to plot.
|
||||
highres_only : bool, optional
|
||||
Whether to only plot the high-resolution region.
|
||||
slice_find : float, optional
|
||||
Which slice to plot in fractional units (i.e. 1. is the last slice)
|
||||
pdf : bool, optional
|
||||
Whether to save the figure as a PDF.
|
||||
|
||||
Returns
|
||||
-------
|
||||
None
|
||||
"""
|
||||
print(f"Plotting projected field `{kind}`. ", flush=True)
|
||||
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
||||
|
@ -383,7 +297,8 @@ def plot_projected_field(kind, nsim, grid, in_rsp, smooth_scale, MAS="PCS",
|
|||
field = File(paths.borg_mcmc(nsim), 'r')
|
||||
field = field["scalars"]["BORG_final_density"][...]
|
||||
else:
|
||||
field = load_field(kind, nsim, grid, MAS=MAS, in_rsp=in_rsp)
|
||||
field = load_field(kind, nsim, grid, MAS=MAS, in_rsp=in_rsp,
|
||||
smooth_scale=smooth_scale)
|
||||
|
||||
if kind == "velocity":
|
||||
field = field[vel_component, ...]
|
||||
|
@ -487,7 +402,6 @@ def plot_projected_field(kind, nsim, grid, in_rsp, smooth_scale, MAS="PCS",
|
|||
else:
|
||||
fig.colorbar(im, cax=cbar_ax, label=clabel)
|
||||
|
||||
|
||||
fig.tight_layout(h_pad=0, w_pad=0)
|
||||
for ext in ["png"] if pdf is False else ["png", "pdf"]:
|
||||
fout = join(
|
||||
|
@ -506,20 +420,9 @@ def plot_projected_field(kind, nsim, grid, in_rsp, smooth_scale, MAS="PCS",
|
|||
###############################################################################
|
||||
|
||||
|
||||
def get_sky_label(kind, volume_weight):
|
||||
def get_sky_label(kind, volume_weight: bool):
|
||||
"""
|
||||
Get the sky label for a given field kind.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
kind : str
|
||||
Field kind.
|
||||
volume_weight : bool
|
||||
Whether to volume weight the field.
|
||||
|
||||
Returns
|
||||
-------
|
||||
label : str
|
||||
"""
|
||||
if volume_weight:
|
||||
if kind == "density":
|
||||
|
@ -667,14 +570,16 @@ if __name__ == "__main__":
|
|||
plot_halos=5e13, volume_weight=True)
|
||||
|
||||
if True:
|
||||
kind = "potential"
|
||||
kind = "environment"
|
||||
grid = 512
|
||||
smooth_scale = 0
|
||||
smooth_scale = 8.0
|
||||
# plot_projected_field("overdensity", 7444, grid, in_rsp=True,
|
||||
# highres_only=False)
|
||||
# for in_rsp in [True, False]:
|
||||
for in_rsp in [True, False]:
|
||||
plot_projected_field(kind, 7444, grid, in_rsp=in_rsp,
|
||||
# nsims = [7444 + n * 24 for n in range(101)]
|
||||
nsim = 7444
|
||||
|
||||
for in_rsp in [False]:
|
||||
plot_projected_field(kind, nsim, grid, in_rsp=in_rsp,
|
||||
smooth_scale=smooth_scale, slice_find=0.5,
|
||||
MAS="PCS", highres_only=True)
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ 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)
|
||||
reader = csiborgtools.summary.kNNCDFReader(paths)
|
||||
|
||||
with plt.style.context(plt_utils.mplstyle):
|
||||
plt.figure()
|
||||
|
|
|
@ -64,7 +64,8 @@ def get_overlap_summary(nsim0, simname, min_logmass, smoothed):
|
|||
cat0 = open_cat(nsim0, simname)
|
||||
catxs = open_cats(nsimxs, simname)
|
||||
|
||||
reader = csiborgtools.read.NPairsOverlap(cat0, catxs, paths, min_logmass)
|
||||
reader = csiborgtools.summary.NPairsOverlap(cat0, catxs, paths,
|
||||
min_logmass)
|
||||
mass0 = reader.cat0(MASS_KINDS[simname])
|
||||
mask = mass0 > 10**min_logmass
|
||||
|
||||
|
@ -85,7 +86,8 @@ def get_expected_mass(nsim0, simname, min_overlap, min_logmass, smoothed):
|
|||
cat0 = open_cat(nsim0, simname)
|
||||
catxs = open_cats(nsimxs, simname)
|
||||
|
||||
reader = csiborgtools.read.NPairsOverlap(cat0, catxs, paths, min_logmass)
|
||||
reader = csiborgtools.summary.NPairsOverlap(cat0, catxs, paths,
|
||||
min_logmass)
|
||||
mass0 = reader.cat0(MASS_KINDS[simname])
|
||||
mask = mass0 > 10**min_logmass
|
||||
mu, std = reader.counterpart_mass(
|
||||
|
@ -115,7 +117,8 @@ def get_mtot_vs_all_pairoverlap(nsim0, simname, mass_kind, min_logmass,
|
|||
cat0 = open_cat(nsim0, simname)
|
||||
catxs = open_cats(nsimxs, simname)
|
||||
|
||||
reader = csiborgtools.read.NPairsOverlap(cat0, catxs, paths, min_logmass)
|
||||
reader = csiborgtools.summary.NPairsOverlap(cat0, catxs, paths,
|
||||
min_logmass)
|
||||
|
||||
x = [None] * len(catxs)
|
||||
y = [None] * len(catxs)
|
||||
|
@ -193,7 +196,8 @@ def get_mtot_vs_maxpairoverlap(nsim0, simname, mass_kind, min_logmass,
|
|||
return 0
|
||||
return numpy.nanmax(y_)
|
||||
|
||||
reader = csiborgtools.read.NPairsOverlap(cat0, catxs, paths, min_logmass)
|
||||
reader = csiborgtools.summary.NPairsOverlap(cat0, catxs, paths,
|
||||
min_logmass)
|
||||
|
||||
x = [None] * len(catxs)
|
||||
y = [None] * len(catxs)
|
||||
|
@ -266,7 +270,8 @@ def get_mtot_vs_maxpairoverlap_consistency(nsim0, simname, mass_kind,
|
|||
cat0 = open_cat(nsim0, simname)
|
||||
catxs = open_cats(nsimxs, simname)
|
||||
|
||||
reader = csiborgtools.read.NPairsOverlap(cat0, catxs, paths, min_logmass)
|
||||
reader = csiborgtools.summary.NPairsOverlap(cat0, catxs, paths,
|
||||
min_logmass)
|
||||
|
||||
x = numpy.log10(cat0[mass_kind])
|
||||
mask = x > min_logmass
|
||||
|
@ -534,12 +539,12 @@ def get_mass_vs_separation(nsim0, nsimx, simname, min_logmass, boxsize,
|
|||
cat0 = open_cat(nsim0, simname)
|
||||
catx = open_cat(nsimx, simname)
|
||||
|
||||
reader = csiborgtools.read.PairOverlap(cat0, catx, paths, min_logmass)
|
||||
reader = csiborgtools.summary.PairOverlap(cat0, catx, paths, min_logmass)
|
||||
|
||||
mass = numpy.log10(reader.cat0(MASS_KINDS[simname]))
|
||||
dist = reader.dist(in_initial=False, boxsize=boxsize, norm_kind="r200c")
|
||||
overlap = reader.overlap(smoothed)
|
||||
dist = csiborgtools.read.weighted_stats(dist, overlap, min_weight=0)
|
||||
dist = csiborgtools.summary.weighted_stats(dist, overlap, min_weight=0)
|
||||
|
||||
mask = numpy.isfinite(dist[:, 0])
|
||||
mass = mass[mask]
|
||||
|
@ -618,7 +623,7 @@ def get_mass_vs_max_overlap_separation(nsim0, nsimx, simname, min_logmass,
|
|||
cat0 = open_cat(nsim0, simname)
|
||||
catx = open_cat(nsimx, simname)
|
||||
|
||||
reader = csiborgtools.read.PairOverlap(cat0, catx, paths, min_logmass)
|
||||
reader = csiborgtools.summary.PairOverlap(cat0, catx, paths, min_logmass)
|
||||
|
||||
mass = numpy.log10(reader.cat0(MASS_KINDS[simname]))
|
||||
dist = reader.dist(in_initial=False, boxsize=boxsize, norm_kind="r200c")
|
||||
|
@ -697,7 +702,8 @@ def get_property_maxoverlap(nsim0, simname, min_logmass, key, min_overlap,
|
|||
cat0 = open_cat(nsim0, simname)
|
||||
catxs = open_cats(nsimxs, simname)
|
||||
|
||||
reader = csiborgtools.read.NPairsOverlap(cat0, catxs, paths, min_logmass)
|
||||
reader = csiborgtools.summary.NPairsOverlap(cat0, catxs, paths,
|
||||
min_logmass)
|
||||
mass0 = reader.cat0(MASS_KINDS[simname])
|
||||
mask = mass0 > 10**min_logmass
|
||||
|
||||
|
@ -1044,7 +1050,7 @@ def matching_max_vs_overlap(simname, nsim0, min_logmass):
|
|||
# None
|
||||
# """
|
||||
# paths = csiborgtools.read.Paths(**kwargs["paths_kind"])
|
||||
# nn_reader = csiborgtools.read.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
# nn_reader = csiborgtools.summary.NearestNeighbourReader(**kwargs, paths=paths)
|
||||
#
|
||||
# xs, ys1, ys2, cs = [], [], [], []
|
||||
# for run in runs:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue