Python astropy.units 模块,kpc() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用astropy.units.kpc()

项目:specdb    作者:specdb    | 项目源码 | 文件源码
def test_meta_from_position(igmsp):
    # One match
    meta = igmsp.meta_from_position((0.0019,17.7737), 1*u.arcsec)
    assert len(meta) == 1
    # Blank
    meta2 = igmsp.meta_from_position((10.038604,55.298477), 1*u.arcsec)
    assert meta2 is None
    # Multiple sources (insure rank order)
    meta3 = igmsp.meta_from_position((0.0055,-1.5), 1*u.deg)
    assert len(meta3) == 2
    assert np.isclose(meta3['R'][0],meta3['R'][1])
    # Multiple meta entries (GGG)
    meta4 = igmsp.meta_from_position('001115.23+144601.8', 1*u.arcsec)
    assert len(meta4) == 2
    assert meta4['R'][0] != meta4['R'][1]
    # Multiple but grab closest source
    meta5 = igmsp.meta_from_position((0.0055,-1.5), 1*u.deg, max_match=1)
    assert len(meta5) == 1
    # Groups
    meta = igmsp.meta_from_position((2.813500,14.767200), 20*u.deg, groups=['GGG','HD-LLS_DR1'])
    for group in meta['GROUP'].data:
        assert group in ['GGG', 'HD-LLS_DR1']
    # Physical separation
    meta6 = igmsp.meta_from_position('001115.23+144601.8', 300*u.kpc)
    assert len(meta6) == 2
项目:MulensModel    作者:rpoleski    | 项目源码 | 文件源码
def test_a_proj_success():
    lens = Lens(mass_1=1.0*u.solMass,mass_2=0.1*u.solMass,a_proj=1.0*u.au,
                distance=6.*u.kpc)
    assert lens.total_mass == 1.1*u.solMass
    assert lens.q == 0.1
项目:MulensModel    作者:rpoleski    | 项目源码 | 文件源码
def distance(self):
        """
        *astropy.Quantity*

        The distance to the source. May be set as a *float*.
        The distance should either be given in pc, or if no unit is
        given, the value is assumed to be kpc (*u.kpc*).

        """
        return self._distance
项目:MulensModel    作者:rpoleski    | 项目源码 | 文件源码
def distance(self, new_distance):
        if new_distance is None:
            self._distance = new_distance
        else:
            if not isinstance(new_distance, u.Quantity):
                self._distance = new_distance * 1000. * u.pc
            else:
                if (new_distance.unit == "pc") or (new_distance.unit == "kpc"):
                    self._distance = new_distance
                else:
                    raise u.UnitsError(
                        'Allowed units for Source distance are "pc" or "kpc"')
项目:formulas    作者:jzuhone    | 项目源码 | 文件源码
def test_nfw_density():
    p = NFW_density_profile()
    r_s = 100*ytu.kpc
    rho_s = 1.0e8*ytu.Msun/ytu.kpc**3
    p.set_param_values(r_s=r_s, rho_s=rho_s)
    x = r_yt/r_s
    assert_allclose(p(r_yt).v, (rho_s/(x*(1.+x)**2)).v)
    assert str(p(r_yt).units) == str(rho_s.units)
项目:formulas    作者:jzuhone    | 项目源码 | 文件源码
def test_hernquist_density():
    p = hernquist_density_profile()
    a = 200.*ytu.kpc
    M_0 = 1.0e14*ytu.Msun
    p.set_param_values(a=a, M_0=M_0)
    x = r_yt/a
    assert_allclose(p(r_yt).v, (M_0/(2*np.pi*a**3)/(x*(1.+x)**3)).v)
    assert str(p(r_yt).units) == str((M_0/a**3).units)
项目:formulas    作者:jzuhone    | 项目源码 | 文件源码
def test_hernquist_mass():
    p = hernquist_mass_profile()
    a = 350.*apu.kpc
    M_0 = 1.0e15*apu.Msun
    p.set_param_values(a=a, M_0=M_0)
    assert_allclose(p(r_ap).to("solMass").value, (M_0*r_ap**2/(r_ap+a)**2).value)
项目:formulas    作者:jzuhone    | 项目源码 | 文件源码
def test_beta_model():
    p = beta_model_profile()
    r_c = 100.*apu.kpc
    rho_c = 1.0e-25*apu.g/apu.cm**3
    beta = 1.0
    p.set_param_values(r_c=r_c, rho_c=rho_c, beta=beta)
    assert_allclose(p(r_ap).value, (rho_c*(1.+(r_ap/r_c)**2)**(-1.5*beta)).value)
项目:formulas    作者:jzuhone    | 项目源码 | 文件源码
def test_AM06_temperature():
    p = AM06_temperature_profile()
    a_c = 60*ytu.kpc
    a = 600.*ytu.kpc
    c = 0.17
    T_0 = 10.*ytu.keV
    p.set_param_values(T_0=T_0, a_c=a_c, c=c, a=a)
    assert_allclose(p(r_yt).value, (T_0/(1.+r_yt/a)*(c+r_yt/a_c)/(1.+r_yt/a_c)).value)
    assert str(p(r_yt).units) == str(T_0.units)
项目:formulas    作者:jzuhone    | 项目源码 | 文件源码
def test_mass_rescaling_yt():
    M = 6.0e14*ytu.Msun
    R = 1500.0*ytu.kpc
    pm = NFW_mass_profile()
    pd = NFW_density_profile()
    pd.set_param_values(r_s=350*ytu.kpc, rho_s=1.0*ytu.Msun/ytu.kpc**3)
    rescale_profile_by_mass(pd, "rho_s", M, R)
    pm.set_param_values(**pd.param_values)
    assert_allclose(pm(R).in_units("Msun").v, M.v)
项目:formulas    作者:jzuhone    | 项目源码 | 文件源码
def test_mass_rescaling_astropy():
    M = 6.0e14*apu.Msun
    R = 1500.0*apu.kpc
    pm = NFW_mass_profile()
    pd = NFW_density_profile()
    pd.set_param_values(r_s=350*apu.kpc, rho_s=1.0*apu.Msun/apu.kpc**3)
    rescale_profile_by_mass(pd, "rho_s", M, R)
    pm.set_param_values(**pd.param_values)
    assert_allclose(pm(R).to("Msun").value, M.value)