Beispiel #1
0
 def __init__(self, light_model_list, smoothing=0.0000001):
     self.profile_type_list = light_model_list
     self.func_list = []
     for profile_type in light_model_list:
         valid = True
         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 Sersic_elliptic
             self.func_list.append(Sersic_elliptic(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 Hernquist_Ellipse
             self.func_list.append(Hernquist_Ellipse())
         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())
         else:
             raise ValueError('Warning! No light model of type', profile_type, ' found!')
Beispiel #2
0
class TestShapeletSet(object):
    """
    class to test Shapelets
    """
    def setup(self):
        self.shapeletSet = ShapeletSet()
        self.shapelets = Shapelets(precalc=False)
        self.x, self.y = util.make_grid(10, 0.1, 1)

    def test_shapelet_set(self):
        """

        :return:
        """
        n_max = 2
        beta = 1.
        amp = [1, 0, 0, 0, 0, 0]
        output = self.shapeletSet.function(np.array(1),
                                           np.array(1),
                                           amp,
                                           n_max,
                                           beta,
                                           center_x=0,
                                           center_y=0)
        assert output == 0.20755374871029739
        input = np.array(0.)
        input += output

        output = self.shapeletSet.function(self.x,
                                           self.y,
                                           amp,
                                           n_max,
                                           beta,
                                           center_x=0,
                                           center_y=0)
        assert output[10] == 0.47957022395315946
        output = self.shapeletSet.function(1,
                                           1,
                                           amp,
                                           n_max,
                                           beta,
                                           center_x=0,
                                           center_y=0)
        assert output == 0.20755374871029739

        n_max = -1
        beta = 1.
        amp = [1, 0, 0, 0, 0, 0]
        output = self.shapeletSet.function(np.array(1),
                                           np.array(1),
                                           amp,
                                           n_max,
                                           beta,
                                           center_x=0,
                                           center_y=0)
        assert output == 0

        beta = 1.
        amp = 1
        shapelets = Shapelets(precalc=False, stable_cut=False)
        output = shapelets.function(np.array(1),
                                    np.array(1),
                                    amp,
                                    beta,
                                    0,
                                    0,
                                    center_x=0,
                                    center_y=0)
        npt.assert_almost_equal(0.2075537487102974, output, decimal=8)

    def test_shapelet_basis(self):
        num_order = 5
        beta = 1
        numPix = 10
        kernel_list = self.shapeletSet.shapelet_basis_2d(
            num_order, beta, numPix)
        assert kernel_list[0][4, 4] == 0.43939128946772255

    def test_decomposition(self):
        """

        :return:
        """
        n_max = 2
        beta = 10.
        deltaPix = 1
        amp = np.array([1, 1, 1, 1, 1, 1])
        x, y = util.make_grid(100, deltaPix, 1)
        input = self.shapeletSet.function(x,
                                          y,
                                          amp,
                                          n_max,
                                          beta,
                                          center_x=0,
                                          center_y=0)
        amp_out = self.shapeletSet.decomposition(input,
                                                 x,
                                                 y,
                                                 n_max,
                                                 beta,
                                                 deltaPix,
                                                 center_x=0,
                                                 center_y=0)
        for i in range(len(amp)):
            npt.assert_almost_equal(amp_out[i], amp[i], decimal=4)

    def test_function_split(self):
        n_max = 2
        beta = 10.
        deltaPix = 0.1
        amp = np.array([1, 1, 1, 1, 1, 1])
        x, y = util.make_grid(10, deltaPix, 1)
        function_set = self.shapeletSet.function_split(x,
                                                       y,
                                                       amp,
                                                       n_max,
                                                       beta,
                                                       center_x=0,
                                                       center_y=0)
        test_flux = self.shapelets.function(x,
                                            y,
                                            amp=1.,
                                            n1=0,
                                            n2=0,
                                            beta=beta,
                                            center_x=0,
                                            center_y=0)
        print(np.shape(function_set))
        print(np.shape(test_flux))
        assert function_set[0][10] == test_flux[10]

    def test_interpolate(self):
        shapeletsInterp = Shapelets(interpolation=True)
        x, y = 0.99, 0
        beta = 0.5
        flux_full = self.shapelets.function(x,
                                            y,
                                            amp=1.,
                                            n1=0,
                                            n2=0,
                                            beta=beta,
                                            center_x=0,
                                            center_y=0)
        flux_interp = shapeletsInterp.function(x,
                                               y,
                                               amp=1.,
                                               n1=0,
                                               n2=0,
                                               beta=beta,
                                               center_x=0,
                                               center_y=0)
        npt.assert_almost_equal(flux_interp, flux_full, decimal=10)

    def test_hermval(self):
        x = np.linspace(0, 2000, 2001)
        n_array = [1, 2, 3, 0, 1]
        import numpy.polynomial.hermite as hermite
        out_true = hermite.hermval(x, n_array)
        out_approx = self.shapelets.hermval(x, n_array)
        shape_true = out_true * np.exp(-x**2 / 2.)
        shape_approx = out_approx * np.exp(-x**2 / 2.)
        npt.assert_almost_equal(shape_approx, shape_true, decimal=6)

        x = 2
        n_array = [1, 2, 3, 0, 1]
        out_true = hermite.hermval(x, n_array)
        out_approx = self.shapelets.hermval(x, n_array)
        npt.assert_almost_equal(out_approx, out_true, decimal=6)

        x = 2001
        n_array = [1, 2, 3, 0, 1]
        out_true = hermite.hermval(x, n_array)
        out_approx = self.shapelets.hermval(x, n_array)
        shape_true = out_true * np.exp(-x**2 / 2.)
        shape_approx = out_approx * np.exp(-x**2 / 2.)
        npt.assert_almost_equal(shape_approx, shape_true, decimal=6)
Beispiel #3
0
 def setup(self):
     self.shapeletSet = ShapeletSet()
     self.shapelets = Shapelets(precalc=False)
     self.x, self.y = util.make_grid(10, 0.1, 1)
Beispiel #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)
Beispiel #5
0
x, y = util.make_grid(numPix=numPix_large - 1,
                      deltapix=1)  # make a coordinate grid
ngc_data_resized = image_util.re_size(
    ngc_cut, factor)  # re-size image to lower resolution

# now we come to the Shapelet decomposition
# we turn the image in a single 1d array
image_1d = util.image2array(ngc_data_resized)  # map 2d image in 1d data array

# we define the shapelet basis set we want the image to decompose in
n_max = 150  # choice of number of shapelet basis functions, 150 is a high resolution number, but takes long
beta = 10  # shapelet scale parameter (in units of resized pixels)

# import the ShapeletSet class
from lenstronomy.LightModel.Profiles.shapelets import ShapeletSet
shapeletSet = ShapeletSet()

# decompose image and return the shapelet coefficients
coeff_ngc = shapeletSet.decomposition(image_1d,
                                      x,
                                      y,
                                      n_max,
                                      beta,
                                      1.,
                                      center_x=0,
                                      center_y=0)
print(len(coeff_ngc), 'number of coefficients')  # number of coefficients

# reconstruct NGC1300 with the shapelet coefficients
image_reconstructed = shapeletSet.function(x,
                                           y,
Beispiel #6
0
from lenstronomy.SimulationAPI.simulations import Simulation
SimAPI = Simulation()
from lenstronomy.LightModel.light_model import LightModel
from lenstronomy.LensModel.lens_model import LensModel
import lenstronomy.Plots.output_plots as lens_plot
from lenstronomy.LensModel.Solver.lens_equation_solver import LensEquationSolver
import lenstronomy.Util.param_util as param_util
from lenstronomy.PointSource.point_source import PointSource
from lenstronomy.ImSim.image_model import ImageModel
import lenstronomy.Util.image_util as image_util
from lenstronomy.Plots.output_plots import LensModelPlot
from lenstronomy.Workflow.fitting_sequence import FittingSequence
import lenstronomy.Plots.output_plots as out_plot
import lenstronomy.Util.util as util
from lenstronomy.LightModel.Profiles.shapelets import ShapeletSet
shapeletSet = ShapeletSet()

#********************************************************************************#
#									DES CATALOGUE					 			 #
#********************************************************************************#

cat0=np.loadtxt('gal.npy').reshape(6,111,110) #is needed give the right shape to the file
pix=110 # to have squared images
cat= cat0[:,0:pix,0:pix]

# To Create a mask around the central object
masksize=40 #mask size in pixels
msmin = int(pix/2) - int(masksize/2)
msmax = int(pix/2) + int(masksize/2)
catmask = cat[:,msmin:msmax,msmin:msmax]
Beispiel #7
0
class TestShapeletSet(object):
    """
    class to test Shapelets
    """
    def setup(self):
        self.shapeletSet = ShapeletSet()
        self.shapelets = Shapelets(precalc=False)
        self.x, self.y = util.make_grid(10, 0.1, 1)

    def test_shapelet_set(self):
        """

        :return:
        """
        n_max = 2
        beta = 1.
        amp = [1, 0, 0, 0, 0, 0]
        output = self.shapeletSet.function(np.array(1),
                                           np.array(1),
                                           amp,
                                           n_max,
                                           beta,
                                           center_x=0,
                                           center_y=0)
        assert output == 0.20755374871029739
        input = np.array(0.)
        input += output

        output = self.shapeletSet.function(self.x,
                                           self.y,
                                           amp,
                                           n_max,
                                           beta,
                                           center_x=0,
                                           center_y=0)
        assert output[10] == 0.47957022395315946
        output = self.shapeletSet.function(1,
                                           1,
                                           amp,
                                           n_max,
                                           beta,
                                           center_x=0,
                                           center_y=0)
        assert output == 0.20755374871029739

    def test_shapelet_basis(self):
        num_order = 5
        beta = 1
        numPix = 10
        kernel_list = self.shapeletSet.shapelet_basis_2d(
            num_order, beta, numPix)
        assert kernel_list[0][4, 4] == 0.43939128946772255

    def test_decomposition(self):
        """

        :return:
        """
        n_max = 2
        beta = 10.
        deltaPix = 1
        amp = np.array([1, 1, 1, 1, 1, 1])
        x, y = util.make_grid(100, deltaPix, 1)
        input = self.shapeletSet.function(x,
                                          y,
                                          amp,
                                          n_max,
                                          beta,
                                          center_x=0,
                                          center_y=0)
        amp_out = self.shapeletSet.decomposition(input,
                                                 x,
                                                 y,
                                                 n_max,
                                                 beta,
                                                 deltaPix,
                                                 center_x=0,
                                                 center_y=0)
        for i in range(len(amp)):
            npt.assert_almost_equal(amp_out[i], amp[i], decimal=4)

    def test_function_split(self):
        n_max = 2
        beta = 10.
        deltaPix = 0.1
        amp = np.array([1, 1, 1, 1, 1, 1])
        x, y = util.make_grid(10, deltaPix, 1)
        function_set = self.shapeletSet.function_split(x,
                                                       y,
                                                       amp,
                                                       n_max,
                                                       beta,
                                                       center_x=0,
                                                       center_y=0)
        test_flux = self.shapelets.function(x,
                                            y,
                                            amp=1.,
                                            n1=0,
                                            n2=0,
                                            beta=beta,
                                            center_x=0,
                                            center_y=0)
        print(np.shape(function_set))
        print(np.shape(test_flux))
        assert function_set[0][10] == test_flux[10]

    def test_interpolate(self):
        shapeletsInterp = Shapelets(interpolation=True)
        x, y = 0.99, 0
        beta = 0.5
        flux_full = self.shapelets.function(x,
                                            y,
                                            amp=1.,
                                            n1=0,
                                            n2=0,
                                            beta=beta,
                                            center_x=0,
                                            center_y=0)
        flux_interp = shapeletsInterp.function(x,
                                               y,
                                               amp=1.,
                                               n1=0,
                                               n2=0,
                                               beta=beta,
                                               center_x=0,
                                               center_y=0)
        npt.assert_almost_equal(flux_interp, flux_full, decimal=10)
    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!')