Ejemplo n.º 1
0
    def __init__(self):

        # read file of parameters of polynomial fit to k-correction
        cmin, cmax, A, B, C, D, E, cmed = \
            np.loadtxt(par.k_corr_file, unpack=True)

        self.z0 = 0.1  # reference redshift

        # Polynomial fit parameters
        self.__A_interpolator = self.__initialize_parameter_interpolator(
            A, cmed)
        self.__B_interpolator = self.__initialize_parameter_interpolator(
            B, cmed)
        self.__C_interpolator = self.__initialize_parameter_interpolator(
            C, cmed)
        self.__D_interpolator = self.__initialize_parameter_interpolator(
            D, cmed)
        self.__E = E[0]

        self.colour_min = np.min(cmed)
        self.colour_max = np.max(cmed)
        self.colour_med = cmed

        self.cosmo = Cosmology(par.h0, par.OmegaM, par.OmegaL)

        # Linear extrapolation
        self.__X_interpolator = lambda x: None
        self.__Y_interpolator = lambda x: None
        self.__X_interpolator, self.__Y_interpolator = \
                                 self.__initialize_line_interpolators()
Ejemplo n.º 2
0
 def set_agelim(self, redshift):
     ''' Set the Age limit based on age of the universe '''
     C = Cosmology()
     # self.age_lims[1] = np.log10(C.lookback_time(20.) -
     #                             C.lookback_time(redshift))
     self.age = np.log10(C.lookback_time(20.) - C.lookback_time(redshift))
     self.tdiff = np.diff(10**np.vstack([[0.] + self.ages, [self.age + 9.] *
                                         (len(self.ages) + 1)]).min(axis=0))
Ejemplo n.º 3
0
 def set_agelim(self, redshift):
     ''' Set the Age limit based on age of the universe '''
     C = Cosmology()
     self.age = np.log10(C.lookback_time(20.) -
                         C.lookback_time(redshift))
     # adjust priors on all age bins that are too old
     indx_too_old = np.where( self.age < np.array(self.ages)-9. )[0]
     if len(indx_too_old) > 1:
         for num in indx_too_old[1:]+1:
             setattr(self, 'sfr_' + str(num), -99.)
             setattr(self, 'sfr_' + str(num) + '_lims', [-99-1e-9,-99+1e-9])
             setattr(self, 'sfr_' + str(num) + '_delta', 1e-9)
Ejemplo n.º 4
0
    def get_r200(self, comoving=True):
        """
        Returns R200mean of each halo

        Args:
            comoving: (optional) if True convert to comoving distance
        Returns:
            array of R200mean [Mpc/h]
        """
        cosmo = Cosmology(par.h0, par.OmegaM, par.OmegaL)
        rho_mean = cosmo.mean_density(self.get("zcos"))
        r200 = (3./(800*np.pi) * self.get("mass") / rho_mean)**(1./3)
        
        if comoving:
            return r200 * (1.+self.get("zcos"))
        else:
            return r200
Ejemplo n.º 5
0
def test():
    from cosmology import Cosmology
    import parameters as par
    cos = Cosmology(par.h0, par.OmegaM, par.OmegaL)

    from halo_catalogue import MXXLCatalogue
    halo_cat = MXXLCatalogue()
    gal_cat = BGSGalaxyCatalogue(halo_cat, cos)

    from hod import HOD_BGS
    hod = HOD_BGS()
    gal_cat.add_galaxies(hod)

    print(len(gal_cat.get("abs_mag")), len(gal_cat.get_halo("ra")))
    print(len(gal_cat.haloes.get("ra")))

    gal_cat.position_galaxies()

    ##gal_cat.cut(gal_cat.get("zcos")<0.1)

    rah, dech = gal_cat.get_halo("ra"), gal_cat.get_halo("dec")
    zcosh, zobsh = gal_cat.get_halo("zcos"), gal_cat.get_halo("zobs")

    ra, dec = gal_cat.get("ra"), gal_cat.get("dec")
    zcos, zobs = gal_cat.get("zcos"), gal_cat.get("zobs")
    ra[ra > 100] -= 360

    is_sat = gal_cat.get("is_sat")

    import matplotlib.pyplot as plt
    plt.scatter(rah, dech, s=3, edgecolor="none")
    plt.scatter(ra[is_sat], dec[is_sat], s=3, edgecolor="none")
    plt.show()

    plt.scatter(zcos, zcosh, s=1, edgecolor="none")
    plt.show()

    plt.scatter(zobs, zobsh, s=1, edgecolor="none")
    plt.show()

    plt.scatter(zcosh, ra - rah, s=1, edgecolor="none")
    plt.show()

    plt.scatter(zcosh, dec - dech, s=1, edgecolor="none")
    plt.show()
Ejemplo n.º 6
0
 def plotpractice(self, wave, z):
     from cosmology import Cosmology
     C = Cosmology()
     D = C.luminosity_distance(z)
     dustem1 = self.evaluate(wave)
     dustem = np.interp(wave, wave * (1. + z),
                     dustem1 * (1. + z))
     dustem/=D**2 #Divide by distance ^ 2 (to get flux)
     dustem*=1.0e-29 #Go from uJy to erg/cm^2/s/Hz
     nu = 3.0e18/wave
     plt.figure()
     plt.loglog(wave/1.0e4, nu*dustem, 'b-')
     xlims = np.array([2.0,1000.])/(1.+z)
     plt.xlim(xlims)
     plt.xlabel(r"$\lambda$ ($\mu m$)")
     plt.ylabel(r"Dust emissivity (erg cm$^{-1}$ s$^{-1}$) ")
     plt.savefig("DustTesting/%.2f_%.4f_%.2f_%.3f.png"%(self.umin,self.gamma,self.qpah,self.mdust))
     plt.show()
Ejemplo n.º 7
0
Archivo: hod.py Proyecto: zxzhai/hod
    def __init__(self):
        self.mf = MassFunction()
        self.cosmo = Cosmology(par.h0, par.OmegaM, par.OmegaL)
        self.lf = LuminosityFunctionTarget(par.lf_file, par.Phi_star,
                                           par.M_star, par.alpha, par.P, par.Q)
        self.kcorr = GAMA_KCorrection()

        self.__slide_interpolator = self.__initialize_slide_factor_interpolator(
        )
        self.__logMmin_interpolator = \
            self.__initialize_mass_interpolator(par.Mmin_Ls, par.Mmin_Mt,
                                               par.Mmin_am)
        self.__logM1_interpolator = \
            self.__initialize_mass_interpolator(par.M1_Ls, par.M1_Mt, par.M1_am)

        self.__central_interpolator = self.__initialize_central_interpolator()

        self.__satellite_interpolator = \
                                  self.__initialize_satellite_interpolator()
Ejemplo n.º 8
0
def get_max_ssp_age(args, z=None):
    '''
    Identify the maximum SSP age for the sample (i.e., at upper/lower redshifts)

    Max SSP age is the time between redshift z=20 and redshift of the galaxy
 
    Parameters
    ----------
    args : class
        The args class is carried from function to function with information
        from command line input and config.py

    z : float (optional)
        if specific redshift is passed, evaluate max age at that redshift
        otherwise, evaluate for the range of redshifts of the sample

    Returns
    -------
    maxage : tuple of (float, float)
        the youngest and oldest maximum age (in log years) of sample galaxies
    '''
    C = Cosmology()
    if z is not None:
        maxage = np.log10(C.lookback_time(20) - C.lookback_time(z)) + 9.
        return maxage

    if not args.test:
        F = Table.read(args.filename, format='ascii')
        z = F['z']
        zrange = (min(z), max(z))
    else:
        zrange = args.test_zrange

    # ages in log years:
    maxage_lo = np.log10(C.lookback_time(20) - C.lookback_time(zrange[1])) + 9.
    maxage_hi = np.log10(C.lookback_time(20) - C.lookback_time(zrange[0])) + 9.
    return (maxage_lo, maxage_hi)
Ejemplo n.º 9
0
 def __init__(self, haloes):
     self._quantities = {}
     self.size = 0
     self.haloes = haloes
     self.cosmology = Cosmology(par.h0, par.OmegaM, par.OmegaL)
Ejemplo n.º 10
0
n_simulations = len(sim_dirs)
sim_ids = range(n_simulations)
sim_ids_local = split_indices(sim_ids, rank, n_procs)
print(f'proc_id: {rank}  sim_ids_local:{sim_ids_local}')

for sim_id in sim_ids_local:
    sim_dir = root_dir + sim_dirs[sim_id] + '/'
    uvb_rates_file = sim_dir + 'UVB_rates.h5'
    output_dir = thermal_dir + f'{sim_dirs[sim_id]}/'
    print(f'UVB Rates File: {uvb_rates_file}')
    print(f'Output Dir:     {output_dir}')
    create_directory(output_dir, print_out=False)

    # Initialize Cosmology
    z_start = 16
    cosmo = Cosmology(z_start)

    # Initialize parameters
    n_samples = 10000
    z_end = 2.
    T_start = 5
    X = 0.75984

    # Set Number Densities
    rho_gas_mean = cosmo.rho_gas_mean  # kg cm^-3
    rho_H = X * rho_gas_mean
    rho_He = (1 - X) * rho_gas_mean
    n_H_comov = rho_H / M_p  # cm^-3
    n_He_comov = rho_He / (4 * M_p)  # cm^-3
    a_start = 1. / (z_start + 1)
    rho_cgs = rho_gas_mean * 1e3 / a_start**3
Ejemplo n.º 11
0
 def set_agelim(self, redshift):
     ''' Set the Age limit based on age of the universe '''
     C = Cosmology()
     self.age = np.log10(C.lookback_time(20.) - C.lookback_time(redshift))
Ejemplo n.º 12
0
 def __init__(self, filename, h0, OmegaM):
     self.k, self.P = np.loadtxt(filename, unpack=True)
     self.cosmo = Cosmology(h0, OmegaM)
     self.tck = self.__get_sigma_spline()  #spline fit to sigma(M,z=0)
Ejemplo n.º 13
0
# coding: utf-8
from cosmology import Cosmology
import numpy as np
import matplotlib.pyplot as plt

c = Cosmology()
z = np.linspace(0, 1, 10001)

fig, ax = plt.subplots(1, 1, figsize=(8, 6))
ax.plot(c.z, c.r)
ax.plot(z, c.z2r(z), '.')
ax.set(xlabel='redshift $z$',
       xlim=[0, 1],
       ylabel='comoving distance $r$ [$h^{-1}$ Mpc]')

fig.tight_layout()

plt.show()