Example #1
0
def volume_radius_dmdr(mass, **cosmology):
    """The volume, radius, and dm/dr for a sphere of the given mass.

    Uses the mean density of the universe.

    Parameters
    ----------

    mass: array
       mass of the sphere in Solar Masses, M_sun. 

    Returns
    -------

    volume in Mpc^3
    radius in Mpc
    dmdr in Msun / Mpc

    """
    rho_crit, rho_0 = cden.cosmo_densities(**cosmology)

    volume = mass / rho_0
    r = (volume / ((4. / 3.) * math.pi))**(1. / 3.)

    dmdr = 4. * math.pi * r**2. * rho_0

    return volume, r, dmdr
Example #2
0
def vvir_from_cosmology(halos, cosmology):
    """
    Computes the peak virial velocity from cosmology, to be used in computing the halo proxy.
    """
    z_mpeak = (1.0-halos['mpeak_scale'])/halos['mpeak_scale']
    OmegaM_mpeak = density.omega_M_z(z_mpeak, **cosmology)
    Delta_vir = (18.0*np.pi**2+82*(OmegaM_mpeak-1.0)-39.0*(OmegaM_mpeak-1.0)**2)/OmegaM_mpeak
    rho_crit, rho_mean = density.cosmo_densities(**cosmology)*u.Msun/(u.Mpc**3)
    Rvir_mpeak = (3.0*halos['mpeak']*u.Msun/(4.0*np.pi*rho_crit*Delta_vir))**(1.0/3.0)
    vvir_mpeak = np.sqrt(const.G*halos['mpeak']*u.astrophys.solMass/Rvir_mpeak).to(u.km/u.s)
    return vvir_mpeak.value
Example #3
0
def calculate_rhoc_cosmopy(redshift=None, aexp=None,
                   cosmology=_get_cosmology()) :
    pass

    redshift = check_redshift_kwargs(redshift=redshift,aexp=aexp)

    H_z = cdist.hubble_z(redshift, **cosmology) # /s

    assert(3.*H_z**2/(8.*np.pi*constants.gravc) == \
               cdens.cosmo_densities(**cosmology)[0]*cdist.e_z(redshift,**cosmology)**2) 

    return 3.*H_z**2/(8.*np.pi*constants.gravc)
Example #4
0
def radius_to_mass(r, **cosmology):
    """The mass of a sphere of radius r in Mpc.

    Uses the mean density of the universe.

    """
    volume = (4. / 3.) * math.pi * r**3.

    if 'rho_0' in cosmology:
        rho_0 = cosmology['rho_0']
    else:
        rho_crit, rho_0 = cden.cosmo_densities(**cosmology)

    mass = volume * rho_0
    return mass
Example #5
0
    def __init__(self, zd=0.3, zs=2., h=0.7, mstar=1e11, mdme=1e11, beta=1., reff_phys=1., rs_phys=10., images=[], source=0., \
                 obs_images=None, obs_lmstar=None, obs_radmagrat=None, obs_timedelay=None, delta_halo=200.):

        self.zd = zd
        self.zs = zs
        self.h = h
        self.halo = None
        self.mstar = mstar
        self.mdme = mdme
        self.beta = beta
        self.rs_phys = rs_phys
        self.delta_halo = delta_halo
        self.reff_phys = reff_phys
        self.caustic = None
        self.radcrit = None
        self.source = source
        self.images = images
        self.timedelay = None
        self.grids = None
        self.radmag_ratio = None
        self.dyndic = None
        self.rein = None
        self.imA = None
        self.imB = None
        self.rvir = None
        self.rs = None
        self.gammap = None
        self.obs_lmstar = obs_lmstar
        self.obs_radmagrat = obs_radmagrat
        self.obs_images = obs_images
        self.obs_timedelay = obs_timedelay

        self.ds = distance.angular_diameter_distance(self.zs, **default_cosmo)
        self.dds = distance.angular_diameter_distance(self.zs, self.zd, **default_cosmo)
        self.dd = distance.angular_diameter_distance(self.zd, **default_cosmo)

        self.S_cr = cgs.c**2/(4.*np.pi*cgs.G)*self.ds*self.dd/self.dds*cgs.Mpc/cgs.M_Sun*cgs.arcsec2rad**2
        self.arcsec2kpc = cgs.arcsec2rad*self.dd*1000.
        self.reff = self.reff_phys/self.arcsec2kpc
        self.rs = self.rs_phys/self.arcsec2kpc
        self.Dt = self.dd*self.ds/self.dds*cgs.Mpc*(1. + self.zd)
        self.rhoc = density.cosmo_densities(**default_cosmo)[0]*distance.e_z(self.zd, **default_cosmo)**2
        self.xmin = 1.01*max(self.reff/50., 0.1*self.rs/50.)
        self.xmax = 0.99*min(10.*self.reff, 100.*self.rs/50.)
Example #6
0
    def __init__(self, zd=0.3, zs=2., h70=1.0, mstar=1e11, mhalo=1e13, reff_phys=1., ns=4., cvir=5., images=[], \
                 source=0., obs_images=None, obs_lmstar=None, obs_radmagrat=None, obs_timedelay=None, delta_halo=200.):

        self.zd = zd
        self.zs = zs
        self.h70 = h70
        self.bulge = None
        self.halo = None
        self.mstar = mstar
        self.mhalo = mhalo
        self.delta_halo = delta_halo
        self.reff_phys = reff_phys
        self.ns = ns
        self.caustic = None
        self.radcrit = None
        self.source = source
        self.images = images
        self.timedelay = None
        self.grids = None
        self.radmag_ratio = None
        self.dyndic = None
        self.rein = None
        self.imA = None
        self.imB = None
        self.rvir = None
        self.rs = None
        self.gammap = None
        self.obs_lmstar = obs_lmstar
        self.obs_radmagrat = obs_radmagrat
        self.obs_images = obs_images
        self.obs_timedelay = obs_timedelay

        self.ds = distance.angular_diameter_distance(self.zs, **default_cosmo)
        self.dds = distance.angular_diameter_distance(self.zs, self.zd, **default_cosmo)
        self.dd = distance.angular_diameter_distance(self.zd, **default_cosmo)

        self.S_cr = cgs.c**2/(4.*np.pi*cgs.G)*self.ds*self.dd/self.dds*cgs.Mpc/cgs.M_Sun*cgs.arcsec2rad**2
        self.arcsec2kpc = cgs.arcsec2rad*self.dd*1000.
        self.reff = self.reff_phys/self.arcsec2kpc
        self.cvir = cvir
        self.Dt = self.dd*self.ds/self.dds*cgs.Mpc/cgs.c*(1. + self.zd)/cgs.c
        self.rhoc = density.cosmo_densities(**default_cosmo)[0]*distance.e_z(self.zd, **default_cosmo)**2
Example #7
0
def m2R(m):
	rhobar = cd.cosmo_densities(**cosmo)[1]  #msun/Mpc
	RL = (3*m/4/n.pi/rhobar)**(1./3)
	return RL
Example #8
0
print opts, args

Om, sig8, ns, h, Ob = 0.315, 0.829, 0.96, 0.673, 0.0487
cosmo = {
    'baryonic_effects': True,
    'omega_k_0': 0,
    'omega_M_0': 0.315,
    'omega_b_0': 0.0487,
    'n': 0.96,
    'N_nu': 0,
    'omega_lambda_0': 0.685,
    'omega_n_0': 0.,
    'sigma_8': 0.829,
    'h': 0.673
}
rhobar = cd.cosmo_densities(**cosmo)[1]  #msun/Mpc


def m2R(m):
    RL = (3 * m / 4 / n.pi / rhobar)**(1. / 3)
    return RL


def m2V(m):
    return m / rhobar


def R2m(RL):
    m = 4 * n.pi / 3 * rhobar * RL**3
    return m
Example #9
0
# print opts, args

Om, sig8, ns, h, Ob = 0.315, 0.829, 0.96, 0.673, 0.0487
cosmo = {
    "baryonic_effects": True,
    "omega_k_0": 0,
    "omega_M_0": 0.315,
    "omega_b_0": 0.0487,
    "n": 0.96,
    "N_nu": 0,
    "omega_lambda_0": 0.685,
    "omega_n_0": 0.0,
    "sigma_8": 0.829,
    "h": 0.673,
}
rhobar = cd.cosmo_densities(**cosmo)[1]


def m2R(m):
    # msun/Mpc
    RL = (3 * m / 4 / n.pi / rhobar) ** (1.0 / 3)
    return RL


def m2V(m):
    return m / rhobar


def R2m(RL):
    m = 4 * n.pi / 3 * rhobar * RL ** 3
    return m
Example #10
0
from scipy.optimize import brenth, brentq
from joblib import Parallel, delayed
import multiprocessing
import profile
num_cores = multiprocessing.cpu_count()

o = optparse.OptionParser()
o.add_option('-d','--del0', dest='del0', default=5.)
o.add_option('-m','--mul', dest='mul', default=1.)
o.add_option('-z','--red', dest='red', default=12.)
opts,args = o.parse_args(sys.argv[1:])
print opts, args

Om,sig8,ns,h,Ob = 0.315, 0.829, 0.96, 0.673, 0.0487
cosmo = {'baryonic_effects':True,'omega_k_0':0,'omega_M_0':0.315, 'omega_b_0':0.0487, 'n':0.96, 'N_nu':0, 'omega_lambda_0':0.685,'omega_n_0':0., 'sigma_8':0.829,'h':0.673}
rhobar = cd.cosmo_densities(**cosmo)[1]  #msun/Mpc
def m2R(m):
	RL = (3*m/4/n.pi/rhobar)**(1./3)
	return RL
def m2V(m):
	return m/rhobar
def R2m(RL):
	m = 4*n.pi/3*rhobar*RL**3
	return m

dmS = n.load('sig0.npz')
MLtemp,SLtemp = dmS['arr_2'],dmS['arr_1']
print 'generating fs2m'
fs2m = interp1d(SLtemp,MLtemp)
print 'generated fs2m'
def S2M(S):
Example #11
0
def m2V(m):
    rhobar = cd.cosmo_densities(**cosmo)[1]  #msun/Mpc
    return m / rhobar
Example #12
0
def m2R(m):
    rhobar = cd.cosmo_densities(**cosmo)[1]  #msun/Mpc
    RL = (3 * m / 4 / n.pi / rhobar)**(1. / 3)
    return RL
Example #13
0
def calculate_rhom_cosmopy(redshift=None, aexp=None,
                   cosmology=_get_cosmology()) :
    pass
    redshift = check_redshift_kwargs(redshift=redshift,aexp=aexp)

    OmM_z = cdens.omega_M_z(redshift,**cosmology)

    assert( OmM_z*calculate_rhoc_cosmopy(redshift=redshift, aexp=aexp, **cosmology) == cdens.cosmo_densities(**cosmology[0])*(1-redshift)**3. )

    return OmM_z*calculate_rhoc_cosmopy(redshift=redshift, aexp=aexp, **cosmology) 
Example #14
0
from scipy.integrate import quad, tplquad
import itertools
from scipy.interpolate import interp1d
from scipy.interpolate import RectBivariateSpline as RBS
import optparse, sys
import gen_inter as GI
# o = optparse.OptionParser()
# o.add_option('-d','--del0', dest='del0', default=5.)
# o.add_option('-m','--mul', dest='mul', default=1.)
# o.add_option('-z','--red', dest='red', default=12.)
# opts,args = o.parse_args(sys.argv[1:])
# print opts, args

Om,sig8,ns,h,Ob = 0.315, 0.829, 0.96, 0.673, 0.0487
cosmo = {'baryonic_effects':True,'omega_k_0':0,'omega_M_0':0.315, 'omega_b_0':0.0487, 'n':0.96, 'N_nu':0, 'omega_lambda_0':0.685,'omega_n_0':0., 'sigma_8':0.829,'h':0.673}
rhobar = cd.cosmo_densities(**cosmo)[1]
def m2R(m):
	  #msun/Mpc
	RL = (3*m/4/n.pi/rhobar)**(1./3)
	return RL
def m2V(m):
	return m/rhobar

def R2m(RL):
	m = 4*n.pi/3*rhobar*RL**3
	return m
def mmin(z,Tvir=1.E4):
	return pb.virial_mass(Tvir,z,**cosmo)
m12 = mmin(12.)
r12 = m2R(m12)
Example #15
0
def m2V(m):
	rhobar = cd.cosmo_densities(**cosmo)[1]  #msun/Mpc
	return m/rhobar
Example #16
0
def R2m(RL):
    rhobar = cd.cosmo_densities(**cosmo)[1]  #msun/Mpc
    m = 4 * n.pi / 3 * rhobar * RL**3
    return m
Example #17
0
def R2m(RL):
	rhobar = cd.cosmo_densities(**cosmo)[1]  #msun/Mpc
	m = 4*n.pi/3*rhobar*RL**3
	return m
Example #18
0
cosmo = {
    'omega_M_0': omegaM,
    'omega_lambda_0': omegaL,
    'omega_k_0': 0.,
    'h': h
}

Nz = 1001
z_grid = np.linspace(0., 5., Nz)
logt_grid = 0. * z_grid
rhoc_grid = 0. * z_grid

for i in range(0, Nz):
    logt_grid[i] = np.log10(
        distance.lookback_time(z_grid[i], 0., **cosmo) / yr) - 9.
    rhoc_grid[i] = density.cosmo_densities(**cosmo)[0] * distance.e_z(
        z_grid[i], **cosmo) * M_Sun / Mpc**3

z_spline = splrep(logt_grid[1:], z_grid[1:])
logt_spline = splrep(z_grid[1:], logt_grid[1:])
rhoc_spline = splrep(z_grid[1:], rhoc_grid[1:])


def z_form_vdisp_func(lvdisp):
    return splev(0.46 + 0.238 * lvdisp, z_spline)


def z_form_mstar_func(lmstar):
    return splev(0.427 + 0.053 * lmstar, z_spline)