Exemple #1
0
    def __init__(self,
                 thread_count=1,
                 fast_inverse=True,
                 second_gen=False,
                 show_pysap_plots=False,
                 force_no_pysap=False):
        """
        Load pySAP package if found, and initialize the Starlet transform.

        :param thread_count: number of threads used for pySAP computations
        :param fast_inverse: if True, reconstruction is simply the sum of each scale (only for 1st generation starlet transform)
        :param second_gen: if True, uses the second generation of starlet transform 
        :param show_pysap_plots: if True, displays pySAP plots when calling the decomposition method
        :param force_no_pysap: if True, does not load pySAP and computes starlet transforms in python.
        """
        self.use_pysap, pysap = self._load_pysap(force_no_pysap)
        if self.use_pysap:
            self._transf_class = pysap.load_transform(
                'BsplineWaveletTransformATrousAlgorithm')
        else:
            warnings.warn(
                "The python package pySAP is not used for starlet operations. "
                "They will be performed using (slower) python routines.")
        self._fast_inverse = fast_inverse
        self._second_gen = second_gen
        self._show_pysap_plots = show_pysap_plots
        self.interpol = Interpol()
        self.thread_count = thread_count
Exemple #2
0
    def test_function(self):
        """

        :return:
        """
        x, y = util.make_grid(numPix=20, deltapix=1.)
        gauss = Gaussian()
        flux = gauss.function(x, y, amp=1., center_x=0., center_y=0., sigma=1.)
        image = util.array2image(flux)
        interp = Interpol()
        kwargs_interp = {
            'image': image,
            'scale': 1.,
            'phi_G': 0.,
            'center_x': 0.,
            'center_y': 0.
        }
        output = interp.function(x, y, **kwargs_interp)
        npt.assert_almost_equal(output, flux, decimal=0)

        flux = gauss.function(x - 1.,
                              y,
                              amp=1.,
                              center_x=0.,
                              center_y=0.,
                              sigma=1.)
        kwargs_interp = {
            'image': image,
            'scale': 1.,
            'phi_G': 0.,
            'center_x': 1.,
            'center_y': 0.
        }
        output = interp.function(x, y, **kwargs_interp)
        npt.assert_almost_equal(output, flux, decimal=0)

        flux = gauss.function(x - 1.,
                              y - 1.,
                              amp=1,
                              center_x=0.,
                              center_y=0.,
                              sigma=1.)
        kwargs_interp = {
            'image': image,
            'scale': 1.,
            'phi_G': 0.,
            'center_x': 1.,
            'center_y': 1.
        }
        output = interp.function(x, y, **kwargs_interp)
        npt.assert_almost_equal(output, flux, decimal=0)

        out = interp.function(x=1000, y=0, **kwargs_interp)
        assert out == 0
 def test_delete_cache(self):
     x, y = util.make_grid(numPix=20, deltapix=1.)
     gauss = Gaussian()
     flux = gauss.function(x, y, amp=1., center_x=0., center_y=0., sigma=1.)
     image = util.array2image(flux)
     interp = Interpol()
     kwargs_interp = {
         'image': image,
         'scale': 1.,
         'phi_G': 0.,
         'center_x': 0.,
         'center_y': 0.
     }
     output = interp.function(x, y, **kwargs_interp)
     assert hasattr(interp, '_image_interp')
     interp.delete_cache()
     assert not hasattr(interp, '_image_interp')
Exemple #4
0
    def __init__(self, light_model_list, smoothing=0.001):
        """

        :param light_model_list: list of light models
        :param smoothing: smoothing factor for certain models (deprecated)
        """
        self.profile_type_list = light_model_list
        self.func_list = []
        for profile_type in light_model_list:
            if profile_type == 'GAUSSIAN':
                from lenstronomy.LightModel.Profiles.gaussian import Gaussian
                self.func_list.append(Gaussian())
            elif profile_type == 'GAUSSIAN_ELLIPSE':
                from lenstronomy.LightModel.Profiles.gaussian import GaussianEllipse
                self.func_list.append(GaussianEllipse())
            elif profile_type == 'ELLIPSOID':
                from lenstronomy.LightModel.Profiles.ellipsoid import Ellipsoid
                self.func_list.append(Ellipsoid())
            elif profile_type == 'MULTI_GAUSSIAN':
                from lenstronomy.LightModel.Profiles.gaussian import MultiGaussian
                self.func_list.append(MultiGaussian())
            elif profile_type == 'MULTI_GAUSSIAN_ELLIPSE':
                from lenstronomy.LightModel.Profiles.gaussian import MultiGaussianEllipse
                self.func_list.append(MultiGaussianEllipse())
            elif profile_type == 'SERSIC':
                from lenstronomy.LightModel.Profiles.sersic import Sersic
                self.func_list.append(Sersic(smoothing=smoothing))
            elif profile_type == 'SERSIC_ELLIPSE':
                from lenstronomy.LightModel.Profiles.sersic import SersicElliptic
                self.func_list.append(
                    SersicElliptic(smoothing=smoothing,
                                   sersic_major_axis=sersic_major_axis_conf))
            elif profile_type == 'CORE_SERSIC':
                from lenstronomy.LightModel.Profiles.sersic import CoreSersic
                self.func_list.append(CoreSersic(smoothing=smoothing))
            elif profile_type == 'SHAPELETS':
                from lenstronomy.LightModel.Profiles.shapelets import ShapeletSet
                self.func_list.append(ShapeletSet())
            elif profile_type == 'SHAPELETS_POLAR':
                from lenstronomy.LightModel.Profiles.shapelets_polar import ShapeletSetPolar
                self.func_list.append(ShapeletSetPolar(exponential=False))
            elif profile_type == 'SHAPELETS_POLAR_EXP':
                from lenstronomy.LightModel.Profiles.shapelets_polar import ShapeletSetPolar
                self.func_list.append(ShapeletSetPolar(exponential=True))
            elif profile_type == 'HERNQUIST':
                from lenstronomy.LightModel.Profiles.hernquist import Hernquist
                self.func_list.append(Hernquist())
            elif profile_type == 'HERNQUIST_ELLIPSE':
                from lenstronomy.LightModel.Profiles.hernquist import HernquistEllipse
                self.func_list.append(HernquistEllipse())
            elif profile_type == 'PJAFFE':
                from lenstronomy.LightModel.Profiles.p_jaffe import PJaffe
                self.func_list.append(PJaffe())
            elif profile_type == 'PJAFFE_ELLIPSE':
                from lenstronomy.LightModel.Profiles.p_jaffe import PJaffe_Ellipse
                self.func_list.append(PJaffe_Ellipse())
            elif profile_type == 'UNIFORM':
                from lenstronomy.LightModel.Profiles.uniform import Uniform
                self.func_list.append(Uniform())
            elif profile_type == 'POWER_LAW':
                from lenstronomy.LightModel.Profiles.power_law import PowerLaw
                self.func_list.append(PowerLaw())
            elif profile_type == 'NIE':
                from lenstronomy.LightModel.Profiles.nie import NIE
                self.func_list.append(NIE())
            elif profile_type == 'CHAMELEON':
                from lenstronomy.LightModel.Profiles.chameleon import Chameleon
                self.func_list.append(Chameleon())
            elif profile_type == 'DOUBLE_CHAMELEON':
                from lenstronomy.LightModel.Profiles.chameleon import DoubleChameleon
                self.func_list.append(DoubleChameleon())
            elif profile_type == 'TRIPLE_CHAMELEON':
                from lenstronomy.LightModel.Profiles.chameleon import TripleChameleon
                self.func_list.append(TripleChameleon())
            elif profile_type == 'INTERPOL':
                from lenstronomy.LightModel.Profiles.interpolation import Interpol
                self.func_list.append(Interpol())
            elif profile_type == 'SLIT_STARLETS':
                from lenstronomy.LightModel.Profiles.starlets import SLIT_Starlets
                self.func_list.append(
                    SLIT_Starlets(fast_inverse=True, second_gen=False))
            elif profile_type == 'SLIT_STARLETS_GEN2':
                from lenstronomy.LightModel.Profiles.starlets import SLIT_Starlets
                self.func_list.append(SLIT_Starlets(second_gen=True))
            else:
                raise ValueError(
                    'No light model of type %s found! Supported are the following models: %s'
                    % (profile_type, _MODELS_SUPPORTED))
        self._num_func = len(self.func_list)
Exemple #5
0
    def test_function(self):
        """

        :return:
        """
        for len_x, len_y in [(20, 20), (14, 20)]:
            x, y = util.make_grid(numPix=(len_x, len_y), deltapix=1.)
            gauss = Gaussian()
            flux = gauss.function(x,
                                  y,
                                  amp=1.,
                                  center_x=0.,
                                  center_y=0.,
                                  sigma=1.)
            image = util.array2image(flux, nx=len_y, ny=len_x)

            interp = Interpol()
            kwargs_interp = {
                'image': image,
                'scale': 1.,
                'phi_G': 0.,
                'center_x': 0.,
                'center_y': 0.
            }
            output = interp.function(x, y, **kwargs_interp)

            npt.assert_equal(output, flux)

            flux = gauss.function(x - 1.,
                                  y,
                                  amp=1.,
                                  center_x=0.,
                                  center_y=0.,
                                  sigma=1.)
            kwargs_interp = {
                'image': image,
                'scale': 1.,
                'phi_G': 0.,
                'center_x': 1.,
                'center_y': 0.
            }
            output = interp.function(x, y, **kwargs_interp)
            npt.assert_almost_equal(output, flux, decimal=0)

            flux = gauss.function(x - 1.,
                                  y - 1.,
                                  amp=1,
                                  center_x=0.,
                                  center_y=0.,
                                  sigma=1.)
            kwargs_interp = {
                'image': image,
                'scale': 1.,
                'phi_G': 0.,
                'center_x': 1.,
                'center_y': 1.
            }
            output = interp.function(x, y, **kwargs_interp)
            npt.assert_almost_equal(output, flux, decimal=0)

            out = interp.function(x=1000, y=0, **kwargs_interp)
            assert out == 0

        # test change of center without re-doing interpolation
        out = interp.function(x=0,
                              y=0,
                              image=image,
                              scale=1.,
                              phi_G=0,
                              center_x=0,
                              center_y=0)
        out_shift = interp.function(x=1,
                                    y=0,
                                    image=image,
                                    scale=1.,
                                    phi_G=0,
                                    center_x=1,
                                    center_y=0)
        assert out_shift == out

        # function must give a single value when evaluated at a single point
        assert isinstance(out, float)

        # test change of scale without re-doing interpolation
        out = interp.function(x=1.,
                              y=0,
                              image=image,
                              scale=1.,
                              phi_G=0,
                              center_x=0,
                              center_y=0)
        out_scaled = interp.function(x=2.,
                                     y=0,
                                     image=image,
                                     scale=2,
                                     phi_G=0,
                                     center_x=0,
                                     center_y=0)
        assert out_scaled == out
    def __init__(self,
                 light_model_list,
                 deflection_scaling_list=None,
                 source_redshift_list=None,
                 smoothing=0.0000001):
        """

        :param light_model_list: list of light models
        :param deflection_scaling_list: list of floats, rescales the original reduced deflection angles from the lens model
        to enable different models to be placed at different optical (redshift) distances. None means they are all
        :param source_redshift_list: list of redshifts of the model components
        :param smoothing: smoothing factor for certain models (deprecated)
        """
        self.profile_type_list = light_model_list
        self.deflection_scaling_list = deflection_scaling_list
        self.redshift_list = source_redshift_list
        self.func_list = []
        for profile_type in light_model_list:
            if profile_type == 'GAUSSIAN':
                from lenstronomy.LightModel.Profiles.gaussian import Gaussian
                self.func_list.append(Gaussian())
            elif profile_type == 'GAUSSIAN_ELLIPSE':
                from lenstronomy.LightModel.Profiles.gaussian import GaussianEllipse
                self.func_list.append(GaussianEllipse())
            elif profile_type == 'MULTI_GAUSSIAN':
                from lenstronomy.LightModel.Profiles.gaussian import MultiGaussian
                self.func_list.append(MultiGaussian())
            elif profile_type == 'MULTI_GAUSSIAN_ELLIPSE':
                from lenstronomy.LightModel.Profiles.gaussian import MultiGaussianEllipse
                self.func_list.append(MultiGaussianEllipse())
            elif profile_type == 'SERSIC':
                from lenstronomy.LightModel.Profiles.sersic import Sersic
                self.func_list.append(Sersic(smoothing=smoothing))
            elif profile_type == 'SERSIC_ELLIPSE':
                from lenstronomy.LightModel.Profiles.sersic import SersicElliptic
                self.func_list.append(SersicElliptic(smoothing=smoothing))
            elif profile_type == 'CORE_SERSIC':
                from lenstronomy.LightModel.Profiles.sersic import CoreSersic
                self.func_list.append(CoreSersic(smoothing=smoothing))
            elif profile_type == 'SHAPELETS':
                from lenstronomy.LightModel.Profiles.shapelets import ShapeletSet
                self.func_list.append(ShapeletSet())
            elif profile_type == 'HERNQUIST':
                from lenstronomy.LightModel.Profiles.hernquist import Hernquist
                self.func_list.append(Hernquist())
            elif profile_type == 'HERNQUIST_ELLIPSE':
                from lenstronomy.LightModel.Profiles.hernquist import HernquistEllipse
                self.func_list.append(HernquistEllipse())
            elif profile_type == 'PJAFFE':
                from lenstronomy.LightModel.Profiles.p_jaffe import PJaffe
                self.func_list.append(PJaffe())
            elif profile_type == 'PJAFFE_ELLIPSE':
                from lenstronomy.LightModel.Profiles.p_jaffe import PJaffe_Ellipse
                self.func_list.append(PJaffe_Ellipse())
            elif profile_type == 'UNIFORM':
                from lenstronomy.LightModel.Profiles.uniform import Uniform
                self.func_list.append(Uniform())
            elif profile_type == 'POWER_LAW':
                from lenstronomy.LightModel.Profiles.power_law import PowerLaw
                self.func_list.append(PowerLaw())
            elif profile_type == 'NIE':
                from lenstronomy.LightModel.Profiles.nie import NIE
                self.func_list.append(NIE())
            elif profile_type == 'CHAMELEON':
                from lenstronomy.LightModel.Profiles.chameleon import Chameleon
                self.func_list.append(Chameleon())
            elif profile_type == 'DOUBLE_CHAMELEON':
                from lenstronomy.LightModel.Profiles.chameleon import DoubleChameleon
                self.func_list.append(DoubleChameleon())
            elif profile_type == 'INTERPOL':
                from lenstronomy.LightModel.Profiles.interpolation import Interpol
                self.func_list.append(Interpol())
            else:
                raise ValueError('Warning! No light model of type',
                                 profile_type, ' found!')
Exemple #7
0
          image_reconstructed = shapeletSet.function(x, y, coeff_ngc, n_max, beta, center_x=0, center_y=0)
          image_reconstructed_2d = util.array2image(image_reconstructed)

          theta_x_high_res, theta_y_high_res = util.make_grid(numPix=numPix*high_res_factor,
                                                              deltapix=deltaPix/high_res_factor)
          beta_x_high_res, beta_y_high_res = lensModel.ray_shooting(theta_x_high_res, theta_y_high_res,
                                                                      kwargs=kwargs_lens_list)
          source_lensed = shapeletSet.function(beta_x_high_res, beta_y_high_res,
                                              coeff_ngc, n_max, beta=.05,
                                              center_x=cen[ii], center_y=0)

          source_lensed = util.array2image(source_lensed)
          kwargs_interp = {'image': ngc_data_resized, 'center_x': 0, 'center_y': 0, 'scale': 0.005, 'phi_G':0.2}

          interp_light = Interpol()
          source_lensed_interp = interp_light.function(beta_x_high_res, beta_y_high_res, **kwargs_interp)
          source_lensed_interp = util.array2image(source_lensed_interp)

          light_model_list = ['SERSIC_ELLIPSE', 'SERSIC_ELLIPSE','NIE']
          kwargs_lens_light = [
              {'amp':  .3, 'R_sersic': 0.04, 'n_sersic': 0.3, 'e1': 0, 'e2': 0, 'center_x': 0, 'center_y': 0},
              {'amp': .01, 'R_sersic': 0.05, 'n_sersic': 0.2, 'e1': 0, 'e2': 0, 'center_x': 0, 'center_y': 0},
              {'amp': .05, 'e1':.5, 'e2':.4, 's_scale':1}
          ]
          lensLightModel = LightModel(light_model_list=light_model_list)

          flux_lens_light = lensLightModel.surface_brightness(theta_x_high_res, theta_y_high_res, kwargs_lens_light)
          flux_lens_light = util.array2image(flux_lens_light)
          image_combined = source_lensed_interp + flux_lens_light