def test_psf_cutout(self): idex_mask = np.zeros((5, 5)) idex_mask[3, 2] = 1 idex_mask[1, 1] = 1 image_data = np.zeros((5, 5)) image_data[1, 1] = 1 kwargs_data = {'image_data': image_data} data = Data(kwargs_data) kwargs_numerics = {'idex_mask': idex_mask} imageNumerics = ImageNumerics(data, self.PSF, **kwargs_numerics) cut_data = imageNumerics._cutout_psf(image_data, subgrid_res=1) print(cut_data) assert cut_data[0, 0] == 1 assert cut_data[2, 1] == 0 nx, ny = np.shape(cut_data) assert nx == 3 assert ny == 2 idex_mask = np.ones((5, 5)) kwargs_data = {'image_data': image_data} data = Data(kwargs_data) kwargs_numerics = {'idex_mask': idex_mask} imageNumerics = ImageNumerics(data, self.PSF, **kwargs_numerics) cut_data = imageNumerics._cutout_psf(image_data, subgrid_res=1) assert cut_data[1, 1] == 1
def test_shift_coords(self): numPix = 10 deltaPix = 0.05 x_grid, y_grid, ra_at_xy_0, dec_at_xy_0, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix = util.make_grid_with_coordtransform( numPix=numPix, deltapix=deltaPix, subgrid_res=1) # mask (1= model this pixel, 0= leave blanck) kwargs_data = { 'ra_at_xy_0': ra_at_xy_0, 'dec_at_xy_0': dec_at_xy_0, 'transform_pix2angle': Mpix2coord, 'image_data': np.ones((numPix, numPix)) } data = Data(kwargs_data) ra_shift = 0.05 dec_shift = 0. kwargs_data['ra_shift'] = ra_shift kwargs_data['dec_shift'] = dec_shift data_shift = Data(kwargs_data) ra, dec = data.map_pix2coord(1, 1) ra_new, dec_new = data_shift.map_pix2coord(1, 1) npt.assert_almost_equal(ra_new - ra, ra_shift, decimal=10) npt.assert_almost_equal(dec_new - dec, dec_shift, decimal=10) ra_2, dec_2 = data_shift.map_pix2coord(0, 1) npt.assert_almost_equal(ra, ra_2, decimal=10) npt.assert_almost_equal(dec, dec_2, decimal=10) x, y = data.map_coord2pix(0, 0) x_new, y_new = data_shift.map_coord2pix(ra_shift, dec_shift) npt.assert_almost_equal(x, x_new, decimal=10) npt.assert_almost_equal(y, y_new, decimal=10)
def setup(self): self.SimAPI = Simulation() # data specifics sigma_bkg = .05 # background noise per pixel exp_time = 100 # exposure time (arbitrary units, flux per pixel is in units #photons/exp_time unit) numPix = 100 # cutout pixel size deltaPix = 0.05 # pixel size in arcsec (area per pixel = deltaPix**2) fwhm = 0.5 # full width half max of PSF # PSF specification kwargs_data = self.SimAPI.data_configure(numPix, deltaPix, exp_time, sigma_bkg) data_class = Data(kwargs_data) kwargs_psf = self.SimAPI.psf_configure(psf_type='GAUSSIAN', fwhm=fwhm, kernelsize=31, deltaPix=deltaPix, truncate=3, kernel=None) psf_class = PSF(kwargs_psf) psf_class._psf_error_map = np.zeros_like(psf_class.kernel_point_source) # 'EXERNAL_SHEAR': external shear kwargs_shear = {'e1': 0.01, 'e2': 0.01} # gamma_ext: shear strength, psi_ext: shear angel (in radian) phi, q = 0.2, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi, q) kwargs_spemd = {'theta_E': 1., 'gamma': 1.8, 'center_x': 0, 'center_y': 0, 'e1': e1, 'e2': e2} lens_model_list = ['SPEP', 'SHEAR'] self.kwargs_lens = [kwargs_spemd, kwargs_shear] lens_model_class = LensModel(lens_model_list=lens_model_list) # list of light profiles (for lens and source) # 'SERSIC': spherical Sersic profile kwargs_sersic = {'amp': 1., 'R_sersic': 0.1, 'n_sersic': 2, 'center_x': 0, 'center_y': 0} # 'SERSIC_ELLIPSE': elliptical Sersic profile 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.01, '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 = self.SimAPI.simulate(imageModel, self.kwargs_lens, self.kwargs_source, self.kwargs_lens_light, self.kwargs_ps) data_class.update_data(image_sim) self.imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class, lens_light_model_class, point_source_class, kwargs_numerics=kwargs_numerics) self.solver = LensEquationSolver(lensModel=self.imageModel.LensModel)
def test_shift_coordinate_grid(self): x_shift = 0.05 y_shift = 0 kwargs_data_shifted = self.SimAPI.shift_coordinate_grid( self.kwargs_data, x_shift, y_shift, pixel_units=False) kwargs_data_new = copy.deepcopy(self.kwargs_data) kwargs_data_new['ra_shift'] = x_shift kwargs_data_new['dec_shift'] = y_shift data = Data(kwargs_data=kwargs_data_shifted) data_new = Data(kwargs_data=kwargs_data_new) ra, dec = 0, 0 x, y = data.map_coord2pix(ra, dec) x_new, y_new = data_new.map_coord2pix(ra, dec) npt.assert_almost_equal(x, x_new, decimal=10) npt.assert_almost_equal(y, y_new, decimal=10) ra, dec = data.map_pix2coord(x, y) ra_new, dec_new = data_new.map_pix2coord(x, y) npt.assert_almost_equal(ra, ra_new, decimal=10) npt.assert_almost_equal(dec, dec_new, decimal=10) x_coords, y_coords = data.coordinates x_coords_new, y_coords_new = data_new.coordinates npt.assert_almost_equal(x_coords[0], x_coords_new[0], decimal=10) npt.assert_almost_equal(y_coords[0], y_coords_new[0], decimal=10)
def __init__(self, collector_area, numPix, deltaPix, readout_noise, sky_brightness, extinction, exposure_time, psf_type, fwhm, *args, **kwargs): """ :param collector_area: area of collector in m^2 :param numPix: number of pixels :param deltaPix: FoV per pixel in units of arcsec :param readout_noise: rms value of readout per pixel in units of photons :param sky_brightness: number of photons of sky per area (arcsec) per time (second) for a collector area (1 m^2) :param extinction: exctinction (galactic and atmosphere combined). Only use this if magnitude calibration is done without it. :param exposure_time: exposure time (seconds) :param psf_type: :param fwhm: :param args: :param kwargs: """ self.simulation = Simulation() sky_per_pixel = sky_brightness * collector_area * deltaPix**2 # time independent noise term per pixel per second sigma_bkg = np.sqrt( readout_noise**2 + exposure_time * sky_per_pixel**2 ) / exposure_time # total Gaussian noise term per pixel in full exposure (in units of counts per second) kwargs_data = self.simulation.data_configure(numPix, deltaPix, exposure_time, sigma_bkg) self._data = Data(kwargs_data) kwargs_psf = self.simulation.psf_configure(psf_type, fwhm) self._psf = PSF(kwargs_psf) self._flux_calibration_factor = collector_area / extinction * deltaPix**2 # transforms intrinsic surface brightness per angular area into the flux normalizations per pixel
def test_point_source_rendering(self): numPix = 20 deltaPix = 0.05 ra_at_xy_0 = 0 dec_at_xy_0 = 0 kwargs_data = {'image_data': np.zeros((numPix, numPix))} data = Data(kwargs_data) kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': 1., 'point_source_subgrid': 1} psf = PSF(kwargs_psf) kwargs_numerics = {'subgrid_res': 2, 'psf_subgrid': True} imageNumerics = ImageNumerics(data, psf, **kwargs_numerics) ra_pos = np.array([10, 7]) dec_pos = np.array([6, 7]) amp = np.array([10, 10]) image = imageNumerics.point_source_rendering_old(ra_pos, dec_pos, amp) image_subgrid = imageNumerics.point_source_rendering(ra_pos, dec_pos, amp) npt.assert_almost_equal(image[10, 7], image_subgrid[10, 7], decimal=8) kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': 2., 'point_source_subgrid': 3} psf = PSF(kwargs_psf) kwargs_numerics = {'subgrid_res': 1, 'psf_subgrid': True} imageNumerics = ImageNumerics(data, psf, **kwargs_numerics) ra_pos = np.array([7.1, 14]) dec_pos = np.array([7, 7.32]) amp = np.array([10, 10]) image = imageNumerics.point_source_rendering(ra_pos, dec_pos, amp) image_subgrid = imageNumerics.point_source_rendering(ra_pos, dec_pos, amp) image_sum = np.sum(image) image_subgrid_sum = np.sum(image_subgrid) npt.assert_almost_equal(image_sum/image_subgrid_sum, 1, decimal=5) assert image[7, 14] <= image_subgrid[7, 14] npt.assert_almost_equal(image[0, 0], image_subgrid[0, 0], decimal=8)
def data_configure(self, numPix, deltaPix, exposure_time=1, sigma_bkg=1): """ configures the data keyword arguments with a coordinate grid centered at zero. :param numPix: number of pixel (numPix x numPix) :param deltaPix: pixel size :param exposure_time: exposure time :param sigma_bkg: background noise (Gaussian sigma) :return: """ mean = 0. # background mean flux (default zero) # 1d list of coordinates (x,y) of a numPix x numPix square grid, centered to zero x_grid, y_grid, ra_at_xy_0, dec_at_xy_0, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix = util.make_grid_with_coordtransform(numPix=numPix, deltapix=deltaPix, subgrid_res=1) # mask (1= model this pixel, 0= leave blanck) exposure_map = np.ones((numPix, numPix)) * exposure_time # individual exposure time/weight per pixel kwargs_data = { 'background_rms': sigma_bkg, 'mean_background': mean, 'exposure_map': exposure_map , 'x_coords': x_grid, 'y_coords': y_grid , 'ra_at_xy_0': ra_at_xy_0, 'dec_at_xy_0': dec_at_xy_0, 'transform_pix2angle': Mpix2coord , 'image_data': np.zeros((numPix, numPix)) } data_class = Data(kwargs_data) #return kwargs_data return data_class
def __init__(self, multi_band_list, lens_model_list=None, source_model_class=None, lens_light_model_class=None, point_source_class=None): imageModel_list = [] self._idex_lens_list = [] for i in range(len(multi_band_list)): kwargs_data = multi_band_list[i][0] kwargs_psf = multi_band_list[i][1] kwargs_numerics = multi_band_list[i][2] index_lens_list = multi_band_list[i][3].get( 'index_lens_list', [k for k in range(len(lens_model_list))]) self._idex_lens_list.append(index_lens_list) lens_model_list_sub = [lens_model_list[k] for k in index_lens_list] lens_model_class = LensModel(lens_model_list=lens_model_list_sub) data_i = Data(kwargs_data=kwargs_data) psf_i = PSF(kwargs_psf=kwargs_psf) point_source_class_i = copy.deepcopy(point_source_class) imageModel = ImageModel(data_i, psf_i, lens_model_class, source_model_class, lens_light_model_class, point_source_class_i, kwargs_numerics=kwargs_numerics) imageModel_list.append(imageModel) super(MultiFrame, self).__init__(imageModel_list)
def create_image_model(kwargs_data, kwargs_psf, kwargs_numerics, kwargs_model): """ :param kwargs_data: :param kwargs_psf: :param kwargs_options: :return: """ data_class = Data(kwargs_data) psf_class = PSF(kwargs_psf) lens_model_class = LensModel( lens_model_list=kwargs_model.get('lens_model_list', []), z_source=kwargs_model.get('z_source', None), redshift_list=kwargs_model.get('redshift_list', None), multi_plane=kwargs_model.get('multi_plane', False)) source_model_class = LightModel( light_model_list=kwargs_model.get('source_light_model_list', [])) lens_light_model_class = LightModel( light_model_list=kwargs_model.get('lens_light_model_list', [])) point_source_class = PointSource( point_source_type_list=kwargs_model.get('point_source_model_list', []), lensModel=lens_model_class, fixed_magnification_list=kwargs_model.get('fixed_magnification_list', None), additional_images_list=kwargs_model.get('additional_images_list', None), min_distance=kwargs_model.get('min_distance', 0.01), search_window=kwargs_model.get('search_window', 5), precision_limit=kwargs_model.get('precision_limit', 10**(-10)), num_iter_max=kwargs_model.get('num_iter_max', 100)) imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class, lens_light_model_class, point_source_class, kwargs_numerics) return imageModel
def test_point_source(self): pointSource = PointSource(point_source_type_list=['SOURCE_POSITION'], fixed_magnification_list=[True]) kwargs_ps = [{'source_amp': 1000, 'ra_source': 0.1, 'dec_source': 0.1}] lensModel = LensModel(lens_model_list=['SIS']) kwargs_lens = [{'theta_E': 1, 'center_x': 0, 'center_y': 0}] numPix = 64 deltaPix = 0.13 kwargs_data = sim_util.data_configure_simple(numPix, deltaPix, exposure_time=1, sigma_bkg=1) data_class = Data(kwargs_data) psf_type = "GAUSSIAN" fwhm = 0.9 kwargs_psf = {'psf_type': psf_type, 'fwhm': fwhm} psf_class = PSF(kwargs_psf) imageModel = ImageModel(data_class=data_class, psf_class=psf_class, lens_model_class=lensModel, point_source_class=pointSource) image = imageModel.image(kwargs_lens=kwargs_lens, kwargs_ps=kwargs_ps) assert np.sum(image) > 0
def setup(self): self.numPix = 10 kwargs_data = {'image_data': np.zeros((self.numPix, self.numPix))} self.Data = Data(kwargs_data) kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': 1} self.PSF = PSF(kwargs_psf) kwargs_numerics = {'subgrid_res': 2, 'psf_subgrid': True} self.ImageNumerics = ImageNumerics(self.Data, self.PSF, **kwargs_numerics)
def test_force_positive_source_surface_brightness(self): kwargs_likelihood = { 'force_positive_source_surface_brightness': True, 'numPix_source': 10, 'deltaPix_source': 0.1 } 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, sigma_bkg=0.1) data_class = Data(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) data_class.update_data(image_sim) likelihood = LikelihoodModule(imSim_class=imageModel, param_class=param_class, **kwargs_likelihood) logL, _ = likelihood.logL(args=param_class.kwargs2args( kwargs_source=kwargs_source)) assert logL <= -10**10
def create_image_model(kwargs_data, kwargs_psf, kwargs_numerics, lens_model_list=[], z_lens=None, z_source=None, lens_redshift_list=None, multi_plane=False, source_light_model_list=[], lens_light_model_list=[], point_source_model_list=[], fixed_magnification_list=None, additional_images_list=None, min_distance=0.01, search_window=5, precision_limit=10**(-10), num_iter_max=100, multi_band_type=None, source_deflection_scaling_list=None, source_redshift_list=None, cosmo=None): """ :param kwargs_data: :param kwargs_psf: :param kwargs_options: :return: """ data_class = Data(kwargs_data) psf_class = PSF(kwargs_psf) lens_model_class = LensModel(lens_model_list=lens_model_list, z_lens=z_lens, z_source=z_source, lens_redshift_list=lens_redshift_list, multi_plane=multi_plane, cosmo=cosmo) source_model_class = LightModel( light_model_list=source_light_model_list, deflection_scaling_list=source_deflection_scaling_list, source_redshift_list=source_redshift_list) lens_light_model_class = LightModel(light_model_list=lens_light_model_list) point_source_class = PointSource( point_source_type_list=point_source_model_list, lensModel=lens_model_class, fixed_magnification_list=fixed_magnification_list, additional_images_list=additional_images_list, min_distance=min_distance, search_window=search_window, precision_limit=precision_limit, num_iter_max=num_iter_max) imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class, lens_light_model_class, point_source_class, kwargs_numerics) return imageModel
def __init__(self, kwargs_data, kwargs_psf, kwargs_numerics, kwargs_model, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, arrow_size=0.02, cmap_string="gist_heat"): """ :param kwargs_options: :param kwargs_data: :param arrow_size: :param cmap_string: """ self._kwargs_data = kwargs_data if isinstance(cmap_string, str) or isinstance(cmap_string, unicode): cmap = plt.get_cmap(cmap_string) else: cmap = cmap_string cmap.set_bad(color='k', alpha=1.) cmap.set_under('k') self._cmap = cmap self._arrow_size = arrow_size data = Data(kwargs_data) self._coords = data._coords nx, ny = np.shape(kwargs_data['image_data']) Mpix2coord = kwargs_data['transform_pix2angle'] self._Mpix2coord = Mpix2coord self._deltaPix = self._coords.pixel_size self._frame_size = self._deltaPix * nx x_grid, y_grid = data.coordinates self._x_grid = util.image2array(x_grid) self._y_grid = util.image2array(y_grid) self._imageModel = class_creator.create_image_model(kwargs_data, kwargs_psf, kwargs_numerics, kwargs_model) self._analysis = LensAnalysis(kwargs_model) self._lensModel = LensModel(lens_model_list=kwargs_model.get('lens_model_list', []), z_source=kwargs_model.get('z_source', None), redshift_list=kwargs_model.get('redshift_list', None), multi_plane=kwargs_model.get('multi_plane', False)) self._lensModelExt = LensModelExtensions(self._lensModel) model, error_map, cov_param, param = self._imageModel.image_linear_solve(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, inv_bool=True) self._kwargs_lens = kwargs_lens self._kwargs_source = kwargs_source self._kwargs_lens_light = kwargs_lens_light self._kwargs_else = kwargs_ps self._model = model self._data = kwargs_data['image_data'] self._cov_param = cov_param self._norm_residuals = self._imageModel.reduced_residuals(model, error_map=error_map) self._reduced_x2 = self._imageModel.reduced_chi2(model, error_map=error_map) log_model = np.log10(model) log_model[np.isnan(log_model)] = -5 self._v_min_default = max(np.min(log_model), -5) self._v_max_default = min(np.max(log_model), 10) print("reduced chi^2 = ", self._reduced_x2)
def lens_model_plot(ax, lensModel, kwargs_lens, numPix=500, deltaPix=0.01, sourcePos_x=0, sourcePos_y=0, point_source=False, with_caustics=False): """ plots a lens model (convergence) and the critical curves and caustics :param ax: :param kwargs_lens: :param numPix: :param deltaPix: :return: """ from lenstronomy.SimulationAPI.simulations import Simulation simAPI = Simulation() kwargs_data = simAPI.data_configure(numPix, deltaPix) data = Data(kwargs_data) _frame_size = numPix * deltaPix _coords = data._coords x_grid, y_grid = data.coordinates lensModelExt = LensModelExtensions(lensModel) #ra_crit_list, dec_crit_list, ra_caustic_list, dec_caustic_list = lensModelExt.critical_curve_caustics( # kwargs_lens, compute_window=_frame_size, grid_scale=deltaPix/2.) x_grid1d = util.image2array(x_grid) y_grid1d = util.image2array(y_grid) kappa_result = lensModel.kappa(x_grid1d, y_grid1d, kwargs_lens) kappa_result = util.array2image(kappa_result) im = ax.matshow(np.log10(kappa_result), origin='lower', extent=[0, _frame_size, 0, _frame_size], cmap='Greys', vmin=-1, vmax=1) #, cmap=self._cmap, vmin=v_min, vmax=v_max) if with_caustics is True: ra_crit_list, dec_crit_list = lensModelExt.critical_curve_tiling(kwargs_lens, compute_window=_frame_size, start_scale=deltaPix, max_order=10) ra_caustic_list, dec_caustic_list = lensModel.ray_shooting(ra_crit_list, dec_crit_list, kwargs_lens) plot_line_set(ax, _coords, ra_caustic_list, dec_caustic_list, color='g') plot_line_set(ax, _coords, ra_crit_list, dec_crit_list, color='r') if point_source: from lenstronomy.LensModel.Solver.lens_equation_solver import LensEquationSolver solver = LensEquationSolver(lensModel) theta_x, theta_y = solver.image_position_from_source(sourcePos_x, sourcePos_y, kwargs_lens) mag_images = lensModel.magnification(theta_x, theta_y, kwargs_lens) x_image, y_image = _coords.map_coord2pix(theta_x, theta_y) abc_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'] for i in range(len(x_image)): x_ = (x_image[i] + 0.5) * deltaPix y_ = (y_image[i] + 0.5) * deltaPix ax.plot(x_, y_, 'dk', markersize=4*(1 + np.log(np.abs(mag_images[i]))), alpha=0.5) ax.text(x_, y_, abc_list[i], fontsize=20, color='k') x_source, y_source = _coords.map_coord2pix(sourcePos_x, sourcePos_y) ax.plot((x_source + 0.5) * deltaPix, (y_source + 0.5) * deltaPix, '*k', markersize=10) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) ax.autoscale(False) #image_position_plot(ax, _coords, self._kwargs_else) #source_position_plot(ax, self._coords, self._kwargs_source) return ax
class TestData(object): def setup(self): self.numPix = 10 kwargs_data = {'image_data': np.zeros((self.numPix, self.numPix))} self.Data = Data(kwargs_data) def test_get_covariance_matrix(self): d = np.array([1, 2, 3]) sigma_b = 1 f = 10. result = self.Data.covariance_matrix(d, sigma_b, f) assert result[0] == 1.1 assert result[1] == 1.2 def test_numData(self): assert self.Data.numData == self.numPix**2 def test_shift_coords(self): numPix = 10 deltaPix = 0.05 x_grid, y_grid, ra_at_xy_0, dec_at_xy_0, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix = util.make_grid_with_coordtransform( numPix=numPix, deltapix=deltaPix, subgrid_res=1) # mask (1= model this pixel, 0= leave blanck) kwargs_data = { 'ra_at_xy_0': ra_at_xy_0, 'dec_at_xy_0': dec_at_xy_0, 'transform_pix2angle': Mpix2coord, 'image_data': np.ones((numPix, numPix)) } data = Data(kwargs_data) ra_shift = 0.05 dec_shift = 0. kwargs_data['ra_shift'] = ra_shift kwargs_data['dec_shift'] = dec_shift data_shift = Data(kwargs_data) ra, dec = data.map_pix2coord(1, 1) ra_new, dec_new = data_shift.map_pix2coord(1, 1) npt.assert_almost_equal(ra_new - ra, ra_shift, decimal=10) npt.assert_almost_equal(dec_new - dec, dec_shift, decimal=10) ra_2, dec_2 = data_shift.map_pix2coord(0, 1) npt.assert_almost_equal(ra, ra_2, decimal=10) npt.assert_almost_equal(dec, dec_2, decimal=10) x, y = data.map_coord2pix(0, 0) x_new, y_new = data_shift.map_coord2pix(ra_shift, dec_shift) npt.assert_almost_equal(x, x_new, decimal=10) npt.assert_almost_equal(y, y_new, decimal=10)
def data_class(self): """ creates a Data() instance of lenstronomy based on knowledge of the observation :return: instance of Data() class """ x_grid, y_grid, ra_at_xy_0, dec_at_xy_0, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix = util.make_grid_with_coordtransform( numPix=self.numpix, deltapix=self.pixel_scale, subgrid_res=1, left_lower=False, inverse=False) kwargs_data = {'numPix': self.numpix, 'ra_at_xy_0': ra_at_xy_0, 'dec_at_xy_0': dec_at_xy_0, 'transform_pix2angle': Mpix2coord, 'background_rms': self.background_noise, 'exp_time': self.scaled_exposure_time} data_class = Data(kwargs_data) return data_class
def test_data_configure_simple(self): # data specifics sigma_bkg = 1. # background noise per pixel exp_time = 10 # exposure time (arbitrary units, flux per pixel is in units #photons/exp_time unit) numPix = 100 # cutout pixel size deltaPix = 0.05 # pixel size in arcsec (area per pixel = deltaPix**2) fwhm = 0.5 # full width half max of PSF # PSF specification kwargs_data = sim_util.data_configure_simple(numPix, deltaPix, exp_time, sigma_bkg) data_class = Data(kwargs_data) assert data_class.deltaPix == deltaPix
def __init__(self, multi_band_list, lens_model_class=None, source_model_list=None, lens_light_model_list=None, point_source_class=None): imageModel_list = [] self._index_source_list = [] self._index_lens_light_list = [] for i in range(len(multi_band_list)): kwargs_data = multi_band_list[i][0] kwargs_psf = multi_band_list[i][1] kwargs_numerics = multi_band_list[i][2] data_i = Data(kwargs_data=kwargs_data) psf_i = PSF(kwargs_psf=kwargs_psf) index_source_list = multi_band_list[i][3].get( 'index_source_light_model', [k for k in range(len(source_model_list))]) self._index_source_list.append(index_source_list) source_model_list_sub = [ source_model_list[k] for k in index_source_list ] source_model_class = LightModel( light_model_list=source_model_list_sub) index_lens_light_list = multi_band_list[i][3].get( 'index_lens_light_model', [k for k in range(len(source_model_list))]) self._index_lens_light_list.append(index_lens_light_list) lens_light_model_list_sub = [ lens_light_model_list[k] for k in index_lens_light_list ] lens_light_model_class = LightModel( light_model_list=lens_light_model_list_sub) imageModel = ImageModel(data_i, psf_i, lens_model_class, source_model_class, lens_light_model_class, point_source_class, kwargs_numerics=kwargs_numerics) imageModel_list.append(imageModel) super(MultiBandMultiModel, self).__init__(imageModel_list)
def test_point_source_rendering(self): # initialize data from lenstronomy.SimulationAPI.simulations import Simulation SimAPI = Simulation() numPix = 100 deltaPix = 0.05 kwargs_data = SimAPI.data_configure(numPix, deltaPix, exposure_time=1, sigma_bkg=1) data_class = Data(kwargs_data) kernel = np.zeros((5, 5)) kernel[2, 2] = 1 kwargs_psf = {'kernel_point_source': kernel, 'kernel_pixel': kernel, 'psf_type': 'PIXEL'} psf_class = PSF(kwargs_psf) lens_model_class = LensModel(['SPEP']) source_model_class = LightModel([]) lens_light_model_class = LightModel([]) kwargs_numerics = {'subgrid_res': 2, 'point_source_subgrid': 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)}] model = makeImage.image(kwargs_lens_init, kwargs_source={}, kwargs_lens_light={}, kwargs_ps=kwargs_else) 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) phi, q = 0., 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi, q) 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)}] model = makeImage.image(kwargs_lens_init, kwargs_source={}, kwargs_lens_light={}, kwargs_ps=kwargs_else) image = makeImage.ImageNumerics.array2image(model) for i in range(len(x_pix)): print(int(y_pix[i]), int(x_pix[i]+0.5)) npt.assert_almost_equal(image[int(y_pix[i]), int(x_pix[i])], 0.5, decimal=1) npt.assert_almost_equal(image[int(y_pix[i]), int(x_pix[i]+0.5)], 0.5, decimal=1)
def creat_image_model(kwargs_data, kwargs_psf, kwargs_numerics, kwargs_model): """ :param kwargs_data: :param kwargs_psf: :param kwargs_options: :return: """ data_class = Data(kwargs_data) psf_class = PSF(kwargs_psf) if 'lens_model_list' in kwargs_model: lens_model_class = LensModel( lens_model_list=kwargs_model.get('lens_model_list', None), z_source=kwargs_model.get('z_source', None), redshift_list=kwargs_model.get('redshift_list', None), multi_plane=kwargs_model.get('multi_plane', False)) else: lens_model_class = None if 'source_light_model_list' in kwargs_model: source_model_class = LightModel(light_model_list=kwargs_model.get( 'source_light_model_list', ['NONE'])) else: source_model_class = None if 'lens_light_model_list' in kwargs_model: lens_light_model_class = LightModel(light_model_list=kwargs_model.get( 'lens_light_model_list', ['NONE'])) else: lens_light_model_class = None if 'point_source_model_list' in kwargs_model: point_source_class = PointSource( point_source_type_list=kwargs_model.get('point_source_model_list', ['NONE']), fixed_magnification_list=kwargs_model.get( 'fixed_magnification_list', None), additional_images_list=kwargs_model.get('additional_images_list', None)) else: point_source_class = None imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class, lens_light_model_class, point_source_class, kwargs_numerics) return imageModel
def __init__(self, multi_band_list, lens_model_class, source_model_class, lens_light_model_class, point_source_class): self._num_bands = len(multi_band_list) self.lensModel = lens_model_class self.pointSource = point_source_class self._imageModel_list = [] for i in range(self._num_bands): kwargs_data = multi_band_list[i][0] kwargs_psf = multi_band_list[i][1] kwargs_numerics = multi_band_list[i][2] data_i = Data(kwargs_data=kwargs_data) psf_i = PSF(kwargs_psf=kwargs_psf) self._imageModel_list.append( ImageModel(data_i, psf_i, lens_model_class, source_model_class, lens_light_model_class, point_source_class, kwargs_numerics=kwargs_numerics))
def __init__(self, multi_band_list, lens_model_class=None, source_model_class=None, lens_light_model_class=None, point_source_class=None): imageModel_list = [] for i in range(len(multi_band_list)): kwargs_data = multi_band_list[i][0] kwargs_psf = multi_band_list[i][1] kwargs_numerics = multi_band_list[i][2] data_i = Data(kwargs_data=kwargs_data) psf_i = PSF(kwargs_psf=kwargs_psf) imageModel = ImageModel(data_i, psf_i, lens_model_class, source_model_class, lens_light_model_class, point_source_class, kwargs_numerics=kwargs_numerics) imageModel_list.append(imageModel) super(MultiBand, self).__init__(imageModel_list)
def setup(self): # data specifics sigma_bkg = 0.01 # background noise per pixel exp_time = 100 # exposure time (arbitrary units, flux per pixel is in units #photons/exp_time unit) numPix = 100 # cutout pixel size deltaPix = 0.05 # pixel size in arcsec (area per pixel = deltaPix**2) fwhm = 0.3 # full width half max of PSF # PSF specification kwargs_data = sim_util.data_configure_simple(numPix, deltaPix, exp_time, sigma_bkg) data_class = Data(kwargs_data) sigma = util.fwhm2sigma(fwhm) x_grid, y_grid = util.make_grid(numPix=31, deltapix=0.05) from lenstronomy.LightModel.Profiles.gaussian import Gaussian gaussian = Gaussian() kernel_point_source = gaussian.function(x_grid, y_grid, amp=1., sigma_x=sigma, sigma_y=sigma, center_x=0, center_y=0) kernel_point_source /= np.sum(kernel_point_source) kernel_point_source = util.array2image(kernel_point_source) self.kwargs_psf = {'psf_type': 'PIXEL', 'kernel_point_source': kernel_point_source} psf_class = PSF(kwargs_psf=self.kwargs_psf) # 'EXERNAL_SHEAR': external shear kwargs_shear = {'e1': 0.01, 'e2': 0.01} # gamma_ext: shear strength, psi_ext: shear angel (in radian) phi, q = 0.2, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi, q) kwargs_spemd = {'theta_E': 1., 'gamma': 1.8, 'center_x': 0, 'center_y': 0, 'e1': e1, 'e2': e2} lens_model_list = ['SPEP', 'SHEAR'] self.kwargs_lens = [kwargs_spemd, kwargs_shear] lens_model_class = LensModel(lens_model_list=lens_model_list) # list of light profiles (for lens and source) # 'SERSIC': spherical Sersic profile kwargs_sersic = {'amp': 1., 'R_sersic': 0.1, 'n_sersic': 2, 'center_x': 0, 'center_y': 0} # 'SERSIC_ELLIPSE': elliptical Sersic profile 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.0, 'dec_source': 0.0, 'source_amp': 10.}] # 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': 3, '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) self.imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class, lens_light_model_class, point_source_class, kwargs_numerics=kwargs_numerics) self.psf_fitting = PsfFitting(self.imageModel)
def setup(self): self.SimAPI = Simulation() # data specifics sigma_bkg = 0.05 # background noise per pixel exp_time = 100 # exposure time (arbitrary units, flux per pixel is in units #photons/exp_time unit) numPix = 50 # cutout pixel size deltaPix = 0.1 # pixel size in arcsec (area per pixel = deltaPix**2) fwhm = 0.5 # full width half max of PSF # PSF specification self.kwargs_data = self.SimAPI.data_configure(numPix, deltaPix, exp_time, sigma_bkg) data_class = Data(self.kwargs_data) kwargs_psf = self.SimAPI.psf_configure(psf_type='GAUSSIAN', fwhm=fwhm, kernelsize=11, deltaPix=deltaPix, truncate=3, kernel=None) self.kwargs_psf = self.SimAPI.psf_configure(psf_type='PIXEL', fwhm=fwhm, kernelsize=11, deltaPix=deltaPix, truncate=6, kernel=kwargs_psf['kernel_point_source']) psf_class = PSF(self.kwargs_psf) # 'EXERNAL_SHEAR': external shear kwargs_shear = {'e1': 0.01, 'e2': 0.01} # gamma_ext: shear strength, psi_ext: shear angel (in radian) kwargs_spemd = {'theta_E': 1., 'gamma': 1.8, 'center_x': 0, 'center_y': 0, 'e1': 0.1, 'e2': 0.1} lens_model_list = ['SPEP', 'SHEAR'] self.kwargs_lens = [kwargs_spemd, kwargs_shear] 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) self.kwargs_ps = [{'ra_source': 0.0, 'dec_source': 0.0, 'source_amp': 1.}] # quasar point source position in the source plane and intrinsic brightness point_source_list = ['SOURCE_POSITION'] point_source_class = PointSource(point_source_type_list=point_source_list, fixed_magnification_list=[True]) kwargs_numerics = {'subgrid_res': 1, 'psf_subgrid': False} 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 = self.SimAPI.simulate(imageModel, self.kwargs_lens, self.kwargs_source, self.kwargs_lens_light, self.kwargs_ps) data_class.update_data(image_sim) self.data_class = data_class self.psf_class = psf_class self.kwargs_data['image_data'] = image_sim self.kwargs_model = {'lens_model_list': lens_model_list, 'source_light_model_list': source_model_list, 'lens_light_model_list': lens_light_model_list, 'point_source_model_list': point_source_list, 'fixed_magnification_list': [False], } self.kwargs_numerics = { 'subgrid_res': 1, 'psf_subgrid': False} num_source_model = len(source_model_list) self.kwargs_constraints = {'joint_center_lens_light': False, 'joint_center_source_light': False, 'num_point_source_list': [4], 'additional_images_list': [False], 'fix_to_point_source_list': [False] * num_source_model, 'image_plane_source_list': [False] * num_source_model, 'solver': False, 'solver_type': 'PROFILE_SHEAR', # 'PROFILE', 'PROFILE_SHEAR', 'ELLIPSE', 'CENTER' } self.kwargs_likelihood = {'force_no_add_image': True, 'source_marg': True, 'point_source_likelihood': False, 'position_uncertainty': 0.004, 'check_solver': False, 'solver_tolerance': 0.001, 'check_positive_flux': True, }
deltaPix = 0.05/4 # pixel size in arcsec (area per pixel = deltaPix**2) psf = pyfits.open('psf_{0}_sub4.fits'.format(filt)) psf_data = psf[0].data cut =25 # psf_data = psf_data[1+cut:-cut,1+cut:-cut]+ 0 #shave PSF to singular size, as max in the middle plt.imshow(psf_data, origin='lower',cmap='gist_heat', norm=LogNorm()) plt.colorbar() plt.close() kwargs_psf_high_res = {'psf_type': 'PIXEL', 'kernel_point_source': psf_data, 'pixel_size': deltaPix} psf_class = PSF(**kwargs_psf_high_res) zp= 25.9463 #Assuming it same as F160W kwargs_data_high_res = sim_util.data_configure_simple(numPix, deltaPix) #,inverse=True) data_class = Data(**kwargs_data_high_res) kwargs_numerics = {'supersampling_factor': 12, 'supersampling_convolution': False} import sys sys.path.insert(0,'../../share_tools/') from gene_para import gene_para for seed in range(702, 799): print(seed) para=gene_para(seed=seed,fixh0=102) #============================================================================== # #######lens light #============================================================================== from lenstronomy.LightModel.light_model import LightModel lens_light_para=para.lens_light() np.random.seed(seed)
def setup(self): self.SimAPI = Simulation() # data specifics sigma_bkg = 0.05 # background noise per pixel exp_time = 100 # exposure time (arbitrary units, flux per pixel is in units #photons/exp_time unit) numPix = 10 # cutout pixel size deltaPix = 0.1 # pixel size in arcsec (area per pixel = deltaPix**2) fwhm = 0.5 # full width half max of PSF # PSF specification kwargs_data = self.SimAPI.data_configure(numPix, deltaPix, exp_time, sigma_bkg) data_class = Data(kwargs_data) kwargs_psf = self.SimAPI.psf_configure(psf_type='GAUSSIAN', fwhm=fwhm, kernelsize=11, deltaPix=deltaPix, truncate=3, kernel=None) kwargs_psf = self.SimAPI.psf_configure( psf_type='PIXEL', fwhm=fwhm, kernelsize=11, deltaPix=deltaPix, truncate=6, kernel=kwargs_psf['kernel_point_source']) psf_class = PSF(kwargs_psf) kwargs_spemd = { 'theta_E': 1., 'gamma': 1.8, 'center_x': 0, 'center_y': 0, 'e1': 0.1, 'e2': 0.1 } lens_model_list = ['SPEP'] 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 = {'subgrid_res': 1, 'psf_subgrid': False} imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class, lens_light_model_class, kwargs_numerics=kwargs_numerics) image_sim = self.SimAPI.simulate(imageModel, self.kwargs_lens, self.kwargs_source, self.kwargs_lens_light) data_class.update_data(image_sim) 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 = {'subgrid_res': 1, 'psf_subgrid': False} num_source_model = len(source_model_list) kwargs_constraints = { 'joint_center_lens_light': False, 'joint_center_source_light': False, 'additional_images_list': [False], 'fix_to_point_source_list': [False] * num_source_model, 'image_plane_source_list': [False] * num_source_model, 'solver': False, } kwargs_likelihood = { 'source_marg': True, 'point_source_likelihood': False, 'position_uncertainty': 0.004, 'check_solver': False, 'solver_tolerance': 0.001, } self.param_class = Param(kwargs_model, kwargs_constraints) self.Likelihood = LikelihoodModule(imSim_class=imageModel, param_class=self.param_class, kwargs_likelihood=kwargs_likelihood) self.sampler = Sampler(likelihoodModule=self.Likelihood)
def setup(self): self.numPix = 10 kwargs_data = {'image_data': np.zeros((self.numPix, self.numPix))} self.Data = Data(kwargs_data)
masksize=40 #mask size in pixels msmin = int(pix/2) - int(masksize/2) msmax = int(pix/2) + int(masksize/2) catmask = cat[:,msmin:msmax,msmin:msmax] # data specifics sigma_bkg = .1 # background noise per pixel exp_time = 90 # exposure time (arbitrary units, flux per pixel is in units #photons/exp_time unit) numPix = pix # cutout pixel size deltaPix = 0.27 # pixel size in arcsec (area per pixel = deltaPix**2) fwhm = 0.958 # full width half max of PSF #Data kwargs_data = SimAPI.data_configure(pix, deltaPix, exp_time, sigma_bkg) data_class = Data(kwargs_data) #Mask kwargs_data_mask = SimAPI.data_configure(masksize, deltaPix, exp_time, sigma_bkg) data_class_mask = Data(kwargs_data_mask) # PSF specification kwargs_psf = SimAPI.psf_configure(psf_type='GAUSSIAN', fwhm=fwhm, kernelsize=31, deltaPix=deltaPix, truncate=6, kernel=None) psf_class = PSF(kwargs_psf) #********************************************************************************# # SOURCE DEFINITION # #********************************************************************************# source_ALL = cat[1] # CIRCULAR MASK FOR THE SOURCE, where pix is the size of the image, radius is the radius of the mask in pixels
def arrival_time_surface(ax, lensModel, kwargs_lens, numPix=500, deltaPix=0.01, sourcePos_x=0, sourcePos_y=0, with_caustics=False, point_source=False, n_levels=10): """ :param ax: :param lensModel: :param kwargs_lens: :param numPix: :param deltaPix: :param sourcePos_x: :param sourcePos_y: :param with_caustics: :return: """ kwargs_data = sim_util.data_configure_simple(numPix, deltaPix) data = Data(kwargs_data) _frame_size = numPix * deltaPix _coords = data._coords x_grid, y_grid = data.coordinates lensModelExt = LensModelExtensions(lensModel) #ra_crit_list, dec_crit_list, ra_caustic_list, dec_caustic_list = lensModelExt.critical_curve_caustics( # kwargs_lens, compute_window=_frame_size, grid_scale=deltaPix/2.) x_grid1d = util.image2array(x_grid) y_grid1d = util.image2array(y_grid) fermat_surface = lensModel.fermat_potential(x_grid1d, y_grid1d, sourcePos_x, sourcePos_y, kwargs_lens) fermat_surface = util.array2image(fermat_surface) vmin = np.min(fermat_surface) vmax = np.max(fermat_surface) levels = np.linspace(start=vmin, stop=vmax, num=n_levels) im = ax.contourf( x_grid, y_grid, fermat_surface, origin='lower', # extent=[0, _frame_size, 0, _frame_size], levels=levels) #, cmap='Greys', vmin=-1, vmax=1) #, cmap=self._cmap, vmin=v_min, vmax=v_max) if with_caustics is True: ra_crit_list, dec_crit_list = lensModelExt.critical_curve_tiling( kwargs_lens, compute_window=_frame_size, start_scale=deltaPix, max_order=10) ra_caustic_list, dec_caustic_list = lensModel.ray_shooting( ra_crit_list, dec_crit_list, kwargs_lens) plot_line_set(ax, _coords, ra_caustic_list, dec_caustic_list, shift=_frame_size / 2., color='g') plot_line_set(ax, _coords, ra_crit_list, dec_crit_list, shift=_frame_size / 2., color='r') if point_source is True: from lenstronomy.LensModel.Solver.lens_equation_solver import LensEquationSolver solver = LensEquationSolver(lensModel) theta_x, theta_y = solver.image_position_from_source( sourcePos_x, sourcePos_y, kwargs_lens, min_distance=deltaPix, search_window=deltaPix * numPix) mag_images = lensModel.magnification(theta_x, theta_y, kwargs_lens) x_image, y_image = _coords.map_coord2pix(theta_x, theta_y) abc_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'] for i in range(len(x_image)): x_ = (x_image[i] + 0.5) * deltaPix - _frame_size / 2 y_ = (y_image[i] + 0.5) * deltaPix - _frame_size / 2 #x_ = x_image[i] * deltaPix #y_ = y_image[i] * deltaPix ax.plot(x_, y_, 'dk', markersize=4 * (1 + np.log(np.abs(mag_images[i]))), alpha=0.5) ax.text(x_, y_, abc_list[i], fontsize=20, color='k') x_source, y_source = _coords.map_coord2pix(sourcePos_x, sourcePos_y) ax.plot((x_source + 0.5) * deltaPix - _frame_size / 2, (y_source + 0.5) * deltaPix - _frame_size / 2, '*k', markersize=10) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) ax.autoscale(False) return ax