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 __init__(self, z_lens, z_source, kwargs_model, kwargs_aperture, kwargs_seeing, anisotropy_model, cosmo=None, lens_model_kinematics_bool=None, light_model_kinematics_bool=None, multi_observations=False, kwargs_numerics_galkin=None, analytic_kinematics=False, Hernquist_approx=False, MGE_light=False, MGE_mass=False, kwargs_mge_light=None, kwargs_mge_mass=None, sampling_number=1000, num_kin_sampling=1000, num_psf_sampling=100): """ :param z_lens: redshift of lens :param z_source: redshift of source :param kwargs_model: model keyword arguments, needs 'lens_model_list', 'lens_light_model_list' :param kwargs_aperture: spectroscopic aperture keyword arguments, see lenstronomy.Galkin.aperture for options :param kwargs_seeing: seeing condition of spectroscopic observation, corresponds to kwargs_psf in the GalKin module specified in lenstronomy.GalKin.psf :param cosmo: astropy.cosmology instance, if None then will be set to the default cosmology :param lens_model_kinematics_bool: bool list of length of the lens model. Only takes a subset of all the models as part of the kinematics computation (can be used to ignore substructure, shear etc that do not describe the main deflector potential :param light_model_kinematics_bool: bool list of length of the light model. Only takes a subset of all the models as part of the kinematics computation (can be used to ignore light components that do not describe the main deflector :param multi_observations: bool, if True uses multi-observation to predict a set of different observations with the GalkinMultiObservation() class. kwargs_aperture and kwargs_seeing require to be lists of the individual observations. :param anisotropy_model: type of stellar anisotropy model. See details in MamonLokasAnisotropy() class of lenstronomy.GalKin.anisotropy :param analytic_kinematics: boolean, if True, used the analytic JAM modeling for a power-law profile on top of a Hernquist light profile ATTENTION: This may not be accurate for your specific problem! :param Hernquist_approx: bool, if True, uses a Hernquist light profile matched to the half light radius of the deflector light profile to compute the kinematics :param MGE_light: bool, if true performs the MGE for the light distribution :param MGE_mass: bool, if true performs the MGE for the mass distribution :param kwargs_numerics_galkin: numerical settings for the integrated line-of-sight velocity dispersion :param kwargs_mge_mass: keyword arguments that go into the MGE decomposition routine :param kwargs_mge_light: keyword arguments that go into the MGE decomposition routine :param sampling_number: int, number of spectral rendering to compute the light weighted integrated LOS dispersion within the aperture. This keyword should be chosen high enough to result in converged results within the tolerance. :param num_kin_sampling: number of kinematic renderings on a total IFU :param num_psf_sampling: number of PSF displacements for each kinematic rendering on the IFU """ self.z_d = z_lens self.z_s = z_source self._kwargs_aperture_kin = kwargs_aperture self._kwargs_psf_kin = kwargs_seeing self.lensCosmo = LensCosmo(z_lens, z_source, cosmo=cosmo) self.LensModel, self.SourceModel, self.LensLightModel, self.PointSource, extinction_class = class_creator.create_class_instances( all_models=True, **kwargs_model) self._lensLightProfile = LightProfileAnalysis( light_model=self.LensLightModel) self._lensMassProfile = LensProfileAnalysis(lens_model=self.LensModel) self._lens_light_model_list = self.LensLightModel.profile_type_list self._lens_model_list = self.LensModel.lens_model_list self._kwargs_cosmo = { 'd_d': self.lensCosmo.dd, 'd_s': self.lensCosmo.ds, 'd_ds': self.lensCosmo.dds } self._lens_model_kinematics_bool = lens_model_kinematics_bool self._light_model_kinematics_bool = light_model_kinematics_bool self._sampling_number = sampling_number self._num_kin_sampling = num_kin_sampling self._num_psf_sampling = num_psf_sampling if kwargs_mge_mass is None: self._kwargs_mge_mass = {'n_comp': 20} else: self._kwargs_mge_mass = kwargs_mge_mass if kwargs_mge_light is None: self._kwargs_mge_light = { 'grid_spacing': 0.01, 'grid_num': 100, 'n_comp': 20, 'center_x': None, 'center_y': None } else: self._kwargs_mge_light = kwargs_mge_light if kwargs_numerics_galkin is None: kwargs_numerics_galkin = { 'interpol_grid_num': 1000, # numerical interpolation, should converge -> infinity 'log_integration': True, # log or linear interpolation of surface brightness and mass models 'max_integrate': 100, 'min_integrate': 0.001 } # lower/upper bound of numerical integrals self._kwargs_numerics_kin = kwargs_numerics_galkin self._anisotropy_model = anisotropy_model self._analytic_kinematics = analytic_kinematics self._Hernquist_approx = Hernquist_approx self._MGE_light = MGE_light self._MGE_mass = MGE_mass self._multi_observations = multi_observations
def __init__(self, multi_band_list, kwargs_model, likelihood_mask_list=None, band_index=0, kwargs_pixelbased=None): """ :param multi_band_list: list of imaging band configurations [[kwargs_data, kwargs_psf, kwargs_numerics],[...], ...] :param kwargs_model: model option keyword arguments :param likelihood_mask_list: list of likelihood masks (booleans with size of the individual images :param band_index: integer, index of the imaging band to model :param kwargs_pixelbased: keyword arguments with various settings related to the pixel-based solver (see SLITronomy documentation) """ self.type = 'single-band-multi-model' if likelihood_mask_list is None: likelihood_mask_list = [None for i in range(len(multi_band_list))] lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances( band_index=band_index, **kwargs_model) kwargs_data = multi_band_list[band_index][0] kwargs_psf = multi_band_list[band_index][1] kwargs_numerics = multi_band_list[band_index][2] data_i = ImageData(**kwargs_data) psf_i = PSF(**kwargs_psf) index_lens_model_list = kwargs_model.get( 'index_lens_model_list', [None for i in range(len(multi_band_list))]) self._index_lens_model = index_lens_model_list[band_index] index_source_list = kwargs_model.get( 'index_source_light_model_list', [None for i in range(len(multi_band_list))]) self._index_source = index_source_list[band_index] index_lens_light_list = kwargs_model.get( 'index_lens_light_model_list', [None for i in range(len(multi_band_list))]) self._index_lens_light = index_lens_light_list[band_index] index_point_source_list = kwargs_model.get( 'index_point_source_model_list', [None for i in range(len(multi_band_list))]) self._index_point_source = index_point_source_list[band_index] index_optical_depth = kwargs_model.get( 'index_optical_depth_model_list', [None for i in range(len(multi_band_list))]) self._index_optical_depth = index_optical_depth[band_index] super(SingleBandMultiModel, self).__init__(data_i, psf_i, lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class, kwargs_numerics=kwargs_numerics, likelihood_mask=likelihood_mask_list[band_index], kwargs_pixelbased=kwargs_pixelbased)
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_data_joint, kwargs_model, param_class, image_likelihood=True, check_bounds=True, check_matched_source_position=False, astrometric_likelihood=False, image_position_likelihood=False, source_position_likelihood=False, image_position_uncertainty=0.004, check_positive_flux=False, source_position_tolerance=0.001, source_position_sigma=0.001, force_no_add_image=False, source_marg=False, linear_prior=None, restrict_image_number=False, max_num_images=None, bands_compute=None, time_delay_likelihood=False, force_minimum_source_surface_brightness=False, flux_min=0, image_likelihood_mask_list=None, flux_ratio_likelihood=False, kwargs_flux_compute={}, prior_lens=[], prior_source=[], prior_extinction=[], prior_lens_light=[], prior_ps=[], prior_special=[], prior_lens_kde=[], prior_source_kde=[], prior_lens_light_kde=[], prior_ps_kde=[], prior_special_kde=[], prior_extinction_kde=[], prior_lens_lognormal=[], prior_source_lognormal=[], prior_extinction_lognormal=[], prior_lens_light_lognormal=[], prior_ps_lognormal=[], prior_special_lognormal=[], custom_logL_addition=None): """ initializing class :param param_class: instance of a Param() class that can cast the sorted list of parameters that are sampled into the conventions of the imSim_class :param image_likelihood: bool, option to compute the imaging likelihood :param source_position_likelihood: bool, if True, ray-traces image positions back to source plane and evaluates relative errors in respect ot the position_uncertainties in the image plane :param check_bounds: bool, option to punish the hard bounds in parameter space :param check_matched_source_position: bool, option to check whether point source position solver finds a solution to match all the image positions in the same source plane coordinate :param astrometric_likelihood: bool, additional likelihood term of the predicted vs modelled point source position :param flaot, image_position_uncertainty: 1-sigma Gaussian uncertainty on the point source position (only used if point_source_likelihood=True) :param check_positive_flux: bool, option to punish models that do not have all positive linear amplitude parameters :param source_position_tolerance: float, punishment of check_solver occurs when image positions are predicted further away than this number :param image_likelihood_mask_list: list of boolean 2d arrays of size of images marking the pixels to be evaluated in the likelihood :param force_no_add_image: bool, if True: computes ALL image positions of the point source. If there are more images predicted than modelled, a punishment occures :param source_marg: marginalization addition on the imaging likelihood based on the covariance of the infered linear coefficients :param linear_prior: float or list of floats (when multi-linear setting is chosen) indicating the range of linear amplitude priors when computing the marginalization term. :param restrict_image_number: bool, if True: computes ALL image positions of the point source. If there are more images predicted than indicated in max_num_images, a punishment occurs :param max_num_images: int, see restrict_image_number :param bands_compute: list of bools with same length as data objects, indicates which "band" to include in the fitting :param time_delay_likelihood: bool, if True computes the time-delay likelihood of the FIRST point source :param force_minimum_source_surface_brightness: bool, if True, evaluates the source surface brightness on a grid and evaluates if all positions have positive flux :param kwargs_flux_compute: keyword arguments of how to compute the image position fluxes (see FluxRatioLikeliood) :param custom_logL_addition: a definition taking as arguments (kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_special, kwargs_extinction) and returns a logL (punishing) value. """ multi_band_list, image_type, time_delays_measured, time_delays_uncertainties, flux_ratios, flux_ratio_errors, ra_image_list, dec_image_list = self._unpack_data( **kwargs_data_joint) if len(multi_band_list) == 0: image_likelihood = False self.param = param_class self._lower_limit, self._upper_limit = self.param.param_limits() lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances( **kwargs_model) self.PointSource = point_source_class self._prior_likelihood = PriorLikelihood( prior_lens, prior_source, prior_lens_light, prior_ps, prior_special, prior_extinction, prior_lens_kde, prior_source_kde, prior_lens_light_kde, prior_ps_kde, prior_special_kde, prior_extinction_kde, prior_lens_lognormal, prior_source_lognormal, prior_lens_light_lognormal, prior_ps_lognormal, prior_special_lognormal, prior_extinction_lognormal, ) self._time_delay_likelihood = time_delay_likelihood if self._time_delay_likelihood is True: self.time_delay_likelihood = TimeDelayLikelihood( time_delays_measured, time_delays_uncertainties, lens_model_class, point_source_class) self._image_likelihood = image_likelihood if self._image_likelihood is True: self.image_likelihood = ImageLikelihood( multi_band_list, image_type, kwargs_model, bands_compute=bands_compute, likelihood_mask_list=image_likelihood_mask_list, source_marg=source_marg, linear_prior=linear_prior, force_minimum_source_surface_brightness= force_minimum_source_surface_brightness, flux_min=flux_min) self._position_likelihood = PositionLikelihood( point_source_class, astrometric_likelihood=astrometric_likelihood, image_position_likelihood=image_position_likelihood, source_position_likelihood=source_position_likelihood, ra_image_list=ra_image_list, dec_image_list=dec_image_list, image_position_uncertainty=image_position_uncertainty, check_matched_source_position=check_matched_source_position, source_position_tolerance=source_position_tolerance, source_position_sigma=source_position_sigma, force_no_add_image=force_no_add_image, restrict_image_number=restrict_image_number, max_num_images=max_num_images) self._flux_ratio_likelihood = flux_ratio_likelihood self._kwargs_flux_compute = kwargs_flux_compute if self._flux_ratio_likelihood is True: self.flux_ratio_likelihood = FluxRatioLikelihood( lens_model_class, flux_ratios, flux_ratio_errors, **self._kwargs_flux_compute) self._check_positive_flux = check_positive_flux self._check_bounds = check_bounds self._custom_logL_addition = custom_logL_addition
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_data_joint, kwargs_model, param_class, image_likelihood=True, check_bounds=True, check_solver=False, point_source_likelihood=False, position_uncertainty=0.004, check_positive_flux=False, solver_tolerance=0.001, force_no_add_image=False, source_marg=False, restrict_image_number=False, max_num_images=None, bands_compute=None, time_delay_likelihood=False, force_minimum_source_surface_brightness=False, flux_min=0, image_likelihood_mask_list=None, flux_ratio_likelihood=False, kwargs_flux_compute={}, prior_lens=[], prior_source=[], prior_lens_light=[], prior_ps=[], prior_cosmo=[]): """ initializing class :param param_class: instance of a Param() class that can cast the sorted list of parameters that are sampled into the conventions of the imSim_class :param image_likelihood: bool, option to compute the imaging likelihood :param check_bounds: bool, option to punish the hard bounds in parameter space :param check_solver: bool, option to check whether point source position solver finds a solution to match all the image positions in the same source plane coordinate :param point_source_likelihood: bool, additional likelihood term of the predicted vs modelled point source position :param flaot, position_uncertainty: 1-sigma Gaussian uncertainty on the point source position (only used if point_source_likelihood=True) :param check_positive_flux: bool, option to punish models that do not have all positive linear amplitude parameters :param solver_tolerance: float, punishment of check_solver occures when image positions are predicted further away than this number :param image_likelihood_mask_list: list of boolean 2d arrays of size of images marking the pixels to be evaluated in the likelihood :param force_no_add_image: bool, if True: computes ALL image positions of the point source. If there are more images predicted than modelled, a punishment occures :param source_marg: marginalization addition on the imaging likelihood based on the covariance of the infered linear coefficients :param restrict_image_number: bool, if True: computes ALL image positions of the point source. If there are more images predicted than indicated in max_num_images, a punishment occures :param max_num_images: int, see restrict_image_number :param bands_compute: list of bools with same length as data objects, indicates which "band" to include in the fitting :param time_delay_likelihood: bool, if True computes the time-delay likelihood of the FIRST point source :param force_minimum_source_surface_brightness: bool, if True, evaluates the source surface brightness on a grid and evaluates if all positions have positive flux :param kwargs_flux_compute: keyword arguments of how to compute the image position fluxes (see FluxRatioLikeliood) """ multi_band_list = kwargs_data_joint.get('multi_band_list', []) multi_band_type = kwargs_data_joint.get('image_type', 'single-band') time_delays_measured = kwargs_data_joint.get('time_delays_measured', None) time_delays_uncertainties = kwargs_data_joint.get( 'time_delays_uncertainties', None) flux_ratios = kwargs_data_joint.get('flux_ratios', None) flux_ratio_errors = kwargs_data_joint.get('flux_ratio_errors', None) self.param = param_class self._lower_limit, self._upper_limit = self.param.param_limits() lens_model_class, source_model_class, lens_light_model_class, point_source_class = class_reator.create_class_instances( **kwargs_model) self.PointSource = point_source_class self._prior_likelihood = PriorLikelihood(prior_lens, prior_source, prior_lens_light, prior_ps, prior_cosmo) self._time_delay_likelihood = time_delay_likelihood if self._time_delay_likelihood is True: self.time_delay_likelihood = TimeDelayLikelihood( time_delays_measured, time_delays_uncertainties, lens_model_class, point_source_class, param_class) self._image_likelihood = image_likelihood if self._image_likelihood is True: self.image_likelihood = ImageLikelihood( multi_band_list, multi_band_type, kwargs_model, bands_compute=bands_compute, likelihood_mask_list=image_likelihood_mask_list, source_marg=source_marg, force_minimum_source_surface_brightness= force_minimum_source_surface_brightness, flux_min=flux_min) self._position_likelihood = PositionLikelihood( point_source_class, param_class, point_source_likelihood, position_uncertainty, check_solver, solver_tolerance, force_no_add_image, restrict_image_number, max_num_images) self._flux_ratio_likelihood = flux_ratio_likelihood self._kwargs_flux_compute = kwargs_flux_compute if self._flux_ratio_likelihood is True: self.flux_ratio_likelihood = FluxRatioLikelihood( point_source_class, lens_model_class, param_class, flux_ratios, flux_ratio_errors, **self._kwargs_flux_compute) self._check_positive_flux = check_positive_flux self._check_bounds = check_bounds
def __init__(self, kwargs_model): self.LensModel, self.SourceModel, self.LensLightModel, self.PointSource, extinction_class = class_creator.create_class_instances( all_models=True, **kwargs_model) #self.LensLightModel = LightModel(kwargs_model.get('lens_light_model_list', [])) #self.LensModel = LensModel(lens_model_list=kwargs_model.get('lens_model_list', []), # z_source=kwargs_model.get('z_source', None), # lens_redshift_list=kwargs_model.get('lens_redshift_list', None), # multi_plane=kwargs_model.get('multi_plane', False)) #self.SourceModel = LightModel(kwargs_model.get('source_light_model_list', [])) self._lensModelExtensions = LensModelExtensions(self.LensModel) #self.PointSource = PointSource(point_source_type_list=kwargs_model.get('point_source_model_list', []), lensModel=self.LensModel) self.kwargs_model = kwargs_model self.NumLensModel = NumericLens( lens_model_list=kwargs_model.get('lens_model_list', []))
def test_create_class_instances(self): lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances( **self.kwargs_model) assert lens_model_class.lens_model_list[0] == 'SIS' lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances( **self.kwargs_model_2) assert lens_model_class.lens_model_list[0] == 'SIS' lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances( **self.kwargs_model_3) assert lens_model_class.lens_model_list[0] == 'SIS' lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances( **self.kwargs_model_4) assert lens_model_class.lens_model_list[0] == 'SIS' assert lens_model_class.lens_model._observed_convention_index[0] == 0
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, multi_band_list, kwargs_model, likelihood_mask_list=None, band_index=0): self.type = 'single-band-multi-model' if likelihood_mask_list is None: likelihood_mask_list = [None for i in range(len(multi_band_list))] lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances(band_index=band_index, **kwargs_model) kwargs_data = multi_band_list[band_index][0] kwargs_psf = multi_band_list[band_index][1] kwargs_numerics = multi_band_list[band_index][2] data_i = ImageData(**kwargs_data) psf_i = PSF(**kwargs_psf) index_lens_model_list = kwargs_model.get('index_lens_model_list', [None for i in range(len(multi_band_list))]) self._index_lens_model = index_lens_model_list[band_index] index_source_list = kwargs_model.get('index_source_light_model_list', [None for i in range(len(multi_band_list))]) self._index_source = index_source_list[band_index] index_lens_light_list = kwargs_model.get('index_lens_light_model_list', [None for i in range(len(multi_band_list))]) self._index_lens_light = index_lens_light_list[band_index] index_point_source_list = kwargs_model.get('index_point_source_model_list', [None for i in range(len(multi_band_list))]) self._index_point_source = index_point_source_list[band_index] index_optical_depth = kwargs_model.get('index_optical_depth_model_list', [None for i in range(len(multi_band_list))]) self._index_optical_depth = index_optical_depth[band_index] super(SingleBandMultiModel, self).__init__(data_i, psf_i, lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class, kwargs_numerics=kwargs_numerics, likelihood_mask=likelihood_mask_list[band_index])
def __init__(self, z_lens, z_source, kwargs_model, cosmo=None, lens_model_kinematics_bool=None, light_model_kinematics_bool=None): """ :param z_lens: redshift of lens :param z_source: redshift of source :param kwargs_model: model keyword arguments :param cosmo: astropy.cosmology instance, if None then will be set to the default cosmology :param lens_model_kinematics_bool: bool list of length of the lens model. Only takes a subset of all the models as part of the kinematics computation (can be used to ignore substructure, shear etc that do not describe the main deflector potential :param light_model_kinematics_bool: bool list of length of the light model. Only takes a subset of all the models as part of the kinematics computation (can be used to ignore light components that do not describe the main deflector """ self.z_d = z_lens self.z_s = z_source self.lensCosmo = LensCosmo(z_lens, z_source, cosmo=cosmo) self.LensModel, self.SourceModel, self.LensLightModel, self.PointSource, extinction_class = class_creator.create_class_instances( all_models=True, **kwargs_model) self._lensLightProfile = LightProfileAnalysis( light_model=self.LensLightModel) self._lensMassProfile = LensProfileAnalysis(lens_model=self.LensModel) self.kwargs_model = kwargs_model self._kwargs_cosmo = { 'D_d': self.lensCosmo.D_d, 'D_s': self.lensCosmo.D_s, 'D_ds': self.lensCosmo.D_ds } self._lens_model_kinematics_bool = lens_model_kinematics_bool self._light_model_kinematics_bool = light_model_kinematics_bool
def setup(self): np.random.seed(42) # 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 kwargs_model = {'lens_model_list': ['SPEP'], 'lens_light_model_list': ['SERSIC'], 'source_light_model_list': ['SERSIC'], 'point_source_model_list': ['SOURCE_POSITION'], 'fixed_magnification_list': [True]} # PSF specification kwargs_band = sim_util.data_configure_simple(numPix, deltaPix, exp_time, sigma_bkg) data_class = ImageData(**kwargs_band) kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': fwhm, 'pixel_size': deltaPix} psf_class = PSF(**kwargs_psf) print(np.shape(psf_class.kernel_point_source), 'test kernel shape -') kwargs_spep = {'theta_E': 1., 'gamma': 1.95, 'center_x': 0, 'center_y': 0, 'e1': 0.1, 'e2': 0.1} self.kwargs_lens = [kwargs_spep] kwargs_sersic = {'amp': 1/0.05**2., 'R_sersic': 0.1, 'n_sersic': 2, 'center_x': 0, 'center_y': 0} # 'SERSIC_ELLIPSE': elliptical Sersic profile kwargs_sersic_ellipse = {'amp': 1., 'R_sersic': .6, 'n_sersic': 3, 'center_x': 0, 'center_y': 0} self.kwargs_lens_light = [kwargs_sersic] self.kwargs_source = [kwargs_sersic_ellipse] self.kwargs_ps = [{'ra_source': 0.55, 'dec_source': 0.02, 'source_amp': 1.}] # quasar point source position in the source plane and intrinsic brightness self.kwargs_cosmo = {'D_dt': 1000} kwargs_numerics = {'supersampling_factor': 1, 'supersampling_convolution': False} lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances(**kwargs_model) imageModel = ImageModel(data_class, psf_class, lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class, kwargs_numerics=kwargs_numerics) image_sim = sim_util.simulate_simple(imageModel, self.kwargs_lens, self.kwargs_source, self.kwargs_lens_light, self.kwargs_ps) ra_pos, dec_pos = imageModel.PointSource.image_position(kwargs_ps=self.kwargs_ps, kwargs_lens=self.kwargs_lens) data_class.update_data(image_sim) kwargs_band['image_data'] = image_sim self.data_class = data_class self.psf_class = psf_class self.kwargs_model = kwargs_model self.kwargs_numerics = { 'supersampling_factor': 1, 'supersampling_convolution': False} kwargs_constraints = { 'num_point_source_list': [4], 'solver_type': 'NONE', # 'PROFILE', 'PROFILE_SHEAR', 'ELLIPSE', 'CENTER' 'Ddt_sampling': True } def condition_definition(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None): logL = 0 if kwargs_lens_light[0]['R_sersic'] > kwargs_source[0]['R_sersic']: logL -= 10**15 return logL kwargs_likelihood = {'force_no_add_image': True, 'source_marg': True, 'astrometric_likelihood': True, 'image_position_uncertainty': 0.004, 'check_matched_source_position': False, 'source_position_tolerance': 0.001, 'source_position_sigma': 0.001, 'check_positive_flux': True, 'flux_ratio_likelihood': True, 'prior_lens': [[0, 'theta_E', 1, 0.1]], 'custom_logL_addition': condition_definition, 'image_position_likelihood': True } self.kwargs_data = {'multi_band_list': [[kwargs_band, kwargs_psf, kwargs_numerics]], 'multi_band_type': 'single-band', 'time_delays_measured': np.ones(4), 'time_delays_uncertainties': np.ones(4), 'flux_ratios': np.ones(4), 'flux_ratio_errors': np.ones(4), 'ra_image_list': ra_pos, 'dec_image_list': dec_pos } self.param_class = Param(self.kwargs_model, **kwargs_constraints) 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.Likelihood = LikelihoodModule(kwargs_data_joint=self.kwargs_data, kwargs_model=kwargs_model, param_class=self.param_class, **kwargs_likelihood) self.kwargs_band = kwargs_band self.kwargs_psf = kwargs_psf self.numPix = numPix
def __init__(self, z_lens, z_source, kwargs_model, cosmo_fiducial=None, lens_model_kinematics_bool=None, light_model_kinematics_bool=None, kwargs_seeing={}, kwargs_aperture={}, anisotropy_model=None): if cosmo_fiducial is None: cosmo_fiducial = default_cosmology.get() self._z_lens = z_lens self._z_source = z_source self._cosmo_fiducial = cosmo_fiducial self._lens_cosmo = LensCosmo(z_lens=z_lens, z_source=z_source, cosmo=self._cosmo_fiducial) self.LensModel, self.SourceModel, self.LensLightModel, self.PointSource, extinction_class = class_creator.create_class_instances( all_models=True, **kwargs_model) super(TDCosmography, self).__init__( z_lens=z_lens, z_source=z_source, kwargs_model=kwargs_model, cosmo=cosmo_fiducial, lens_model_kinematics_bool=lens_model_kinematics_bool, light_model_kinematics_bool=light_model_kinematics_bool, kwargs_seeing=kwargs_seeing, kwargs_aperture=kwargs_aperture, anisotropy_model=anisotropy_model)
def __init__(self, z_lens, z_source, kwargs_model, cosmo_fiducial=None, lens_model_kinematics_bool=None, light_model_kinematics_bool=None, kwargs_seeing=None, kwargs_aperture=None, anisotropy_model=None, **kwargs_kin_api): """ :param z_lens: redshift of deflector :param z_source: redshift of source :param kwargs_model: model configurations (according to FittingSequence) :param cosmo_fiducial: fiducial cosmology used to compute angular diameter distances where required :param lens_model_kinematics_bool: (optional) bool list, corresponding to lens models being included into the kinematics modeling :param light_model_kinematics_bool: (optional) bool list, corresponding to lens light models being included into the kinematics modeling :param kwargs_seeing: seeing conditions (see observation class in Galkin) :param kwargs_aperture: aperture keyword arguments (see aperture class in Galkin) :param anisotropy_model: string, anisotropy model type :param kwargs_kin_api: additional keyword arguments for KinematicsAPI class instance """ if cosmo_fiducial is None: cosmo_fiducial = default_cosmology.get() if kwargs_seeing is None: kwargs_seeing = {} if kwargs_aperture is None: kwargs_aperture = {} self._z_lens = z_lens self._z_source = z_source self._cosmo_fiducial = cosmo_fiducial self._lens_cosmo = LensCosmo(z_lens=z_lens, z_source=z_source, cosmo=self._cosmo_fiducial) self.LensModel, self.SourceModel, self.LensLightModel, self.PointSource, extinction_class = class_creator.create_class_instances( all_models=True, **kwargs_model) super(TDCosmography, self).__init__( z_lens=z_lens, z_source=z_source, kwargs_model=kwargs_model, cosmo=cosmo_fiducial, lens_model_kinematics_bool=lens_model_kinematics_bool, light_model_kinematics_bool=light_model_kinematics_bool, kwargs_seeing=kwargs_seeing, kwargs_aperture=kwargs_aperture, anisotropy_model=anisotropy_model, **kwargs_kin_api)
def _class_instances(self, kwargs_model, kwargs_imaging, kwargs_position, kwargs_flux, kwargs_time_delay): """ :param kwargs_model: lenstronomy model keyword arguments :param kwargs_imaging: keyword arguments for imaging likelihood :param kwargs_position: keyword arguments for positional likelihood :param kwargs_flux: keyword arguments for flux ratio likelihood :param kwargs_time_delay: keyword arguments for time delay likelihood :return: updated model instances of this class """ lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances( **kwargs_model) self.PointSource = point_source_class if self._time_delay_likelihood is True: self.time_delay_likelihood = TimeDelayLikelihood( lens_model_class=lens_model_class, point_source_class=point_source_class, **kwargs_time_delay) if self._image_likelihood is True: self.image_likelihood = ImageLikelihood(kwargs_model=kwargs_model, **kwargs_imaging) self._position_likelihood = PositionLikelihood(point_source_class, **kwargs_position) if self._flux_ratio_likelihood is True: self.flux_ratio_likelihood = FluxRatioLikelihood( lens_model_class, **kwargs_flux)