예제 #1
0
 def test_concentration(self):
     m200 = 1e15
     c = 5.0
     z = 0.3
     nfw = NFW(m200, c, z)
     c500 = nfw.radius_Delta(500) / nfw.r_s
     assert_almost_equal(c500, [3.3051557218506047])
예제 #2
0
 def test_sigma(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     s = nfw.sigma(1.12)
     assert_almost_equal(s.value / 1e13, 8.419216818682797)
예제 #3
0
 def test_mess(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     m = nfw.mass(1.32)
     assert_almost_equal(m.value / 1e14, 7.6572975645639385)
예제 #4
0
 def test_sigma(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     s = nfw.sigma(1.12)
     assert_almost_equal(s.value / 1e13, 8.419216818682797)
예제 #5
0
 def test_mass_Delta(self):
     m200 = 1e15
     c = 5.0
     z = 0.3
     nfw = NFW(m200, c, z)
     m500 = nfw.mass_Delta(500)
     assert_almost_equal(m500.value / 1e14, 7.221140, 6)
예제 #6
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_sigma(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     s = nfw.sigma(1.12)
     assert_almost_equal(s.value / 1e13, 8.418908648577666)
예제 #7
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_mean_density(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     rho = nfw.mean_density(1.23)
     assert_almost_equal(rho.value / 1e13, 9.256897197704966)
예제 #8
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_mess(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     m = nfw.mass(1.32)
     assert_almost_equal(m.value / 1e14, 7.656709240756399)
예제 #9
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_mean_crit_consistency(self):
     m200b = 1e15
     c = 5
     z = 0.3
     nfw = NFW(m200b, c, z, overdensity_type='mean')
     m200c = nfw.mass_Delta(200, overdensity_type='critical').value
     assert_almost_equal(m200c / 1e15, 2.062054316492159)
예제 #10
0
 def test_mean_crit_consistency(self):
     m200b = 1e15
     c = 5
     z = 0.3
     nfw = NFW(m200b, c, z, overdensity_type="mean")
     m200c = nfw.mass_Delta(200, overdensity_type="critical").value
     assert_almost_equal(m200c / 1e15, 2.062054316492159)
예제 #11
0
 def test_mean_density(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     rho = nfw.mean_density(1.23)
     assert_almost_equal(rho.value / 1e13, 9.257628230844219)
예제 #12
0
 def test_density(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     rho = nfw.density(1.23)
     assert_almost_equal(rho.value / 1e13, 2.628799454816062)
예제 #13
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_density(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     rho = nfw.density(1.23)
     assert_almost_equal(rho.value / 1e13, 2.628686177054833)
예제 #14
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_mass_Delta(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     m500 = nfw.mass_Delta(500)
     assert_almost_equal(m500.value / 1e14, 7.221140, 6)
예제 #15
0
 def test_density(self):
     m200 = 1e15
     c = 5.0
     z = 0.3
     nfw = NFW(m200, c, z)
     rho = nfw.density(1.23)
     assert_almost_equal(rho.value / 1e13, 2.628686177054833)
예제 #16
0
 def test_mean_density(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     rho = nfw.mean_density(1.23)
     assert_almost_equal(rho.value / 1e13, 9.257628230844219)
예제 #17
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
    def test_cosmo_consistency(self):
        save_cosmo = astropy.cosmology.default_cosmology.get()
        m200 = 5e14
        c = 3.5
        z = 0.15
        # Halo 1 with variable cosmology
        nfw1 = NFW(m200, c, z)
        # Halo 2 with cosmology fixed to the current one
        nfw2 = NFW(m200, c, z, cosmology=save_cosmo)
        # Halo 3 with cosmology fixed to WMAP9
        wmap9 = astropy.cosmology.WMAP9
        nfw3 = NFW(m200, c, z, cosmology=wmap9)

        assert_almost_equal(
            nfw1.radius_Delta(200).value,
            nfw2.radius_Delta(200).value,
            err_msg="Disagreement after init with same cosmology")
        astropy.cosmology.default_cosmology.set(wmap9)
        try:
            assert_almost_equal(
                nfw1.radius_Delta(200).value,
                nfw3.radius_Delta(200).value,
                err_msg="Disagreement after changing cosmology")
        except:
            astropy.cosmology.default_cosmology.set(save_cosmo)
            raise
        astropy.cosmology.default_cosmology.set(save_cosmo)
예제 #18
0
 def test_mean_density(self):
     m200 = 1e15
     c = 5.0
     z = 0.3
     nfw = NFW(m200, c, z)
     rho = nfw.mean_density(1.23)
     assert_almost_equal(rho.value / 1e13, 9.256897197704966)
예제 #19
0
 def test_sigma(self):
     m200 = 1e15
     c = 5.0
     z = 0.3
     nfw = NFW(m200, c, z)
     s = nfw.sigma(1.12)
     assert_almost_equal(s.value / 1e13, 8.418908648577666)
예제 #20
0
 def test_mess(self):
     m200 = 1e15
     c = 5.0
     z = 0.3
     nfw = NFW(m200, c, z)
     m = nfw.mass(1.32)
     assert_almost_equal(m.value / 1e14, 7.656709240756399)
예제 #21
0
 def _mdelta_to_mdelta_via_m200(self, m_in, func, overdensity_in,
                                overdensity_out, z):
     m200 = mass_concentration.mdelta_to_m200(m_in, func, overdensity_in,
                                              (z, self._cosmo))
     nfw = NFW(m200, func(m200, z, self._cosmo), z)
     m_out = nfw.mass_Delta(overdensity_out)
     return m_out
예제 #22
0
 def test_delta_sigma(self):
     m200 = 1e15
     c = 5.0
     z = 0.3
     nfw = NFW(m200, c, z)
     ds = nfw.delta_sigma([0.1, 1.12])
     ref_arr = np.array([5.28752650, 1.38772723])
     assert_array_almost_equal(ds.value / 1e14, ref_arr)
예제 #23
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_delta_sigma(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     ds = nfw.delta_sigma([0.1, 1.12])
     ref_arr = np.array([5.28752650, 1.38772723])
     assert_array_almost_equal(ds.value / 1e14, ref_arr)
예제 #24
0
 def test_radius_mass_consistency(self):
     m200 = 1e15
     c = 5.0
     z = 0.3
     nfw = NFW(m200, c, z)
     r200 = nfw.radius_Delta(200)
     nfw2 = NFW(r200, c, z, size_type="radius")
     assert_almost_equal(nfw2.mass_Delta(200).value / 1e14, m200 / 1e14)
예제 #25
0
 def test_mass_consistency(self):
     m200 = 1e15
     c = 5.0
     z = 0.3
     nfw = NFW(m200, c, z)
     m500 = nfw.mass_Delta(500)
     c500 = nfw.radius_Delta(500) / nfw.r_s
     nfw2 = NFW(m500, c500, z, overdensity=500)
     assert_almost_equal(nfw2.mass_Delta(200).value / 1e14, m200 / 1e14)
예제 #26
0
 def test_m200_to_mdelta(self):
     m_in = u.Quantity(4e14, u.solMass)
     z = 0.45
     func = mass_concentration.duffy_concentration
     mdelta = mass_concentration.m200_to_mdelta(m_in, func, 500,
                                                (z, self._cosmo))
     nfw = NFW(m_in, func(m_in, z, self._cosmo), z)
     m500 = nfw.mass_Delta(500)
     assert_quantity_allclose(mdelta, m500)
예제 #27
0
 def test_mass_unit_consistency(self):
     m200 = 5e14
     c = 3
     z = 0.4
     nfw1 = NFW(m200, c, z)
     nfw2 = NFW(m200 * u.solMass, c, z)
     r1 = nfw1.radius_Delta(200)
     r2 = nfw2.radius_Delta(200)
     r1 = u.Quantity(r1, r2.unit)
     assert_almost_equal(r1.value, r2.value)
예제 #28
0
 def test_radius_Delta(self):
     m200 = 1e15
     c = 5.0
     z = 0.3
     nfw = NFW(m200, c, z)
     r200 = nfw.radius_Delta(200)
     assert_almost_equal(r200.value, 1.8624221298548365)
     r500 = nfw.radius_Delta(500)
     assert_almost_equal(r500.value, 1.231119031798481)
     r2500 = nfw.radius_Delta(2500)
     assert_almost_equal(r2500.value, 0.5520242539181)
예제 #29
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_var_cosmo_attr(self):
     m200 = 5e14
     c = 3.5
     z = 0.15
     nfw1 = NFW(m200, c, z)
     assert (nfw1.var_cosmology)
     nfw2 = NFW(m200,
                c,
                z,
                cosmology=astropy.cosmology.default_cosmology.get())
     assert (not nfw2.var_cosmology)
예제 #30
0
 def test_radius_Delta(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     r200 = nfw.radius_Delta(200)
     assert_almost_equal(r200.value, 1.8622494961043254)
     r500 = nfw.radius_Delta(500)
     assert_almost_equal(r500.value, 1.2310049155128235)
     r2500 = nfw.radius_Delta(2500)
     assert_almost_equal(r2500.value, 0.5519730850580377)
예제 #31
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_radius_Delta(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     r200 = nfw.radius_Delta(200)
     assert_almost_equal(r200.value, 1.8624221298548365)
     r500 = nfw.radius_Delta(500)
     assert_almost_equal(r500.value, 1.231119031798481)
     r2500 = nfw.radius_Delta(2500)
     assert_almost_equal(r2500.value, 0.5520242539181)
예제 #32
0
 def test_radius_Delta(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     r200 = nfw.radius_Delta(200)
     assert_almost_equal(r200.value, 1.8622494961043254)
     r500 = nfw.radius_Delta(500)
     assert_almost_equal(r500.value, 1.2310049155128235)
     r2500 = nfw.radius_Delta(2500)
     assert_almost_equal(r2500.value, 0.5519730850580377)
예제 #33
0
 def test_concentration(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     c500 = nfw.radius_Delta(500) / nfw.r_s
     assert_almost_equal(c500, [3.3051557218506047])
     c500c = nfw.concentration(500)
     assert_almost_equal(c500, c500c)
     c500m = nfw.concentration(500, "mean")
     assert_almost_equal(c500m, 4.592128764327895)
     assert_almost_equal(nfw.concentration(), 5)
예제 #34
0
 def test_projected_mass(self):
     m200 = 1e15
     c = 3
     z = 0.3
     nfw = NFW(m200, c, z)
     r = np.linspace(0.2, 3, 20) * u.Mpc
     m_proj = nfw.projected_mass(r) / 1e14
     # Comparison array was computed by numerical integration
     m_comp = np.array([1.16764258,  2.43852383,  3.73913358,  5.00209594,
                        6.20564153,  7.34451809,  8.41992698,  9.43555485,
                        10.39589583, 11.3055228 , 12.16877709, 12.98964993,
                        13.77175259, 14.51832709, 15.23227395, 15.91618585,
                        16.57238171, 17.20293864, 17.80972092, 18.39440572])
     assert_array_almost_equal(m_proj.value, m_comp)
예제 #35
0
 def test_projected_mass(self):
     m200 = 1e15
     c = 3
     z = 0.3
     nfw = NFW(m200, c, z)
     r = np.linspace(0.2, 3, 20) * u.Mpc
     m_proj = nfw.projected_mass(r) / 1e14
     # Comparison array was computed by numerical integration
     m_comp = np.array([
         1.16764258, 2.43852383, 3.73913358, 5.00209594, 6.20564153,
         7.34451809, 8.41992698, 9.43555485, 10.39589583, 11.3055228,
         12.16877709, 12.98964993, 13.77175259, 14.51832709, 15.23227395,
         15.91618585, 16.57238171, 17.20293864, 17.80972092, 18.39440572
     ])
     assert_array_almost_equal(m_proj.value, m_comp)
예제 #36
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_projected_mass(self):
     m200 = 1e15
     c = 3
     z = 0.3
     nfw = NFW(m200, c, z)
     r = np.linspace(0.2, 3, 20) * u.Mpc
     m_proj = nfw.projected_mass(r) / 1e14
     # Comparison array was computed by numerical integration
     m_comp = np.array([
         1.16749071e+14, 2.43823901e+14, 3.73873287e+14, 5.00159715e+14,
         6.20505986e+14, 7.34386597e+14, 8.41921446e+14, 9.43479009e+14,
         1.03950855e+15, 1.13046724e+15, 1.21678913e+15, 1.29887325e+15,
         1.37708069e+15, 1.45173558e+15, 1.52312796e+15, 1.59151704e+15,
         1.65713471e+15, 1.72018864e+15, 1.78086525e+15, 1.83933223e+15
     ]) / 1e14
     assert_array_almost_equal(m_proj.value, m_comp)
예제 #37
0
 def test_mdelta_to_m200(self):
     m_in = u.Quantity(2e14, u.solMass)
     z = 0.2
     func = mass_concentration.duffy_concentration
     delta_in = 450
     # consistency with mdelta_to_mdelta
     md1 = mass_concentration.mdelta_to_m200(m_in, func, delta_in,
                                             (z, self._cosmo))
     md2 = mass_concentration.mdelta_to_mdelta(m_in, func,
                                               delta_in, 200,
                                               (z, self._cosmo))
     assert_quantity_allclose(md1, md2)
     # consistency with mass_Delta in NFW
     nfw = NFW(md1, func(md1, z, self._cosmo), z)
     m_out = nfw.mass_Delta(450)
     assert_quantity_allclose(m_in, m_out)
예제 #38
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_mass_init(self):
     m200 = 1e15 * u.solMass
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     assert_equal(nfw.c, c)
     assert_equal(nfw.z, z)
     assert_almost_equal(nfw.r_s.value, 0.3724844259709579)
예제 #39
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_radius_unit_consistency(self):
     r200 = 1.5
     c = 4
     z = 0.2
     nfw1 = NFW(r200, c, z, size_type='radius')
     nfw2 = NFW(r200 * u.Mpc, c, z, size_type='radius')
     nfw3 = NFW(r200 * 1000 * u.kiloparsec, c, z, size_type='radius')
     m200_1 = nfw1.mass_Delta(200)
     m200_2 = nfw2.mass_Delta(200)
     m200_3 = nfw3.mass_Delta(200)
     m200_1 = u.Quantity(m200_1, m200_3.unit)
     m200_2 = u.Quantity(m200_2, m200_3.unit)
     assert_almost_equal(m200_1.value, m200_2.value)
     assert_almost_equal(m200_1.value, m200_3.value)
예제 #40
0
    def test_cosmo_consistency(self):
        save_cosmo = astropy.cosmology.default_cosmology.get()
        m200 = 5e14
        c = 3.5
        z = 0.15
        # Halo 1 with variable cosmology
        nfw1 = NFW(m200, c, z)
        # Halo 2 with cosmology fixed to the current one
        nfw2 = NFW(m200, c, z, cosmology=save_cosmo)
        # Halo 3 with cosmology fixed to WMAP9
        wmap9 = astropy.cosmology.WMAP9
        nfw3 = NFW(m200, c, z, cosmology=wmap9)

        assert_almost_equal(
            nfw1.radius_Delta(200).value,
            nfw2.radius_Delta(200).value,
            err_msg="Disagreement after init with same cosmology",
        )
        astropy.cosmology.default_cosmology.set(wmap9)
        try:
            assert_almost_equal(
                nfw1.radius_Delta(200).value,
                nfw3.radius_Delta(200).value,
                err_msg="Disagreement after changing cosmology",
            )
        except:
            astropy.cosmology.default_cosmology.set(save_cosmo)
            raise
        astropy.cosmology.default_cosmology.set(save_cosmo)
예제 #41
0
 def test_var_cosmo_obj(self):
     wmap9 = astropy.cosmology.WMAP9
     save_cosmo = astropy.cosmology.default_cosmology.get()
     m200 = 5e14
     c = 3.5
     z = 0.15
     nfw = NFW(m200, c, z)
     assert nfw.cosmology is save_cosmo
     astropy.cosmology.default_cosmology.set(wmap9)
     try:
         assert nfw.cosmology is wmap9
     except:
         astropy.cosmology.default_cosmology.set(save_cosmo)
         raise
     # Ensure that accessing the cosmology property also updates
     # the other properties.
     assert_almost_equal(nfw.radius_Delta(325).value, 1.2525923457595705)
     astropy.cosmology.default_cosmology.set(save_cosmo)
예제 #42
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_mass_consistency(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     m500 = nfw.mass_Delta(500)
     c500 = nfw.radius_Delta(500) / nfw.r_s
     nfw2 = NFW(m500, c500, z, overdensity=500)
     assert_almost_equal(nfw2.mass_Delta(200).value / 1e14, m200 / 1e14)
예제 #43
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_radius_mass_consistency(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     r200 = nfw.radius_Delta(200)
     nfw2 = NFW(r200, c, z, size_type="radius")
     assert_almost_equal(nfw2.mass_Delta(200).value / 1e14, m200 / 1e14)
예제 #44
0
 def test_var_cosmo_obj(self):
     wmap9 = astropy.cosmology.WMAP9
     save_cosmo = astropy.cosmology.default_cosmology.get()
     m200 = 5e14
     c = 3.5
     z = 0.15
     nfw = NFW(m200, c, z)
     assert(nfw.cosmology is save_cosmo)
     astropy.cosmology.default_cosmology.set(wmap9)
     try:
         assert(nfw.cosmology is wmap9)
     except:
         astropy.cosmology.default_cosmology.set(save_cosmo)
         raise
     # Ensure that accessing the cosmology property also updates
     # the other properties.
     assert_almost_equal(nfw.radius_Delta(325).value, 1.2524762382195782)
     # Now test that the r_s property correctly handels the update
     astropy.cosmology.default_cosmology.set(save_cosmo)
     assert_almost_equal(nfw.r_s.value, 0.44568171135722084)
     # And change the cosmology again to make sure that r_Delta handles
     # the update correctly
     astropy.cosmology.default_cosmology.set(wmap9)
     assert_almost_equal(nfw.r_Delta.value, 1.5732366512813496)
예제 #45
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_var_cosmo_obj(self):
     wmap9 = astropy.cosmology.WMAP9
     save_cosmo = astropy.cosmology.default_cosmology.get()
     m200 = 5e14
     c = 3.5
     z = 0.15
     nfw = NFW(m200, c, z)
     assert (nfw.cosmology is save_cosmo)
     astropy.cosmology.default_cosmology.set(wmap9)
     try:
         assert (nfw.cosmology is wmap9)
     except:
         astropy.cosmology.default_cosmology.set(save_cosmo)
         raise
     # Ensure that accessing the cosmology property also updates
     # the other properties.
     assert_almost_equal(nfw.radius_Delta(325).value, 1.2525923457595705)
     # Now test that the r_s property correctly handels the update
     astropy.cosmology.default_cosmology.set(save_cosmo)
     assert_almost_equal(nfw.r_s.value, 0.4457230268230224)
     # And change the cosmology again to make sure that r_Delta handles
     # the update correctly
     astropy.cosmology.default_cosmology.set(wmap9)
     assert_almost_equal(nfw.r_Delta.value, 1.573382494078073)
예제 #46
0
 def test_projected_mass(self):
     m200 = 1e15
     c = 3
     z = 0.3
     nfw = NFW(m200, c, z)
     r = np.linspace(0.2, 3, 20) * u.Mpc
     m_proj = nfw.projected_mass(r) / 1e14
     # Comparison array was computed by numerical integration
     m_comp = (
         np.array(
             [
                 1.16749071e14,
                 2.43823901e14,
                 3.73873287e14,
                 5.00159715e14,
                 6.20505986e14,
                 7.34386597e14,
                 8.41921446e14,
                 9.43479009e14,
                 1.03950855e15,
                 1.13046724e15,
                 1.21678913e15,
                 1.29887325e15,
                 1.37708069e15,
                 1.45173558e15,
                 1.52312796e15,
                 1.59151704e15,
                 1.65713471e15,
                 1.72018864e15,
                 1.78086525e15,
                 1.83933223e15,
             ]
         )
         / 1e14
     )
     assert_array_almost_equal(m_proj.value, m_comp)
예제 #47
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_mass_unit_consistency(self):
     m200 = 5e14
     c = 3
     z = 0.4
     nfw1 = NFW(m200, c, z)
     nfw2 = NFW(m200 * u.solMass, c, z)
     r1 = nfw1.radius_Delta(200)
     r2 = nfw2.radius_Delta(200)
     r1 = u.Quantity(r1, r2.unit)
     assert_almost_equal(r1.value, r2.value)
예제 #48
0
    def test_mdelta_to_mdelta(self):
        func = mass_concentration.duffy_concentration
        # Consistency
        z = 0.3
        m_in = u.Quantity(5e14, u.solMass)
        mdelta = mass_concentration.mdelta_to_mdelta(5e14, func, 500, 200,
                                                     (z, self._cosmo))
        c = func(mdelta, z, self._cosmo)
        nfw = NFW(mdelta, c, z)
        m_out = nfw.mass_Delta(500)
        assert_quantity_allclose(m_in, m_out)

        mdelta1 = mass_concentration.mdelta_to_mdelta(m_in, func, 200, 500,
                                                      (z, self._cosmo))
        nfw = NFW(m_in, func(m_in, z, self._cosmo), z)
        mdelta2 = nfw.mass_Delta(500)
        assert_quantity_allclose(mdelta1, mdelta2)
        # common cases:
        m_in = u.Quantity(1e14, u.solMass)
        z = 0
        mdelta1 = mass_concentration.mdelta_to_mdelta(m_in, func, 2500, 500,
                                                      (z, self._cosmo))
        mdelta2 = self._mdelta_to_mdelta_via_m200(m_in, func, 2500, 500, z)
        assert_quantity_allclose(mdelta1, mdelta2)

        # Test some extreme cases
        # first almost equal input and output overdensities
        m_in = u.Quantity(1e14, u.solMass)
        z = 1
        m200 = mass_concentration.mdelta_to_mdelta(m_in, func, 199, 200,
                                                   (z, self._cosmo))
        m_out = mass_concentration.mdelta_to_mdelta(m200, func, 200, 199,
                                                    (z, self._cosmo))
        assert_quantity_allclose(m_in, m_out)

        # identical input/output overdensity
        mdelta = mass_concentration.mdelta_to_mdelta(1e14, func, 200, 200,
                                                     (1, self._cosmo))
        assert_equal(mdelta.value, 1e14)

        # Large overdensity_in, small overdensity_out
        m_in = 1e15
        z = 0
        mdelta1 = mass_concentration.mdelta_to_mdelta(m_in, func, 2500, 50,
                                                      (z, self._cosmo))
        mdelta2 = self._mdelta_to_mdelta_via_m200(m_in, func, 2500, 50, z)
        assert_quantity_allclose(mdelta1, mdelta2)

        # Small overdensity_in, large overdensity_out, small halo mass
        m_in = 1e9
        z = 1
        mdelta1 = mass_concentration.mdelta_to_mdelta(m_in, func, 50, 2500,
                                                      (z, self._cosmo))
        mdelta2 = self._mdelta_to_mdelta_via_m200(m_in, func, 50, 2500, z)
        assert_quantity_allclose(mdelta1, mdelta2)
예제 #49
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_concentration(self):
     m200 = 1e15
     c = 5.
     z = 0.3
     nfw = NFW(m200, c, z)
     c500 = nfw.radius_Delta(500) / nfw.r_s
     assert_almost_equal(c500, [3.3051557218506047])
     c500c = nfw.concentration(500)
     assert_almost_equal(c500, c500c)
     c500m = nfw.concentration(500, "mean")
     assert_almost_equal(c500m, 4.592128764327895)
     assert_almost_equal(nfw.concentration(), 5)
예제 #50
0
 def test_radius_unit_consistency(self):
     r200 = 1.5
     c = 4
     z = 0.2
     nfw1 = NFW(r200, c, z, size_type="radius")
     nfw2 = NFW(r200 * u.Mpc, c, z, size_type="radius")
     nfw3 = NFW(r200 * 1000 * u.kiloparsec, c, z, size_type="radius")
     m200_1 = nfw1.mass_Delta(200)
     m200_2 = nfw2.mass_Delta(200)
     m200_3 = nfw3.mass_Delta(200)
     m200_1 = u.Quantity(m200_1, m200_3.unit)
     m200_2 = u.Quantity(m200_2, m200_3.unit)
     assert_almost_equal(m200_1.value, m200_2.value)
     assert_almost_equal(m200_1.value, m200_3.value)
예제 #51
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_overdensity_init(self):
     nfw = NFW(1e15, 4, 0.3, overdensity=500, overdensity_type="mean")
     assert_equal(nfw.overdensity, 500)
     assert (nfw.overdensity_type == "mean")
예제 #52
0
def DStheo(theta, args):
    """
    Computes de theoretical :math:`\Delta\Sigma_{NFW}` profile for a given mass
    :math:`m_{200}`, z and cosmology.

    Parameters
    ----------
    theta: tuple
        Parameters for the mcmc
    args: dict
        Contains the cosmology and other mean values computed from the data

    Returns
    -------
    ds: np.array
        The thoretical :math:`\Delta\Sigma_{NFW}` profile

    Notes
    -----
    The parameters for the NFW function are the mass :math:`m_{200}` and the
    concentration :math:`c_{200}`. However, in this anlysis, we use the
    Duffy et al. (2008) concetration-mass relation to get the profile only
    as a function of the mass. See: https://github.com/joergdietrich/NFW for
    more details on the NFW function.
    """
    runtype = args['runtype']
    runconfig = args['runconfig']

    if runtype == 'data':
        if runconfig == 'Full':
            m200, pcc, Am, B0, Rs = theta  #M200c [Msun]
        elif runconfig == 'OnlyM':
            m200 = theta[0]
        elif runconfig == 'FixAm':
            m200, pcc, B0, Rs = theta
    elif runtype == 'cal':
        m200 = theta[0]
    elif runtype == 'calsys':
        if runconfig == 'Full':
            m200, pcc, Am, B0, Rs = theta  #M200c [Msun]

    h = args['h']
    z_mean = args['z_mean']
    R = args['R']  #in physical [Mpc]
    cosmo = args['cosmo']  #astropy cosmology object
    cmodel = args[
        'cmodel']  #diemer18 (obs.: lastest version of Colossus renamed to diemer19)
    twohalo = args['twohalo']
    factor2h = args['factor2h']  #boolean, if True multiply 2-halo term by h
    cosmodict = args['cosmodict']
    omega_m = cosmodict['om']
    sigma_crit_inv = args['Sigma_crit_inv']

    #Setting up the cosmology for Colossus
    params = {
        'flat': True,
        'H0': cosmodict['h'] * 100.,
        'Om0': cosmodict['om'],
        'Ob0': cosmodict['ob'],
        'sigma8': cosmodict['sigma8'],
        'ns': cosmodict['ns']
    }
    cosmology.addCosmology('myCosmo', params)
    cosmoc = cosmology.setCosmology('myCosmo')
    cmodel = cmodel

    c200c = concentration.concentration(
        m200 * h, '200c', z_mean, model=cmodel,
        conversion_profile='nfw')  #m200c_in is [Msun/h], m200c_out is [Msun/h]
    nfw = NFW(m200,
              c200c,
              z_mean,
              cosmology=cosmo,
              overdensity_type='critical')  #input mass should be in [Msun]

    #For DeltaSigma calculation, data and sim, the radius has to be in physical [Mpc]
    if runtype == 'cal':
        ds = (nfw.delta_sigma(R).value
              ) / 1.e12  #DeltaSigma is in units of physical [M_sun/Mpc^2]
        #This two-halo part was not used in the analysis, the compuation is too slow
        if twohalo:
            #Adding the 2-halo term
            b = bias.haloBias(m200 * h, z_mean, '200c',
                              model='tinker10')  #mass_in is [Msun/h]
            outer_term_xi = profile_outer.OuterTermCorrelationFunction(
                z=z_mean, bias=b)
            p_nfw = profile_nfw.NFWProfile(
                M=m200 * h,
                c=c200c,
                z=z_mean,
                mdef='200c',
                outer_terms=[outer_term_xi])  #mass_in is [Msun/h]

            #Radius in physical kpc/h
            two_nfw0 = p_nfw.deltaSigmaOuter((R * 1e3) * h,
                                             interpolate=True,
                                             interpolate_surface_density=False,
                                             min_r_interpolate=1.e-6 * h,
                                             max_r_integrate=2.e5 * h,
                                             max_r_interpolate=2.e5 * h)
            two_nfw1 = two_nfw0 / 1.e6  #in physical [h Msun/pc^2]

            if factor2h:
                two_nfw = h * (two_nfw1 * h
                               )  #something like physical [Msun/(h pc^2)]
            else:
                two_nfw = (
                    two_nfw1 * h
                )  #in physical [Msun/pc^2] #This should be the right one

            ds_model = ds + two_nfw  #NFW + 2-halo in physical [Msun/pc^2] if factor2h=False
        else:
            ds_model = ds
        return ds_model  #physical [M_sun/pc^2]

    if runtype == 'data' or runtype == 'calsys':

        ds = (
            nfw.delta_sigma(R).value
        ) / 1.e12  #units of h Msun/pc^2 physical (but h=1, so actually is M_sun/pc^2)
        sigma = (nfw.sigma(R).value) / 1.e12

        # Computing miscetering correction from data
        m200p = m200
        z = np.array([z_mean])

        if runtype == 'data':
            cluster = ClusterEnsemble(z,
                                      cosmology=FlatLambdaCDM(H0=100, Om0=0.3),
                                      cm='Diemer18',
                                      cmval=c200c)
            misc_off = 0.1326  #here in [Mpc], since h=1

        elif runtype == 'calsys':
            cluster = ClusterEnsemble(z,
                                      cosmology=FlatLambdaCDM(H0=h * 100,
                                                              Om0=omega_m),
                                      cm='Diemer18',
                                      cmval=c200c)
            misc_off = 0.1326 / h  #input needs to be in units of [Mpc]

        if np.shape(m200p) == (1, 1):
            m200p = np.reshape(m200p, (1, ))
        try:
            cluster.m200 = m200p  #M200c [Msun]
        except TypeError:
            cluster.m200 = np.array([m200p])

        rbins = R  # in physical [Mpc]

        offsets = np.ones(cluster.z.shape[0]) * misc_off
        cluster.calc_nfw(rbins, offsets=offsets)  #NFW with offset

        dsigma_offset = cluster.deltasigma_nfw.mean(
            axis=0)  #physical [M_sun/pc^2], but if h=1 is [h M_sun/pc**2]
        DSmisc = dsigma_offset.value  #physical [Msun/pc^2]

        sigma_offset = cluster.sigma_nfw.mean(
            axis=0)  #physical [M_sun/pc**2], but if h=1 is [h M_sun/pc**2]
        Smisc = sigma_offset.value  #physical [Msun/pc^2]

        if runconfig == 'OnlyM':
            pcc = 0.75
            B0 = 0.50
            Rs = 2.00

        #The final model
        full_Sigma = pcc * sigma + (1 - pcc) * Smisc

        full_model = pcc * ds + (1 - pcc) * DSmisc

        if runconfig == 'Full':
            full_model *= Am  #shear+photo-z bias correction
        elif runconfig == 'OnlyM' or 'FixAm':
            full_model = full_model

        #Note: R (rbins) and Rs are in physical [Mpc], need to be comoving [Mpc/h]
        boost_model = ct.boostfactors.boost_nfw_at_R(rbins * h * (1 + z_mean),
                                                     B0, Rs * h * (1 + z_mean))

        full_model /= boost_model  #boost-factor

        full_model /= (1 - full_Sigma * sigma_crit_inv)  #Reduced shear

        return full_model  # in physical [M_sun/pc^2]
예제 #53
0
 def test_mass_init_bckg(self):
     m200 = 1e15
     c = 5
     z = 0.2
     nfw = NFW(m200, c, z, overdensity_type='mean')
     assert_almost_equal(nfw.radius_Delta(200).value, 3.708462946948883)
def get_delta_sigma(m200, c200, zl, r):
    nfw = NFW(m200, c200, zl)
    return nfw.delta_sigma(r)
예제 #55
0
 def test_mass_init_bckg(self):
     m200 = 1e15
     c = 5
     z = 0.2
     nfw = NFW(m200, c, z, overdensity_type="mean")
     assert_almost_equal(nfw.radius_Delta(200).value, 3.708806727880765)
예제 #56
0
파일: test_nfw.py 프로젝트: Python3pkg/NFW
 def test_mass_init_bckg(self):
     m200 = 1e15
     c = 5
     z = 0.2
     nfw = NFW(m200, c, z, overdensity_type='mean')
     assert_almost_equal(nfw.radius_Delta(200).value, 3.708806727880765)