def test_source_position_plot(self): from lenstronomy.PointSource.point_source import PointSource from lenstronomy.LensModel.lens_model import LensModel lensModel = LensModel(lens_model_list=['SIS']) ps = PointSource(point_source_type_list=[ 'UNLENSED', 'LENSED_POSITION', 'SOURCE_POSITION' ], lensModel=lensModel) kwargs_lens = [{'theta_E': 1., 'center_x': 0, 'center_y': 0}] kwargs_ps = [{ 'ra_image': [1., 1.], 'dec_image': [0, 1], 'point_amp': [1, 1] }, { 'ra_image': [1.], 'dec_image': [1.], 'point_amp': [10] }, { 'ra_source': 0.1, 'dec_source': 0, 'point_amp': 1. }] ra_source, dec_source = ps.source_position(kwargs_ps, kwargs_lens) from lenstronomy.Data.coord_transforms import Coordinates coords_source = Coordinates( transform_pix2angle=np.array([[1, 0], [0, 1]]) * 0.1, ra_at_xy_0=-2, dec_at_xy_0=-2) f, ax = plt.subplots(1, 1, figsize=(4, 4)) plot_util.source_position_plot(ax, coords_source, ra_source, dec_source) plt.close()
def error_map_source_plot(self, ax, numPix, deltaPix_source, v_min=None, v_max=None, with_caustics=False, font_size=15, point_source_position=True): """ plots the uncertainty in the surface brightness in the source from the linear inversion by taking the diagonal elements of the covariance matrix of the inversion of the basis set to be propagated to the source plane. #TODO illustration of the uncertainties in real space with the full covariance matrix is subtle. The best way is probably to draw realizations from the covariance matrix. :param ax: matplotlib axis instance :param numPix: number of pixels in plot per axis :param deltaPix_source: pixel spacing in the source resolution illustrated in plot :param v_min: minimum plotting scale of the map :param v_max: maximum plotting scale of the map :param with_caustics: plot the caustics on top of the source reconstruction (may take some time) :param font_size: font size of labels :param point_source_position: boolean, if True, plots a point at the position of the point source :return: plot of source surface brightness errors in the reconstruction on the axis instance """ x_grid_source, y_grid_source = util.make_grid_transformed(numPix, self._coords.transform_pix2angle * deltaPix_source / self._deltaPix) x_center = self._kwargs_source_partial[0]['center_x'] y_center = self._kwargs_source_partial[0]['center_y'] x_grid_source += x_center y_grid_source += y_center coords_source = Coordinates(self._coords.transform_pix2angle * deltaPix_source / self._deltaPix, ra_at_xy_0=x_grid_source[0], dec_at_xy_0=y_grid_source[0]) error_map_source = self.bandmodel.error_map_source(self._kwargs_source_partial, x_grid_source, y_grid_source, self._cov_param, model_index_select=False) error_map_source = util.array2image(error_map_source) d_s = numPix * deltaPix_source im = ax.matshow(error_map_source, origin='lower', extent=[0, d_s, 0, d_s], cmap=self._cmap, vmin=v_min, vmax=v_max) # source ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) ax.autoscale(False) divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) cb = plt.colorbar(im, cax=cax) cb.set_label(r'error variance', fontsize=font_size) if with_caustics: ra_caustic_list, dec_caustic_list = self._caustics() plot_util.plot_line_set(ax, coords_source, ra_caustic_list, dec_caustic_list, color='b') plot_util.scale_bar(ax, d_s, dist=0.1, text='0.1"', color='w', flipped=False, font_size=font_size) plot_util.coordinate_arrows(ax, d_s, coords_source, arrow_size=self._arrow_size, color='w', font_size=font_size) plot_util.text_description(ax, d_s, text="Error map in source", color="w", backgroundcolor='k', flipped=False, font_size=font_size) if point_source_position is True: ra_source, dec_source = self.bandmodel.PointSource.source_position(self._kwargs_ps_partial, self._kwargs_lens_partial) plot_util.source_position_plot(ax, coords_source, ra_source, dec_source) return ax
def source_plot(self, ax, numPix, deltaPix_source, center=None, v_min=None, v_max=None, with_caustics=False, caustic_color='yellow', font_size=15, plot_scale='log', scale_size=0.1, text="Reconstructed source", colorbar_label=r'log$_{10}$ flux', point_source_position=True, **kwargs): """ :param ax: :param numPix: :param deltaPix_source: :param center: [center_x, center_y], if specified, uses this as the center :param v_min: :param v_max: :param caustic_color: :param font_size: :param plot_scale: string, log or linear, scale of surface brightness plot :param kwargs: :return: """ if v_min is None: v_min = self._v_min_default if v_max is None: v_max = self._v_max_default d_s = numPix * deltaPix_source source, coords_source = self.source(numPix, deltaPix_source, center=center) if plot_scale == 'log': source[source < 10**v_min] = 10**( v_min) # to remove weird shadow in plot source_scale = np.log10(source) elif plot_scale == 'linear': source_scale = source else: raise ValueError( 'variable plot_scale needs to be "log" or "linear", not %s.' % plot_scale) im = ax.matshow(source_scale, origin='lower', extent=[0, d_s, 0, d_s], cmap=self._cmap, vmin=v_min, vmax=v_max) # source ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) ax.autoscale(False) divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) cb = plt.colorbar(im, cax=cax) cb.set_label(colorbar_label, fontsize=font_size) if with_caustics is True: ra_caustic_list, dec_caustic_list = self._caustics() plot_util.plot_line_set(ax, coords_source, ra_caustic_list, dec_caustic_list, color=caustic_color, points_only=self._caustic_points_only) plot_util.plot_line_set(ax, coords_source, ra_caustic_list, dec_caustic_list, color=caustic_color, points_only=self._caustic_points_only, **kwargs.get('kwargs_caustic', {})) plot_util.scale_bar(ax, d_s, dist=scale_size, text='{:.1f}"'.format(scale_size), color='w', flipped=False, font_size=font_size) if 'no_arrow' not in kwargs or not kwargs['no_arrow']: plot_util.coordinate_arrows(ax, self._frame_size, self._coords, color='w', arrow_size=self._arrow_size, font_size=font_size) plot_util.text_description(ax, d_s, text=text, color="w", backgroundcolor='k', flipped=False, font_size=font_size) if point_source_position is True: ra_source, dec_source = self._bandmodel.PointSource.source_position( self._kwargs_ps_partial, self._kwargs_lens_partial) plot_util.source_position_plot(ax, coords_source, ra_source, dec_source) return ax
def error_map_source_plot(self, ax, numPix, deltaPix_source, v_min=None, v_max=None, with_caustics=False, font_size=15, point_source_position=True): x_grid_source, y_grid_source = util.make_grid_transformed( numPix, self._coords.transform_pix2angle * deltaPix_source / self._deltaPix) x_center = self._kwargs_source_partial[0]['center_x'] y_center = self._kwargs_source_partial[0]['center_y'] x_grid_source += x_center y_grid_source += y_center coords_source = Coordinates(self._coords.transform_pix2angle * deltaPix_source / self._deltaPix, ra_at_xy_0=x_grid_source[0], dec_at_xy_0=y_grid_source[0]) error_map_source = self.bandmodel.error_map_source( self._kwargs_source_partial, x_grid_source, y_grid_source, self._cov_param) error_map_source = util.array2image(error_map_source) d_s = numPix * deltaPix_source im = ax.matshow(error_map_source, origin='lower', extent=[0, d_s, 0, d_s], cmap=self._cmap, vmin=v_min, vmax=v_max) # source ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) ax.autoscale(False) divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) cb = plt.colorbar(im, cax=cax) cb.set_label(r'error variance', fontsize=font_size) if with_caustics: ra_caustic_list, dec_caustic_list = self._caustics() plot_util.plot_line_set(ax, coords_source, ra_caustic_list, dec_caustic_list, color='b') plot_util.scale_bar(ax, d_s, dist=0.1, text='0.1"', color='w', flipped=False, font_size=font_size) plot_util.coordinate_arrows(ax, d_s, coords_source, arrow_size=self._arrow_size, color='w', font_size=font_size) plot_util.text_description(ax, d_s, text="Error map in source", color="w", backgroundcolor='k', flipped=False, font_size=font_size) if point_source_position is True: ra_source, dec_source = self.bandmodel.PointSource.source_position( self._kwargs_ps_partial, self._kwargs_lens_partial) plot_util.source_position_plot(ax, coords_source, ra_source, dec_source) return ax