Exemple #1
0
    def __init__(self):
        """
        Container class to compute the Cl due to high-z contributions; we first define the window functions 

        """

        # Set constants
        self.fromHztoeV = 6.58e-16
        self.gramstoeV = 1 / (1.78 * 1e-33)
        self.mtoev = 1 / (1.97 * 1e-7)
        self.H0 = cosmo.H(0).value * 1e3 / (1e3 * const.kpc.value
                                            )  #expressed in 1/s
        self.rhocritical = cosmo.critical_density(0).value * self.gramstoeV / (
            1e-2)**3  # eV/m**3
        self.Om0 = cosmo.Om0  #total matter
        self.OLambda0 = cosmo.Ode0  # cosmological constant
        self.DM0 = self.Om0 - cosmo.Ob0  # dark matter
        self.evtonJoule = 1.60218 * 1e-10  # from eV to nJ
        self.evtoJoule = 1.60218 * 1e-19  # from eV to J
        self.h = 0.6766
        PS1h = np.loadtxt(
            "/Users/andreacaputo/Desktop/Phd/AxionDecayCrossCorr/Codes/NIRB_PS/PS_DM_1h.dat"
        )
        PS2h = np.loadtxt(
            "/Users/andreacaputo/Desktop/Phd/AxionDecayCrossCorr/Codes/NIRB_PS/PS_DM_2h.dat"
        )
        self.Mpctometer = 3.086e+22  # from Mpc to meters
        self.Mpc = 1e3 * const.kpc.value
        self.zmin = 0.001
        self.zmax = 30.001
        self.zbins = 301
        self.h = cosmo.h
        self.TotPower = PS1h + PS2h
        self.z_vect = np.linspace(self.zmin, self.zmax, self.zbins)
        self.k_vect = PS1h[:, 0] * self.h
        self.Power = self.TotPower[:, 1:] / self.h**3
        self.Praw_prova = interp2d(self.k_vect, self.z_vect,
                                   np.transpose(self.Power))
        self.Msun = const.M_sun.value  #Kg
        self.Lsun = const.L_sun.value  # in W
        self.Sb = const.sigma_sb.value  # Stefan-Boltzmann constant in  W/m**2/K**4
        self.Rsun = const.R_sun.value  # in meters
        self.hplanck = const.h.value  # Js
        self.cc = const.c.value  #m/s
        self.kb = const.k_B.value  # kb constant J/K
        self.mp = const.m_p.value  # proton mass in Kg
        self.Hseconds = cosmo.H(0).value / (1e6 * u.parsec.to(u.km))  # in 1/s
        self.nHnebula = 1e4 / (
            1e-2)**3  # in m**-3, is also equal to the electron number density
        self.eVtoK = 1.16e4  # from eV to K
        self.year = 3.154e+7  # from year to seconds
        self.Ry = 1.1e7  #1/m Rydberg constant
        self.ergtoJoule = 1e-7  # from erg to Joule
        self.fromJouletoeV = 6.242e+18  # from Joule to eV
        self.Mpc = 1e3 * const.kpc.value
        self.RyK = 13.6057 * self.eVtoK
        self.Tgas = 3e4  # Kelvin, below Eq.9 in the paper, said to be used to calculate alphaB
        self.nuly = 2.4663495e15  # Lyman alpha frequency in Hz, which corresponds to a photon energy of
Exemple #2
0
    def __init__(self):
        """
        Container class to compute window functions due to resolution and volume effects. See for example https://arxiv.org/pdf/1907.10067.pdf

        """

        # Set constants
        self.fromHztoeV = 6.58e-16
        self.gramstoeV = 1 / (1.78 * 1e-33)
        self.mtoev = 1 / (1.97 * 1e-7)
        self.H0 = cosmo.H(0).value * 1e3 / (1e3 * const.kpc.value
                                            )  #expressed in 1/s
        self.rhocritical = cosmo.critical_density(0).value * self.gramstoeV / (
            1e-2)**3  # eV/m**3
        self.Om0 = cosmo.Om0  #total matter
        self.OLambda0 = cosmo.Ode0  # cosmological constant
        self.DM0 = self.Om0 - cosmo.Ob0  # dark matter
        self.evtonJoule = 1.60218 * 1e-10  # from eV to nJ
        self.evtoJoule = 1.60218 * 1e-19  # from eV to J
        self.h = 0.6766
        self.Mpc = 1e3 * const.kpc.value
        self.zmin = 0.001
        self.zmax = 30.001
        self.zbins = 301
        self.h = cosmo.h
Exemple #3
0
def z_distort(gals, z, L):

    # Convert z-axis to redshift space
    gals['zn_z'] += gals['zn_velZ'] * (1 + z) / Planck13.H(z).value

    # fix z coordinate positions if they fall outside the box
    gals.loc[gals['zn_z'] < 0, 'zn_z'] = gals.loc[gals['zn_z'] < 0, 'zn_z'] + L
    gals.loc[gals['zn_z'] > L, 'zn_z'] = gals.loc[gals['zn_z'] > L, 'zn_z'] - L

    return gals
def M_to_sigma(M, z=0, mode='3D'):
    if mode == '3D':
        ndim_scale = np.sqrt(3)
    elif mode == '1D':
        ndim_scale = 1.
    # return prefac * .00989 * U.km / U.s \
    #     * np.power(M.to(U.Msun).value, 1 / 3)
    # Note: Delta_vir returns the overdensity in units of background,
    # which is Delta_c * Om in B&N98 notation.
    return 0.016742 * U.km * U.s**-1 * np.power(
        np.power(M.to(U.Msun).value, 2) * Delta_vir(z) / Delta_vir(0) *
        cosmo.Om(z) / cosmo.Om0 * np.power(cosmo.H(z) / cosmo.H0, 2),
        1 / 6) / ndim_scale
    def __init__(self):
        """
        Container class to compute various quantities for low-z Galaxy as studied here --> https://arxiv.org/pdf/1201.4398.pdf

        """

        # Set constants
        self.fromHztoeV = 6.58e-16
        self.gramstoeV = 1 / (1.78 * 1e-33)
        self.mtoev = 1 / (1.97 * 1e-7)
        self.H0 = cosmo.H(0).value * 1e3 / (1e3 * const.kpc.value
                                            )  #expressed in 1/s
        self.rhocritical = cosmo.critical_density(0).value * self.gramstoeV / (
            1e-2)**3  # eV/m**3
        self.Om0 = cosmo.Om0  #total matter
        self.OLambda0 = cosmo.Ode0  # cosmological constant
        self.DM0 = self.Om0 - cosmo.Ob0  # dark matter
        self.evtonJoule = 1.60218 * 1e-10  # from eV to nJ
        self.evtoJoule = 1.60218 * 1e-19  # from eV to J
        self.h = 0.6766
        self.Mpc = 1e3 * const.kpc.value
        self.zmin = 0.001
        self.zmax = 30.001
        self.zbins = 301
        self.h = cosmo.h
        self.lambda_eff = np.array([
            0.15, 0.36, 0.45, 0.55, 0.65, 0.79, 0.91, 1.27, 1.63, 2.20, 3.60,
            4.50
        ])
        self.Mstar0_vect = np.array([
            -19.62, -20.20, -21.35, -22.13, -22.40, -22.80, -22.86, -23.04,
            -23.41, -22.97, -22.40, -21.84
        ])
        self.q_vect = np.array(
            [1.1, 1.0, 0.6, 0.5, 0.5, 0.4, 0.4, 0.4, 0.5, 0.4, 0.2, 0.3])
        self.phistar0_vect = np.array([
            2.43, 5.46, 3.41, 2.42, 2.25, 2.05, 2.55, 2.21, 1.91, 2.74, 3.29,
            3.29
        ])
        self.p_vect = np.array(
            [0.2, 0.5, 0.4, 0.5, 0.5, 0.4, 0.4, 0.6, 0.8, 0.8, 0.8, 0.8])
        self.alpha0_vect = np.array(
            [-1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1.])
        self.r_vect = np.array([
            0.086, 0.076, 0.055, 0.060, 0.070, 0.070, 0.060, 0.035, 0.035,
            0.035, 0.035, 0.035
        ])
        self.zmax_vect = np.array(
            [8.0, 4.5, 4.5, 3.6, 3.0, 3.0, 2.9, 3.2, 3.2, 3.8, 0.7, 0.7])
    def __init__(self):
        """
        Container class to compute the Power spectrum and the Cl 

        """
        # Set constants
        self.fromHztoeV = 6.58e-16
        self.gramstoeV = 1 / (1.78 * 1e-33)
        self.mtoev = 1 / (1.97 * 1e-7)
        self.H0 = cosmo.H(0).value * 1e3 / (1e3 * const.kpc.value
                                            )  #expressed in 1/s
        self.rhocritical = cosmo.critical_density(0).value * self.gramstoeV / (
            1e-2)**3  # eV/m**3
        self.Om0 = cosmo.Om0  #total matter
        self.OLambda0 = cosmo.Ode0  # cosmological constant
        self.DM0 = self.Om0 - cosmo.Ob0  # dark matter
        self.evtonJoule = 1.60218 * 1e-10  # from eV to nJ
        self.evtoJoule = 1.60218 * 1e-19  # from eV to J
        PSgal1h = np.loadtxt(
            "/Users/andreacaputo/Desktop/Phd/AxionDecayCrossCorr/Codes/NIRB_PS/PS_GALl_1h.dat"
        )
        PSgal2h = np.loadtxt(
            "/Users/andreacaputo/Desktop/Phd/AxionDecayCrossCorr/Codes/NIRB_PS/PS_GALl_2h.dat"
        )
        self.Mpc = 1e3 * const.kpc.value
        self.zmin = 0.001
        self.zmax = 30.001
        self.zbins = 301
        self.h = cosmo.h
        self.z_vect = np.linspace(self.zmin, self.zmax, self.zbins)
        self.k_vect = PSgal1h[:, 0] * self.h
        self.Power1h = PSgal1h[:, 1:] / (self.h**3)
        self.Power2h = PSgal2h[:, 1:] / (self.h**3)
        self.Power = self.Power1h + self.Power2h
        self.Praw_prova1h = interp2d(self.k_vect, self.z_vect,
                                     np.transpose(self.Power1h))
        self.Praw_prova2h = interp2d(self.k_vect, self.z_vect,
                                     np.transpose(self.Power2h))
        self.Praw_prova = interp2d(self.k_vect, self.z_vect,
                                   np.transpose(self.Power))
Exemple #7
0
    freqs = f['data'].attrs['nu']  # MHz
    ras = f['data'].attrs['ra']  # degree
    decs = f['data'].attrs['dec']  # degree

ras = np.radians(ras)  # radians
decs = np.radians(decs)  # radians

nf = freqs.shape[0]
nra = ras.shape[0]
ndec = decs.shape[0]

freq0 = 1420.4  # MHz
freqc = freqs[nf / 2]  # central frequency, MHz
zc = freq0 / freqc - 1.0  # central redshifts
rc = cosmo.comoving_distance(zc).value  # Mpc
rcp = const.c * (1 + zc)**2 / (1.0e6 * freq0 * 1.0e3 * cosmo.H(zc).value
                               )  # Mpc/Hz, cosmo.H(z) in unit km/s/Mpc
Omega = (ras[-1] - ras[0]) * (
    decs[-1] - decs[0])  # this is true approximately for a small flat sky area

# zs = freq0 / freqs - 1.0 # redshifts

# # get comoving distance
# cd = cosmo.comoving_distance(zs).value # Mpc
# # print cosmo.h
# cd /= cosmo.h # Mpc / h
# # get k_parallel by approximate cd as uniform
# k_paras = np.fft.fftshift(2*np.pi * np.fft.fftfreq(nf, d=(cd[0]-cd[-1])/nf)) # h Mpc^-1
# k_paras = k_paras[nf/2:] # get only positive k_paras

data_fft2 = np.zeros((nf, nra, ndec), dtype=np.complex128)
def rcrit200(M, z):

    H = cosmo.H(z).value * converts_H_to_SI

    return ((G * M) / (200 * H**2))**(1 / 3.)
def XLT(nu, z):

    return (const.c**3 * (1 + z)**2 /
            (8 * np.pi * const.k_B * nu**3 * cosmo.H(z))).to(u.K * u.Mpc**3 /
                                                             u.W)
Exemple #10
0
sigma = Tsys * omega / np.sqrt(npol * nbl * dfreq * dt)
print sigma

# generate noise
np.random.seed(0)
noise = np.random.normal(loc=0.0, scale=sigma, size=(nf, nra, ndec)) # K


data = fg_data + HI_data + noise


freq0 = 1420.4 # MHz
freqc = freqs[nf/2] # central frequency, MHz
zc = freq0 / freqc - 1.0 # central redshifts
rc = cosmo.comoving_distance(zc).value # Mpc
rcp = const.c * (1 + zc)**2 / (1.0e6*freq0 * 1.0e3*cosmo.H(zc).value) # Mpc/Hz, cosmo.H(z) in unit km/s/Mpc
Omega = (ras[-1] - ras[0]) * (decs[-1] - decs[0]) # this is true approximately for a small flat sky area


data_fft2 = np.zeros((nf, nra, ndec), dtype=np.complex128)
for fi in range(nf):
    data_fft2[fi] = Omega * np.fft.fftshift(np.fft.ifft2(data[fi])) # K^2
    # # for check
    # print np.allclose(np.fft.fft2(np.fft.ifftshift(data_fft2[fi])).real / Omega, data[fi])

Ux = np.fft.fftshift(np.fft.fftfreq(nra, d=ras[1] - ras[0]))
Uy = np.fft.fftshift(np.fft.fftfreq(ndec, d=decs[1] - decs[0]))

lmodes = defaultdict(list)
for xi in range(nra):
    for yi in range(ndec):
Exemple #11
0
from astropy.cosmology import Planck13 as cosmo
from astropy.cosmology import z_at_value
from astropy.constants import c
import numpy as np
import pandas as pd

t0 = cosmo.age(0)

t = np.linspace(0, t0, 100)[1:-1]
z = [z_at_value(cosmo.age, i) for i in t]

a = cosmo.scale_factor(z)
a_dot = np.gradient(a, t[1] - t[0])  # derivative of a with respect to t

h_calculated = (a_dot / a).to('km / (Mpc s)')
H = cosmo.H(z)

df = pd.DataFrame({
    't': t,
    'a': a,
    'a_dot': a_dot,
    'h calculé': h_calculated,
    'H': H
})

print(df)

fig, ax = plt.subplots()
ax.scatter(t, a, s=1, c='b')  # a
ax.scatter(t, a_dot, s=1, c='r')  # derivative of a
plt.xlabel('t')
    def tointegrate(self, lobs, mlim, k, z):

        lowz = LowGal()
        return (1e-3 * const.c.value / cosmo.H(z).value) * self.PSgal(
            k, z) * (lowz.WindowGal(
                lobs, mlim, z))**2 / (cosmo.comoving_distance(z).value)**2
 def WindowGal(self, lobs, mlim, z):  # nW/m^2/sr/Mpc ---> H/c dF/dz
     c_km = 1e-3 * const.c.value
     return cosmo.H(z).value / c_km * self.dFdz(lobs, mlim, z)
 def dVdz(self, z):
     dH0 = (1e-3 * const.c.value / cosmo.H(0).value)
     return cosmo.comoving_distance(z).value**2 * dH0 / self.E(z)
def single_frame(num, max_pixel, nframes):

    snap = "%04d" % num

    # Define path
    path = '/cosma/home/dp004/dc-rope1/cosma7/SWIFT/DMO_1380_data/ani_hydro_' + snap + ".hdf5"

    snap = "%05d" % num

    data = load(path)

    meta = data.metadata
    boxsize = meta.boxsize[0]
    z = meta.redshift

    print(boxsize, z)

    # Define centre
    cent = np.array([boxsize / 2, boxsize / 2, boxsize / 2])

    # Define targets
    targets = [
        [0, 0, 0],
    ]

    # Define anchors dict for camera parameters
    anchors = {}
    anchors['sim_times'] = [
        0.0, 'same', 'same', 'same', 'same', 'same', 'same', 'same'
    ]
    anchors['id_frames'] = np.linspace(0, nframes, 8, dtype=int)
    anchors['id_targets'] = [
        0, 'same', 'same', 'same', 'same', 'same', 'same', 'same'
    ]
    anchors['r'] = [
        0.1, 'same', 'same', 'same', 'same', 'same', 'same', 'same'
    ]
    anchors['t'] = [5, 'same', 'same', 'same', 'same', 'same', 'same', 'same']
    anchors['p'] = [
        -50, 'same', 'same', 'same', 'same', 'same', 'same', 'same'
    ]
    anchors['zoom'] = [
        1., 'same', 'same', 'same', 'same', 'same', 'same', 'same'
    ]
    anchors['extent'] = [
        10, 'same', 'same', 'same', 'same', 'same', 'same', 'same'
    ]

    # Define the camera trajectory
    cam_data = camera_tools.get_camera_trajectory(targets, anchors)

    poss = data.dark_matter.coordinates.value
    hsmls = data.dark_matter.softenings.value / (1 + z)
    print(hsmls)

    poss -= cent

    poss[np.where(poss > boxsize.value / 2)] -= boxsize.value
    poss[np.where(poss < -boxsize.value / 2)] += boxsize.value

    poss /= (1 + z)

    tree = cKDTree(poss)

    dists, _ = tree.query(np.array([0, 0, 0]), k=poss.shape[0])

    v = cosmo.H(z) * dists
    print(cosmo.H(z))
    print(v)

    # Get images
    rgb_DM, ang_extent = getimage(cam_data, poss, hsmls, num, z, v)
    i = cam_data[num]
    extent = ang_extent
    print(ang_extent, extent)

    dpi = rgb_DM.shape[0]
    print(dpi, rgb_DM.shape)
    fig = plt.figure(figsize=(1, 1.77777777778), dpi=dpi)
    ax = fig.add_subplot(111)

    ax.imshow(rgb_DM, extent=ang_extent, origin='lower')
    ax.tick_params(axis='both',
                   left=False,
                   top=False,
                   right=False,
                   bottom=False,
                   labelleft=False,
                   labeltop=False,
                   labelright=False,
                   labelbottom=False)

    ax.text(0.975,
            0.05,
            "$t=$%.1f Gyr" % cosmo.age(z).value,
            transform=ax.transAxes,
            verticalalignment="top",
            horizontalalignment='right',
            fontsize=1,
            color="w")

    ax.plot([0.05, 0.15], [0.025, 0.025],
            lw=0.1,
            color='w',
            clip_on=False,
            transform=ax.transAxes)

    ax.plot([0.05, 0.05], [0.022, 0.027],
            lw=0.15,
            color='w',
            clip_on=False,
            transform=ax.transAxes)
    ax.plot([0.15, 0.15], [0.022, 0.027],
            lw=0.15,
            color='w',
            clip_on=False,
            transform=ax.transAxes)

    # ax.plot([0.05, 0.15], [0.105, 0.105], lw=0.1, color='w', clip_on=False,
    #         transform=ax.transAxes)
    #
    # ax.plot([0.05, 0.05], [0.102, 0.107], lw=0.15, color='w', clip_on=False,
    #         transform=ax.transAxes)
    # ax.plot([0.15, 0.15], [0.102, 0.107], lw=0.15, color='w', clip_on=False,
    #         transform=ax.transAxes)

    axis_to_data = ax.transAxes + ax.transData.inverted()
    left = axis_to_data.transform((0.05, 0.075))
    right = axis_to_data.transform((0.15, 0.075))
    dist = extent[1] * (right[0] - left[0]) / (ang_extent[1] - ang_extent[0])

    print(left, right, (right[0] - left[0]) / (ang_extent[1] - ang_extent[0]),
          dist)

    if dist > 0.1:
        ax.text(0.1,
                0.065,
                '%.1f $^\circ$' % dist,
                transform=ax.transAxes,
                verticalalignment="top",
                horizontalalignment='center',
                fontsize=1,
                color="w")
    # elif 100 > dist * 10**3 > 1:
    #     ax.text(0.1, 0.065, "%.1f pkpc" % dist * 10**3,
    #             transform=ax.transAxes, verticalalignment="top",
    #             horizontalalignment='center', fontsize=1, color="w")
    # else:
    #     ax.text(0.1, 0.065, "%.1f pkpc" % dist * 10**6,
    #             transform=ax.transAxes, verticalalignment="top",
    #             horizontalalignment='center', fontsize=1, color="w")

    plt.margins(0, 0)

    fig.savefig('plots/Ani/Recession/DM_recession_animation_' + snap + '.png',
                bbox_inches='tight',
                pad_inches=0)
    plt.close(fig)
Exemple #16
0
def sigma_par(dnu, nuObs, z):

    # cutoff for line-of-sight modes

    return (const.c * dnu * (1 + z) / (cosmo.H(z) * nuObs)).to(u.Mpc)  # in Mpc
Exemple #17
0
 def E(self, z):
     return cosmo.H(z).value / cosmo.H(0).value
Exemple #18
0
3) The third method is using astropy's '.lookback_distance()' method.
"""

from astropy.cosmology import Planck13 as cosmo
from astropy.constants import G, c
import numpy as np
import matplotlib.pyplot as plt

Or0 = cosmo.Ogamma(0) + cosmo.Onu(0)
Om0 = cosmo.Om(0)
Ode0 = cosmo.Ode(0)

# deceleration parameter (equation 6.11)
q0 = Or0 + 0.5 * Om0 - Ode0

H0 = cosmo.H(0).to('1 / s')

z = np.linspace(0, 2, 100)

# current proper distance in terms of z (equation 6.12)
dp0_612 = c * z / H0
dp0_612 = dp0_612.to('Mpc')

# current proper distance in terms of z (equation 6.19)
dp0_619 = (z * c / H0) * (1 - (z * (1 + q0) / 2))
dp0_619 = dp0_619.to('Mpc')

# current proper distance in terms of z (equation 6.19)

fig, ax = plt.subplots()
ax.scatter(z, dp0_612, s=1, label='d=cz/H0')
Exemple #19
0
    def to_integrateCooray(self, nuobs, k, z, T, fesc):

        factor = (1e-3 * const.c.value / cosmo.H(z).value) * (PSgal(
            k, z)) / (cosmo.comoving_distance(z).value)**2

        return factor * self.WindowHighzCooray(T, z, fesc, nuobs)**2
Exemple #20
0
    Mstar_30 = np.concatenate(Mstar_30) * 1e10
    sfr_30 = np.concatenate(sfr_30)

    ok = np.where(lum_to_M(L_FUV) < low)[0]
    L_FUV, L_NUV, L_FUV_int, Mstar_30 = L_FUV[ok], L_NUV[ok], L_FUV_int[
        ok], Mstar_30[ok]
    sfr_30 = sfr_30[ok] / Mstar_30

    beta = np.log10(L_FUV / L_NUV) / np.log10(1500. / 2500.) - 2.0
    att = -2.5 * np.log10(L_FUV / L_FUV_int)
    zpos = -17.5

    if tag == '010_z005p000':
        from astropy.cosmology import Planck13
        from astropy import units as u
        tmp = 1 / Planck13.H(5).decompose()
        print((1.0 / (3 * tmp.to(u.yr))).value)
        check = np.logical_and(Mstar_30 > 1e10, att < 0.4)
        print(sfr_30[check])
        print(beta[check])

    if input == plt_options[0]:
        x, y, z, w = lum_to_M(L_FUV), att, beta, ws[ok]
        gridsize = (50, 21)
        extent = [*[low, -24.5], *ylims]
        add = ''
        savename = F'att_lfuv_beta_z5_10'
        xlabel = r'M$_{1500}$'
    elif input == plt_options[1]:
        x, y, z, w = lum_to_M(L_FUV_int), att, beta, ws[ok]
        gridsize = (55, 21)
# page 156 pdf
import numpy as np
from astropy.cosmology import Planck13 as cosmo
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()

Or0 = cosmo.Ogamma(0) + cosmo.Onu(0)
Om0 = cosmo.Om(0)
Ode0 = cosmo.Ode(0)

H0 = cosmo.H(0)
t0 = cosmo.age(0)
q0 = Or0 + 0.5*Om0 - Ode0 #equation 6.11

t = np.linspace(0, t0, 1000)

a = 1 + H0*(t-t0) - 0.5*q0*(H0**2)*(t-t0)**2

fig, ax = plt.subplots()
ax.scatter(t, a, s=1)
plt.show()