Ejemplo n.º 1
0
 def setup(self):
     lens_model = LensModel(lens_model_list=['SIS'])
     self.kwargs_lens = [{'theta_E': 1, 'center_x': 0, 'center_y': 0}]
     self.ps_mag = SourcePositions(lens_model=lens_model,
                                   fixed_magnification=True)
     self.ps = SourcePositions(lens_model=lens_model,
                               fixed_magnification=False)
     self.kwargs = {'point_amp': [2, 1], 'ra_source': 0.1, 'dec_source': 0}
     self.kwargs_mag = {'source_amp': 1, 'ra_source': 0.1, 'dec_source': 0}
class TestLensedPosition(object):
    def setup(self):
        lens_model = LensModel(lens_model_list=['SIS'])
        self.kwargs_lens = [{'theta_E': 1, 'center_x': 0, 'center_y': 0}]
        self.ps_mag = SourcePositions(lens_model=lens_model,
                                      fixed_magnification=True)
        self.ps = SourcePositions(lens_model=lens_model,
                                  fixed_magnification=False)
        self.kwargs = {'point_amp': [2, 1], 'ra_source': 0.1, 'dec_source': 0}
        self.kwargs_mag = {'source_amp': 1, 'ra_source': 0.1, 'dec_source': 0}

    def test_image_position(self):
        x_img, y_img = self.ps.image_position(self.kwargs, self.kwargs_lens)

        lens_model = LensModel(lens_model_list=['SIS'])
        x_src, y_src = lens_model.ray_shooting(x_img,
                                               y_img,
                                               kwargs=self.kwargs_lens)
        npt.assert_almost_equal(x_src, self.kwargs['ra_source'])
        npt.assert_almost_equal(y_src, self.kwargs['dec_source'])

    def test_source_position(self):
        x_src, y_src = self.ps.source_position(self.kwargs,
                                               kwargs_lens=self.kwargs_lens)
        npt.assert_almost_equal(x_src, self.kwargs['ra_source'])
        npt.assert_almost_equal(y_src, self.kwargs['dec_source'])

    def test_image_amplitude(self):
        x_img, y_img = self.ps.image_position(self.kwargs,
                                              kwargs_lens=self.kwargs_lens)
        amp = self.ps_mag.image_amplitude(self.kwargs_mag,
                                          kwargs_lens=self.kwargs_lens,
                                          x_pos=None,
                                          y_pos=None,
                                          magnification_limit=None,
                                          kwargs_lens_eqn_solver=None)
        amp_pos = self.ps_mag.image_amplitude(self.kwargs_mag,
                                              kwargs_lens=self.kwargs_lens,
                                              x_pos=x_img,
                                              y_pos=y_img,
                                              magnification_limit=None,
                                              kwargs_lens_eqn_solver=None)
        npt.assert_almost_equal(amp_pos, amp)

        amp = self.ps.image_amplitude(self.kwargs,
                                      kwargs_lens=self.kwargs_lens,
                                      x_pos=x_img,
                                      y_pos=y_img,
                                      magnification_limit=None,
                                      kwargs_lens_eqn_solver=None)
        npt.assert_almost_equal(amp, self.kwargs['point_amp'])

    def test_source_amplitude(self):
        amp = self.ps.source_amplitude(self.kwargs,
                                       kwargs_lens=self.kwargs_lens)
        amp_mag = self.ps_mag.source_amplitude(self.kwargs_mag,
                                               kwargs_lens=self.kwargs_lens)
        npt.assert_almost_equal(amp_mag, self.kwargs_mag['source_amp'])
        assert amp != amp_mag
Ejemplo n.º 3
0
    def __init__(self, point_source_type_list, lensModel=None, fixed_magnification_list=None,
                 additional_images_list=None, flux_from_point_source_list=None, magnification_limit=None,
                 save_cache=False, kwargs_lens_eqn_solver=None):
        """

        :param point_source_type_list: list of point source types
        :param lensModel: instance of the LensModel() class
        :param fixed_magnification_list: list of booleans (same length as point_source_type_list).
         If True, magnification ratio of point sources is fixed to the one given by the lens model
        :param additional_images_list: list of booleans (same length as point_source_type_list). If True, search for
        additional images of the same source is conducted.
        :param flux_from_point_source_list: list of booleans (optional), if set, will only return image positions
         (for imaging modeling) for the subset of the point source lists that =True. This option enables to model
         imaging data with transient point sources, when the point source positions are measured and present at a
         different time than the imaging data
        :param magnification_limit: float >0 or None, if float is set and additional images are computed, only those
         images will be computed that exceed the lensing magnification (absolute value) limit
        :param save_cache: bool, saves image positions and only if delete_cache is executed, a new solution of the lens
         equation is conducted with the lens model parameters provided. This can increase the speed as multiple times
         the image positions are requested for the same lens model. Attention in usage!
        :param kwargs_lens_eqn_solver: keyword arguments specifying the numerical settings for the lens equation solver
         see LensEquationSolver() class for details

        for the kwargs_lens_eqn_solver parameters: have a look at the lensEquationSolver class, such as:
        min_distance=0.01, search_window=5, precision_limit=10**(-10), num_iter_max=100

        """
        self._lensModel = lensModel
        self.point_source_type_list = point_source_type_list
        self._point_source_list = []
        if fixed_magnification_list is None:
            fixed_magnification_list = [False] * len(point_source_type_list)
        self._fixed_magnification_list = fixed_magnification_list
        if additional_images_list is None:
            additional_images_list = [False] * len(point_source_type_list)
        if flux_from_point_source_list is None:
            flux_from_point_source_list = [True] * len(point_source_type_list)
        self._flux_from_point_source_list = flux_from_point_source_list
        for i, model in enumerate(point_source_type_list):
            if model == 'UNLENSED':
                from lenstronomy.PointSource.Types.unlensed import Unlensed
                self._point_source_list.append(PointSourceCached(Unlensed(), save_cache=save_cache))
            elif model == 'LENSED_POSITION':
                from lenstronomy.PointSource.Types.lensed_position import LensedPositions
                self._point_source_list.append(PointSourceCached(LensedPositions(lensModel, fixed_magnification=fixed_magnification_list[i],
                                                               additional_image=additional_images_list[i]), save_cache=save_cache))
            elif model == 'SOURCE_POSITION':
                from lenstronomy.PointSource.Types.source_position import SourcePositions
                self._point_source_list.append(PointSourceCached(SourcePositions(lensModel,
                                                                 fixed_magnification=fixed_magnification_list[i]),
                                                                 save_cache=save_cache))
            else:
                raise ValueError("Point-source model %s not available. Supported models are %s ."
                                 % (model, _SUPPORTED_MODELS))
        if kwargs_lens_eqn_solver is None:
            kwargs_lens_eqn_solver = {}
        self._kwargs_lens_eqn_solver = kwargs_lens_eqn_solver
        self._magnification_limit = magnification_limit
        self._save_cache = save_cache