Exemple #1
0
def luminosity_distance(z, k=0):
    ''' Calculate the luminosity distance for a given redshift.
    
    Parameters:
        * z (float or array): the redshift(s)
        * k = 0 (float): the curvature constant.
        
    Returns:
        The luminosity distance in Mpc
     '''

    if not (type(z) is np.ndarray): #Allow for passing a single z
        z = np.array([z])
    n = len(z)

    if const.lam == 0:
        denom = np.sqrt(1+2*const.q0*z) + 1 + const.q0*z 
        dlum = (const.c*z/const.H0)*(1 + z*(1-const.q0)/denom)
        return dlum
    else:
        dlum = np.zeros(n)
        for i in xrange(n):
            if z[i] <= 0:
                dlum[i] = 0.0
            else:
                dlum[i] = quadrature(_ldist, 0, z[i])[0]

    if k > 0:
        dlum = np.sinh(np.sqrt(k)*dlum)/np.sqrt(k)
    elif k < 0:
        dlum = np.sin(np.sqrt(-k)*dlum)/np.sqrt(-k)
    return outputify(const.c*(1+z)*dlum/const.H0)
Exemple #2
0
def z_to_cdist(z):
    ''' Calculate the comoving distance 

    Parameters:
        z (float): redshift

    Returns:
        Comoving distance in Mpc
    '''
    Ez_func = lambda x: 1./np.sqrt(const.Omega0*(1.+x)**3+const.lam)
    dist = const.c/const.H0 * quadrature(Ez_func, 0, z)[0]
    return outputify(dist)
Exemple #3
0
def angular_size(dl, z):
    ''' Calculate the angular size of an object at a given
    redshift.
    
    Parameters:
        * dl (float or array): the physical size in kpc
        * z (float or array): the redshift of the object
        
    Returns:
        The angluar size in arcseconds 
        
    '''

    angle = 180./(3.1415)*3600.*dl*(1+z)**2/(1000*luminosity_distance(z))
    return outputify(angle)
Exemple #4
0
def z_to_cdist(z):
    ''' Calculate the comoving distance 

    Parameters:
        z (float or array): redshift

    Returns:
        Comoving distance in Mpc
    '''
    z = np.atleast_1d(z)
    dist = np.zeros_like(z)
    for i in range(len(z)):
        Ez_func = lambda x: 1./np.sqrt(const.Omega0*(1.+x)**3+const.lam)
        dist[i] = const.c/const.H0 * quadrature(Ez_func, 0, z[i])[0]
    return outputify(dist)
Exemple #5
0
def cdist_to_z(dist):
    ''' Calculate the redshift correspoding to the given redshift. 

    Parameters:
        * dist (float or array): the distance in comoving Mpc

    Returns:
        redshift corresponding to the distance.

        .. note::
            Uses a precalculated table for interpolation. Only valid for 
            0 <= z < 100 
        
    '''
    dist = np.atleast_1d(dist)
    z = np.zeros_like(dist)
    func = interp1d(precalc_table_cdist, precalc_table_z, kind='cubic')

    for i in range(len(dist)):
        z[i] = func(dist[i])
    return outputify(z)