csiborgtools/scripts_plots/paper_environment.ipynb
Richard Stiskalek aaa14fc880
Add density field plot and start preparing CSiBORG2 (#94)
* Add RAMSES2HDF5 conversion

* Upload changes

* Clean up

* More clean up

* updates

* Little change

* pep9

* Add basic SPH calculation for a snapshot

* Add submit script

* Remove echo

* Little changes

* Send off changes

* Little formatting

* Little updates

* Add nthreads argument

* Upload chagnes

* Add nthreads arguemnts

* Some local changes..

* Update scripts

* Add submission script

* Update script

* Update params

* Rename CSiBORGBox to CSiBORG1box

* Rename CSiBORG1 reader

* Move files

* Rename folder again

* Add basic plotting here

* Add new skeletons

* Move def

* Update nbs

* Edit directories

* Rename files

* Add units to converted snapshots

* Fix empty dataset bug

* Delete file

* Edits to submission scripts

* Edit paths

* Update .gitignore

* Fix attrs

* Update weighting

* Fix RA/dec bug

* Add FORNAX cluster

* Little edit

* Remove boxes since will no longer need

* Move func back

* Edit to include sort by membership

* Edit paths

* Purge basic things

* Start removing

* Bring file back

* Scratch

* Update the rest

* Improve the entire file

* Remove old things

* Remove old

* Delete old things

* Fully updates

* Rename file

* Edit submit script

* Little things

* Add print statement

* Add here cols_to_structured

* Edit halo cat

* Remove old import

* Add comment

* Update paths manager

* Move file

* Remove file

* Add chains
2023-12-13 16:08:25 +00:00

786 KiB

In [1]:
import numpy as np
import scipy.integrate
import symbolic_pofk.linear
import symbolic_pofk.syrenhalofit as syrenhalofit
In [26]:
def compute_sigma8_from_pk(k, pk):
    """Given a power spectrum P(k), compute sigma8."""
    R = 8.0
    x = k * R
    W = np.zeros(x.shape)
    m = x < 1.e-3
    W[m] = 1.0
    W[~m] =3.0 / x[~m]**3 * (np.sin(x[~m]) - x[~m] * np.cos(x[~m]))
    y = pk * W**2 * k**3
    sigma2 = scipy.integrate.simpson(y, x=np.log(x))
    sigma = np.sqrt(sigma2 / (2.0 * np.pi**2))

    return sigma

# Cosmological parameters
As = 2.105  # 10^9 A_s
h = 0.6766
Om = 0.3111
Ob = 0.02242 / h ** 2
ns = 0.9665
tau = 0.0561

# Define k integration range


def linear_sigma8(As, Om, Ob, h, ns):
    """Calculated from Deaglan's emulator."""
    return symbolic_pofk.linear.As_to_sigma8(As, Om, Ob, h, ns)
    # print('sigma8 from emulator', sigma8)

# # Test linear sigma8
# pk_lin = symbolic_pofk.linear.plin_emulated(k, sigma8, Om, Ob, h, ns,
#     emulator='fiducial', extrapolate=True)
# new_sigma8 = compute_sigma8(k, pk_lin)
# print('sigma8 from integral:', new_sigma8)

# Get non-linear sigma8
def nonlinear_sigma8(As, Om0, Ob, h, ns, ks):
    a = 1.
    sigma8 = linear_sigma8(As, Om0, Ob, h, ns)  # Linear sigma8
    pk_nl = syrenhalofit.run_halofit(
        ks, sigma8, Om, Ob, h, ns, a, emulator='fiducial', extrapolate=True,
        which_params='Bartlett', add_correction=True)
    return compute_sigma8_from_pk(ks, pk_nl)
# print('non-linear sigma8:', sigma8_nl)
# print('sigma8 non-linear bigger by a factor', sigma8_nl / sigma8)
In [18]:
kmin, kmax, nk = 1e-4, 1e1, 256
ks = np.logspace(np.log10(kmin), np.log10(kmax), nk) # Wavenumber
In [21]:
linear_sigma8(As, Om, Ob, h, ns)
Out[21]:
0.825706107176727
In [20]:
nonlinear_sigma8(As, Om, Ob, h, ns, ks)
Out[20]:
0.9203769215120938
In [25]:
1e-10 * np.exp(3.0448)
Out[25]:
2.1005829616811546e-09
In [ ]: