Ejemplo n.º 1
0
    def align_images(self,
                     n_particles=10,
                     n_iterations=10,
                     lowerLimit=-0.2,
                     upperLimit=0.2,
                     threadCount=1,
                     compute_bands=None):
        """
        aligns the coordinate systems of different exposures within a fixed model parameterisation by executing a PSO
        with relative coordinate shifts as free parameters

        :param n_particles: number of particles in the Particle Swarm Optimization
        :param n_iterations: number of iterations in the optimization process
        :param lowerLimit: lower limit of relative shift
        :param upperLimit: upper limit of relative shift
        :param verbose: bool, print statements
        :param compute_bands: bool list, if multiple bands, this process can be limited to a subset of bands
        :return:
        """
        kwargs_model = self._updateManager.kwargs_model
        kwargs_likelihood = self._updateManager.kwargs_likelihood
        likelihood_mask_list = kwargs_likelihood.get(
            'image_likelihood_mask_list', None)
        kwargs_temp = self.best_fit(bijective=False)
        if compute_bands is None:
            compute_bands = [True] * len(self.multi_band_list)

        for i in range(len(self.multi_band_list)):
            if compute_bands[i] is True:

                alignmentFitting = AlignmentFitting(
                    self.multi_band_list,
                    kwargs_model,
                    kwargs_temp,
                    band_index=i,
                    likelihood_mask_list=likelihood_mask_list)

                kwargs_data, chain = alignmentFitting.pso(
                    n_particles=n_particles,
                    n_iterations=n_iterations,
                    lowerLimit=lowerLimit,
                    upperLimit=upperLimit,
                    threadCount=threadCount,
                    mpi=self._mpi,
                    print_key='Alignment fitting for band %s ...' % i)
                print('Align completed for band %s.' % i)
                print('ra_shift: %s,  dec_shift: %s' %
                      (kwargs_data['ra_shift'], kwargs_data['dec_shift']))
                self.multi_band_list[i][0] = kwargs_data
        return 0
Ejemplo n.º 2
0
    def align_images(self, fitting_kwargs, lens_input, source_input,
                     lens_light_input, ps_input, cosmo_input):
        lens_updated = self._param.update_lens_scaling(cosmo_input, lens_input)
        source_updated = self._param.image2source_plane(
            source_input, lens_updated)
        mpi = fitting_kwargs.get('mpi', False)
        compute_bool = fitting_kwargs.get('compute_bands',
                                          [True] * len(self.multi_band_list))
        n_particles = fitting_kwargs.get('n_particles', 10)
        n_iterations = fitting_kwargs.get('n_iterations', 10)
        lowerLimit = fitting_kwargs.get('lower_limit_shift', -0.2)
        upperLimit = fitting_kwargs.get('upper_limit_shift', 0.2)

        for i in range(len(self.multi_band_list)):
            if compute_bool[i] is True:
                kwargs_data = self.multi_band_list[i][0]
                kwargs_psf = self.multi_band_list[i][1]
                kwargs_numerics = self.multi_band_list[i][2]
                alignmentFitting = AlignmentFitting(kwargs_data,
                                                    kwargs_psf,
                                                    kwargs_numerics,
                                                    self.kwargs_model,
                                                    lens_updated,
                                                    source_updated,
                                                    lens_light_input,
                                                    ps_input,
                                                    compute_bool=compute_bool)

                kwargs_data, chain = alignmentFitting.pso(
                    n_particles,
                    n_iterations,
                    lowerLimit,
                    upperLimit,
                    threadCount=1,
                    mpi=mpi,
                    print_key='Alignment fitting for band %s ...' % i)
                print('Align completed for band %s.' % i)
                self.multi_band_list[i][0] = kwargs_data
        return 0