Skip to content

Commit

Permalink
Merge pull request lenstronomy#487 from sibirrer/main
Browse files Browse the repository at this point in the history
Minor changes in documentation and re-naming
  • Loading branch information
sibirrer authored Jul 17, 2023
2 parents 58db21a + 6281d38 commit 9774122
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
38 changes: 18 additions & 20 deletions lenstronomy/LensModel/Profiles/nfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class NFW(LensProfileBase):
this class contains functions concerning the NFW profile
relation are: R_200 = c * Rs
The definition of 'Rs' is in angular (arc second) units and the normalization is put in in regards to a deflection
The definition of 'Rs' is in angular (arc second) units and the normalization is put in with regard to a deflection
angle at 'Rs' - 'alpha_Rs'. To convert a physical mass and concentration definition into those lensing quantities
for a specific redshift configuration and cosmological model, you can find routines in lenstronomy.Cosmo.lens_cosmo.py
for a specific redshift configuration and cosmological model, you can find routines in
lenstronomy.Cosmo.lens_cosmo.py
Examples for converting angular to physical mass units
------------------------------------------------------
Expand Down Expand Up @@ -123,9 +124,10 @@ def hessian(self, x, y, Rs, alpha_Rs, center_x=0, center_y=0):
f_xy = gamma2
return f_xx, f_xy, f_xy, f_yy

def density(self, R, Rs, rho0):
@staticmethod
def density(R, Rs, rho0):
"""
three dimensional NFW profile
three-dimensional NFW profile
:param R: radius of interest
:type R: float/numpy array
Expand All @@ -152,16 +154,14 @@ def density_lens(self, r, Rs, alpha_Rs):

def density_2d(self, x, y, Rs, rho0, center_x=0, center_y=0):
"""
projected two dimensional NFW profile (kappa)
projected two-dimensional NFW profile (kappa)
:param R: radius of interest
:type R: float/numpy array
:param x: x-coordinate
:param y: y-coordinate
:param Rs: scale radius
:type Rs: float
:param rho0: density normalization (characteristic density)
:type rho0: float
:param r200: radius of (sub)halo
:type r200: float>0
:param center_x: x-centroid position
:param center_y: y-centroid position
:return: Epsilon(R) projected density at radius R
Expand Down Expand Up @@ -236,8 +236,6 @@ def nfwPot(self, R, Rs, rho0):
:type Rs: float
:param rho0: density normalization (characteristic density)
:type rho0: float
:param r200: radius of (sub)halo
:type r200: float>0
:return: Epsilon(R) projected density at radius R
"""
x = R/Rs
Expand All @@ -255,10 +253,10 @@ def nfwAlpha(self, R, Rs, rho0, ax_x, ax_y):
:type Rs: float
:param rho0: density normalization (characteristic density)
:type rho0: float
:param r200: radius of (sub)halo
:type r200: float>0
:param axis: projection to either x- or y-axis
:type axis: same as R
:param ax_x: projection to either x- or y-axis
:type ax_x: same as R
:param ax_y: projection to either x- or y-axis
:type ax_y: same as R
:return: Epsilon(R) projected density at radius R
"""
R = np.maximum(R, 0.00000001)
Expand All @@ -278,18 +276,18 @@ def nfwGamma(self, R, Rs, rho0, ax_x, ax_y):
:type Rs: float
:param rho0: density normalization (characteristic density)
:type rho0: float
:param r200: radius of (sub)halo
:type r200: float>0
:param axis: projection to either x- or y-axis
:type axis: same as R
:param ax_x: projection to either x- or y-axis
:type ax_x: same as R
:param ax_y: projection to either x- or y-axis
:type ax_y: same as R
:return: Epsilon(R) projected density at radius R
"""
c = 0.000001
R = np.maximum(R, c)
x = R/Rs
gx = self.g_(x)
Fx = self.F_(x)
a = 2*rho0*Rs*(2*gx/x**2 - Fx)#/x #2*rho0*Rs*(2*gx/x**2 - Fx)*axis/x
a = 2*rho0*Rs*(2*gx/x**2 - Fx) # /x #2*rho0*Rs*(2*gx/x**2 - Fx)*axis/x
return a*(ax_y**2-ax_x**2)/R**2, -a*2*(ax_x*ax_y)/R**2

def F_(self, X):
Expand Down
2 changes: 2 additions & 0 deletions lenstronomy/Util/image_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def re_size_array(x_in, y_in, input_values, x_out, y_out):
:param y_out:
:return:
"""
# from skimage.transform import resize
# resize(input_values)
interp_2d = interpolate.interp2d(x_in, y_in, input_values, kind='linear')
# interp_2d = scipy.interpolate.RectBivariateSpline(x_in, y_in, input_values, kx=1, ky=1)
out_values = interp_2d.__call__(x_out, y_out)
Expand Down
13 changes: 10 additions & 3 deletions lenstronomy/Util/numba_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
if numba_enabled:
try:
import numba
from numba import extending
except ImportError:
numba_enabled = False
numba = None
extending = None

__all__ = ['jit', 'generated_jit', 'nan_to_num', 'nan_to_num_arr', 'nan_to_num_single']
__all__ = ['jit', 'overload', 'nan_to_num', 'nan_to_num_arr', 'nan_to_num_single']


def jit(nopython=nopython, cache=cache, parallel=parallel, fastmath=fastmath, error_model=error_model, inline='never'):
Expand All @@ -40,23 +42,28 @@ def wrapper(func):
return wrapper


def generated_jit(nopython=nopython, cache=cache, parallel=parallel, fastmath=fastmath, error_model=error_model):
def overload(nopython=nopython, cache=cache, parallel=parallel, fastmath=fastmath, error_model=error_model):
"""
Wrapper around numba.generated_jit. Allows you to redirect a function to another based on its type
- see the Numba docs for more info
"""
if numba_enabled:

def wrapper(func):
# TODO change to overload, but currently breaks tests with nopython
return numba.generated_jit(func, nopython=nopython, cache=cache, parallel=parallel, fastmath=fastmath,
error_model=error_model)
# return extending.overload(func, jit_options={'nopython': nopython, 'cache': cache,
# 'parallel': parallel,
# 'fastmath': fastmath, 'error_model': error_model})
else:
def wrapper(func):
return func

return wrapper


@generated_jit()
@overload()
def nan_to_num(x, posinf=1e10, neginf=-1e10, nan=0.):
"""
Implements a Numba equivalent to np.nan_to_num (with copy=False!) array or scalar in Numba.
Expand Down
2 changes: 1 addition & 1 deletion test/test_LensModel/test_Profiles/test_interpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ def test_shift(self):


if __name__ == '__main__':
pytest.main("-k TestInterpol")
pytest.main()

0 comments on commit 9774122

Please sign in to comment.