mirror of
https://github.com/Richard-Sti/csiborgtools.git
synced 2024-12-22 17:08:03 +00:00
8a56c22813
* add listing of snapshots * change distance to comoving * ignore cp files * rename nb * add str to list * add NFW profile shapes * add fits imports * Rename to Nsnap * in clumps_read only select props * make clumpid int * expand doc * add import * edit readme * distribute halos * add profile & posterior * add import * add import * add documentation * add rvs and init guess * update todo * update nb * add file * return end index too * change clump_ids format to int32 * skeleton of dump particle * update nb * add func to drop 0 clump indxs parts * add import * add halo dump * switch to float32 * Update TODO * update TODO * add func that loads a split * add halo object * Rename to clump * make post work with a clump * add optimiser * add Nsplits * ignore submission scripts * ignore .out * add dumppath * add job splitting * add split halos script * rename file * renaem files * rm file * rename imports * edit desc * add pick clump * add number of particles * update TODO * update todo * add script * add dumping * change dumpdir structure * change dumpdir * add import * Remove tqdm * Increase the number of splits * rm shuffle option * Change to remove split * add emojis * fix part counts in splits * change num of splits * rm with particle cut * keep splits * fit only if 10 part and more * add min distance * rm warning about not set vels * update TODO * calculate rho0 too * add results collection * add import * add func to combine splits * update TODO * add extract cols * update nb * update TODO
420 KiB
420 KiB
Using a calibrated flow model to predict $z_{\rm cosmo}$¶
In [5]:
# Copyright (C) 2024 Richard Stiskalek
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import numpy as np
import matplotlib.pyplot as plt
from h5py import File
from tqdm import tqdm
import csiborgtools
%load_ext autoreload
%autoreload 2
%matplotlib inline
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
In [2]:
def load_calibration(catalogue, simname, nsim, ksmooth):
fname = f"/mnt/extraspace/rstiskalek/csiborg_postprocessing/peculiar_velocity/flow_samples_{catalogue}_{simname}_smooth_{ksmooth}.hdf5" # noqa
keys = ["Vext_x", "Vext_y", "Vext_z", "alpha", "beta", "sigma_v"]
# SN_keys = ['mag_cal', 'alpha_cal', 'beta_cal']
# SN_keys = []
calibration_samples = {}
with File(fname, 'r') as f:
for key in keys:
calibration_samples[key] = f[f"sim_{nsim}/{key}"][:][::10]
# for key in SN_keys:
# calibration_samples[key] = f[f"sim_{nsim}/{key}"][:]
return calibration_samples
Test running a model¶
In [135]:
# fpath_data = "/mnt/extraspace/rstiskalek/catalogs/PV_compilation_Supranta2019.hdf5"
fpath_data = "/mnt/extraspace/rstiskalek/catalogs/PV_mock_CB2_17417_large.hdf5"
simname = "csiborg2_main"
catalogue = "CB2_large"
nsims = paths.get_ics(simname)[:-1]
ksmooth = 1
loaders = []
models = []
zcosmo_mean = None
zobs = None
for i, nsim in enumerate(tqdm(nsims)):
loader = csiborgtools.flow.DataLoader(simname, i, catalogue, fpath_data, paths, ksmooth=ksmooth)
calibration_samples = load_calibration(catalogue, simname, nsim, ksmooth)
model = csiborgtools.flow.Observed2CosmologicalRedshift(calibration_samples, loader.rdist, loader._Omega_m)
if i == 0:
zcosmo_mean = loader.cat["zcosmo"]
zobs = loader.cat["zobs"]
vrad = loader.cat["vrad"]
loaders.append(loader)
models.append(model)
In [143]:
n = 400
zcosmo, pzcosmo = csiborgtools.flow.stack_pzosmo_over_realizations(
n, models, loaders, "zobs")
In [144]:
plt.figure()
# for i in range(len(nsims)):
# mask = pzcosmo[i] > 1e-5
# plt.plot(zcosmo[mask], pzcosmo[i][mask], color="black", alpha=0.1)
# mu = np.nanmean(pzcosmo, axis=0)
mask = pzcosmo > 1e-5
plt.plot(zcosmo[mask], pzcosmo[mask], color="black", label=r"$p(z_{\rm cosmo})$")
plt.ylim(0)
plt.axvline(zcosmo_mean[n], color="green", label=r"$z_{\rm cosmo}$")
plt.axvline(zobs[n], color="red", label=r"$z_{\rm CMB}$")
plt.xlabel(r"$z$")
plt.ylabel(r"$p(z)$")
plt.legend()
plt.tight_layout()
# plt.savefig("../plots/zcosmo_posterior_mock_example_B.png", dpi=450)
plt.show()
In [ ]: