csiborgtools/scripts_plots/paper_environment.ipynb
Richard Stiskalek 9e4b34f579
Overlap fixing and more (#107)
* 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
2024-01-30 16:14:07 +00:00

829 KiB

In [ ]:
# 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
import csiborgtools

SPEED_OF_LIGHT = 299792.458  # km / s


%load_ext autoreload
%autoreload 2
%matplotlib inline

paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)

Read in upGLADE

  • Mask out galaxies with bad redshifts
  • Convert heliocentric redshifts to the CMB frame.
In [ ]:
fname = "/mnt/users/rstiskalek/csiborgtools/data/upglade_all_z0p05_new.h5"
data = {}
with File(fname, "r") as f:
    for i, key in enumerate(["RA", "dec", "zhelio", "e_zhelio"]):
        data[key] = f["data"]["block0_values"][:, i]
data["DEC"] = data.pop("dec")

print(f"Initially, we have {data['zhelio'].size} objects.")

# Ask about this
mask = (data["e_zhelio"] < 0) | (data["zhelio"] < 0)
print(f"Masking {mask.sum()} objects that have `e_zhelio` < 0 or `zhelio` < 0.")
for key in data.keys():
    data[key][mask] = np.nan

mask = (data["e_zhelio"] / data["zhelio"] > 0.15)
print(f"Masking {mask.sum()} objects that have `e_zhelio` / `zhelio` > 0.15.")
for key in data.keys():
    data[key][mask] = np.nan

print(f"Finally, we have {np.sum(np.isfinite(data['zhelio']))} objects.")
In [ ]:
plt.figure()
plt.scatter(data["zhelio"], data["e_zhelio"], s=0.1)

plt.yscale("log")
plt.xscale("log")
plt.xlabel(r"$z_{\rm helio}$")
plt.ylabel(r"$\sigma_{z_{\rm helio}}$")

plt.tight_layout()
plt.show()
In [ ]:
zcmb, e_zcmb = csiborgtools.heliocentric_to_cmb(data["zhelio"], data["RA"], data["DEC"], data["e_zhelio"])
data["zcmb"] = zcmb
data["e_zcmb"] = e_zcmb


mask = (data["zcmb"] > 0.06) #& ~np.isnan(data["zhelio"])
print(f"Masking {mask.sum()} objects that have `zcmb` > 0.06.")
for key in data.keys():
    data[key][mask] = np.nan

print(f"Finally, we have {np.sum(np.isfinite(data['zhelio']))} objects.")
In [ ]:
plt.figure()

plt.scatter(data["zcmb"], data["e_zcmb"], s=0.001)
plt.xlabel(r"$z_{\rm CMB}$")
plt.ylabel(r"$\sigma_{z_{\rm CMB}}$")

plt.xlim(0, 0.05)
plt.ylim(0, 0.008)

plt.tight_layout()
plt.savefig("../../plots/UPGLADE_zcmb_vs_ezcmb.png")
plt.show()
  • Write only masked galaxies to this file, but also save the mask.
In [ ]:
fname_here = fname.replace(".h5", "_PROCESSED.h5")
mask = np.isfinite(data["RA"])
print(f"Writing {mask.sum()} objects to `{fname_here}`.")

with File(fname_here, "w") as f:
    for key in data.keys():
        f[key] = data[key][mask]

    f["mask"] = mask
  • Having generated this file, next step is to run field_los.py to evaluate the density and velocity field along the LOS of each object that is not masked.
  • Then, the next step is to run post_upglade.py to calculate the cosmological redshift of each object in UPGLADE.
    • Based on Carrick2015 samples calibrated against Pantheon+

Results verification

In [ ]:
fname = "/mnt/extraspace/rstiskalek/csiborg_postprocessing/peculiar_velocity/UPGLADE/zcosmo_UPGLADE.hdf5"

with File(fname, "r") as f:
    indxs = f["indxs"][:]
    mean_zcosmo = f["mean_zcosmo"][:]
    std_zcosmo = f["std_zcosmo"][:]


plt.figure()
plt.scatter(mean_zcosmo, std_zcosmo, s=0.001)

plt.xlabel(r"$z_{\rm cosmo}$")
plt.ylabel(r"$\sigma_{z_{\rm cosmo}}$")

plt.xlim(0, 0.05)
plt.ylim(0, 0.006)
plt.tight_layout()
plt.savefig("../../plots/UPGLADE_zcosmo_vs_ezcosmo.png")


plt.show()

Combine datasets

i.e. match to the original UPGLADE file

In [ ]:
data["zcosmo"] = np.zeros_like(data["RA"])
data["zcosmo"][mask] = mean_zcosmo

data["e_zcosmo"] = np.zeros_like(data["RA"])
data["e_zcosmo"][mask] = std_zcosmo
In [ ]:
plt.figure()
plt.scatter(data["zcmb"], data["zcosmo"], s=0.01)
plt.axline([0, 0], slope=1, color="red", ls="--")

plt.xlabel(r"$z_{\rm CMB}$")
plt.ylabel(r"$z_{\rm cosmo}$")
plt.xlim(0)
plt.ylim(0)

plt.tight_layout()
plt.savefig("../../plots/UPGLADE_zcmb_vs_zcosmo.png")

plt.show()
In [ ]:
plt.figure()
plt.scatter(data["zcmb"], (data["zcosmo"] - data["zcmb"]) * SPEED_OF_LIGHT, s=0.001)

plt.xlabel(r"$z_{\rm CMB}$")
plt.ylabel(r"$c (z_{\rm cosmo} - z_{\rm CMB}) ~ [\mathrm{km} / \mathrm{s}]$")
plt.xlim(0)
plt.ylim(-1000, 1000)

plt.tight_layout()
plt.savefig("../../plots/UPGLADE_zcmb_vs_dzcosmo.png")
plt.show()

Save the data

  • In a format matching what Gergely shared.
In [ ]:
fname = "/mnt/users/rstiskalek/csiborgtools/data/upglade_z_0p05_all_WZCOSMO.h5"
print(f"Writing to `{fname}`.")

with File(fname, "w") as f:
    for key in data.keys():
        f.create_dataset(key, data=data[key])
In [ ]: