コード例 #1
0
    def test_image2source(self):
        lensing_op = LensingOperator(self.lens_model, self.image_grid_class,
                                     self.source_grid_class_default,
                                     self.num_pix)
        image_1d = util.image2array(self.source_light_lensed)
        image_1d_delensed = lensing_op.image2source(
            image_1d, kwargs_lens=self.kwargs_lens)
        assert len(image_1d_delensed.shape) == 1

        image_2d = self.source_light_lensed
        image_2d_delensed = lensing_op.image2source_2d(
            image_2d, kwargs_lens=self.kwargs_lens, update_mapping=True)
        assert len(image_2d_delensed.shape) == 2
コード例 #2
0
    def test_matrix_product(self):
        lensing_op = LensingOperator(self.lens_model,
                                     self.image_grid_class,
                                     self.source_grid_class_default,
                                     self.num_pix,
                                     source_interpolation='nearest_legacy')
        lensing_op.update_mapping(self.kwargs_lens)

        lensing_op_mat = LensingOperator(self.lens_model,
                                         self.image_grid_class,
                                         self.source_grid_class_default,
                                         self.num_pix,
                                         source_interpolation='nearest')
        lensing_op_mat.update_mapping(self.kwargs_lens)

        source_1d = util.image2array(self.source_light_delensed)
        image_1d = util.image2array(self.source_light_lensed)

        npt.assert_equal(lensing_op.source2image(source_1d),
                         lensing_op_mat.source2image(source_1d))
        npt.assert_equal(lensing_op.image2source(image_1d),
                         lensing_op_mat.image2source(image_1d))
コード例 #3
0
    def test_minimal_source_plane(self):
        source_1d = util.image2array(self.source_light_delensed)

        # test with no mask
        lensing_op = LensingOperator(self.lens_model,
                                     self.image_grid_class,
                                     self.source_grid_class_default,
                                     self.num_pix,
                                     source_interpolation='nearest',
                                     minimal_source_plane=True)
        lensing_op.update_mapping(self.kwargs_lens)
        image_1d = util.image2array(self.source_light_lensed)
        assert lensing_op.image2source(image_1d).size < source_1d.size

        # test with mask
        lensing_op = LensingOperator(self.lens_model,
                                     self.image_grid_class,
                                     self.source_grid_class_default,
                                     self.num_pix,
                                     source_interpolation='nearest',
                                     minimal_source_plane=True)
        lensing_op.set_likelihood_mask(self.likelihood_mask)
        lensing_op.update_mapping(self.kwargs_lens)
        image_1d = util.image2array(self.source_light_lensed)
        assert lensing_op.image2source(image_1d).size < source_1d.size

        # for 'bilinear' operator, only works with no mask (for now)
        lensing_op = LensingOperator(self.lens_model,
                                     self.image_grid_class,
                                     self.source_grid_class_default,
                                     self.num_pix,
                                     source_interpolation='bilinear',
                                     minimal_source_plane=True)
        lensing_op.update_mapping(self.kwargs_lens)
        image_1d = util.image2array(self.source_light_lensed)
        assert lensing_op.image2source(image_1d).size < source_1d.size
コード例 #4
0
    def test_interpol_mapping(self):
        """testing than image2source / source2image are close to the parametric mapping"""
        lensing_op = LensingOperator(self.lens_model,
                                     self.image_grid_class,
                                     self.source_grid_class_default,
                                     self.num_pix,
                                     source_interpolation='bilinear')
        lensing_op.update_mapping(self.kwargs_lens)

        source_1d = util.image2array(self.source_light_delensed)
        image_1d = util.image2array(self.source_light_lensed)

        source_1d_lensed = lensing_op.source2image(source_1d)
        image_1d_delensed = lensing_op.image2source(image_1d)
        assert source_1d_lensed.shape == image_1d.shape
        assert image_1d_delensed.shape == source_1d.shape

        npt.assert_almost_equal(source_1d_lensed / source_1d_lensed.max(),
                                image_1d / image_1d.max(),
                                decimal=0.8)
        npt.assert_almost_equal(image_1d_delensed / image_1d_delensed.max(),
                                source_1d / source_1d.max(),
                                decimal=0.8)