How to use the lenstronomy.LensModel.Profiles.base_profile.LensProfileBase function in lenstronomy

To help you get started, we’ve selected a few lenstronomy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sibirrer / lenstronomy / test / test_LensModel / test_Profiles / test_base_profile.py View on Github external
def test_base_functions(self):
        base = LensProfileBase()
        base.set_static()
        base.set_dynamic()
github sibirrer / lenstronomy / lenstronomy / LensModel / Profiles / cored_density_2.py View on Github external
__author__ = 'sibirrer'

import numpy as np
from scipy.integrate import quad
from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
from lenstronomy.Util import derivative_util as calc_util


class CoredDensity2(LensProfileBase):
    """
    class for a uniform cored density dropping steep in the outskirts
    credits for suggesting this profile goes to Kfir Blum
    3d rho(r) = 2/pi * Sigma_crit R_c**2 * (R_c**2 + r**2)**(-3/2)
    This profile drops as rho(r) **(-3) like an NFW profile

    """
    model_name = 'CORED_DENSITY_2'
    _s = 0.000001  # numerical limit for minimal radius
    param_names = ['sigma0', 'r_core', 'center_x', 'center_y']
    lower_limit_default = {'sigma0': -1, 'r_core': 0, 'center_x': -100, 'center_y': -100}
    upper_limit_default = {'sigma0': 10, 'r_core': 100, 'center_x': 100, 'center_y': 100}

    def function(self, x, y, sigma0, r_core, center_x=0, center_y=0):
        """
        potential of cored density profile
github sibirrer / lenstronomy / lenstronomy / LensModel / Profiles / flexion.py View on Github external
from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase


class Flexion(LensProfileBase):
    """
    class for flexion
    """
    param_names = ['g1', 'g2', 'g3', 'g4', 'ra_0', 'dec_0']
    lower_limit_default = {'g1': -0.1, 'g2': -0.1, 'g3': -0.1, 'g4': -0.1, 'ra_0': -100, 'dec_0': -100}
    upper_limit_default = {'g1': 0.1, 'g2': 0.1, 'g3': 0.1, 'g4': 0.1, 'ra_0': 100, 'dec_0': 100}

    def function(self, x, y, g1, g2, g3, g4, ra_0=0, dec_0=0):
        x_ = x - ra_0
        y_ = y - dec_0
        f_ = 1./6 * (g1 * x_**3 + 3*g2 * x_**2 * y_ + 3*g3 * x_ * y_**2 + g4 * y_**3)
        return f_

    def derivatives(self, x, y, g1, g2, g3, g4, ra_0=0, dec_0=0):
        x_ = x - ra_0
        y_ = y - dec_0
github sibirrer / lenstronomy / lenstronomy / LensModel / Profiles / cnfw.py View on Github external
__author__ = 'dgilman'

import numpy as np
from lenstronomy.LensModel.Profiles.nfw import NFW
from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
import warnings


class CNFW(LensProfileBase):
    """
    this class computes the lensing quantities of a cored NFW profile:
    rho = rho0 * (r + r_core)^-1 * (r + rs)^-2

    """
    param_names = ['Rs', 'alpha_Rs', 'r_core', 'center_x', 'center_y']
    lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'r_core': 0, 'center_x': -100, 'center_y': -100}
    upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'r_core': 100, 'center_x': 100, 'center_y': 100}

    def __init__(self):
        """

        :param interpol: bool, if True, interpolates the functions F(), g() and h()
        """
        self._nfw = NFW()
        super(CNFW, self).__init__()
github sibirrer / lenstronomy / lenstronomy / LensModel / Profiles / interpol.py View on Github external
self._f_yy_interp = scipy.interpolate.RectBivariateSpline(y_grid, x_grid, f_yy, kx=1, ky=1, s=0)
        return self._f_yy_interp(y, x)

    def do_interp(self, x_grid, y_grid, f_, f_x, f_y, f_xx=None, f_yy=None, f_xy=None):
        self._f_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_, kx=1, ky=1, s=0)
        self._f_x_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_x, kx=1, ky=1, s=0)
        self._f_y_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_y, kx=1, ky=1, s=0)
        if f_xx is not None:
            self._f_xx_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_xx, kx=1, ky=1, s=0)
        if f_xy is not None:
            self._f_xy_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_xy, kx=1, ky=1, s=0)
        if f_yy is not None:
            self._f_yy_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_yy, kx=1, ky=1, s=0)


class InterpolScaled(LensProfileBase):
    """
    class for handling an interpolated lensing map and has the freedom to scale its lensing effect.
    Applications are e.g. mass to light ratio.
    """
    param_names = ['scale_factor', 'grid_interp_x', 'grid_interp_y', 'f_', 'f_x', 'f_y', 'f_xx', 'f_yy', 'f_xy']
    lower_limit_default = {'scale_factor': 0}
    upper_limit_default = {'scale_factor': 100}

    def __init__(self, grid=True, min_grid_number=100):
        self.interp_func = Interpol(grid, min_grid_number=min_grid_number)
        super(InterpolScaled, self).__init__()

    def function(self, x, y, scale_factor=1, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None,
                 f_xx=None, f_yy=None, f_xy=None):
        """
github sibirrer / lenstronomy / lenstronomy / LensModel / Profiles / curved_arc.py View on Github external
import numpy as np
from lenstronomy.LensModel.Profiles.spp import SPP
from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase


class CurvedArc(LensProfileBase):
    """
    lens model that describes a section of a highly magnified deflector region.
    The parameterization is chosen to describe local observables efficient.

    Observables are:
    - curvature radius (basically bending relative to the center of the profile)
    - radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope)
    - tangential stretch (plus sign). Infinity means at critical curve
    - direction of curvature
    - position of arc

    Requirements:
    - Should work with other perturbative models without breaking its meaning (say when adding additional shear terms)
    - Must best reflect the observables in lensing
    - minimal covariances between the parameters, intuitive parameterization.
github sibirrer / lenstronomy / lenstronomy / LensModel / Profiles / sie.py View on Github external
from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
import numpy as np


class SIE(LensProfileBase):
    """
    class for singular isothermal ellipsoid (SIS with ellipticity)
    """
    param_names = ['theta_E', 'e1', 'e2', 'center_x', 'center_y']
    lower_limit_default = {'theta_E': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100}
    upper_limit_default = {'theta_E': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100}

    def __init__(self, NIE=True, suppress_fastell=False):
        """

        :param NIE: bool, if True, is using the NIE analytic model. Otherwise it uses PEMD with gamma=2 from fastell4py
        :param suppress_fastell: bool, if True, does not raise if fastell4py is not installed
        """
        self._nie = NIE
        if NIE:
            from lenstronomy.LensModel.Profiles.nie import NIE
github sibirrer / lenstronomy / lenstronomy / LensModel / Profiles / tnfw.py View on Github external
def __init__(self):
        """

        :param interpol: bool, if True, interpolates the functions F(), g() and h()
        """
        self._s = 0.001
        super(LensProfileBase, self).__init__()
github sibirrer / lenstronomy / lenstronomy / LensModel / Profiles / const_mag.py View on Github external
__author__ = 'gipagano'

import numpy as np
import lenstronomy.Util.util as util
from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase

class ConstMag(LensProfileBase):
    """
    this class implements the macromodel potential of `Diego et al. `_
    Convergence and shear are computed according to `Diego2018 `_
    """
    
    param_names = ['center_x', 'center_y','mu_r', 'mu_t', 'parity', 'phi_G']
    lower_limit_default = {'center_x': -100, 'center_y': -100, 'mu_r':1, 'mu_t': 1000, 'parity': -1, 'phi_G':0.0}
    upper_limit_default = {'center_x': 100, 'center_y': 100, 'mu_r':1, 'mu_t': 1000, 'parity': 1, 'phi_G':np.pi}
    
    def function(self, x, y, mu_r, mu_t, parity, phi_G, center_x=0, center_y=0):
        """
        
        :param x: x-coord (in angles)
        :param y: y-coord (in angles)
        :param mu_r: radial magnification 
        :param mu_t: tangential magnification
github sibirrer / lenstronomy / lenstronomy / LensModel / Profiles / nie_potential.py View on Github external
def _theta_q_convert(self, theta_E, q):
        """
        converts a spherical averaged Einstein radius/core radius to an elliptical (major axis) Einstein radius.
        This then follows the convention of the SPEMD profile in lenstronomy.
        (theta_E / theta_E_gravlens) = sqrt[ (1+q^2) / (2 q) ]

        :param theta_E: Einstein radius in lenstronomy conventions
        :param q: axis ratio minor/major
        :return: theta_E in convention of kappa=  b *(q2(s2 + x2) + y2􏰉)−1/2
        """
        theta_E_new = theta_E / (np.sqrt((1.+q**2) / (2. * q))) #/ (1+(1-q)/2.)
        return theta_E_new

        
        
class NIEPotentialMajorAxis(LensProfileBase):
    """
    this class implements the elliptical potential of Eq. (67) of `LECTURES ON GRAVITATIONAL LENSING `_ 
    and Eq. (1) of `Blandford & Kochanek 1987 `_,
    mapped to Eq. (8) of `Barnaka1998 `_
    to find the ellipticity bounds
    """

    param_names = ['theta_E', 'theta_c', 'eps', 'center_x', 'center_y']

    def __init__(self, diff=0.0000000001):
        self._diff = diff
        super(NIEPotentialMajorAxis, self).__init__()

    def function(self, x, y, theta_E, theta_c, eps):
        f_  = theta_E*np.sqrt(theta_c**2+(1-eps)*x**2+(1+eps)*y**2)
        return f_