Ejemplo n.º 1
0
def mean_field_rho_mean(snapshot, field, ret_rho_mean=False):
    '''
    Computes mean (volume and mass weighted) temperature at the mean density
    '''
    import numpy as np
    from seren3.cosmology import rho_mean_z
    from seren3.utils import approx_equal

    cosmo = snapshot.cosmo
    rho_mean = snapshot.array(rho_mean_z(cosmo["omega_b_0"], **cosmo),
                              "kg m**-3")

    field_list = []
    mass = []
    units = None

    for dset in snapshot.g[["rho", "mass", field]]:
        ix = np.where(approx_equal(rho_mean, dset['rho'], tol=None, rel=1e-5))
        if (len(ix[0]) > 0):
            if (units is None):
                units = str(dset[field].units)
            field_list.extend(dset[field][ix])
            mass.extend(dset["mass"][ix])

    mass = np.array(mass)
    field_list = np.array(field_list)
    mw = snapshot.array(np.sum(field_list * mass) / mass.sum(), units)

    if ret_rho_mean:
        return mw, rho_mean
    return mw
Ejemplo n.º 2
0
    def __init__(self, **cosmo):
        self.gammaF = 4 * math.pi / 3
        self.cosmo = cosmo

        omega0 = cosmo["omega_M_0"]
        rho_bar = SimArray(cosmology.rho_mean_z(omega0, **cosmo), "kg m**-3")
        self.rho_bar = rho_bar.in_units("Msol Mpc^-3")  # h^2 a^-3")
        self.rho_bar *= cosmo['h']**2 * cosmo['aexp']**3
        self.rho_bar.units = "Msol Mpc^-3 h^2 a^-3"
Ejemplo n.º 3
0
def dm_delta(context, dset, **kwargs):
    from seren3.cosmology import rho_mean_z
    
    rhoc = dm_rho(context, dset, **kwargs)

    cosmo = context.cosmo
    omega0 = cosmo['omega_M_0'] - cosmo['omega_b_0']

    rho_mean = rho_mean_z(omega0, **cosmo)

    delta = (rhoc - rho_mean) / rho_mean

    return delta
Ejemplo n.º 4
0
def deltab(sim):
    from seren3 import cosmology
    from seren3.array import SimArray

    omega_b_0 = 0.045
    cosmo = sim.properties.copy()
    cosmo["z"] = (1. / cosmo['a']) - 1.

    rho_mean = SimArray(cosmology.rho_mean_z(omega_b_0, **cosmo), "kg m**-3")
    rho = sim.g["rho"].in_units("kg m**-3")

    db = (rho - rho_mean) / rho_mean
    return db
Ejemplo n.º 5
0
    def deltac(self):
        '''
        Returns CDM overdensity field
        '''
        from seren3.cosmology import rho_mean_z

        cosmo = self.base.cosmo
        omega0 = cosmo['omega_M_0'] - cosmo['omega_b_0']

        rho_mean = rho_mean_z(omega0, **cosmo)

        rhoc = self.rhoc
        delta = (rhoc - rho_mean) / rho_mean

        return delta
Ejemplo n.º 6
0
def deltac_cic(context, rhoc=None):
    '''
    Returns CDM overdensity field
    '''
    from seren3.cosmology import rho_mean_z

    cosmo = context.cosmo  # get the cosmological context - this is a dictionary
    omega0 = cosmo['omega_M_0'] - cosmo['omega_b_0']  # CDM density param.

    rho_mean = rho_mean_z(omega0, **cosmo)  # mean (CDM) density at this redshift

    if (rhoc is None):
        rhoc = rhoc_cic(context)
    delta = (rhoc - rho_mean) / rho_mean  # the CDM overdensity

    return delta
Ejemplo n.º 7
0
    def rho_mean(self, species='baryon'):
        '''
        Mean density at current redshift of baryons or cdm
        '''
        from seren3.cosmology import rho_mean_z
        cosmo = self.base.cosmo
        omega_0 = 0.
        if (species == 'b') or (species == 'baryon'):
            omega_0 = cosmo['omega_b_0']
        elif (species == 'c') or (species == 'cdm'):
            omega_0 = cosmo['omega_M_0'] - cosmo['omega_b_0']
        else:
            raise Exception("Unknown species %s" % species)

        rho_mean = rho_mean_z(omega_0, **cosmo)
        return SimArray(rho_mean, "kg m**-3")
Ejemplo n.º 8
0
    def rho_mean(self, species):
        '''
        Compute mean density of given species at current redshift
        '''
        from seren3 import cosmology
        cosmo = self.header.cosmo
        cosmo["z"] = int(cosmo["z"])

        omega0 = 0.
        if ('b' == species) or ('baryons' == species):
            omega0 = cosmo['omega_b_0']
        elif ('c' == species) or ('cdm' == species):
            omega0 = cosmo['omega_M_0'] - cosmo['omega_b_0']
        elif ('tot' == species) or ('total' == species):
            omega0 = cosmo['omega_M_0']
        else:
            raise Exception("Unknown species: %s" % species)
        rho_mean = SimArray(cosmology.rho_mean_z(omega0, **cosmo), "kg m**-3")
        return rho_mean