Ejemplo n.º 1
0
    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': 2, '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
Ejemplo n.º 2
0
def getAmp_lenstronomy(SERSIC_in_mag, zp=None):
    kwargs_lens_light = [{
        'amp':
        1,
        'R_sersic':
        SERSIC_in_mag['R_sersic'] / np.sqrt(SERSIC_in_mag['q']),
        'n_sersic':
        SERSIC_in_mag['n_sersic'],
        'center_x':
        0.0,
        'center_y':
        0.0,
        'e1':
        SERSIC_in_mag['e1'],
        'e2':
        SERSIC_in_mag['e2']
    }]
    from lenstronomy.LightModel.light_model import LightModel
    light = LightModel(['SERSIC_ELLIPSE'])
    total_flux = light.total_flux(kwargs_lens_light)[
        0]  #The total flux for each sersic components as list
    mag = SERSIC_in_mag['mag_sersic']
    cnts = 10.**(-0.4 * (mag - zp))
    amp = cnts / total_flux
    return amp
Ejemplo n.º 3
0
 def test_raise(self):
     with self.assertRaises(ValueError):
         lighModel = LightModel(light_model_list=['WRONG'])
     with self.assertRaises(ValueError):
         lighModel = LightModel(light_model_list=['UNIFORM'])
         lighModel.light_3d(r=1, kwargs_list=[{'amp': 1}])
     with self.assertRaises(ValueError):
         lighModel = LightModel(light_model_list=['UNIFORM'])
         lighModel.profile_type_list = ['WRONG']
         lighModel.functions_split(x=0, y=0, kwargs_list=[{}])
     with self.assertRaises(ValueError):
         lighModel = LightModel(light_model_list=['UNIFORM'])
         lighModel.profile_type_list = ['WRONG']
         lighModel.num_param_linear(kwargs_list=[{}])
     with self.assertRaises(ValueError):
         lighModel = LightModel(light_model_list=['UNIFORM'])
         lighModel.profile_type_list = ['WRONG']
         lighModel.update_linear(param=[1], i=0, kwargs_list=[{}])
     with self.assertRaises(ValueError):
         lighModel = LightModel(light_model_list=['UNIFORM'])
         lighModel.profile_type_list = ['WRONG']
         lighModel.total_flux(kwargs_list=[{}])
Ejemplo n.º 4
0
def model_flux_cal(params_list, model_list=None):
    """
    Calculate the flux of a Sersic (i.e., itergral to infinite) which is same defination as Galfit.
    
    Parameter
    --------
        params_list: 
            a list of (Sersic) Soure params defined by Lenstronomy.
            
        model_list: 
            a list of names of light profile model.
        
    Return
    --------
        The flux value of Sersic.
    """
    from lenstronomy.LightModel.light_model import LightModel
    if model_list is None:
        model_list = ['SERSIC_ELLIPSE'] * len(params_list)
    light = LightModel(model_list)
    flux = light.total_flux(params_list)
    return flux
Ejemplo n.º 5
0
    lens_light_tran_Reff=lens_light_para['R_sersic']/np.sqrt(lens_light_para['q'])  #!!!
    #lens_light_tran_Reff = 1.1
    lens_light_para['e1'], lens_light_para['e2'] = param_util.phi_q2_ellipticity(phi=lens_light_para['phi_G'], q=lens_light_para['q'])
    
    lens_amp=mva.getAmp_lenstronomy(SERSIC_in_mag=lens_light_para,zp=zp)
    lens_light_para['amp_sersic']=lens_amp
    lens_light_model_list = ['SERSIC_ELLIPSE']
    kwargs_lens_light = {'amp':lens_light_para['amp_sersic'], 'R_sersic': lens_light_tran_Reff, 'n_sersic': lens_light_para['n_sersic'],
    					  'center_x': 0.0, 'center_y': 0.0, 'e1':lens_light_para['e1'], 'e2':lens_light_para['e2']}
    kwargs_lens_light_copy = copy.deepcopy(kwargs_lens_light)
    kwargs_lens_light_copy['phi_G'] =  lens_light_para['phi_G']
    kwargs_lens_light_copy['q'] =  lens_light_para['q']
    
    lens_light_para['amp_sersic'] = 1
    light = LightModel(['SERSIC_ELLIPSE'])
    total_flux_testamp1 = light.total_flux([kwargs_lens_light])  #The total flux for each sersic components as list
    flux_should = 10.**(-0.4*(lens_light_para['mag_sersic']-zp))

#%%    
    
    kwargs_lens_light_list = [kwargs_lens_light]
    lens_light_model_class = LightModel(light_model_list=lens_light_model_list)
    
    #==============================================================================
    # ##### lens mass model 
    #==============================================================================
    from lenstronomy.LensModel.lens_model import LensModel
    kwargs_spemd = para.spemd()
    
    kwargs_spemd['q'] = 0.9 + np.random.normal(0,0.01)
    kwargs_spemd['e1'], kwargs_spemd['e2'] = param_util.phi_q2_ellipticity(phi=kwargs_spemd['phi_G'], q=kwargs_spemd['q'])
Ejemplo n.º 6
0
# plt.show()

logL = modelPlot._imageModel.likelihood_data_given_model(source_marg=False,
                                                         linear_prior=None,
                                                         **kwargs_result)
n_data = modelPlot._imageModel.num_data_evaluate
print(-logL * 2 / n_data,
      'reduced X^2 of all evaluated imaging data combined.')

model, _, _, _ = modelPlot._imageModel.image_linear_solve(inv_bool=True,
                                                          **kwargs_result)
model = model[0]
data = multi_band_list[0][0]['image_data']
noise_map = multi_band_list[0][0]['noise_map']
chisq_map = (data - model)**2 / noise_map**2 * QSO_msk

plt.imshow(chisq_map, origin='lower', norm=LogNorm())
plt.colorbar()
plt.show()

print(np.average(chisq_map))
print('numbers of pixel have chisq larger than 1000:',
      chisq_map[chisq_map > 1000].shape[0])
chisq_map[chisq_map > 1000] = 1  # remove these pixels to 1
print(np.average(chisq_map))

#%%
from lenstronomy.LightModel.light_model import LightModel
light = LightModel(kwargs_model['source_light_model_list'])
total_flux = light.total_flux(kwargs_result['kwargs_source'])