def __init__(self, data_class, psf_class, lens_model_class=None, source_model_class=None, lens_light_model_class=None, point_source_class=None, extinction_class=None, kwargs_numerics=None): """ :param data_class: instance of ImageData() or PixelGrid() class :param psf_class: instance of PSF() class :param lens_model_class: instance of LensModel() class :param source_model_class: instance of LightModel() class describing the source parameters :param lens_light_model_class: instance of LightModel() class describing the lens light parameters :param point_source_class: instance of PointSource() class describing the point sources :param kwargs_numerics: keyword argument with various numeric description (see ImageNumerics class for options) """ self.type = 'single-band' self.PSF = psf_class self.Data = data_class self.PSF.set_pixel_size(self.Data.pixel_width) if kwargs_numerics is None: kwargs_numerics = {} self.ImageNumerics = NumericsSubFrame(pixel_grid=self.Data, psf=self.PSF, **kwargs_numerics) if lens_model_class is None: lens_model_class = LensModel(lens_model_list=[]) self.LensModel = lens_model_class if point_source_class is None: point_source_class = PointSource(point_source_type_list=[]) self.PointSource = point_source_class self.PointSource.update_lens_model(lens_model_class=lens_model_class) x_center, y_center = self.Data.center self.PointSource.update_search_window( search_window=np.max(self.Data.width), x_center=x_center, y_center=y_center, min_distance=self.Data.pixel_width, only_from_unspecified=True) self._psf_error_map = self.PSF.psf_error_map_bool if source_model_class is None: source_model_class = LightModel(light_model_list=[]) self.SourceModel = source_model_class if lens_light_model_class is None: lens_light_model_class = LightModel(light_model_list=[]) self.LensLightModel = lens_light_model_class self.source_mapping = Image2SourceMapping( lensModel=lens_model_class, sourceModel=source_model_class) self.num_bands = 1 self._kwargs_numerics = kwargs_numerics if extinction_class is None: extinction_class = DifferentialExtinction(optical_depth_model=[]) self._extinction = extinction_class
def __init__(self, data_class, psf_class=None, lens_model_class=None, source_model_class=None, lens_light_model_class=None, point_source_class=None, kwargs_numerics={}): """ :param data_class: instance of Data() class :param psf_class: instance of PSF() class :param lens_model_class: instance of LensModel() class :param source_model_class: instance of LightModel() class describing the source parameters :param lens_light_model_class: instance of LightModel() class describing the lens light parameters :param point_source_class: instance of PointSource() class describing the point sources :param kwargs_numerics: keyword argument with various numeric description (see ImageNumerics class for options) """ self.type = 'single-band' self.PSF = psf_class self.Data = data_class self.ImageNumerics = ImageNumerics(pixel_grid=self.Data, psf=self.PSF, **kwargs_numerics) if lens_model_class is None: lens_model_class = LensModel(lens_model_list=[]) self.LensModel = lens_model_class self.PointSource = point_source_class self._error_map_bool_list = None if self.PointSource is not None: self.PointSource.update_lens_model( lens_model_class=lens_model_class) x_center, y_center = self.Data.center self.PointSource.update_search_window( search_window=np.max(self.Data.width), x_center=x_center, y_center=y_center, min_distance=self.Data.pixel_width) if self.PSF.psf_error_map is not None: self._psf_error_map = True self._error_map_bool_list = kwargs_numerics.get( 'error_map_bool_list', [True] * len(self.PointSource.point_source_type_list)) else: self._psf_error_map = False else: self._psf_error_map = False if source_model_class is None: source_model_class = LightModel(light_model_list=[]) self.SourceModel = source_model_class if lens_light_model_class is None: lens_light_model_class = LightModel(light_model_list=[]) self.LensLightModel = lens_light_model_class self.source_mapping = Image2SourceMapping( lensModel=lens_model_class, sourceModel=source_model_class) self.num_bands = 1
def test_raise(self): with self.assertRaises(ValueError): lensModel = LensModel(lens_model_list=['SIS'], multi_plane=True, z_source=3, lens_redshift_list=[0.2], cosmo=None) lightModel = LightModel(light_model_list=['UNIFORM'], deflection_scaling_list=[1.], source_redshift_list=None) class_instance = Image2SourceMapping(lensModel, lightModel) with self.assertRaises(ValueError): lensModel = LensModel(lens_model_list=['SIS'], multi_plane=True, z_source=3, lens_redshift_list=[0.2], cosmo=None) lightModel = LightModel(light_model_list=['UNIFORM'], deflection_scaling_list=None, source_redshift_list=[0, 1, 2]) class_instance = Image2SourceMapping(lensModel, lightModel) with self.assertRaises(ValueError): lensModel = LensModel(lens_model_list=['SIS'], multi_plane=True, z_source=0.5, lens_redshift_list=[0.2], cosmo=None) lightModel = LightModel(light_model_list=['UNIFORM'], deflection_scaling_list=None, source_redshift_list=[1]) class_instance = Image2SourceMapping(lensModel, lightModel) with self.assertRaises(ValueError): lensModel = LensModel(lens_model_list=['SIS'], multi_plane=False, z_source=0.5, cosmo=None) lightModel = LightModel(light_model_list=['UNIFORM'], deflection_scaling_list=[1, 1]) class_instance = Image2SourceMapping(lensModel, lightModel)
def _update_lens_model(self, kwargs_special): """ updates lens model instance of this class (and all class instances related to it) when an update to the modeled redshifts of the deflector and/or source planes are made :param kwargs_special: keyword arguments from SpecialParam() class return of sampling arguments :return: None, internal calls instance updated """ kwargs_model, update_bool = self.update_kwargs_model(kwargs_special) if update_bool is True: # TODO: this class instances are effectively duplicated in the likelihood module and may cause a lot of overhead # in the calculation as the instances are re-generated every step, and even so doing it twice! self._lens_model_class, self._source_model_class, _, _, _ = class_creator.create_class_instances( all_models=True, **kwargs_model) self._image2SourceMapping = Image2SourceMapping(lensModel=self._lens_model_class, sourceModel=self._source_model_class)
def test__re_order_split(self): lensModel = LensModel(lens_model_list=['SIS', 'SIS'], multi_plane=True, lens_redshift_list=[0.5, 0.4], z_source=3) mapping = Image2SourceMapping( lensModel, LightModel(light_model_list=['SERSIC', 'SHAPELETS'], deflection_scaling_list=None, source_redshift_list=[2, 0.3])) n_list = [1, 2] response = np.zeros((3, 3)) response[1:] = 1 response_reshuffled = mapping._re_order_split(response, n_list) assert response_reshuffled[0, 0] == 1 assert response_reshuffled[1, 0] == 0
def setup(self): lens_model_list = ['SIS', 'SIS'] self.kwargs_lens = [{'theta_E': 1, 'center_x': 0, 'center_y': 0}, {'theta_E': 0.5, 'center_x': 1, 'center_y':1}] singlePlane = LensModel(lens_model_list=lens_model_list) multiPlane = LensModel(lens_model_list=lens_model_list, multi_plane=True, z_source=3, lens_redshift_list=[0.2, 0.5], cosmo=None) pseudoMultiPlane = LensModel(lens_model_list=lens_model_list, multi_plane=True, z_source=3, lens_redshift_list=[0.5, 0.5], cosmo=None) # test single plane single source # test single plane multi source # test pseudo multi plane single source light_model_list = ['SERSIC', 'SERSIC'] self.kwargs_light = [{'amp': 1, 'R_sersic': 1, 'n_sersic': 2, 'center_x': 0, 'center_y': 0}, {'amp':2, 'R_sersic': 0.5, 'n_sersic': 1, 'center_x': 1, 'center_y': 1}] self.singlePlane_singlePlane = Image2SourceMapping(singlePlane, LightModel(light_model_list, deflection_scaling_list=None, source_redshift_list=None)) self.singlePlane_pseudoMulti = Image2SourceMapping(singlePlane, LightModel(light_model_list, deflection_scaling_list=[1, 1], source_redshift_list=None)) self.pseudoMulti_pseudoMulti = Image2SourceMapping(pseudoMultiPlane, LightModel(light_model_list, deflection_scaling_list=None, source_redshift_list=[3, 3])) self.pseudoMulti_single = Image2SourceMapping(pseudoMultiPlane, LightModel(light_model_list, deflection_scaling_list=None, source_redshift_list=None)) self.multi_single = Image2SourceMapping(multiPlane, LightModel(light_model_list, deflection_scaling_list=None, source_redshift_list=None)) self.multi_pseudoMulti = Image2SourceMapping(multiPlane, LightModel(light_model_list, deflection_scaling_list=None, source_redshift_list=[3, 3])) self.multi_multi = Image2SourceMapping(multiPlane, LightModel(light_model_list, deflection_scaling_list=None, source_redshift_list=[0.3, 2]))
def __init__(self, data_class, psf_class, lens_model_class=None, source_model_class=None, lens_light_model_class=None, point_source_class=None, extinction_class=None, kwargs_numerics=None, kwargs_pixelbased=None): """ :param data_class: instance of ImageData() or PixelGrid() class :param psf_class: instance of PSF() class :param lens_model_class: instance of LensModel() class :param source_model_class: instance of LightModel() class describing the source parameters :param lens_light_model_class: instance of LightModel() class describing the lens light parameters :param point_source_class: instance of PointSource() class describing the point sources :param kwargs_numerics: keyword arguments with various numeric description (see ImageNumerics class for options) :param kwargs_pixelbased: keyword arguments with various settings related to the pixel-based solver (see SLITronomy documentation) """ self.type = 'single-band' self.num_bands = 1 self.PSF = psf_class self.Data = data_class self.PSF.set_pixel_size(self.Data.pixel_width) if kwargs_numerics is None: kwargs_numerics = {} self.ImageNumerics = NumericsSubFrame(pixel_grid=self.Data, psf=self.PSF, **kwargs_numerics) if lens_model_class is None: lens_model_class = LensModel(lens_model_list=[]) self.LensModel = lens_model_class if point_source_class is None: point_source_class = PointSource(point_source_type_list=[]) self.PointSource = point_source_class self.PointSource.update_lens_model(lens_model_class=lens_model_class) x_center, y_center = self.Data.center self.PointSource.update_search_window( search_window=np.max(self.Data.width), x_center=x_center, y_center=y_center, min_distance=self.Data.pixel_width, only_from_unspecified=True) self._psf_error_map = self.PSF.psf_error_map_bool if source_model_class is None: source_model_class = LightModel(light_model_list=[]) self.SourceModel = source_model_class if lens_light_model_class is None: lens_light_model_class = LightModel(light_model_list=[]) self.LensLightModel = lens_light_model_class self._kwargs_numerics = kwargs_numerics if extinction_class is None: extinction_class = DifferentialExtinction(optical_depth_model=[]) self._extinction = extinction_class if kwargs_pixelbased is None: kwargs_pixelbased = {} else: kwargs_pixelbased = kwargs_pixelbased.copy() self._pixelbased_bool = self._detect_pixelbased_models() if self._pixelbased_bool is True: from slitronomy.Util.class_util import create_solver_class # requirement on SLITronomy is exclusively here self.SourceNumerics = self._setup_pixelbased_source_numerics( kwargs_numerics, kwargs_pixelbased) self.PixelSolver = create_solver_class( self.Data, self.PSF, self.ImageNumerics, self.SourceNumerics, self.LensModel, self.SourceModel, self.LensLightModel, self.PointSource, self._extinction, kwargs_pixelbased) self.source_mapping = None # handled with pixelated operator else: self.source_mapping = Image2SourceMapping( lensModel=lens_model_class, sourceModel=source_model_class)
def __init__(self, kwargs_model, kwargs_fixed_lens=None, kwargs_fixed_source=None, kwargs_fixed_lens_light=None, kwargs_fixed_ps=None, kwargs_fixed_special=None, kwargs_fixed_extinction=None, kwargs_lower_lens=None, kwargs_lower_source=None, kwargs_lower_lens_light=None, kwargs_lower_ps=None, kwargs_lower_special=None, kwargs_lower_extinction=None, kwargs_upper_lens=None, kwargs_upper_source=None, kwargs_upper_lens_light=None, kwargs_upper_ps=None, kwargs_upper_special=None, kwargs_upper_extinction=None, kwargs_lens_init=None, linear_solver=True, joint_lens_with_lens=[], joint_lens_light_with_lens_light=[], joint_source_with_source=[], joint_lens_with_light=[], joint_source_with_point_source=[], joint_lens_light_with_point_source=[], joint_extinction_with_lens_light=[], joint_lens_with_source_light=[], mass_scaling_list=None, point_source_offset=False, num_point_source_list=None, image_plane_source_list=None, solver_type='NONE', Ddt_sampling=None, source_size=False, num_tau0=0, lens_redshift_sampling_indexes=None, source_redshift_sampling_indexes=None, source_grid_offset=False, num_shapelet_lens=0, log_sampling_lens=[]): """ :param kwargs_model: keyword arguments to describe all model components used in class_creator.create_class_instances() :param kwargs_fixed_lens: fixed parameters for lens model (keyword argument list) :param kwargs_fixed_source: fixed parameters for source model (keyword argument list) :param kwargs_fixed_lens_light: fixed parameters for lens light model (keyword argument list) :param kwargs_fixed_ps: fixed parameters for point source model (keyword argument list) :param kwargs_fixed_special: fixed parameters for special model parameters (keyword arguments) :param kwargs_fixed_extinction: fixed parameters for extinction model parameters (keyword argument list) :param kwargs_lower_lens: lower limits for parameters of lens model (keyword argument list) :param kwargs_lower_source: lower limits for parameters of source model (keyword argument list) :param kwargs_lower_lens_light: lower limits for parameters of lens light model (keyword argument list) :param kwargs_lower_ps: lower limits for parameters of point source model (keyword argument list) :param kwargs_lower_special: lower limits for parameters of special model parameters (keyword arguments) :param kwargs_lower_extinction: lower limits for parameters of extinction model (keyword argument list) :param kwargs_upper_lens: upper limits for parameters of lens model (keyword argument list) :param kwargs_upper_source: upper limits for parameters of source model (keyword argument list) :param kwargs_upper_lens_light: upper limits for parameters of lens light model (keyword argument list) :param kwargs_upper_ps: upper limits for parameters of point source model (keyword argument list) :param kwargs_upper_special: upper limits for parameters of special model parameters (keyword arguments) :param kwargs_upper_extinction: upper limits for parameters of extinction model (keyword argument list) :param kwargs_lens_init: initial guess of lens model keyword arguments (only relevant as the starting point of the non-linear solver) :param linear_solver: bool, if True fixes the linear amplitude parameters 'amp' (avoid sampling) such that they get overwritten by the linear solver solution. :param joint_lens_with_lens: list [[i_lens, k_lens, ['param_name1', 'param_name2', ...]], [...], ...], joint parameter between two lens models :param joint_lens_light_with_lens_light: list [[i_lens_light, k_lens_light, ['param_name1', 'param_name2', ...]], [...], ...], joint parameter between two lens light models, the second adopts the value of the first :param joint_source_with_source: [[i_source, k_source, ['param_name1', 'param_name2', ...]], [...], ...], joint parameter between two source surface brightness models, the second adopts the value of the first :param joint_lens_with_light: list [[i_light, k_lens, ['param_name1', 'param_name2', ...]], [...], ...], joint parameter between lens model and lens light model :param joint_source_with_point_source: list [[i_point_source, k_source], [...], ...], joint position parameter between lens model and source light model :param joint_lens_light_with_point_source: list [[i_point_source, k_lens_light], [...], ...], joint position parameter between lens model and lens light model :param joint_extinction_with_lens_light: list [[i_lens_light, k_extinction, ['param_name1', 'param_name2', ...]], [...], ...], joint parameters between the lens surface brightness and the optical depth models :param joint_lens_with_source_light: [[i_source, k_lens, ['param_name1', 'param_name2', ...]], [...], ...], joint parameter between lens model and source light model. Samples light model parameter only. :param mass_scaling_list: boolean list of length of lens model list (optional) models with identical integers will be scaled with the same additional scaling factor. First integer starts with 1 (not 0) :param point_source_offset: bool, if True, adds relative offsets ot the modeled image positions relative to the time-delay and lens equation solver :param num_point_source_list: list of number of point sources per point source model class :param image_plane_source_list: optional, list of booleans for the source_light components. If a component is set =True it will parameterized the positions in the image plane and ray-trace the parameters back to the source position on the fly during the fitting. :param solver_type: string, option for specific solver type see detailed instruction of the Solver4Point and Solver2Point classes :param Ddt_sampling: bool, if True, samples the time-delay distance D_dt (in units of Mpc) :param source_size: bool, if True, samples a source size parameters to be evaluated in the flux ratio likelihood :param num_tau0: integer, number of different optical depth re-normalization factors :param lens_redshift_sampling_indexes: list of integers corresponding to the lens model components whose redshifts are a free parameter (only has an effect in multi-plane lensing) with same indexes indicating joint redshift, in ascending numbering e.g. [-1, 0, 0, 1, 0, 2], -1 indicating not sampled fixed indexes :param source_redshift_sampling_indexes: list of integers corresponding to the source model components whose redshifts are a free parameter (only has an effect in multi-plane lensing) with same indexes indicating joint redshift, in ascending numbering e.g. [-1, 0, 0, 1, 0, 2], -1 indicating not sampled fixed indexes. These indexes are the sample as for the lens :param source_grid_offset: optional, if True when using a pixel-based modelling (e.g. with STARLETS-like profiles), adds two additional sampled parameters describing RA/Dec offsets between data coordinate grid and pixelated source plane coordinate grid. :param num_shapelet_lens: number of shapelet coefficients in the 'SHAPELETS_CART' or 'SHAPELETS_POLAR' mass profile. :param log_sampling_lens: Sample the log10 of the lens model parameters. Format : [[i_lens, ['param_name1', 'param_name2', ...]], [...], ...], """ self._lens_model_list = kwargs_model.get('lens_model_list', []) self._lens_redshift_list = kwargs_model.get('lens_redshift_list', None) self._source_light_model_list = kwargs_model.get( 'source_light_model_list', []) self._source_redshift_list = kwargs_model.get('source_redshift_list', None) self._lens_light_model_list = kwargs_model.get('lens_light_model_list', []) self._point_source_model_list = kwargs_model.get( 'point_source_model_list', []) self._optical_depth_model_list = kwargs_model.get( 'optical_depth_model_list', []) self._kwargs_model = kwargs_model # check how many redshifts need to be sampled num_z_sampling = 0 if lens_redshift_sampling_indexes is not None: num_z_sampling = int(np.max(lens_redshift_sampling_indexes) + 1) if source_redshift_sampling_indexes is not None: num_z_source = int(np.max(source_redshift_sampling_indexes) + 1) num_z_sampling = max(num_z_sampling, num_z_source) self._num_z_sampling, self._lens_redshift_sampling_indexes, self._source_redshift_sampling_indexes = num_z_sampling, lens_redshift_sampling_indexes, source_redshift_sampling_indexes self._lens_model_class, self._source_model_class, _, _, _ = class_creator.create_class_instances( all_models=True, **kwargs_model) self._image2SourceMapping = Image2SourceMapping( lensModel=self._lens_model_class, sourceModel=self._source_model_class) if kwargs_fixed_lens is None: kwargs_fixed_lens = [{} for i in range(len(self._lens_model_list))] if kwargs_fixed_source is None: kwargs_fixed_source = [ {} for i in range(len(self._source_light_model_list)) ] if kwargs_fixed_lens_light is None: kwargs_fixed_lens_light = [ {} for i in range(len(self._lens_light_model_list)) ] if kwargs_fixed_ps is None: kwargs_fixed_ps = [ {} for i in range(len(self._point_source_model_list)) ] if kwargs_fixed_special is None: kwargs_fixed_special = {} self._joint_lens_with_lens = joint_lens_with_lens self._joint_lens_light_with_lens_light = joint_lens_light_with_lens_light self._joint_source_with_source = joint_source_with_source self._joint_lens_with_light = joint_lens_with_light self._joint_lens_with_source_light = joint_lens_with_source_light self._joint_source_with_point_source = copy.deepcopy( joint_source_with_point_source) # Set up the parameters being sampled in log space in a similar way than the parameters being fixed. self._log_sampling_lens = log_sampling_lens kwargs_logsampling_lens = [[] for i in range(len(self._lens_model_list))] kwargs_logsampling_lens = self._update_log_sampling( kwargs_logsampling_lens, log_sampling_lens) for param_list in self._joint_source_with_point_source: if len(param_list) == 2: param_list.append(['center_x', 'center_y']) self._joint_lens_light_with_point_source = copy.deepcopy( joint_lens_light_with_point_source) for param_list in self._joint_lens_light_with_point_source: if len(param_list) == 2: param_list.append(['center_x', 'center_y']) if mass_scaling_list is None: mass_scaling_list = [False] * len(self._lens_model_list) self._mass_scaling_list = mass_scaling_list if 1 in self._mass_scaling_list: self._num_scale_factor = np.max(self._mass_scaling_list) self._mass_scaling = True else: self._num_scale_factor = 0 self._mass_scaling = False self._point_source_offset = point_source_offset if num_point_source_list is None: num_point_source_list = [1] * len(self._point_source_model_list) # Attention: if joint coordinates with other source profiles, only indicate one as bool if image_plane_source_list is None: image_plane_source_list = [False] * len( self._source_light_model_list) self._image_plane_source_list = image_plane_source_list try: self._num_images = num_point_source_list[0] except: self._num_images = 0 self._solver_type = solver_type if self._solver_type == 'NONE': self._solver = False else: self._solver = True self._solver_module = Solver(solver_type=self._solver_type, lensModel=self._lens_model_class, num_images=self._num_images) source_model_list = self._source_light_model_list if len(source_model_list) != 1 or source_model_list[0] not in [ 'SLIT_STARLETS', 'SLIT_STARLETS_GEN2' ]: # source_grid_offset only defined for source profiles compatible with pixel-based solver source_grid_offset = False self._joint_extinction_with_lens_light = joint_extinction_with_lens_light # fix parameters joint within the same model types kwargs_fixed_lens_updated = self._add_fixed_lens( kwargs_fixed_lens, kwargs_lens_init) kwargs_fixed_lens_updated = self._fix_joint_param( kwargs_fixed_lens_updated, self._joint_lens_with_lens) kwargs_fixed_lens_updated = self._fix_joint_param( kwargs_fixed_lens_updated, self._joint_lens_with_source_light) kwargs_fixed_lens_light_updated = self._fix_joint_param( kwargs_fixed_lens_light, self._joint_lens_light_with_lens_light) kwargs_fixed_source_updated = self._fix_joint_param( kwargs_fixed_source, self._joint_source_with_source) kwargs_fixed_ps_updated = copy.deepcopy(kwargs_fixed_ps) kwargs_fixed_extinction_updated = self._fix_joint_param( kwargs_fixed_extinction, self._joint_extinction_with_lens_light) # fix parameters joint with other model types kwargs_fixed_lens_updated = self._fix_joint_param( kwargs_fixed_lens_updated, self._joint_lens_with_light) kwargs_fixed_source_updated = self._fix_joint_param( kwargs_fixed_source_updated, self._joint_source_with_point_source) kwargs_fixed_lens_light_updated = self._fix_joint_param( kwargs_fixed_lens_light_updated, self._joint_lens_light_with_point_source) self.lensParams = LensParam(self._lens_model_list, kwargs_fixed_lens_updated, kwargs_logsampling=kwargs_logsampling_lens, num_images=self._num_images, solver_type=self._solver_type, kwargs_lower=kwargs_lower_lens, kwargs_upper=kwargs_upper_lens, num_shapelet_lens=num_shapelet_lens) self.lensLightParams = LightParam(self._lens_light_model_list, kwargs_fixed_lens_light_updated, param_type='lens_light', linear_solver=linear_solver, kwargs_lower=kwargs_lower_lens_light, kwargs_upper=kwargs_upper_lens_light) self.souceParams = LightParam(self._source_light_model_list, kwargs_fixed_source_updated, param_type='source_light', linear_solver=linear_solver, kwargs_lower=kwargs_lower_source, kwargs_upper=kwargs_upper_source) self.pointSourceParams = PointSourceParam( self._point_source_model_list, kwargs_fixed_ps_updated, num_point_source_list=num_point_source_list, linear_solver=linear_solver, kwargs_lower=kwargs_lower_ps, kwargs_upper=kwargs_upper_ps) self.extinctionParams = LightParam( self._optical_depth_model_list, kwargs_fixed_extinction_updated, kwargs_lower=kwargs_lower_extinction, kwargs_upper=kwargs_upper_extinction, linear_solver=False) self.specialParams = SpecialParam( Ddt_sampling=Ddt_sampling, mass_scaling=self._mass_scaling, kwargs_fixed=kwargs_fixed_special, num_scale_factor=self._num_scale_factor, kwargs_lower=kwargs_lower_special, kwargs_upper=kwargs_upper_special, point_source_offset=self._point_source_offset, num_images=self._num_images, source_size=source_size, num_tau0=num_tau0, num_z_sampling=num_z_sampling, source_grid_offset=source_grid_offset) for lens_source_joint in self._joint_lens_with_source_light: i_source = lens_source_joint[0] if i_source in self._image_plane_source_list: raise ValueError( "linking a source light model with a lens model AND simultaneously parameterizing the" " source position in the image plane is not valid!")
def __init__(self, kwargs_model, kwargs_fixed_lens=None, kwargs_fixed_source=None, kwargs_fixed_lens_light=None, kwargs_fixed_ps=None, kwargs_fixed_special=None, kwargs_fixed_extinction=None, kwargs_lower_lens=None, kwargs_lower_source=None, kwargs_lower_lens_light=None, kwargs_lower_ps=None, kwargs_lower_special=None, kwargs_lower_extinction=None, kwargs_upper_lens=None, kwargs_upper_source=None, kwargs_upper_lens_light=None, kwargs_upper_ps=None, kwargs_upper_special=None, kwargs_upper_extinction=None, kwargs_lens_init=None, linear_solver=True, joint_lens_with_lens=[], joint_lens_light_with_lens_light=[], joint_source_with_source=[], joint_lens_with_light=[], joint_source_with_point_source=[], joint_lens_light_with_point_source=[], joint_extinction_with_lens_light=[], joint_lens_with_source_light=[], mass_scaling_list=None, point_source_offset=False, num_point_source_list=None, image_plane_source_list=None, solver_type='NONE', Ddt_sampling=None, source_size=False, num_tau0=0): """ :return: """ self._lens_model_list = kwargs_model.get('lens_model_list', []) self._source_light_model_list = kwargs_model.get('source_light_model_list', []) self._lens_light_model_list = kwargs_model.get('lens_light_model_list', []) self._point_source_model_list = kwargs_model.get('point_source_model_list', []) self._optical_depth_model_list = kwargs_model.get('optical_depth_model_list', []) lens_model_class, source_model_class, _, _, _ = class_creator.create_class_instances(all_models=True, **kwargs_model) self._image2SourceMapping = Image2SourceMapping(lensModel=lens_model_class, sourceModel=source_model_class) if kwargs_fixed_lens is None: kwargs_fixed_lens = [{} for i in range(len(self._lens_model_list))] if kwargs_fixed_source is None: kwargs_fixed_source = [{} for i in range(len(self._source_light_model_list))] if kwargs_fixed_lens_light is None: kwargs_fixed_lens_light = [{} for i in range(len(self._lens_light_model_list))] if kwargs_fixed_ps is None: kwargs_fixed_ps = [{} for i in range(len(self._point_source_model_list))] if kwargs_fixed_special is None: kwargs_fixed_special = {} self._joint_lens_with_lens = joint_lens_with_lens self._joint_lens_light_with_lens_light = joint_lens_light_with_lens_light self._joint_source_with_source = joint_source_with_source self._joint_lens_with_light = joint_lens_with_light self._joint_lens_with_source_light = joint_lens_with_source_light self._joint_source_with_point_source = copy.deepcopy(joint_source_with_point_source) for param_list in self._joint_source_with_point_source: if len(param_list) == 2: param_list.append(['center_x', 'center_y']) self._joint_lens_light_with_point_source = copy.deepcopy(joint_lens_light_with_point_source) for param_list in self._joint_lens_light_with_point_source: if len(param_list) == 2: param_list.append(['center_x', 'center_y']) if mass_scaling_list is None: mass_scaling_list = [False] * len(self._lens_model_list) self._mass_scaling_list = mass_scaling_list if 1 in self._mass_scaling_list: self._num_scale_factor = np.max(self._mass_scaling_list) self._mass_scaling = True else: self._num_scale_factor = 0 self._mass_scaling = False self._point_source_offset = point_source_offset if num_point_source_list is None: num_point_source_list = [1] * len(self._point_source_model_list) # Attention: if joint coordinates with other source profiles, only indicate one as bool if image_plane_source_list is None: image_plane_source_list = [False] * len(self._source_light_model_list) self._image_plane_source_list = image_plane_source_list try: self._num_images = num_point_source_list[0] except: self._num_images = 0 self._solver_type = solver_type if self._solver_type == 'NONE': self._solver = False else: self._solver = True self._solver_module = Solver(solver_type=self._solver_type, lensModel=lens_model_class, num_images=self._num_images) self._joint_extinction_with_lens_light = joint_extinction_with_lens_light # fix parameters joint within the same model types kwargs_fixed_lens_updated = self._add_fixed_lens(kwargs_fixed_lens, kwargs_lens_init) kwargs_fixed_lens_updated = self._fix_joint_param(kwargs_fixed_lens_updated, self._joint_lens_with_lens) kwargs_fixed_lens_updated = self._fix_joint_param(kwargs_fixed_lens_updated, self._joint_lens_with_source_light) kwargs_fixed_lens_light_updated = self._fix_joint_param(kwargs_fixed_lens_light, self._joint_lens_light_with_lens_light) kwargs_fixed_source_updated = self._fix_joint_param(kwargs_fixed_source, self._joint_source_with_source) kwargs_fixed_ps_updated = copy.deepcopy(kwargs_fixed_ps) kwargs_fixed_extinction_updated = self._fix_joint_param(kwargs_fixed_extinction, self._joint_extinction_with_lens_light) # fix parameters joint with other model types kwargs_fixed_lens_updated = self._fix_joint_param(kwargs_fixed_lens_updated, self._joint_lens_with_light) kwargs_fixed_source_updated = self._fix_joint_param(kwargs_fixed_source_updated, self._joint_source_with_point_source) kwargs_fixed_lens_light_updated = self._fix_joint_param(kwargs_fixed_lens_light_updated, self._joint_lens_light_with_point_source) self.lensParams = LensParam(self._lens_model_list, kwargs_fixed_lens_updated, num_images=self._num_images, solver_type=self._solver_type, kwargs_lower=kwargs_lower_lens, kwargs_upper=kwargs_upper_lens) self.lensLightParams = LightParam(self._lens_light_model_list, kwargs_fixed_lens_light_updated, type='lens_light', linear_solver=linear_solver, kwargs_lower=kwargs_lower_lens_light, kwargs_upper=kwargs_upper_lens_light) self.souceParams = LightParam(self._source_light_model_list, kwargs_fixed_source_updated, type='source_light', linear_solver=linear_solver, kwargs_lower=kwargs_lower_source, kwargs_upper=kwargs_upper_source) self.pointSourceParams = PointSourceParam(self._point_source_model_list, kwargs_fixed_ps_updated, num_point_source_list=num_point_source_list, linear_solver=linear_solver, kwargs_lower=kwargs_lower_ps, kwargs_upper=kwargs_upper_ps) self.extinctionParams = LightParam(self._optical_depth_model_list, kwargs_fixed_extinction_updated, kwargs_lower=kwargs_lower_extinction, kwargs_upper=kwargs_upper_extinction, linear_solver=False) self.specialParams = SpecialParam(Ddt_sampling=Ddt_sampling, mass_scaling=self._mass_scaling, kwargs_fixed=kwargs_fixed_special, num_scale_factor=self._num_scale_factor, kwargs_lower=kwargs_lower_special, kwargs_upper=kwargs_upper_special, point_source_offset=self._point_source_offset, num_images=self._num_images, source_size=source_size, num_tau0=num_tau0) for lens_source_joint in self._joint_lens_with_source_light: i_source = lens_source_joint[0] if i_source in self._image_plane_source_list: raise ValueError("linking a source light model with a lens model AND simultaneously parameterizing the" " source position in the image plane is not valid!")
def __init__(self, kwargs_model, kwargs_fixed_lens=None, kwargs_fixed_source=None, kwargs_fixed_lens_light=None, kwargs_fixed_ps=None, kwargs_fixed_special=None, kwargs_fixed_extinction=None, kwargs_lower_lens=None, kwargs_lower_source=None, kwargs_lower_lens_light=None, kwargs_lower_ps=None, kwargs_lower_special=None, kwargs_lower_extinction=None, kwargs_upper_lens=None, kwargs_upper_source=None, kwargs_upper_lens_light=None, kwargs_upper_ps=None, kwargs_upper_special=None, kwargs_upper_extinction=None, kwargs_lens_init=None, linear_solver=True, joint_lens_with_lens=[], joint_lens_light_with_lens_light=[], joint_source_with_source=[], joint_lens_with_light=[], joint_source_with_point_source=[], joint_lens_light_with_point_source=[], joint_extinction_with_lens_light=[], joint_lens_with_source_light=[], mass_scaling_list=None, point_source_offset=False, num_point_source_list=None, image_plane_source_list=None, solver_type='NONE', Ddt_sampling=None, source_size=False, num_tau0=0, lens_redshift_sampling_indexes=None, source_redshift_sampling_indexes=None, source_grid_offset=False, num_shapelet_lens=0): """ :param kwargs_model: :param kwargs_fixed_lens: :param kwargs_fixed_source: :param kwargs_fixed_lens_light: :param kwargs_fixed_ps: :param kwargs_fixed_special: :param kwargs_fixed_extinction: :param kwargs_lower_lens: :param kwargs_lower_source: :param kwargs_lower_lens_light: :param kwargs_lower_ps: :param kwargs_lower_special: :param kwargs_lower_extinction: :param kwargs_upper_lens: :param kwargs_upper_source: :param kwargs_upper_lens_light: :param kwargs_upper_ps: :param kwargs_upper_special: :param kwargs_upper_extinction: :param kwargs_lens_init: :param linear_solver: :param joint_lens_with_lens: :param joint_lens_light_with_lens_light: :param joint_source_with_source: :param joint_lens_with_light: :param joint_source_with_point_source: :param joint_lens_light_with_point_source: :param joint_extinction_with_lens_light: :param joint_lens_with_source_light: :param mass_scaling_list: :param point_source_offset: :param num_point_source_list: :param image_plane_source_list: optional, list of booleans for the source_light components. If a component is set =True it will parameterized the positions in the image plane and ray-trace the parameters back to the source position on the fly during the fitting. :param solver_type: :param Ddt_sampling: :param source_size: :param num_tau0: :param lens_redshift_sampling_indexes: list of integers corresponding to the lens model components whose redshifts are a free parameter (only has an effect in multi-plane lensing) with same indexes indicating joint redshift, in ascending numbering e.g. [-1, 0, 0, 1, 0, 2], -1 indicating not sampled fixed indexes :param source_redshift_sampling_indexes: list of integers corresponding to the source model components whose redshifts are a free parameter (only has an effect in multi-plane lensing) with same indexes indicating joint redshift, in ascending numbering e.g. [-1, 0, 0, 1, 0, 2], -1 indicating not sampled fixed indexes. These indexes are the sample as for the lens :param source_grid_offset: optional, if True when using a pixel-based modelling (e.g. with STARLETS-like profiles), adds two additional sampled parameters describing RA/Dec offsets between data coordinate grid and pixelated source plane coordinate grid. :param num_shapelet_lens: number of shapelet coefficients in the 'SHAPELETS_CART' or 'SHAPELETS_POLAR' mass profile. """ self._lens_model_list = kwargs_model.get('lens_model_list', []) self._lens_redshift_list = kwargs_model.get('lens_redshift_list', None) self._source_light_model_list = kwargs_model.get( 'source_light_model_list', []) self._source_redshift_list = kwargs_model.get('source_redshift_list', None) self._lens_light_model_list = kwargs_model.get('lens_light_model_list', []) self._point_source_model_list = kwargs_model.get( 'point_source_model_list', []) self._optical_depth_model_list = kwargs_model.get( 'optical_depth_model_list', []) self._kwargs_model = kwargs_model # check how many redshifts need to be sampled num_z_sampling = 0 if lens_redshift_sampling_indexes is not None: num_z_sampling = int(np.max(lens_redshift_sampling_indexes) + 1) if source_redshift_sampling_indexes is not None: num_z_source = int(np.max(source_redshift_sampling_indexes) + 1) num_z_sampling = max(num_z_sampling, num_z_source) self._num_z_sampling, self._lens_redshift_sampling_indexes, self._source_redshift_sampling_indexes = num_z_sampling, lens_redshift_sampling_indexes, source_redshift_sampling_indexes self._lens_model_class, self._source_model_class, _, _, _ = class_creator.create_class_instances( all_models=True, **kwargs_model) self._image2SourceMapping = Image2SourceMapping( lensModel=self._lens_model_class, sourceModel=self._source_model_class) if kwargs_fixed_lens is None: kwargs_fixed_lens = [{} for i in range(len(self._lens_model_list))] if kwargs_fixed_source is None: kwargs_fixed_source = [ {} for i in range(len(self._source_light_model_list)) ] if kwargs_fixed_lens_light is None: kwargs_fixed_lens_light = [ {} for i in range(len(self._lens_light_model_list)) ] if kwargs_fixed_ps is None: kwargs_fixed_ps = [ {} for i in range(len(self._point_source_model_list)) ] if kwargs_fixed_special is None: kwargs_fixed_special = {} self._joint_lens_with_lens = joint_lens_with_lens self._joint_lens_light_with_lens_light = joint_lens_light_with_lens_light self._joint_source_with_source = joint_source_with_source self._joint_lens_with_light = joint_lens_with_light self._joint_lens_with_source_light = joint_lens_with_source_light self._joint_source_with_point_source = copy.deepcopy( joint_source_with_point_source) for param_list in self._joint_source_with_point_source: if len(param_list) == 2: param_list.append(['center_x', 'center_y']) self._joint_lens_light_with_point_source = copy.deepcopy( joint_lens_light_with_point_source) for param_list in self._joint_lens_light_with_point_source: if len(param_list) == 2: param_list.append(['center_x', 'center_y']) if mass_scaling_list is None: mass_scaling_list = [False] * len(self._lens_model_list) self._mass_scaling_list = mass_scaling_list if 1 in self._mass_scaling_list: self._num_scale_factor = np.max(self._mass_scaling_list) self._mass_scaling = True else: self._num_scale_factor = 0 self._mass_scaling = False self._point_source_offset = point_source_offset if num_point_source_list is None: num_point_source_list = [1] * len(self._point_source_model_list) # Attention: if joint coordinates with other source profiles, only indicate one as bool if image_plane_source_list is None: image_plane_source_list = [False] * len( self._source_light_model_list) self._image_plane_source_list = image_plane_source_list try: self._num_images = num_point_source_list[0] except: self._num_images = 0 self._solver_type = solver_type if self._solver_type == 'NONE': self._solver = False else: self._solver = True self._solver_module = Solver(solver_type=self._solver_type, lensModel=self._lens_model_class, num_images=self._num_images) source_model_list = self._source_light_model_list if (len(source_model_list) != 1 or source_model_list[0] not in ['SLIT_STARLETS', 'SLIT_STARLETS_GEN2']): # source_grid_offset only defined for source profiles compatible with pixel-based solver source_grid_offset = False self._joint_extinction_with_lens_light = joint_extinction_with_lens_light # fix parameters joint within the same model types kwargs_fixed_lens_updated = self._add_fixed_lens( kwargs_fixed_lens, kwargs_lens_init) kwargs_fixed_lens_updated = self._fix_joint_param( kwargs_fixed_lens_updated, self._joint_lens_with_lens) kwargs_fixed_lens_updated = self._fix_joint_param( kwargs_fixed_lens_updated, self._joint_lens_with_source_light) kwargs_fixed_lens_light_updated = self._fix_joint_param( kwargs_fixed_lens_light, self._joint_lens_light_with_lens_light) kwargs_fixed_source_updated = self._fix_joint_param( kwargs_fixed_source, self._joint_source_with_source) kwargs_fixed_ps_updated = copy.deepcopy(kwargs_fixed_ps) kwargs_fixed_extinction_updated = self._fix_joint_param( kwargs_fixed_extinction, self._joint_extinction_with_lens_light) # fix parameters joint with other model types kwargs_fixed_lens_updated = self._fix_joint_param( kwargs_fixed_lens_updated, self._joint_lens_with_light) kwargs_fixed_source_updated = self._fix_joint_param( kwargs_fixed_source_updated, self._joint_source_with_point_source) kwargs_fixed_lens_light_updated = self._fix_joint_param( kwargs_fixed_lens_light_updated, self._joint_lens_light_with_point_source) self.lensParams = LensParam(self._lens_model_list, kwargs_fixed_lens_updated, num_images=self._num_images, solver_type=self._solver_type, kwargs_lower=kwargs_lower_lens, kwargs_upper=kwargs_upper_lens, num_shapelet_lens=num_shapelet_lens) self.lensLightParams = LightParam(self._lens_light_model_list, kwargs_fixed_lens_light_updated, type='lens_light', linear_solver=linear_solver, kwargs_lower=kwargs_lower_lens_light, kwargs_upper=kwargs_upper_lens_light) self.souceParams = LightParam(self._source_light_model_list, kwargs_fixed_source_updated, type='source_light', linear_solver=linear_solver, kwargs_lower=kwargs_lower_source, kwargs_upper=kwargs_upper_source) self.pointSourceParams = PointSourceParam( self._point_source_model_list, kwargs_fixed_ps_updated, num_point_source_list=num_point_source_list, linear_solver=linear_solver, kwargs_lower=kwargs_lower_ps, kwargs_upper=kwargs_upper_ps) self.extinctionParams = LightParam( self._optical_depth_model_list, kwargs_fixed_extinction_updated, kwargs_lower=kwargs_lower_extinction, kwargs_upper=kwargs_upper_extinction, linear_solver=False) self.specialParams = SpecialParam( Ddt_sampling=Ddt_sampling, mass_scaling=self._mass_scaling, kwargs_fixed=kwargs_fixed_special, num_scale_factor=self._num_scale_factor, kwargs_lower=kwargs_lower_special, kwargs_upper=kwargs_upper_special, point_source_offset=self._point_source_offset, num_images=self._num_images, source_size=source_size, num_tau0=num_tau0, num_z_sampling=num_z_sampling, source_grid_offset=source_grid_offset) for lens_source_joint in self._joint_lens_with_source_light: i_source = lens_source_joint[0] if i_source in self._image_plane_source_list: raise ValueError( "linking a source light model with a lens model AND simultaneously parameterizing the" " source position in the image plane is not valid!")
def __init__(self, kwargs_model, kwargs_fixed_lens=None, kwargs_fixed_source=None, kwargs_fixed_lens_light=None, kwargs_fixed_ps=None, kwargs_fixed_cosmo=None, kwargs_lower_lens=None, kwargs_lower_source=None, kwargs_lower_lens_light=None, kwargs_lower_ps=None, kwargs_lower_cosmo=None, kwargs_upper_lens=None, kwargs_upper_source=None, kwargs_upper_lens_light=None, kwargs_upper_ps=None, kwargs_upper_cosmo=None, kwargs_lens_init=None, linear_solver=True, joint_lens_with_lens=[], joint_lens_light_with_lens_light=[], joint_source_with_source=[], joint_lens_with_light=[], joint_source_with_point_source=[], joint_lens_light_with_point_source=[], mass_scaling_list=None, point_source_offset=False, num_point_source_list=None, image_plane_source_list=None, solver_type='NONE', cosmo_type=None): """ :return: """ self._lens_model_list = kwargs_model.get('lens_model_list', []) self._source_light_model_list = kwargs_model.get('source_light_model_list', []) self._lens_light_model_list = kwargs_model.get('lens_light_model_list', []) self._point_source_model_list = kwargs_model.get('point_source_model_list', []) lensModel = LensModel(lens_model_list=self._lens_model_list, z_source=kwargs_model.get('z_source', None), lens_redshift_list=kwargs_model.get('redshift_list', None), multi_plane=kwargs_model.get('multi_plane', False)) sourceModel = LightModel(light_model_list=self._source_light_model_list, deflection_scaling_list=kwargs_model.get('source_deflection_scaling_list', None), source_redshift_list=kwargs_model.get('source_redshift_list', None)) self._image2SourceMapping = Image2SourceMapping(lensModel=lensModel, sourceModel=sourceModel) if kwargs_fixed_lens is None: kwargs_fixed_lens = [{} for i in range(len(self._lens_model_list))] if kwargs_fixed_source is None: kwargs_fixed_source = [{} for i in range(len(self._source_light_model_list))] if kwargs_fixed_lens_light is None: kwargs_fixed_lens_light = [{} for i in range(len(self._lens_light_model_list))] if kwargs_fixed_ps is None: kwargs_fixed_ps = [{} for i in range(len(self._point_source_model_list))] if kwargs_fixed_cosmo is None: kwargs_fixed_cosmo = {} self._joint_lens_with_lens = joint_lens_with_lens self._joint_lens_light_with_lens_light = joint_lens_light_with_lens_light self._joint_source_with_source = joint_source_with_source self._joint_lens_with_light = joint_lens_with_light self._joint_source_with_point_source = copy.deepcopy(joint_source_with_point_source) for param_list in self._joint_source_with_point_source: if len(param_list) == 2: param_list.append(['center_x', 'center_y']) self._joint_lens_light_with_point_source = copy.deepcopy(joint_lens_light_with_point_source) for param_list in self._joint_lens_light_with_point_source: if len(param_list) == 2: param_list.append(['center_x', 'center_y']) if mass_scaling_list is None: mass_scaling_list = [False] * len(self._lens_model_list) self._mass_scaling_list = mass_scaling_list if 1 in self._mass_scaling_list: self._num_scale_factor = np.max(self._mass_scaling_list) self._mass_scaling = True else: self._num_scale_factor = 0 self._mass_scaling = False self._point_source_offset = point_source_offset if num_point_source_list is None: num_point_source_list = [1] * len(self._point_source_model_list) # Attention: if joint coordinates with other source profiles, only indicate one as bool if image_plane_source_list is None: image_plane_source_list = [False] * len(self._source_light_model_list) self._image_plane_source_list = image_plane_source_list try: self._num_images = num_point_source_list[0] except: self._num_images = 0 self._solver_type = solver_type if self._solver_type == 'NONE': self._solver = False else: self._solver = True self._solver_module = Solver(solver_type=self._solver_type, lensModel=lensModel, num_images=self._num_images) # fix parameters joint within the same model types kwargs_fixed_lens_updated = self._add_fixed_lens(kwargs_fixed_lens, kwargs_lens_init) kwargs_fixed_lens_updated = self._fix_joint_param(kwargs_fixed_lens_updated, self._joint_lens_with_lens) kwargs_fixed_lens_light_updated = self._fix_joint_param(kwargs_fixed_lens_light, self._joint_lens_light_with_lens_light) kwargs_fixed_source_updated = self._fix_joint_param(kwargs_fixed_source, self._joint_source_with_source) kwargs_fixed_ps_updated = copy.deepcopy(kwargs_fixed_ps) # fix parameters joint with other model types kwargs_fixed_lens_updated = self._fix_joint_param(kwargs_fixed_lens_updated, self._joint_lens_with_light) kwargs_fixed_source_updated = self._fix_joint_param(kwargs_fixed_source_updated, self._joint_source_with_point_source) kwargs_fixed_lens_light_updated = self._fix_joint_param(kwargs_fixed_lens_light_updated, self._joint_lens_light_with_point_source) self.lensParams = LensParam(self._lens_model_list, kwargs_fixed_lens_updated, num_images=self._num_images, solver_type=self._solver_type, kwargs_lower=kwargs_lower_lens, kwargs_upper=kwargs_upper_lens) self.lensLightParams = LightParam(self._lens_light_model_list, kwargs_fixed_lens_light_updated, type='lens_light', linear_solver=linear_solver, kwargs_lower=kwargs_lower_lens_light, kwargs_upper=kwargs_upper_lens_light) self.souceParams = LightParam(self._source_light_model_list, kwargs_fixed_source_updated, type='source_light', linear_solver=linear_solver, kwargs_lower=kwargs_lower_source, kwargs_upper=kwargs_upper_source) self.pointSourceParams = PointSourceParam(self._point_source_model_list, kwargs_fixed_ps_updated, num_point_source_list=num_point_source_list, linear_solver=linear_solver, kwargs_lower=kwargs_lower_ps, kwargs_upper=kwargs_upper_ps) self.cosmoParams = CosmoParam(cosmo_type=cosmo_type, mass_scaling=self._mass_scaling, kwargs_fixed=kwargs_fixed_cosmo, num_scale_factor=self._num_scale_factor, kwargs_lower=kwargs_lower_cosmo, kwargs_upper=kwargs_upper_cosmo, point_source_offset=self._point_source_offset, num_images=self._num_images)