Example #1
0
    def __init__(self,
                 kwargs_model,
                 kwargs_cosmo,
                 interpol_grid_num=100,
                 log_integration=False,
                 max_integrate=100,
                 min_integrate=0.001):
        """

        :param interpol_grid_num:
        :param log_integration:
        :param max_integrate:
        :param min_integrate:
        """
        mass_profile_list = kwargs_model.get('mass_profile_list')
        light_profile_list = kwargs_model.get('light_profile_list')
        anisotropy_model = kwargs_model.get('anisotropy_model')
        self._interp_grid_num = interpol_grid_num
        self._log_int = log_integration
        self._max_integrate = max_integrate  # maximal integration (and interpolation) in units of arcsecs
        self._min_integrate = min_integrate  # min integration (and interpolation) in units of arcsecs
        self._max_interpolate = max_integrate  # we chose to set the interpolation range to the integration range
        self._min_interpolate = min_integrate  # we chose to set the interpolation range to the integration range
        self.lightProfile = LightProfile(light_profile_list,
                                         interpol_grid_num=interpol_grid_num,
                                         max_interpolate=max_integrate,
                                         min_interpolate=min_integrate)
        Anisotropy.__init__(self, anisotropy_type=anisotropy_model)
        self.cosmo = Cosmo(**kwargs_cosmo)
        self._mass_profile = SinglePlane(mass_profile_list)
Example #2
0
 def __init__(self,
              aperture='slit',
              mass_profile='power_law',
              light_profile='Hernquist',
              anisotropy_type='r_ani',
              psf_fwhm=0.7,
              kwargs_cosmo={
                  'D_d': 1000,
                  'D_s': 2000,
                  'D_ds': 500
              }):
     """
     initializes the observation condition and masks
     :param aperture_type: string
     :param psf_fwhm: float
     """
     self._mass_profile = mass_profile
     self._fwhm = psf_fwhm
     self._kwargs_cosmo = kwargs_cosmo
     self.lightProfile = LightProfileOld(light_profile)
     self.aperture = Aperture(aperture)
     self.anisotropy = Anisotropy(anisotropy_type)
     self.FWHM = psf_fwhm
     self.jeans_solver = JeansSolver(kwargs_cosmo, mass_profile,
                                     light_profile, anisotropy_type)
Example #3
0
    def test_generalizedOM(self):
        # generalized OM model
        gom = Anisotropy(anisotropy_type='GOM')
        r = self._r_array
        R = 2
        om = Anisotropy(anisotropy_type='OM')
        kwargs_om = {'r_ani': 1.}
        kwargs_gom = {'r_ani': 1., 'beta_inf': 1.}
        beta_gom = gom.beta_r(r, **kwargs_gom)
        beta_om = om.beta_r(r, **kwargs_om)
        npt.assert_almost_equal(beta_gom, beta_om, decimal=5)

        f_om = om.anisotropy_solution(r, **kwargs_om)
        f_gom = gom.anisotropy_solution(r, **kwargs_gom)
        npt.assert_almost_equal(f_gom, f_om, decimal=5)

        K_gom = gom.K(r, R, **kwargs_gom)
        K_om = om.K(r, R, **kwargs_om)
        npt.assert_almost_equal(K_gom, K_om, decimal=3)

        from lenstronomy.GalKin.anisotropy import GeneralizedOM
        gom_class = GeneralizedOM()
        _F = gom_class._F(a=3 / 2., z=0.5, beta_inf=1)
        _F_array = gom_class._F(a=3 / 2., z=np.array([0.5]), beta_inf=1)
        npt.assert_almost_equal(_F_array[0], _F, decimal=5)
Example #4
0
    def __init__(self,
                 kwargs_model,
                 kwargs_cosmo,
                 interpol_grid_num=1000,
                 log_integration=True,
                 max_integrate=1000,
                 min_integrate=0.0001,
                 max_light_draw=None,
                 lum_weight_int_method=True):
        """
        What we need:
        - max projected R to have ACCURATE I_R_sigma values
        - make sure everything outside cancels out (or is not rendered)

        :param interpol_grid_num: number of interpolation bins for integrand and interpolated functions
        :param log_integration: bool, if True, performs the numerical integral in log space distance (adviced)
         (only applies for lum_weight_int_method=True)
        :param max_integrate: maximum radius (in arc seconds) of the Jeans equation integral
         (assumes zero tracer particles outside this radius)
        :param max_light_draw: float; (optional) if set, draws up to this radius, else uses max_interpolate value
        :param lum_weight_int_method: bool, luminosity weighted dispersion integral to calculate LOS projected Jean's
         solution. ATTENTION: currently less accurate than 3d solution
        :param min_integrate:
        """
        mass_profile_list = kwargs_model.get('mass_profile_list')
        light_profile_list = kwargs_model.get('light_profile_list')
        anisotropy_model = kwargs_model.get('anisotropy_model')
        self._interp_grid_num = interpol_grid_num
        self._log_int = log_integration
        self._max_integrate = max_integrate  # maximal integration (and interpolation) in units of arcsecs
        self._min_integrate = min_integrate  # min integration (and interpolation) in units of arcsecs
        self._max_interpolate = max_integrate  # we chose to set the interpolation range to the integration range
        self._min_interpolate = min_integrate  # we chose to set the interpolation range to the integration range
        if max_light_draw is None:
            max_light_draw = max_integrate  # make sure the actual solution for the kinematics is only computed way inside the integral
        self.lightProfile = LightProfile(light_profile_list,
                                         interpol_grid_num=interpol_grid_num,
                                         max_interpolate=max_integrate,
                                         min_interpolate=min_integrate,
                                         max_draw=max_light_draw)
        Anisotropy.__init__(self, anisotropy_type=anisotropy_model)
        self.cosmo = Cosmo(**kwargs_cosmo)
        self._mass_profile = SinglePlane(mass_profile_list)
        self._lum_weight_int_method = lum_weight_int_method
Example #5
0
    def __init__(self,
                 kwargs_cosmo,
                 interpol_grid_num=100,
                 log_integration=False,
                 max_integrate=100,
                 min_integrate=0.001):
        """

        :param kwargs_cosmo: keyword argument with angular diameter distances
        """

        self._interp_grid_num = interpol_grid_num
        self._log_int = log_integration
        self._max_integrate = max_integrate  # maximal integration (and interpolation) in units of arcsecs
        self._min_integrate = min_integrate  # min integration (and interpolation) in units of arcsecs
        self._max_interpolate = max_integrate  # we chose to set the interpolation range to the integration range
        self._min_interpolate = min_integrate  # we chose to set the interpolation range to the integration range

        self._cosmo = Cosmo(**kwargs_cosmo)
        self._spp = SPP()
        Anisotropy.__init__(self, anisotropy_type='OM')
 def test_J_beta_rs(self):
     anisotropy_const = Anisotropy(anisotropy_type='const')
     anisotropy_r_ani = Anisotropy(anisotropy_type='r_ani')
     kwargs = {'r_ani': 2, 'beta': 1}
     r, s = 0.8, 3
     J_rs_const = anisotropy_const.J_beta_rs(r, s, kwargs)
     J_rs_r_ani = anisotropy_r_ani.J_beta_rs(r, s, kwargs)
     npt.assert_almost_equal(J_rs_const, 14.0625, decimal=5)
     npt.assert_almost_equal(J_rs_r_ani, 2.8017241379310343, decimal=5)
    def test_isotropic_anisotropy(self):

        # radial
        r = 2.
        R = 1.
        isotropic = Anisotropy(anisotropy_type='isotropic')
        kwargs_iso = {}
        beta = isotropic.beta_r(r, **kwargs_iso)
        k = isotropic.K(r, R, **kwargs_iso)
        f = isotropic.anisotropy_solution(r, **kwargs_iso)
        assert f == 1
        print(beta, 'test')
        const = Anisotropy(anisotropy_type='const')
        kwargs = {'beta': beta}
        k_const = const.K(r, R, **kwargs)
        print(k, k_const)
        npt.assert_almost_equal(k, k_const, decimal=5)
    def test_radial_anisotropy(self):

        # radial
        r = 2.
        R = 1.
        radial = Anisotropy(anisotropy_type='radial')
        kwargs_rad = {}
        beta = radial.beta_r(r, **kwargs_rad)
        k = radial.K(r, R, **kwargs_rad)
        f = radial.anisotropy_solution(r, **kwargs_rad)
        assert f == r**2
        const = Anisotropy(anisotropy_type='const')
        kwargs = {'beta': beta}
        print(beta, 'beta')
        #kwargs = {'beta': 1}
        k_mamon = const.K(r, R, **kwargs)
        print(k, k_mamon)
        npt.assert_almost_equal(k, k_mamon, decimal=5)
    def test_beta(self):
        r = 2.

        anisoClass = Anisotropy(anisotropy_type='const')
        kwargs = {'beta': 1.}
        beta = anisoClass.beta_r(r, **kwargs)
        npt.assert_almost_equal(beta, 1, decimal=5)

        anisoClass = Anisotropy(anisotropy_type='Colin')
        kwargs = {'r_ani': 1}
        beta = anisoClass.beta_r(r, **kwargs)
        npt.assert_almost_equal(beta, 1. / 3, decimal=5)

        anisoClass = Anisotropy(anisotropy_type='radial')
        kwargs = {}
        beta = anisoClass.beta_r(r, **kwargs)
        npt.assert_almost_equal(beta, 1, decimal=5)

        anisoClass = Anisotropy(anisotropy_type='isotropic')
        kwargs = {}
        beta = anisoClass.beta_r(r, **kwargs)
        npt.assert_almost_equal(beta, 0, decimal=5)

        anisoClass = Anisotropy(anisotropy_type='OM')
        kwargs = {'r_ani': 1}
        beta = anisoClass.beta_r(r, **kwargs)
        npt.assert_almost_equal(beta, 0.8, decimal=5)
    def test_K(self):

        anisoClass = Anisotropy(anisotropy_type='const')
        kwargs = {'beta': 1.0}
        k = anisoClass.K(self._r_array, self._R_array, **kwargs)
        npt.assert_almost_equal(k[0], 0.61418484930437822, decimal=5)

        anisoClass = Anisotropy(anisotropy_type='Colin')
        kwargs = {'r_ani': 1}
        k = anisoClass.K(self._r_array, self._R_array, **kwargs)
        npt.assert_almost_equal(k[0], 0.91696135187291117, decimal=5)
        k = anisoClass.K(self._r_array, self._R_array - 0.001, **kwargs)
        npt.assert_almost_equal(k[0], 0.91696135187291117, decimal=2)
        k = anisoClass.K(self._r_array, self._R_array + 0.001, **kwargs)
        npt.assert_almost_equal(k[0], 0.91696135187291117, decimal=2)

        anisoClass = Anisotropy(anisotropy_type='radial')
        kwargs = {}
        k = anisoClass.K(self._r_array, self._R_array, **kwargs)
        npt.assert_almost_equal(k[0], 0.61418484930437856, decimal=5)

        anisoClass = Anisotropy(anisotropy_type='isotropic')
        kwargs = {}
        k = anisoClass.K(self._r_array, self._R_array, **kwargs)
        npt.assert_almost_equal(k[0], 0.8660254037844386, decimal=5)

        anisoClass = Anisotropy(anisotropy_type='OM')
        kwargs = {'r_ani': 1}
        k = anisoClass.K(self._r_array, self._R_array, **kwargs)
        npt.assert_almost_equal(k[0], 0.95827704196894481, decimal=5)
    def test_raise(self):
        with self.assertRaises(ValueError):
            Anisotropy(anisotropy_type='wrong')
        with self.assertRaises(ValueError):
            ani = Anisotropy(anisotropy_type='Colin')
            ani.K(r=1, R=2, r_ani=1)

        with self.assertRaises(ValueError):
            ani = Anisotropy(anisotropy_type='const')
            ani.anisotropy_solution(r=1)

        with self.assertRaises(ValueError):
            const = Anisotropy(anisotropy_type='const')
            kwargs = {'beta': 1}
            f_const = const.anisotropy_solution(r=1, **kwargs)
Example #12
0
class GalKinAnalytic(object):
    """
    master class for all computations
    """
    def __init__(self,
                 aperture='slit',
                 mass_profile='power_law',
                 light_profile='Hernquist',
                 anisotropy_type='r_ani',
                 psf_fwhm=0.7,
                 kwargs_cosmo={
                     'D_d': 1000,
                     'D_s': 2000,
                     'D_ds': 500
                 }):
        """
        initializes the observation condition and masks
        :param aperture_type: string
        :param psf_fwhm: float
        """
        self._mass_profile = mass_profile
        self._fwhm = psf_fwhm
        self._kwargs_cosmo = kwargs_cosmo
        self.lightProfile = LightProfileOld(light_profile)
        self.aperture = Aperture(aperture)
        self.anisotropy = Anisotropy(anisotropy_type)
        self.FWHM = psf_fwhm
        self.jeans_solver = JeansSolver(kwargs_cosmo, mass_profile,
                                        light_profile, anisotropy_type)

    def vel_disp(self,
                 kwargs_profile,
                 kwargs_aperture,
                 kwargs_light,
                 kwargs_anisotropy,
                 num=1000):
        """
        computes the averaged LOS velocity dispersion in the slit (convolved)
        :param gamma:
        :param phi_E:
        :param r_eff:
        :param r_ani:
        :param R_slit:
        :param FWHM:
        :return:
        """
        sigma_s2_sum = 0
        for i in range(0, num):
            sigma_s2_draw = self._vel_disp_one(kwargs_profile, kwargs_aperture,
                                               kwargs_light, kwargs_anisotropy)
            sigma_s2_sum += sigma_s2_draw
        sigma_s2_average = sigma_s2_sum / num
        return np.sqrt(sigma_s2_average)

    def _vel_disp_one(self, kwargs_profile, kwargs_aperture, kwargs_light,
                      kwargs_anisotropy):
        """
        computes one realisation of the velocity dispersion realized in the slit
        :param gamma:
        :param rho0_r0_gamma:
        :param r_eff:
        :param r_ani:
        :param R_slit:
        :param dR_slit:
        :param FWHM:
        :return:
        """

        while True:
            r = self.lightProfile.draw_light(kwargs_light)  # draw r
            R, x, y = util.R_r(r)  # draw projected R
            x_, y_ = util.displace_PSF(x, y, self.FWHM)  # displace via PSF
            bool = self.aperture.aperture_select(x_, y_, kwargs_aperture)
            if bool is True:
                break
        sigma_s2 = self.sigma_s2(r, R, kwargs_profile, kwargs_anisotropy,
                                 kwargs_light)
        return sigma_s2

    def sigma_s2(self, r, R, kwargs_profile, kwargs_anisotropy, kwargs_light):
        """
        projected velocity dispersion
        :param r:
        :param R:
        :param r_ani:
        :param a:
        :param gamma:
        :param phi_E:
        :return:
        """
        beta = self.anisotropy.beta_r(r, kwargs_anisotropy)
        return (1 - beta * R**2 / r**2) * self.sigma_r2(
            r, kwargs_profile, kwargs_anisotropy, kwargs_light)

    def sigma_r2(self, r, kwargs_profile, kwargs_anisotropy, kwargs_light):
        """
        computes radial velocity dispersion at radius r (solving the Jeans equation
        :param r:
        :return:
        """
        return self.jeans_solver.sigma_r2(r, kwargs_profile, kwargs_anisotropy,
                                          kwargs_light)