Пример #1
0
class TestHernquistEllipseCSE(object):
    """
    tests the Gaussian methods
    """
    def setup(self):
        self.hernquist = Hernquist()
        self.hernquist_cse = HernquistEllipseCSE()

    def test_function(self):
        x = np.linspace(0.01, 2, 10)
        y = np.zeros_like(x)
        kwargs = {'sigma0': 2, 'Rs': 2, 'center_x': 0, 'center_y': 0}

        f_nfw = self.hernquist.function(x, y, **kwargs)
        f_cse = self.hernquist_cse.function(x, y, e1=0, e2=0, **kwargs)
        npt.assert_almost_equal(f_cse / f_nfw, 1, decimal=5)

    def test_derivatives(self):
        x = np.linspace(0.01, 2, 10)
        y = np.zeros_like(x)
        kwargs = {'sigma0': 0.5, 'Rs': 2, 'center_x': 0, 'center_y': 0}

        f_x_nfw, f_y_nfw = self.hernquist.derivatives(x, y, **kwargs)
        f_x_cse, f_y_cse = self.hernquist_cse.derivatives(x, y, e1=0, e2=0, **kwargs)
        npt.assert_almost_equal(f_x_cse, f_x_nfw, decimal=5)
        npt.assert_almost_equal(f_y_cse, f_y_nfw, decimal=5)

    def test_hessian(self):
        x = np.linspace(0.01, 5, 30)
        y = np.zeros_like(x)
        kwargs = {'sigma0': 0.5, 'Rs': 2, 'center_x': 0, 'center_y': 0}

        f_xx_nfw, f_xy_nfw, f_yx_nfw, f_yy_nfw = self.hernquist.hessian(x, y, **kwargs)
        f_xx_cse, f_xy_cse, f_yx_cse, f_yy_cse = self.hernquist_cse.hessian(x, y, e1=0, e2=0, **kwargs)
        npt.assert_almost_equal(f_xx_cse / f_xx_nfw, 1, decimal=2)
        npt.assert_almost_equal(f_xy_cse, f_xy_nfw, decimal=5)
        npt.assert_almost_equal(f_yx_cse, f_yx_nfw, decimal=5)
        npt.assert_almost_equal(f_yy_cse, f_yy_nfw, decimal=5)

    def test_mass_3d_lens(self):
        R = 1
        Rs = 3
        alpha_Rs = 1
        m_3d_nfw = self.hernquist.mass_3d_lens(R, Rs, alpha_Rs)
        m_3d_cse = self.hernquist_cse.mass_3d_lens(R, Rs, alpha_Rs)
        npt.assert_almost_equal(m_3d_nfw, m_3d_cse, decimal=8)
Пример #2
0
class TestHernquist(object):
    def setup(self):
        self.profile = Hernquist()

    def test_function(self):
        x = np.array([1])
        y = np.array([2])
        Rs = 1.
        sigma0 = 0.5
        values = self.profile.function(x, y, sigma0, Rs)
        npt.assert_almost_equal(values[0], 0.66514613455415028, decimal=8)
        x = np.array([0])
        y = np.array([0])
        Rs = 1.
        sigma0 = 0.5
        values = self.profile.function(x, y, sigma0, Rs)
        npt.assert_almost_equal(values[0], 0, decimal=6)

        x = np.array([2, 3, 4])
        y = np.array([1, 1, 1])
        values = self.profile.function(x, y, sigma0, Rs)
        npt.assert_almost_equal(values[0], 0.66514613455415028, decimal=8)
        npt.assert_almost_equal(values[1], 0.87449395673649566, decimal=8)
        npt.assert_almost_equal(values[2], 1.0549139073851708, decimal=8)

    def test_derivatives(self):
        x = 1
        y = 2
        Rs = 1.
        sigma0 = 0.5
        f_x, f_y = self.profile.derivatives(x, y, sigma0, Rs)
        npt.assert_almost_equal(f_x, 0.11160641027573866, decimal=8)
        npt.assert_almost_equal(f_y, 0.22321282055147731, decimal=8)
        x = np.array([0])
        y = np.array([0])
        f_x, f_y = self.profile.derivatives(x, y, sigma0, Rs)
        npt.assert_almost_equal(f_x, 0, decimal=8)
        npt.assert_almost_equal(f_y, 0, decimal=8)

    def test_hessian(self):
        x = np.array([1])
        y = np.array([2])
        Rs = 1.
        sigma0 = 0.5
        f_xx, f_xy, f_yx, f_yy = self.profile.hessian(x, y, sigma0, Rs)
        npt.assert_almost_equal(f_xx[0], 0.0779016004481825, decimal=6)
        npt.assert_almost_equal(f_yy[0], -0.023212809452388683, decimal=6)
        npt.assert_almost_equal(f_xy[0], -0.0674096084507525, decimal=6)
        npt.assert_almost_equal(f_xy, f_yx, decimal=8)

    def test_mass_tot(self):
        rho0 = 1
        Rs = 3
        m_tot = self.profile.mass_tot(rho0, Rs)
        npt.assert_almost_equal(m_tot, 169.64600329384882, decimal=6)

    def test_grav_pot(self):
        x, y = 1, 0
        rho0 = 1
        Rs = 3
        grav_pot = self.profile.grav_pot(x,
                                         y,
                                         rho0,
                                         Rs,
                                         center_x=0,
                                         center_y=0)
        npt.assert_almost_equal(grav_pot, 42.411500823462205, decimal=8)

    def test_sigma0_definition(self):
        Rs = 2.
        sigma0 = 0.5
        f_x, f_y = self.profile.derivatives(Rs, 0, sigma0, Rs)
        alpha = f_x
        npt.assert_almost_equal(alpha, 2 / 3. * sigma0 * Rs, decimal=5)