Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.kwargs_lens = [kwargs_spemd]
lens_model_class = LensModel(lens_model_list=lens_model_list)
kwargs_sersic = {'amp': 1., 'R_sersic': 0.1, 'n_sersic': 2, 'center_x': 0, 'center_y': 0}
# 'SERSIC_ELLIPSE': elliptical Sersic profile
kwargs_sersic_ellipse = {'amp': 1., 'R_sersic': .6, 'n_sersic': 3, 'center_x': 0, 'center_y': 0,
'e1': 0.1, 'e2': 0.1}
lens_light_model_list = ['SERSIC']
self.kwargs_lens_light = [kwargs_sersic]
lens_light_model_class = LightModel(light_model_list=lens_light_model_list)
source_model_list = ['SERSIC_ELLIPSE']
self.kwargs_source = [kwargs_sersic_ellipse]
source_model_class = LightModel(light_model_list=source_model_list)
kwargs_numerics = {'supersampling_factor': 1, 'supersampling_convolution': False, 'compute_mode': 'regular'}
imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class,
lens_light_model_class, kwargs_numerics=kwargs_numerics)
image_sim = sim_util.simulate_simple(imageModel, self.kwargs_lens, self.kwargs_source,
self.kwargs_lens_light)
data_class.update_data(image_sim)
kwargs_data['image_data'] = image_sim
kwargs_data_joint = {'multi_band_list': [[kwargs_data, kwargs_psf, kwargs_numerics]], 'multi_band_type': 'single-band'}
self.data_class = data_class
self.psf_class = psf_class
kwargs_model = {'lens_model_list': lens_model_list,
'source_light_model_list': source_model_list,
'lens_light_model_list': lens_light_model_list,
'fixed_magnification_list': [False],
}
self.kwargs_numerics = {
kwargs_spemd = {'theta_E': 1., 'gamma': 1.95, 'center_x': 0, 'center_y': 0, 'e1': 0.1, 'e2': 0.1}
self.kwargs_lens = [kwargs_spemd]
kwargs_sersic = {'amp': 1/0.05**2., 'R_sersic': 0.1, 'n_sersic': 2, 'center_x': 0, 'center_y': 0}
# 'SERSIC_ELLIPSE': elliptical Sersic profile
kwargs_sersic_ellipse = {'amp': 1., 'R_sersic': .6, 'n_sersic': 3, 'center_x': 0, 'center_y': 0,
'e1': 0.1, 'e2': 0.1}
self.kwargs_lens_light = [kwargs_sersic]
self.kwargs_source = [kwargs_sersic_ellipse]
self.kwargs_ps = [{'ra_source': 0.55, 'dec_source': 0.02,
'source_amp': 1.}] # quasar point source position in the source plane and intrinsic brightness
self.kwargs_cosmo = {'D_dt': 1000}
kwargs_numerics = {'supersampling_factor': 1, 'supersampling_convolution': False}
lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances(**kwargs_model)
imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class,
lens_light_model_class, point_source_class, extinction_class, kwargs_numerics=kwargs_numerics)
image_sim = sim_util.simulate_simple(imageModel, self.kwargs_lens, self.kwargs_source,
self.kwargs_lens_light, self.kwargs_ps)
ra_pos, dec_pos = imageModel.PointSource.image_position(kwargs_ps=self.kwargs_ps, kwargs_lens=self.kwargs_lens)
data_class.update_data(image_sim)
kwargs_band['image_data'] = image_sim
self.data_class = data_class
self.psf_class = psf_class
self.kwargs_model = kwargs_model
self.kwargs_numerics = {
'supersampling_factor': 1,
'supersampling_convolution': False}
kwargs_constraints = {
kwargs_likelihood = {'force_minimum_source_surface_brightness': True}
kwargs_model = {'source_light_model_list': ['SERSIC']}
kwargs_constraints = {}
param_class = Param(kwargs_model, **kwargs_constraints)
kwargs_data = sim_util.data_configure_simple(numPix=10, deltaPix=0.1, exposure_time=1, background_rms=0.1)
data_class = ImageData(**kwargs_data)
kwargs_psf = {'psf_type': 'NONE'}
psf_class = PSF(**kwargs_psf)
kwargs_sersic = {'amp': -1., 'R_sersic': 0.1, 'n_sersic': 2, 'center_x': 0, 'center_y': 0}
source_model_list = ['SERSIC']
kwargs_source = [kwargs_sersic]
source_model_class = LightModel(light_model_list=source_model_list)
imageModel = ImageModel(data_class, psf_class, lens_model_class=None, source_model_class=source_model_class)
image_sim = sim_util.simulate_simple(imageModel, [], kwargs_source)
kwargs_data['image_data'] = image_sim
kwargs_data_joint = {'multi_band_list': [[kwargs_data, kwargs_psf, {}]], 'multi_band_type': 'single-band'}
likelihood = LikelihoodModule(kwargs_data_joint=kwargs_data_joint, kwargs_model=kwargs_model, param_class=param_class, **kwargs_likelihood)
logL = likelihood.logL(args=param_class.kwargs2args(kwargs_source=kwargs_source), verbose=True)
assert logL <= -10**10
# initialize data
numPix = 100
deltaPix = 0.05
kwargs_data = sim_util.data_configure_simple(numPix, deltaPix, exposure_time=1, background_rms=1)
data_class = ImageData(**kwargs_data)
kernel = np.zeros((5, 5))
kernel[2, 2] = 1
kwargs_psf = {'kernel_point_source': kernel, 'psf_type': 'PIXEL', 'psf_error_map': np.ones_like(kernel) * 0.001}
psf_class = PSF(**kwargs_psf)
lens_model_class = LensModel(['SPEP'])
source_model_class = LightModel([])
lens_light_model_class = LightModel([])
kwargs_numerics = {'supersampling_factor': 2, 'supersampling_convolution': True, 'point_source_supersampling_factor': 1}
point_source_class = PointSource(point_source_type_list=['LENSED_POSITION'], fixed_magnification_list=[False])
makeImage = ImageModel(data_class, psf_class, lens_model_class, source_model_class, lens_light_model_class, point_source_class, kwargs_numerics=kwargs_numerics)
# chose point source positions
x_pix = np.array([10, 5, 10, 90])
y_pix = np.array([40, 50, 60, 50])
ra_pos, dec_pos = makeImage.Data.map_pix2coord(x_pix, y_pix)
e1, e2 = param_util.phi_q2_ellipticity(0, 0.8)
kwargs_lens_init = [{'theta_E': 1, 'gamma': 2, 'e1': e1, 'e2': e2, 'center_x': 0, 'center_y': 0}]
kwargs_else = [{'ra_image': ra_pos, 'dec_image': dec_pos, 'point_amp': np.ones_like(ra_pos)}]
image = makeImage.image(kwargs_lens_init, kwargs_source={}, kwargs_lens_light={}, kwargs_ps=kwargs_else)
#print(np.shape(model), 'test')
#image = makeImage.ImageNumerics.array2image(model)
for i in range(len(x_pix)):
npt.assert_almost_equal(image[y_pix[i], x_pix[i]], 1, decimal=2)
x_pix = np.array([10.5, 5.5, 10.5, 90.5])
y_pix = np.array([40, 50, 60, 50])
ra_pos, dec_pos = makeImage.Data.map_pix2coord(x_pix, y_pix)
# make instance of the PixelGrid class
from lenstronomy.Data.pixel_grid import PixelGrid
kwargs_grid = {'nx': numPix, 'ny': numPix, 'transform_pix2angle': Mpix2coord, 'ra_at_xy_0': ra_at_xy_0,
'dec_at_xy_0': dec_at_xy_0}
self.pixel_grid = PixelGrid(**kwargs_grid)
# make instance of the PSF class
from lenstronomy.Data.psf import PSF
kwargs_psf = {'psf_type': 'PIXEL', 'kernel_point_source': kernel_super,
'point_source_supersampling_factor': self._supersampling_factor}
self.psf_class = PSF(**kwargs_psf)
# without convolution
image_model_true = ImageModel(self.pixel_grid, self.psf_class, lens_light_model_class=self.lightModel,
kwargs_numerics=self.kwargs_numerics_true)
self.image_true = image_model_true.image(kwargs_lens_light=self.kwargs_light)
phi, q = 0.2, 0.9
e1, e2 = param_util.phi_q2_ellipticity(phi, q)
kwargs_sersic_ellipse = {'amp': 1., 'R_sersic': .6, 'n_sersic': 7, 'center_x': 0, 'center_y': 0,
'e1': e1, 'e2': e2}
lens_light_model_list = ['SERSIC']
self.kwargs_lens_light = [kwargs_sersic]
lens_light_model_class = LightModel(light_model_list=lens_light_model_list)
source_model_list = ['SERSIC_ELLIPSE']
self.kwargs_source = [kwargs_sersic_ellipse]
source_model_class = LightModel(light_model_list=source_model_list)
self.kwargs_ps = [{'ra_source': 0.0001, 'dec_source': 0.0,
'source_amp': 1.}] # quasar point source position in the source plane and intrinsic brightness
point_source_class = PointSource(point_source_type_list=['SOURCE_POSITION'], fixed_magnification_list=[True])
kwargs_numerics = {'subgrid_res': 2, 'psf_subgrid': True}
imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class, lens_light_model_class,
point_source_class, kwargs_numerics=kwargs_numerics)
image_sim = sim_util.simulate_simple(imageModel, self.kwargs_lens, self.kwargs_source,
self.kwargs_lens_light, self.kwargs_ps)
data_class.update_data(image_sim)
kwargs_data['image_data'] = image_sim
self.solver = LensEquationSolver(lensModel=lens_model_class)
idex_lens_1 = [0, 1]
idex_lens_2 = [2, 3]
multi_band_list = [[kwargs_data, kwargs_psf, kwargs_numerics, {'index_lens_model_list': idex_lens_1}], [kwargs_data, kwargs_psf, kwargs_numerics, {'index_lens_model_list': idex_lens_2}]]
lens_model_list_joint = lens_model_list + lens_model_list
self.kwargs_lens_joint = self.kwargs_lens + self.kwargs_lens
self.imageModel = MultiFrame(multi_band_list, lens_model_list_joint, source_model_class, lens_light_model_class, point_source_class)
self.kwargs_lens = [kwargs_spemd]
lens_model_class = LensModel(lens_model_list=lens_model_list)
kwargs_sersic = {'amp': 1., 'R_sersic': 0.1, 'n_sersic': 2, 'center_x': 0, 'center_y': 0}
# 'SERSIC_ELLIPSE': elliptical Sersic profile
kwargs_sersic_ellipse = {'amp': 1., 'R_sersic': .6, 'n_sersic': 3, 'center_x': 0, 'center_y': 0,
'e1': 0.1, 'e2': 0.1}
lens_light_model_list = ['SERSIC']
self.kwargs_lens_light = [kwargs_sersic]
lens_light_model_class = LightModel(light_model_list=lens_light_model_list)
source_model_list = ['SERSIC_ELLIPSE']
self.kwargs_source = [kwargs_sersic_ellipse]
source_model_class = LightModel(light_model_list=source_model_list)
kwargs_numerics = {'supersampling_factor': 1, 'supersampling_convolution': False, 'compute_mode': 'regular'}
imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class,
lens_light_model_class, kwargs_numerics=kwargs_numerics)
image_sim = sim_util.simulate_simple(imageModel, self.kwargs_lens, self.kwargs_source,
self.kwargs_lens_light)
data_class.update_data(image_sim)
kwargs_data['image_data'] = image_sim
kwargs_data_joint = {'multi_band_list': [[kwargs_data, kwargs_psf, kwargs_numerics]], 'multi_band_type': 'single-band'}
self.data_class = data_class
self.psf_class = psf_class
kwargs_model = {'lens_model_list': lens_model_list,
'source_light_model_list': source_model_list,
'lens_light_model_list': lens_light_model_list,
'fixed_magnification_list': [False],
}
self.kwargs_numerics = {
def test_extinction_map(self):
kwargs_data = sim_util.data_configure_simple(numPix=10, deltaPix=1, exposure_time=1, background_rms=1)
data_class = ImageData(**kwargs_data)
extinction_class = DifferentialExtinction(optical_depth_model=['UNIFORM'], tau0_index=0)
imageModel = ImageModel(data_class, PSF(), extinction_class=extinction_class)
extinction = imageModel.extinction_map(kwargs_extinction=[{'amp': 1}], kwargs_special={'tau0_list': [1, 0, 0]})
npt.assert_almost_equal(extinction, np.exp(-1))
:return:
"""
lensLightModel = LightModel(kwargs_options.get('lens_light_model_list', []))
sourceModel = LightModel(kwargs_options.get('source_light_model_list', []))
lensModel = LensModel(lens_model_list=kwargs_options.get('lens_model_list', []))
pointSource = PointSource(point_source_type_list=kwargs_options.get('point_source_list', []),
lensModel=lensModel,
fixed_magnification_list=kwargs_options.get('fixed_magnification_list', None),
additional_images_list=kwargs_options.get('additional_images', None))
norm_factor_source = self._flux_calibration_factor * source_colour
norm_factor_lens_light = self._flux_calibration_factor * lens_colour
norm_factor_point_source = self._flux_calibration_factor * quasar_colour
kwargs_source_updated, kwargs_lens_light_updated, kwargs_else_updated = self.simulation.normalize_flux(kwargs_options, kwargs_source, kwargs_lens_light, kwargs_else, norm_factor_source,
norm_factor_lens_light, norm_factor_point_source)
imageModel = ImageModel(self._data, self._psf, lensModel, sourceModel, lensLightModel, pointSource, kwargs_numerics={})
image = self.simulation.simulate(imageModel, kwargs_lens, kwargs_source_updated, kwargs_lens_light_updated, kwargs_else_updated, no_noise=no_noise, source_add=source_add, lens_light_add=lens_light_add, point_source_add=point_source_add)
return image
:param kwargs_else:
:return:
"""
subgrid_res = kwargs_options['subgrid_res']
num_order = kwargs_options.get('shapelet_order', 0)
image = []
residuals = []
for i in range(self.num_bands(kwargs_data)):
kwargs_data_i = kwargs_data[i]
kwargs_psf_i = kwargs_psf["image"+str(i+1)]
param_i = param[i]
deltaPix = kwargs_data_i['deltaPix']
x_grid, y_grid = kwargs_data_i['x_coords'], kwargs_data_i['y_coords']
x_grid_sub, y_grid_sub = util.make_subgrid(x_grid, y_grid, subgrid_res)
numPix = len(kwargs_data_i['image_data'])
makeImage = ImageModel(kwargs_options, kwargs_data_i)
image_i, error_map = makeImage.make_image_with_params(x_grid_sub, y_grid_sub, kwargs_lens, kwargs_source, kwargs_psf_i,
kwargs_lens_light,
kwargs_else, numPix, deltaPix, subgrid_res, param_i, num_order)
residuals_i = util.image2array(makeImage.reduced_residuals(image_i, error_map))
residuals.append(residuals_i)
if add_noise:
image_i = makeImage.add_noise2image(image_i)
image.append(image_i)
return image, residuals