Ejemplo n.º 1
0
    def __init__(self,
                 multi_band_list,
                 kwargs_model,
                 kwargs_params,
                 arrow_size=0.02,
                 cmap_string="gist_heat",
                 likelihood_mask_list=None,
                 bands_compute=None,
                 multi_band_type='multi-linear',
                 band_index=0,
                 source_marg=False,
                 linear_prior=None):
        """

        :param multi_band_list:
        :param kwargs_model:
        :param kwargs_params:
        :param arrow_size:
        :param cmap_string:
        :param likelihood_mask_list:
        :param bands_compute:
        :param multi_band_type:
        :param band_index:
        :param source_marg:
        :param linear_prior:
        """
        if bands_compute is None:
            bands_compute = [True] * len(multi_band_list)
        if multi_band_type == 'single-band':
            multi_band_type = 'multi-linear'  # this makes sure that the linear inversion outputs are coming in a list
        self._imageModel = class_creator.create_im_sim(
            multi_band_list,
            multi_band_type,
            kwargs_model,
            bands_compute=bands_compute,
            likelihood_mask_list=likelihood_mask_list,
            band_index=band_index)

        model, error_map, cov_param, param = self._imageModel.image_linear_solve(
            inv_bool=True, **kwargs_params)
        logL = self._imageModel.likelihood_data_given_model(
            source_marg=source_marg,
            linear_prior=linear_prior,
            **kwargs_params)

        n_data = self._imageModel.num_data_evaluate
        if n_data > 0:
            print(logL * 2 / n_data,
                  'reduced X^2 of all evaluated imaging data combined.')

        self._band_plot_list = []
        self._index_list = []
        index = 0
        for i in range(len(multi_band_list)):
            if bands_compute[i] is True:
                if multi_band_type == 'joint-linear':
                    param_i = param
                    cov_param_i = cov_param
                else:
                    param_i = param[index]
                    cov_param_i = cov_param[index]

                bandplot = ModelBandPlot(
                    multi_band_list,
                    kwargs_model,
                    model[index],
                    error_map[index],
                    cov_param_i,
                    param_i,
                    copy.deepcopy(kwargs_params),
                    likelihood_mask_list=likelihood_mask_list,
                    band_index=i,
                    arrow_size=arrow_size,
                    cmap_string=cmap_string)
                self._band_plot_list.append(bandplot)
                self._index_list.append(index)
            else:
                self._index_list.append(-1)
            index += 1
Ejemplo n.º 2
0
    def __init__(self,
                 multi_band_list,
                 kwargs_model,
                 kwargs_params,
                 multi_band_type='multi-linear',
                 kwargs_likelihood=None,
                 verbose=True):
        """

        :param multi_band_list: list of imaging data configuration [[kwargs_data, kwargs_psf, kwargs_numerics], [...]]
        :param kwargs_model: model keyword argument list
        :param kwargs_params: keyword arguments of the model parameters, same as output of FittingSequence() 'kwargs_result'
        :param multi_band_type: string, option when having multiple imaging data sets modelled simultaneously. Options are:
            - 'multi-linear': linear amplitudes are inferred on single data set
            - 'linear-joint': linear amplitudes ae jointly inferred
            - 'single-band': single band
        :param kwargs_likelihood: likelihood keyword arguments as supported by the Likelihood() class
        :param verbose: if True (default), computes and prints the total log-likelihood.
        This can deactivated for speedup purposes (does not run linear inversion again), and reduces the number of prints.
        """
        # here we retrieve those settings in the likelihood keyword arguments that are relevant for the image reconstruction
        if kwargs_likelihood is None:
            kwargs_likelihood = {}
        image_likelihood_mask_list = kwargs_likelihood.get(
            'image_likelihood_mask_list', None)
        source_marg = kwargs_likelihood.get('source_marg', False)
        linear_prior = kwargs_likelihood.get('linear_prior', None)
        bands_compute = kwargs_likelihood.get('bands_compute', None)
        if bands_compute is None:
            bands_compute = [True] * len(multi_band_list)
        if multi_band_type == 'single-band':
            multi_band_type = 'multi-linear'  # this makes sure that the linear inversion outputs are coming in a list
        self._imageModel = class_creator.create_im_sim(
            multi_band_list,
            multi_band_type,
            kwargs_model,
            bands_compute=bands_compute,
            likelihood_mask_list=image_likelihood_mask_list)

        # here we perform the (joint) linear inversion with all data
        model, error_map, cov_param, param = self._imageModel.image_linear_solve(
            inv_bool=True, **kwargs_params)
        check_solver_error(param)

        if verbose:
            logL = self._imageModel.likelihood_data_given_model(
                source_marg=source_marg,
                linear_prior=linear_prior,
                **kwargs_params)
            n_data = self._imageModel.num_data_evaluate
            if n_data > 0:
                print(logL * 2 / n_data,
                      'reduced X^2 of all evaluated imaging data combined.')

        self.model_band_list = []
        for i in range(len(multi_band_list)):
            if bands_compute[i] is True:
                if multi_band_type == 'joint-linear':
                    param_i = param
                    cov_param_i = cov_param
                else:
                    param_i = param[i]
                    cov_param_i = cov_param[i]

                model_band = ModelBand(
                    multi_band_list,
                    kwargs_model,
                    model[i],
                    error_map[i],
                    cov_param_i,
                    param_i,
                    copy.deepcopy(kwargs_params),
                    image_likelihood_mask_list=image_likelihood_mask_list,
                    band_index=i,
                    verbose=verbose)
                self.model_band_list.append(model_band)
            else:
                self.model_band_list.append(None)
Ejemplo n.º 3
0
    def __init__(self,
                 multi_band_list,
                 kwargs_model,
                 kwargs_params,
                 image_likelihood_mask_list=None,
                 bands_compute=None,
                 multi_band_type='multi-linear',
                 source_marg=False,
                 linear_prior=None,
                 arrow_size=0.02,
                 cmap_string="gist_heat",
                 fast_caustic=True,
                 linear_solver=True):
        """

        :param multi_band_list: list of [[kwargs_data, kwargs_psf, kwargs_numerics], [], ..]
        :param multi_band_type: string, option when having multiple imaging data sets modelled simultaneously.
         Options are:
         - 'multi-linear': linear amplitudes are inferred on single data set
         - 'linear-joint': linear amplitudes ae jointly inferred
         - 'single-band': single band
        :param kwargs_model: model keyword arguments
        :param bands_compute: (optional), bool list to indicate which band to be included in the modeling
        :param image_likelihood_mask_list: list of image likelihood mask
         (same size as image_data with 1 indicating being evaluated and 0 being left out)
        :param kwargs_params: keyword arguments of 'kwargs_lens', 'kwargs_source' etc as coming as kwargs_result from
         FittingSequence class
        :param source_marg:
        :param linear_prior:
        :param arrow_size:
        :param cmap_string:
        :param fast_caustic: boolean; if True, uses fast (but less accurate) caustic calculation method
        :param linear_solver: bool, if True (default) fixes the linear amplitude parameters 'amp' (avoid sampling) such
         that they get overwritten by the linear solver solution.
        """
        if bands_compute is None:
            bands_compute = [True] * len(multi_band_list)
        if multi_band_type == 'single-band':
            multi_band_type = 'multi-linear'  # this makes sure that the linear inversion outputs are coming in a list
        self._imageModel = class_creator.create_im_sim(
            multi_band_list,
            multi_band_type,
            kwargs_model,
            bands_compute=bands_compute,
            linear_solver=linear_solver,
            image_likelihood_mask_list=image_likelihood_mask_list)

        model, error_map, cov_param, param = self._imageModel.image_linear_solve(
            inv_bool=True, **kwargs_params)

        check_solver_error(param)
        log_l = self._imageModel.likelihood_data_given_model(
            source_marg=source_marg,
            linear_prior=linear_prior,
            **kwargs_params)

        n_data = self._imageModel.num_data_evaluate
        if n_data > 0:
            print(
                log_l * 2 / n_data,
                'reduced X^2 of all evaluated imaging data combined '
                '(without degrees of freedom subtracted).')

        self._band_plot_list = []
        self._index_list = []
        index = 0
        for i in range(len(multi_band_list)):
            if bands_compute[i] is True:
                if multi_band_type == 'joint-linear':
                    param_i = param
                    cov_param_i = cov_param
                else:
                    param_i = param[index]
                    cov_param_i = cov_param[index]

                bandplot = ModelBandPlot(
                    multi_band_list,
                    kwargs_model,
                    model[index],
                    error_map[index],
                    cov_param_i,
                    param_i,
                    copy.deepcopy(kwargs_params),
                    likelihood_mask_list=image_likelihood_mask_list,
                    band_index=i,
                    arrow_size=arrow_size,
                    cmap_string=cmap_string,
                    fast_caustic=fast_caustic)

                self._band_plot_list.append(bandplot)
                self._index_list.append(index)
            else:
                self._index_list.append(-1)
            index += 1