Пример #1
0
def P(f):
    """
    Pressure
    """
    pres = f['rho'] * f['cs']**2
    if 'dustFrac' in f.all_keys():
        pres *= (1 - f['dustFrac'])
    pres_unit = sutil.get_snap_unit(f, 'pres_unit')
    return pres.in_units(pres_unit)
Пример #2
0
def u_smoothlength(f):
    """
    Returns the auxilliary array of the same name (excluding the 'u_' prefix)
    with units inferred from the runtime parameters.
    """
    array_name = 'smoothlength'

    if not pynbody.units.has_units(f[array_name]):
        # Infer units
        units = sutil.get_snap_unit(f, 'l_unit')
        f[array_name].units = units
    return f[array_name]
Пример #3
0
def cs(f):
    """
    Sound speed
    """
    if sutil.is_isothermal(f):
        gamma = 1.
    else:
        gamma = sutil.get_snap_gamma(f)
    m = sutil.get_snap_mu(f)
    v_unit = sutil.get_snap_unit(f, 'v_unit')
    c = np.sqrt(kB * f['temp'] * gamma / m).in_units(v_unit)
    return c
Пример #4
0
def u_dustVel(f):
    """
    Returns the auxilliary array of the same name (excluding the 'u_' prefix)
    with units inferred from the runtime parameters.
    """
    array_name = 'dustVel'

    if not pynbody.units.has_units(f[array_name]):
        # Infer units
        units = sutil.get_snap_unit(f, 'v_unit')
        f[array_name].units = units

    # This is a necessary check -- currently the master branch of pynbody
    # cannot load 3D arrays.  This has been implemented on branch issue-379
    # of ibackus' fork, but the pull request has not been merged
    if (np.ndim(f[array_name]) != 2) or (f[array_name].shape[1] != 3):
        raise RuntimeError, "dustVel is a 3D array but was not read as one."\
        "  This is problem with pynbody"
    return f[array_name]
Пример #5
0
def u_dustGrainSize(f):
    """
    Returns the dust grain size with units for onefluid dust.
    
    If grain growth is not on, i.e. if there is not a variable dust size,
    the dust size is found in the snapshot param
    
    If grain growth is turned on, i.e. if there is a variable grain size,
    the 'dustGrainSize' is returned with proper units.
    """
    l_unit = sutil.get_snap_unit(f, 'l_unit')
    try:
        if not pynbody.units.has_units(f['dustGrainSize']):
            f['dustGrainSize'].units = l_unit
        grainSize = f['dustGrainSize']
    except KeyError:
        grainSize = sutil.get_snap_param(f, 'dDustSize')
        grainSize = SimArray(grainSize * np.ones(len(f)), l_unit)
    return grainSize
Пример #6
0
def roche_rho(f):
    r"""
    Roche density
    
    .. math::
        \rho_{roche} \equiv M_{star}/r^3
    
    where :math:`r` is the distance to the center of mass of the star(s).  The
    total star mass is used.
    """
    parent = sutil.get_parent_snap(f)
    if parent != f:
        warnings.warn("Accessing stars from parent snapshot")

    star_mass = parent.s['mass'].sum()
    star_pos = pynbody.analysis.halo.center_of_mass(parent.s)
    r_star = np.sqrt(((f['pos'] - star_pos)**2).sum(1))
    rho = 16. * star_mass / r_star**3
    rho_unit = sutil.get_snap_unit(parent, 'rho_unit')
    return rho.in_units(rho_unit)