コード例 #1
0
 def normalize_flux_source(self, kwargs_options, kwargs_source, norm_factor_source):
     """
     normalized the flux of the source
     :param kwargs_options:
     :param kwargs_source:
     :param norm_factor_source:
     :return:
     """
     kwargs_source_updated = copy.deepcopy(kwargs_source)
     sourceModel = LightModel(kwargs_options.get('source_light_model_list', ['NONE']))
     kwargs_source_updated = sourceModel.re_normalize_flux(kwargs_source_updated, norm_factor_source)
     return kwargs_source_updated
コード例 #2
0
class TestLightModel(object):
    """
    tests the source model routines
    """

    def setup(self):
        self.light_model_list = ['GAUSSIAN', 'MULTI_GAUSSIAN', 'SERSIC', 'SERSIC_ELLIPSE', 'DOUBLE_SERSIC',
                                 'CORE_SERSIC', 'DOUBLE_CORE_SERSIC', 'BULDGE_DISK', 'SHAPELETS', 'HERNQUIST',
                                 'HERNQUIST_ELLIPSE', 'PJAFFE', 'PJAFFE_ELLIPSE', 'UNIFORM', 'NONE'
                                 ]
        self.kwargs = [
            {'amp': 1., 'sigma_x': 1, 'sigma_y': 1., 'center_x': 0, 'center_y': 0},  # 'GAUSSIAN'
            {'amp': [1., 2], 'sigma': [1, 3], 'center_x': 0, 'center_y': 0},  # 'MULTI_GAUSSIAN'
            {'I0_sersic': 1, 'R_sersic': 0.5, 'n_sersic': 1, 'center_x': 0, 'center_y': 0},  # 'SERSIC'
            {'I0_sersic': 1, 'R_sersic': 0.5, 'n_sersic': 1, 'q': 0.8, 'phi_G': 0.5, 'center_x': 0, 'center_y': 0},  # 'SERSIC_ELLIPSE'
            {'I0_sersic': 1, 'R_sersic': 0.5, 'n_sersic': 1, 'q': 0.8, 'phi_G': 0.5, 'center_x': 0, 'center_y': 0,
             'I0_2': 1, 'R_2': 0.05, 'n_2': 2, 'phi_G_2': 0, 'q_2': 1},  # 'DOUBLE_SERSIC'
            {'I0_sersic': 1, 'R_sersic': 0.5, 'Re': 0.1, 'gamma': 2., 'n_sersic': 1, 'q': 0.8, 'phi_G': 0.5, 'center_x': 0, 'center_y': 0},
            # 'CORE_SERSIC'
            {'I0_sersic': 1, 'R_sersic': 0.5, 'Re': 0.1, 'gamma': 2., 'n_sersic': 1, 'q': 0.8, 'phi_G': 0.5,
             'center_x': 0, 'center_y': 0, 'I0_2': 1, 'R_2': 0.05, 'n_2': 2, 'phi_G_2': 0, 'q_2': 1},
            # 'DOUBLE_CORE_SERSIC'
            {'I0_b': 1, 'R_b': 0.1, 'phi_G_b': 0, 'q_b': 1, 'I0_d': 2, 'R_d': 1, 'phi_G_d': 0.5, 'q_d': 0.7, 'center_x': 0, 'center_y': 0},  # BULDGE_DISK
            {'amp': [1, 1, 1], 'beta': 0.5, 'n_max': 1, 'center_x': 0, 'center_y': 0},  # 'SHAPELETS'
            {'sigma0': 1, 'Rs': 0.5, 'center_x': 0, 'center_y': 0},  # 'HERNQUIST'
            {'sigma0': 1, 'Rs': 0.5, 'center_x': 0, 'center_y': 0, 'q': 0.8, 'phi_G': 0},  # 'HERNQUIST_ELLIPSE'
            {'sigma0': 1, 'Ra': 1, 'Rs': 0.5, 'center_x': 0, 'center_y': 0},  # 'PJAFFE'
            {'sigma0': 1, 'Ra': 1, 'Rs': 0.5, 'center_x': 0, 'center_y': 0, 'q': 0.8, 'phi_G': 0},  # 'PJAFFE_ELLIPSE'
            {'mean': 1},  # 'UNIFORM'
            {}]# 'NONE'

        self.LightModel = LightModel(light_model_list=self.light_model_list)

    def test_init(self):
        model_list = ['CORE_SERSIC', 'DOUBLE_CORE_SERSIC', 'BULDGE_DISK', 'SHAPELETS', 'UNIFORM']
        lightModel = LightModel(light_model_list=model_list)
        assert len(lightModel.profile_type_list) == len(model_list)

    def test_surface_brightness(self):
        output = self.LightModel.surface_brightness(x=1, y=1, kwargs_list=self.kwargs)
        npt.assert_almost_equal(output, 2.544428612985992, decimal=6)

    def test_surface_brightness_array(self):
        output = self.LightModel.surface_brightness(x=[1], y=[1], kwargs_list=self.kwargs)
        npt.assert_almost_equal(output[0], 2.544428612985992, decimal=6)

    def test_functions_split(self):
        output = self.LightModel.functions_split(x=1., y=1., kwargs_list=self.kwargs)
        assert output[0][0] == 0.058549831524319168

    def test_re_normalize_flux(self):
        kwargs_out = self.LightModel.re_normalize_flux(kwargs_list=self.kwargs, norm_factor=2)
        assert kwargs_out[0]['amp'] == 2 * self.kwargs[0]['amp']
コード例 #3
0
 def normalize_flux(self, kwargs_options, kwargs_source, kwargs_lens_light, kwargs_ps, norm_factor_source=1, norm_factor_lens_light=1, norm_factor_point_source=1.):
     """
     multiplies the surface brightness amplitudes with a norm_factor
     aim: mimic different telescopes photon collection area or colours for different imaging bands
     :param kwargs_source:
     :param kwargs_lens_light:
     :param norm_factor:
     :return:
     """
     lensLightModel = LightModel(kwargs_options.get('lens_light_model_list', ['NONE']))
     sourceModel = LightModel(kwargs_options.get('source_light_model_list', ['NONE']))
     lensModel = LensModel(lens_model_list=kwargs_options.get('lens_model_list', ['NONE']))
     pointSource = PointSource(point_source_type_list=kwargs_options.get('point_source_list', ['NONE']),
                                       lensModel=lensModel, fixed_magnification_list=kwargs_options.get('fixed_magnification_list', [False]),
                                    additional_images_list=kwargs_options.get('additional_images_list', [False]))
     kwargs_source_updated = copy.deepcopy(kwargs_source)
     kwargs_lens_light_updated = copy.deepcopy(kwargs_lens_light)
     kwargs_ps_updated = copy.deepcopy(kwargs_ps)
     kwargs_source_updated = sourceModel.re_normalize_flux(kwargs_source_updated, norm_factor_source)
     kwargs_lens_light_updated = lensLightModel.re_normalize_flux(kwargs_lens_light_updated, norm_factor_lens_light)
     kwargs_ps_updated = pointSource.re_normalize_flux(kwargs_ps_updated, norm_factor_point_source)
     return kwargs_source_updated, kwargs_lens_light_updated, kwargs_ps_updated
コード例 #4
0
class TestLightModel(object):
    """
    tests the source model routines
    """
    def setup(self):
        self.light_model_list = [
            'GAUSSIAN', 'MULTI_GAUSSIAN', 'SERSIC', 'SERSIC_ELLIPSE',
            'CORE_SERSIC', 'SHAPELETS', 'HERNQUIST', 'HERNQUIST_ELLIPSE',
            'PJAFFE', 'PJAFFE_ELLIPSE', 'UNIFORM', 'POWER_LAW', 'NIE',
            'INTERPOL', 'SHAPELETS_POLAR_EXP'
        ]
        phi_G, q = 0.5, 0.8
        e1, e2 = param_util.phi_q2_ellipticity(phi_G, q)
        self.kwargs = [
            {
                'amp': 1.,
                'sigma_x': 1,
                'sigma_y': 1.,
                'center_x': 0,
                'center_y': 0
            },  # 'GAUSSIAN'
            {
                'amp': [1., 2],
                'sigma': [1, 3],
                'center_x': 0,
                'center_y': 0
            },  # 'MULTI_GAUSSIAN'
            {
                'amp': 1,
                'R_sersic': 0.5,
                'n_sersic': 1,
                'center_x': 0,
                'center_y': 0
            },  # 'SERSIC'
            {
                'amp': 1,
                'R_sersic': 0.5,
                'n_sersic': 1,
                'e1': e1,
                'e2': e2,
                'center_x': 0,
                'center_y': 0
            },  # 'SERSIC_ELLIPSE'
            {
                'amp': 1,
                'R_sersic': 0.5,
                'Re': 0.1,
                'gamma': 2.,
                'n_sersic': 1,
                'e1': e1,
                'e2': e2,
                'center_x': 0,
                'center_y': 0
            },
            # 'CORE_SERSIC'
            {
                'amp': [1, 1, 1],
                'beta': 0.5,
                'n_max': 1,
                'center_x': 0,
                'center_y': 0
            },  # 'SHAPELETS'
            {
                'amp': 1,
                'Rs': 0.5,
                'center_x': 0,
                'center_y': 0
            },  # 'HERNQUIST'
            {
                'amp': 1,
                'Rs': 0.5,
                'center_x': 0,
                'center_y': 0,
                'e1': e1,
                'e2': e2
            },  # 'HERNQUIST_ELLIPSE'
            {
                'amp': 1,
                'Ra': 1,
                'Rs': 0.5,
                'center_x': 0,
                'center_y': 0
            },  # 'PJAFFE'
            {
                'amp': 1,
                'Ra': 1,
                'Rs': 0.5,
                'center_x': 0,
                'center_y': 0,
                'e1': e1,
                'e2': e2
            },  # 'PJAFFE_ELLIPSE'
            {
                'amp': 1
            },  # 'UNIFORM'
            {
                'amp': 1.,
                'gamma': 2.,
                'e1': e1,
                'e2': e2,
                'center_x': 0,
                'center_y': 0
            },  # 'POWER_LAW'
            {
                'amp': .001,
                'e1': 0,
                'e2': 1.,
                'center_x': 0,
                'center_y': 0,
                's_scale': 1.
            },  # 'NIE'
            {
                'image': np.zeros((10, 10)),
                'scale': 1,
                'phi_G': 0,
                'center_x': 0,
                'center_y': 0
            },
            {
                'amp': [1],
                'n_max': 0,
                'beta': 1,
                'center_x': 0,
                'center_y': 0
            }
        ]

        self.LightModel = LightModel(light_model_list=self.light_model_list)

    def test_init(self):
        model_list = [
            'CORE_SERSIC', 'SHAPELETS', 'SHAPELETS_POLAR',
            'SHAPELETS_POLAR_EXP', 'UNIFORM', 'CHAMELEON', 'DOUBLE_CHAMELEON',
            'TRIPLE_CHAMELEON'
        ]
        lightModel = LightModel(light_model_list=model_list)
        assert len(lightModel.profile_type_list) == len(model_list)

    def test_surface_brightness(self):
        output = self.LightModel.surface_brightness(x=1,
                                                    y=1,
                                                    kwargs_list=self.kwargs)
        npt.assert_almost_equal(output, 3.7065728131855824, decimal=6)

    def test_surface_brightness_array(self):
        output = self.LightModel.surface_brightness(x=[1],
                                                    y=[1],
                                                    kwargs_list=self.kwargs)
        npt.assert_almost_equal(output[0], 3.7065728131855824, decimal=6)

    def test_functions_split(self):
        output = self.LightModel.functions_split(x=1.,
                                                 y=1.,
                                                 kwargs_list=self.kwargs)
        npt.assert_almost_equal(output[0][0], 0.058549831524319168, decimal=6)

    def test_re_normalize_flux(self):
        kwargs_out = self.LightModel.re_normalize_flux(kwargs_list=self.kwargs,
                                                       norm_factor=2)
        assert kwargs_out[0]['amp'] == 2 * self.kwargs[0]['amp']

    def test_param_name_list(self):
        param_name_list = self.LightModel.param_name_list()
        assert len(self.light_model_list) == len(param_name_list)

    def test_num_param_linear(self):
        num = self.LightModel.num_param_linear(self.kwargs, list_return=False)
        assert num == 18

        num_list = self.LightModel.num_param_linear(self.kwargs,
                                                    list_return=True)
        assert num_list[0] == 1

    def test_update_linear(self):
        response, n = self.LightModel.functions_split(1, 1, self.kwargs)
        param = np.ones(n) * 2
        kwargs_out, i = self.LightModel.update_linear(param,
                                                      i=0,
                                                      kwargs_list=self.kwargs)
        assert i == n
        assert kwargs_out[0]['amp'] == 2

    def test_total_flux(self):
        light_model_list = [
            'SERSIC', 'SERSIC_ELLIPSE', 'INTERPOL', 'GAUSSIAN',
            'GAUSSIAN_ELLIPSE', 'MULTI_GAUSSIAN', 'MULTI_GAUSSIAN_ELLIPSE'
        ]
        kwargs_list = [
            {
                'amp': 1,
                'R_sersic': 0.5,
                'n_sersic': 1,
                'center_x': 0,
                'center_y': 0
            },  # 'SERSIC'
            {
                'amp': 1,
                'R_sersic': 0.5,
                'n_sersic': 1,
                'e1': 0.1,
                'e2': 0,
                'center_x': 0,
                'center_y': 0
            },  # 'SERSIC_ELLIPSE'
            {
                'image': np.ones((10, 10)),
                'scale': 1,
                'phi_G': 0,
                'center_x': 0,
                'center_y': 0
            },  # 'INTERPOL'
            {
                'amp': 2,
                'sigma_x': 2,
                'sigma_y': 1,
                'center_x': 0,
                'center_y': 0
            },  # 'GAUSSIAN'
            {
                'amp': 2,
                'sigma': 2,
                'e1': 0.1,
                'e2': 0,
                'center_x': 0,
                'center_y': 0
            },  # 'GAUSSIAN_ELLIPSE'
            {
                'amp': [1, 1],
                'sigma': [2, 1],
                'center_x': 0,
                'center_y': 0
            },  # 'MULTI_GAUSSIAN'
            {
                'amp': [1, 1],
                'sigma': [2, 1],
                'e1': 0.1,
                'e2': 0,
                'center_x': 0,
                'center_y': 0
            }  # 'MULTI_GAUSSIAN_ELLIPSE'
        ]
        lightModel = LightModel(light_model_list=light_model_list)
        total_flux_list = lightModel.total_flux(kwargs_list)
        assert total_flux_list[2] == 100
        assert total_flux_list[3] == 2
        assert total_flux_list[4] == 2
        assert total_flux_list[5] == 2
        assert total_flux_list[6] == 2

        total_flux_list = lightModel.total_flux(kwargs_list, norm=True)
        assert total_flux_list[2] == 100
        assert total_flux_list[3] == 1
        assert total_flux_list[4] == 1
        assert total_flux_list[5] == 2
        assert total_flux_list[6] == 2
コード例 #5
0
class TestLightModel(object):
    """
    tests the source model routines
    """
    def setup(self):
        self.light_model_list = [
            'GAUSSIAN', 'MULTI_GAUSSIAN', 'SERSIC', 'SERSIC_ELLIPSE',
            'CORE_SERSIC', 'SHAPELETS', 'HERNQUIST', 'HERNQUIST_ELLIPSE',
            'PJAFFE', 'PJAFFE_ELLIPSE', 'UNIFORM', 'POWER_LAW', 'NIE'
        ]
        phi_G, q = 0.5, 0.8
        e1, e2 = param_util.phi_q2_ellipticity(phi_G, q)
        self.kwargs = [
            {
                'amp': 1.,
                'sigma_x': 1,
                'sigma_y': 1.,
                'center_x': 0,
                'center_y': 0
            },  # 'GAUSSIAN'
            {
                'amp': [1., 2],
                'sigma': [1, 3],
                'center_x': 0,
                'center_y': 0
            },  # 'MULTI_GAUSSIAN'
            {
                'amp': 1,
                'R_sersic': 0.5,
                'n_sersic': 1,
                'center_x': 0,
                'center_y': 0
            },  # 'SERSIC'
            {
                'amp': 1,
                'R_sersic': 0.5,
                'n_sersic': 1,
                'e1': e1,
                'e2': e2,
                'center_x': 0,
                'center_y': 0
            },  # 'SERSIC_ELLIPSE'
            {
                'amp': 1,
                'R_sersic': 0.5,
                'Re': 0.1,
                'gamma': 2.,
                'n_sersic': 1,
                'e1': e1,
                'e2': e2,
                'center_x': 0,
                'center_y': 0
            },
            # 'CORE_SERSIC'
            {
                'amp': [1, 1, 1],
                'beta': 0.5,
                'n_max': 1,
                'center_x': 0,
                'center_y': 0
            },  # 'SHAPELETS'
            {
                'amp': 1,
                'Rs': 0.5,
                'center_x': 0,
                'center_y': 0
            },  # 'HERNQUIST'
            {
                'amp': 1,
                'Rs': 0.5,
                'center_x': 0,
                'center_y': 0,
                'e1': e1,
                'e2': e2
            },  # 'HERNQUIST_ELLIPSE'
            {
                'amp': 1,
                'Ra': 1,
                'Rs': 0.5,
                'center_x': 0,
                'center_y': 0
            },  # 'PJAFFE'
            {
                'amp': 1,
                'Ra': 1,
                'Rs': 0.5,
                'center_x': 0,
                'center_y': 0,
                'e1': e1,
                'e2': e2
            },  # 'PJAFFE_ELLIPSE'
            {
                'amp': 1
            },  # 'UNIFORM'
            {
                'amp': 1.,
                'gamma': 2.,
                'e1': e1,
                'e2': e2,
                'center_x': 0,
                'center_y': 0
            },  # 'POWER_LAW'
            {
                'amp': .001,
                'e1': 0,
                'e2': 1.,
                'center_x': 0,
                'center_y': 0,
                's_scale': 1.
            },  # 'NIE'
        ]

        self.LightModel = LightModel(light_model_list=self.light_model_list)

    def test_init(self):
        model_list = [
            'CORE_SERSIC', 'SHAPELETS', 'UNIFORM', 'CHAMELEON',
            'DOUBLE_CHAMELEON'
        ]
        lightModel = LightModel(light_model_list=model_list)
        assert len(lightModel.profile_type_list) == len(model_list)

    def test_surface_brightness(self):
        output = self.LightModel.surface_brightness(x=1,
                                                    y=1,
                                                    kwargs_list=self.kwargs)
        npt.assert_almost_equal(output, 3.512593731652167, decimal=6)

    def test_surface_brightness_array(self):
        output = self.LightModel.surface_brightness(x=[1],
                                                    y=[1],
                                                    kwargs_list=self.kwargs)
        npt.assert_almost_equal(output[0], 3.512593731652167, decimal=6)

    def test_functions_split(self):
        output = self.LightModel.functions_split(x=1.,
                                                 y=1.,
                                                 kwargs_list=self.kwargs)
        npt.assert_almost_equal(output[0][0], 0.058549831524319168, decimal=6)

    def test_re_normalize_flux(self):
        kwargs_out = self.LightModel.re_normalize_flux(kwargs_list=self.kwargs,
                                                       norm_factor=2)
        assert kwargs_out[0]['amp'] == 2 * self.kwargs[0]['amp']

    def test_param_name_list(self):
        param_name_list = self.LightModel.param_name_list()
        assert len(self.light_model_list) == len(param_name_list)

    def test_update_linear(self):
        response, n = self.LightModel.functions_split(1, 1, self.kwargs)
        param = np.ones(n) * 2
        kwargs_out, i = self.LightModel.update_linear(param,
                                                      i=0,
                                                      kwargs_list=self.kwargs)
        assert i == n
        assert kwargs_out[0]['amp'] == 2