def test_PJaffa_density_deflection(self):
        """
        tests whether the unit conversion between the lensing parameter 'sigma0' and the units in the density profile are ok
        :return:
        """

        from lenstronomy.LensModel.Profiles.p_jaffe import PJaffe as Model
        lensModel = Model()
        sigma0 = 1.
        Ra = 0.2
        Rs = 2.
        rho0 = lensModel.sigma2rho(sigma0, Ra, Rs)
        kwargs_lens = {
            'sigma0': sigma0,
            'Ra': Ra,
            'Rs': Rs,
            'center_x': 0,
            'center_y': 0
        }
        kwargs_density = {'rho0': rho0, 'Ra': Ra, 'Rs': Rs}
        r = 1.
        mass_2d = lensModel.mass_2d(r, **kwargs_density)
        alpha_mass = mass_2d / r
        alpha_r, _ = lensModel.derivatives(r, 0, **kwargs_lens)
        npt.assert_almost_equal(alpha_mass / np.pi, alpha_r, decimal=5)
    def test_sie_density_deflection(self):
        """
        tests whether the unit conversion between the lensing parameter 'sigma0' and the units in the density profile are ok
        :return:
        """

        from lenstronomy.LensModel.Profiles.sie import SIE as Model
        lensModel = Model()
        theta_E = 1.
        rho0 = lensModel.theta2rho(theta_E)
        kwargs_lens = {'theta_E': theta_E, 'e1': 0, 'e2': 0}
        kwargs_density = {'rho0': rho0, 'e1': 0, 'e2': 0}
        r = .5
        mass_2d = lensModel.mass_2d(r, **kwargs_density)
        alpha_mass = mass_2d / r
        alpha_r, _ = lensModel.derivatives(r, 0, **kwargs_lens)
        npt.assert_almost_equal(alpha_mass / np.pi, alpha_r, decimal=5)
    def test_gaussian_density_deflection(self):
        """
        tests whether the unit conversion between the lensing parameter 'sigma0' and the units in the density profile are ok
        :return:
        """

        from lenstronomy.LensModel.Profiles.gaussian_kappa import GaussianKappa as Model
        lensModel = Model()
        amp = 1. / 4.
        sigma = 2.
        amp_lens = lensModel._amp3d_to_2d(amp, sigma, sigma)
        kwargs_lens = {'amp': amp_lens, 'sigma': sigma}
        kwargs_density = {'amp': amp, 'sigma': sigma}
        r = .5
        mass_2d = lensModel.mass_2d(r, **kwargs_density)
        alpha_mass = mass_2d / r
        alpha_r, _ = lensModel.derivatives(r, 0, **kwargs_lens)
        npt.assert_almost_equal(alpha_mass / np.pi, alpha_r, decimal=5)
    def test_nfw_density_deflection(self):
        """
        tests whether the unit conversion between the lensing parameter 'sigma0' and the units in the density profile are ok
        :return:
        """

        from lenstronomy.LensModel.Profiles.nfw import NFW as Model
        lensModel = Model()
        alpha_Rs = 1.
        Rs = 2.
        rho0 = lensModel.alpha2rho0(alpha_Rs, Rs)
        kwargs_lens = {'alpha_Rs': alpha_Rs, 'Rs': Rs}
        kwargs_density = {'rho0': rho0, 'Rs': Rs}
        r = 2.
        mass_2d = lensModel.mass_2d(r, **kwargs_density)
        alpha_mass = mass_2d / r
        alpha_r, _ = lensModel.derivatives(r, 0, **kwargs_lens)
        npt.assert_almost_equal(alpha_mass / np.pi, alpha_r, decimal=5)
    def assert_lens_integrals(self, Model, kwargs, pi_convention=True):
        """
        checks whether the integral in projection of the density_lens() function is the convergence

        :param Model: lens model instance
        :param kwargs: keyword arguments of lens model
        :return:
        """
        lensModel = Model()
        int_profile = ProfileIntegrals(lensModel)
        r = 2.
        kappa_num = int_profile.density_2d(r, kwargs, lens_param=True)
        f_xx, f_xy, f_yx, f_yy = lensModel.hessian(r, 0, **kwargs)
        kappa = 1. / 2 * (f_xx + f_yy)
        npt.assert_almost_equal(kappa_num, kappa, decimal=2)
        try:
            del kwargs['center_x']
            del kwargs['center_y']
        except:
            pass
        bool_mass_2d_lens = False
        try:
            mass_2d = lensModel.mass_2d_lens(r, **kwargs)
            bool_mass_2d_lens = True
        except:
            pass
        if bool_mass_2d_lens:
            alpha_x, alpha_y = lensModel.derivatives(r, 0, **kwargs)
            alpha = np.sqrt(alpha_x**2 + alpha_y**2)
            if pi_convention:
                npt.assert_almost_equal(alpha, mass_2d / r / np.pi, decimal=5)
            else:
                npt.assert_almost_equal(alpha, mass_2d / r, decimal=5)
        try:
            mass_3d = lensModel.mass_3d_lens(r, **kwargs)
            bool_mass_3d_lens = True
        except:
            bool_mass_3d_lens = False
        if bool_mass_3d_lens:
            mass_3d_num = int_profile.mass_enclosed_3d(r,
                                                       kwargs_profile=kwargs,
                                                       lens_param=True)
            print(mass_3d, mass_3d_num, 'test num')
            npt.assert_almost_equal(mass_3d / mass_3d_num, 1, decimal=2)
    def assert_lens_integrals(self, Model, kwargs):
        """
        checks whether the integral in projection of the density_lens() function is the convergence

        :param Model: lens model instance
        :param kwargs: keyword arguments of lens model
        :return:
        """
        lensModel = Model()
        int_profile = ProfileIntegrals(lensModel)
        r = 2.
        kappa_num = int_profile.density_2d(r, kwargs, lens_param=True)
        f_xx, f_yy, f_xy = lensModel.hessian(r, 0, **kwargs)
        kappa = 1. / 2 * (f_xx + f_yy)
        npt.assert_almost_equal(kappa_num, kappa, decimal=2)
        if hasattr(lensModel, 'mass_2d_lens'):
            mass_2d = lensModel.mass_2d_lens(r, **kwargs)
            alpha_x, alpha_y = lensModel.derivatives(r, 0, **kwargs)
            alpha = np.sqrt(alpha_x**2 + alpha_y**2)
            npt.assert_almost_equal(alpha, mass_2d / r / np.pi, decimal=5)
Exemple #7
0
class PJaffe_Ellipse(LensProfileBase):
    """
    this class contains functions concerning the NFW profile

    relation are: R_200 = c * Rs
    """
    param_names = ['sigma0', 'Ra', 'Rs', 'e1', 'e2', 'center_x', 'center_y']
    lower_limit_default = {
        'sigma0': 0,
        'Ra': 0,
        'Rs': 0,
        'e1': -0.5,
        'e2': -0.5,
        'center_x': -100,
        'center_y': -100
    }
    upper_limit_default = {
        'sigma0': 10,
        'Ra': 100,
        'Rs': 100,
        'e1': 0.5,
        'e2': 0.5,
        'center_x': 100,
        'center_y': 100
    }

    def __init__(self):
        self.spherical = PJaffe()
        self._diff = 0.000001
        super(PJaffe_Ellipse, self).__init__()

    def function(self, x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0):
        """
        returns double integral of NFW profile
        """
        phi_G, q = param_util.ellipticity2phi_q(e1, e2)
        x_shift = x - center_x
        y_shift = y - center_y
        cos_phi = np.cos(phi_G)
        sin_phi = np.sin(phi_G)
        e = min(abs(1. - q), 0.99)
        x_ = (cos_phi * x_shift + sin_phi * y_shift) * np.sqrt(1 - e)
        y_ = (-sin_phi * x_shift + cos_phi * y_shift) * np.sqrt(1 + e)
        f_ = self.spherical.function(x_, y_, sigma0, Ra, Rs)
        return f_

    def derivatives(self,
                    x,
                    y,
                    sigma0,
                    Ra,
                    Rs,
                    e1,
                    e2,
                    center_x=0,
                    center_y=0):
        """
        returns df/dx and df/dy of the function (integral of NFW)
        """
        phi_G, q = param_util.ellipticity2phi_q(e1, e2)
        x_shift = x - center_x
        y_shift = y - center_y
        cos_phi = np.cos(phi_G)
        sin_phi = np.sin(phi_G)
        e = min(abs(1. - q), 0.99)
        x_ = (cos_phi * x_shift + sin_phi * y_shift) * np.sqrt(1 - e)
        y_ = (-sin_phi * x_shift + cos_phi * y_shift) * np.sqrt(1 + e)

        f_x_prim, f_y_prim = self.spherical.derivatives(x_,
                                                        y_,
                                                        sigma0,
                                                        Ra,
                                                        Rs,
                                                        center_x=0,
                                                        center_y=0)
        f_x_prim *= np.sqrt(1 - e)
        f_y_prim *= np.sqrt(1 + e)
        f_x = cos_phi * f_x_prim - sin_phi * f_y_prim
        f_y = sin_phi * f_x_prim + cos_phi * f_y_prim
        return f_x, f_y

    def hessian(self, x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0):
        """
        returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy
        """
        alpha_ra, alpha_dec = self.derivatives(x, y, sigma0, Ra, Rs, e1, e2,
                                               center_x, center_y)
        diff = self._diff
        alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, sigma0, Ra,
                                                     Rs, e1, e2, center_x,
                                                     center_y)
        alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, sigma0, Ra,
                                                     Rs, e1, e2, center_x,
                                                     center_y)

        f_xx = (alpha_ra_dx - alpha_ra) / diff
        f_xy = (alpha_ra_dy - alpha_ra) / diff
        #f_yx = (alpha_dec_dx - alpha_dec)/diff
        f_yy = (alpha_dec_dy - alpha_dec) / diff

        return f_xx, f_yy, f_xy

    def mass_3d_lens(self, r, sigma0, Ra, Rs, e1=0, e2=0):
        """

        :param r:
        :param sigma0:
        :param Ra:
        :param Rs:
        :param q:
        :param phi_G:
        :return:
        """
        return self.spherical.mass_3d_lens(r, sigma0, Ra, Rs)
class PJaffe_Ellipse(LensProfileBase):
    """
    class to compute the DUAL PSEUDO ISOTHERMAL ELLIPTICAL MASS DISTRIBUTION
    based on Eliasdottir (2007) https://arxiv.org/pdf/0710.5636.pdf Appendix A
    with the ellipticity implemented in the potential

    Module name: 'PJAFFE_ELLIPSE';

    An alternative name is dPIED.

    The 3D density distribution is

    .. math::
        \\rho(r) = \\frac{\\rho_0}{(1+r^2/Ra^2)(1+r^2/Rs^2)}

    with :math:`Rs > Ra`.

    The projected density is

    .. math::
        \\Sigma(R) = \\Sigma_0 \\frac{Ra Rs}{Rs-Ra}\\left(\\frac{1}{\\sqrt{Ra^2+R^2}} - \\frac{1}{\\sqrt{Rs^2+R^2}} \\right)

    with

    .. math::
        \\Sigma_0 = \\pi \\rho_0 \\frac{Ra Rs}{Rs + Ra}

    In the lensing parameterization,

    .. math::
        \\sigma_0 = \\frac{\\Sigma_0}{\\Sigma_{\\rm crit}}

    """
    param_names = ['sigma0', 'Ra', 'Rs', 'e1', 'e2', 'center_x', 'center_y']
    lower_limit_default = {
        'sigma0': 0,
        'Ra': 0,
        'Rs': 0,
        'e1': -0.5,
        'e2': -0.5,
        'center_x': -100,
        'center_y': -100
    }
    upper_limit_default = {
        'sigma0': 10,
        'Ra': 100,
        'Rs': 100,
        'e1': 0.5,
        'e2': 0.5,
        'center_x': 100,
        'center_y': 100
    }

    def __init__(self):
        self.spherical = PJaffe()
        self._diff = 0.000001
        super(PJaffe_Ellipse, self).__init__()

    def function(self, x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0):
        """
        returns double integral of NFW profile
        """
        x_, y_ = param_util.transform_e1e2_square_average(
            x, y, e1, e2, center_x, center_y)
        f_ = self.spherical.function(x_, y_, sigma0, Ra, Rs)
        return f_

    def derivatives(self,
                    x,
                    y,
                    sigma0,
                    Ra,
                    Rs,
                    e1,
                    e2,
                    center_x=0,
                    center_y=0):
        """
        returns df/dx and df/dy of the function (integral of NFW)
        """
        phi_G, q = param_util.ellipticity2phi_q(e1, e2)
        x_, y_ = param_util.transform_e1e2_square_average(
            x, y, e1, e2, center_x, center_y)
        e = param_util.q2e(q)
        cos_phi = np.cos(phi_G)
        sin_phi = np.sin(phi_G)
        f_x_prim, f_y_prim = self.spherical.derivatives(x_,
                                                        y_,
                                                        sigma0,
                                                        Ra,
                                                        Rs,
                                                        center_x=0,
                                                        center_y=0)
        f_x_prim *= np.sqrt(1 - e)
        f_y_prim *= np.sqrt(1 + e)
        f_x = cos_phi * f_x_prim - sin_phi * f_y_prim
        f_y = sin_phi * f_x_prim + cos_phi * f_y_prim
        return f_x, f_y

    def hessian(self, x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0):
        """
        returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2
        """
        alpha_ra, alpha_dec = self.derivatives(x, y, sigma0, Ra, Rs, e1, e2,
                                               center_x, center_y)
        diff = self._diff
        alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, sigma0, Ra,
                                                     Rs, e1, e2, center_x,
                                                     center_y)
        alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, sigma0, Ra,
                                                     Rs, e1, e2, center_x,
                                                     center_y)

        f_xx = (alpha_ra_dx - alpha_ra) / diff
        f_xy = (alpha_ra_dy - alpha_ra) / diff
        f_yx = (alpha_dec_dx - alpha_dec) / diff
        f_yy = (alpha_dec_dy - alpha_dec) / diff

        return f_xx, f_xy, f_yx, f_yy

    def mass_3d_lens(self, r, sigma0, Ra, Rs, e1=0, e2=0):
        """

        :param r:
        :param sigma0:
        :param Ra:
        :param Rs:
        :param e1:
        :param e2:
        :return:
        """
        return self.spherical.mass_3d_lens(r, sigma0, Ra, Rs)
Exemple #9
0
class TestP_JAFFW(object):
    """
    tests the Gaussian methods
    """
    def setup(self):
        self.profile = PJaffe()

    def test_function(self):
        x = np.array([1])
        y = np.array([2])
        sigma0 = 1.
        Ra, Rs = 0.5, 0.8
        values = self.profile.function(x, y, sigma0, Ra, Rs)
        assert values[0] == 0.87301557036070054
        x = np.array([0])
        y = np.array([0])
        sigma0 = 1.
        Ra, Rs = 0.5, 0.8
        values = self.profile.function(x, y, sigma0, Ra, Rs)
        assert values[0] == 0.20267440905756931

        x = np.array([2, 3, 4])
        y = np.array([1, 1, 1])
        values = self.profile.function(x, y, sigma0, Ra, Rs)
        assert values[0] == 0.87301557036070054
        assert values[1] == 1.0842781309377669
        assert values[2] == 1.2588604178849985

    def test_derivatives(self):
        x = np.array([1])
        y = np.array([2])
        sigma0 = 1.
        Ra, Rs = 0.5, 0.8
        f_x, f_y = self.profile.derivatives(x, y, sigma0, Ra, Rs)
        assert f_x[0] == 0.11542369603751264
        assert f_y[0] == 0.23084739207502528
        x = np.array([0])
        y = np.array([0])
        f_x, f_y = self.profile.derivatives(x, y, sigma0, Ra, Rs)
        assert f_x[0] == 0
        assert f_y[0] == 0

        x = np.array([1, 3, 4])
        y = np.array([2, 1, 1])
        values = self.profile.derivatives(x, y, sigma0, Ra, Rs)
        assert values[0][0] == 0.11542369603751264
        assert values[1][0] == 0.23084739207502528
        assert values[0][1] == 0.19172866612512479
        assert values[1][1] == 0.063909555375041588

    def test_hessian(self):
        x = np.array([1])
        y = np.array([2])
        sigma0 = 1.
        Ra, Rs = 0.5, 0.8
        f_xx, f_yy, f_xy = self.profile.hessian(x, y, sigma0, Ra, Rs)
        assert f_xx[0] == 0.077446121589827679
        assert f_yy[0] == -0.036486601753227141
        assert f_xy[0] == -0.075955148895369876
        x = np.array([1, 3, 4])
        y = np.array([2, 1, 1])
        values = self.profile.hessian(x, y, sigma0, Ra, Rs)
        assert values[0][0] == 0.077446121589827679
        assert values[1][0] == -0.036486601753227141
        assert values[2][0] == -0.075955148895369876
        assert values[0][1] == -0.037260794616683197
        assert values[1][1] == 0.052668405375961035
        assert values[2][1] == -0.033723449997241584

    def test_mass_tot(self):
        rho0 = 1.
        Ra, Rs = 0.5, 0.8
        values = self.profile.mass_tot(rho0, Ra, Rs)
        npt.assert_almost_equal(values, 2.429441083345073, decimal=10)

    def test_mass_3d_lens(self):
        mass = self.profile.mass_3d_lens(r=1, sigma0=1, Ra=0.5, Rs=0.8)
        npt.assert_almost_equal(mass, 0.87077306005349242, decimal=8)

    def test_grav_pot(self):
        x = 1
        y = 2
        rho0 = 1.
        Ra, Rs = 0.5, 0.8
        grav_pot = self.profile.grav_pot(x,
                                         y,
                                         rho0,
                                         Ra,
                                         Rs,
                                         center_x=0,
                                         center_y=0)
        npt.assert_almost_equal(grav_pot, 0.89106542283974155, decimal=10)
Exemple #10
0
class PJaffe_Ellipse(object):
    """
    this class contains functions concerning the NFW profile

    relation are: R_200 = c * Rs
    """
    def __init__(self):
        self.spherical = PJaffe()
        self._diff = 0.000001

    def function(self, x, y, sigma0, Ra, Rs, q, phi_G, center_x=0, center_y=0):
        """
        returns double integral of NFW profile
        """

        x_shift = x - center_x
        y_shift = y - center_y
        cos_phi = np.cos(phi_G)
        sin_phi = np.sin(phi_G)
        e = min(abs(1. - q), 0.99)
        x_ = (cos_phi * x_shift + sin_phi * y_shift) * np.sqrt(1 - e)
        y_ = (-sin_phi * x_shift + cos_phi * y_shift) * np.sqrt(1 + e)
        f_ = self.spherical.function(x_, y_, sigma0, Ra, Rs)
        return f_

    def derivatives(self,
                    x,
                    y,
                    sigma0,
                    Ra,
                    Rs,
                    q,
                    phi_G,
                    center_x=0,
                    center_y=0):
        """
        returns df/dx and df/dy of the function (integral of NFW)
        """
        x_shift = x - center_x
        y_shift = y - center_y
        cos_phi = np.cos(phi_G)
        sin_phi = np.sin(phi_G)
        e = min(abs(1. - q), 0.99)
        x_ = (cos_phi * x_shift + sin_phi * y_shift) * np.sqrt(1 - e)
        y_ = (-sin_phi * x_shift + cos_phi * y_shift) * np.sqrt(1 + e)

        f_x_prim, f_y_prim = self.spherical.derivatives(x_,
                                                        y_,
                                                        sigma0,
                                                        Ra,
                                                        Rs,
                                                        center_x=0,
                                                        center_y=0)
        f_x_prim *= np.sqrt(1 - e)
        f_y_prim *= np.sqrt(1 + e)
        f_x = cos_phi * f_x_prim - sin_phi * f_y_prim
        f_y = sin_phi * f_x_prim + cos_phi * f_y_prim
        return f_x, f_y

    def hessian(self, x, y, sigma0, Ra, Rs, q, phi_G, center_x=0, center_y=0):
        """
        returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy
        """
        alpha_ra, alpha_dec = self.derivatives(x, y, sigma0, Ra, Rs, q, phi_G,
                                               center_x, center_y)
        diff = self._diff
        alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, sigma0, Ra,
                                                     Rs, q, phi_G, center_x,
                                                     center_y)
        alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, sigma0, Ra,
                                                     Rs, q, phi_G, center_x,
                                                     center_y)

        f_xx = (alpha_ra_dx - alpha_ra) / diff
        f_xy = (alpha_ra_dy - alpha_ra) / diff
        #f_yx = (alpha_dec_dx - alpha_dec)/diff
        f_yy = (alpha_dec_dy - alpha_dec) / diff

        return f_xx, f_yy, f_xy

    def mass_3d_lens(self, r, sigma0, Ra, Rs, q=1, phi_G=0):
        """

        :param r:
        :param sigma0:
        :param Ra:
        :param Rs:
        :param q:
        :param phi_G:
        :return:
        """
        return self.spherical.mass_3d_lens(r, sigma0, Ra, Rs)
Exemple #11
0
class TestP_JAFFW(object):
    """
    tests the Gaussian methods
    """
    def setup(self):
        self.profile = PJaffe()

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

        x = np.array([2, 3, 4])
        y = np.array([1, 1, 1])
        values = self.profile.function(x, y, sigma0, Ra, Rs)
        npt.assert_almost_equal(values[0], 0.87301557036070054, decimal=8)
        npt.assert_almost_equal(values[1], 1.0842781309377669, decimal=8)
        npt.assert_almost_equal(values[2], 1.2588604178849985, decimal=8)

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

        x = np.array([1, 3, 4])
        y = np.array([2, 1, 1])
        values = self.profile.derivatives(x, y, sigma0, Ra, Rs)
        npt.assert_almost_equal(values[0][0], 0.11542369603751264, decimal=8)
        npt.assert_almost_equal(values[1][0], 0.23084739207502528, decimal=8)
        npt.assert_almost_equal(values[0][1], 0.19172866612512479, decimal=8)
        npt.assert_almost_equal(values[1][1], 0.063909555375041588, decimal=8)

    def test_hessian(self):
        x = np.array([1])
        y = np.array([2])
        sigma0 = 1.
        Ra, Rs = 0.5, 0.8
        f_xx, f_xy, f_yx, f_yy = self.profile.hessian(x, y, sigma0, Ra, Rs)
        npt.assert_almost_equal(f_xx[0], 0.077446121589827679, decimal=8)
        npt.assert_almost_equal(f_yy[0], -0.036486601753227141, decimal=8)
        npt.assert_almost_equal(f_xy[0], -0.075955148895369876, decimal=8)
        x = np.array([1, 3, 4])
        y = np.array([2, 1, 1])
        values = self.profile.hessian(x, y, sigma0, Ra, Rs)
        npt.assert_almost_equal(values[0][0], 0.077446121589827679, decimal=8)
        npt.assert_almost_equal(values[3][0], -0.036486601753227141, decimal=8)
        npt.assert_almost_equal(values[1][0], values[2][0], decimal=8)

    def test_mass_tot(self):
        rho0 = 1.
        Ra, Rs = 0.5, 0.8
        values = self.profile.mass_tot(rho0, Ra, Rs)
        npt.assert_almost_equal(values, 2.429441083345073, decimal=10)

    def test_mass_3d_lens(self):
        mass = self.profile.mass_3d_lens(r=1, sigma0=1, Ra=0.5, Rs=0.8)
        npt.assert_almost_equal(mass, 0.87077306005349242, decimal=8)

    def test_grav_pot(self):
        x = 1
        y = 2
        rho0 = 1.
        r = np.sqrt(x**2 + y**2)
        Ra, Rs = 0.5, 0.8
        grav_pot = self.profile.grav_pot(r, rho0, Ra, Rs)
        npt.assert_almost_equal(grav_pot, 0.89106542283974155, decimal=10)