Skip to content

Commit

Permalink
Merge branch 'lenstronomy:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sibirrer committed Aug 30, 2024
2 parents 5f83c92 + 5980c8b commit 511ae21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lenstronomy/LensModel/Profiles/cored_steep_ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class CSE(LensProfileBase):
"s": 10000,
"e1": 0.5,
"e2": 0.5,
"center_x": -100,
"center_y": -100,
"center_x": 100,
"center_y": 100,
}

def __init__(self, axis="product_avg"):
Expand Down Expand Up @@ -175,9 +175,8 @@ class CSEMajorAxis(LensProfileBase):
"A": 1000,
"s": 10000,
"q": 0.99999,
"e2": 0.5,
"center_x": -100,
"center_y": -100,
"center_x": 100,
"center_y": 100,
}

def function(self, x, y, a, s, q):
Expand Down Expand Up @@ -275,7 +274,7 @@ def function(self, x, y, a_list, s_list, q):
:param q: axis ratio
:return: lensing potential
"""
f_ = np.zeros_like(x)
f_ = np.zeros_like(x, dtype=float)
for a, s in zip(a_list, s_list):
f_ += self.major_axis_model.function(x, y, a, s, q)
return f_
Expand All @@ -290,7 +289,7 @@ def derivatives(self, x, y, a_list, s_list, q):
:param q: axis ratio
:return: deflection in x- and y-direction
"""
f_x, f_y = np.zeros_like(x), np.zeros_like(y)
f_x, f_y = np.zeros_like(x, dtype=float), np.zeros_like(y, dtype=float)
for a, s in zip(a_list, s_list):
f_x_, f_y_ = self.major_axis_model.derivatives(x, y, a, s, q)
f_x += f_x_
Expand All @@ -307,7 +306,11 @@ def hessian(self, x, y, a_list, s_list, q):
:param q: axis ratio
:return: hessian elements f_xx, f_xy, f_yx, f_yy
"""
f_xx, f_xy, f_yy = np.zeros_like(x), np.zeros_like(x), np.zeros_like(x)
f_xx, f_xy, f_yy = (
np.zeros_like(x, dtype=float),
np.zeros_like(x, dtype=float),
np.zeros_like(x, dtype=float),
)
for a, s in zip(a_list, s_list):
f_xx_, f_xy_, _, f_yy_ = self.major_axis_model.hessian(x, y, a, s, q)
f_xx += f_xx_
Expand Down Expand Up @@ -346,9 +349,8 @@ class CSEProductAvg(LensProfileBase):
"A": 1000,
"s": 10000,
"q": 0.99999,
"e2": 0.5,
"center_x": -100,
"center_y": -100,
"center_x": 100,
"center_y": 100,
}

def __init__(self):
Expand Down Expand Up @@ -425,7 +427,7 @@ def function(self, x, y, a_list, s_list, q):
:param q: axis ratio
:return: lensing potential
"""
f_ = np.zeros_like(x)
f_ = np.zeros_like(x, dtype=float)
for a, s in zip(a_list, s_list):
f_ += self.major_axis_model.function(x, y, a, s, q)
return f_
Expand All @@ -440,7 +442,7 @@ def derivatives(self, x, y, a_list, s_list, q):
:param q: axis ratio
:return: deflection in x- and y-direction
"""
f_x, f_y = np.zeros_like(x), np.zeros_like(y)
f_x, f_y = np.zeros_like(x, dtype=float), np.zeros_like(y, dtype=float)
for a, s in zip(a_list, s_list):
f_x_, f_y_ = self.major_axis_model.derivatives(x, y, a, s, q)
f_x += f_x_
Expand All @@ -457,7 +459,11 @@ def hessian(self, x, y, a_list, s_list, q):
:param q: axis ratio
:return: hessian elements f_xx, f_xy, f_yx, f_yy
"""
f_xx, f_xy, f_yy = np.zeros_like(x), np.zeros_like(x), np.zeros_like(x)
f_xx, f_xy, f_yy = (
np.zeros_like(x, dtype=float),
np.zeros_like(x, dtype=float),
np.zeros_like(x, dtype=float),
)
for a, s in zip(a_list, s_list):
f_xx_, f_xy_, _, f_yy_ = self.major_axis_model.hessian(x, y, a, s, q)
f_xx += f_xx_
Expand Down
7 changes: 7 additions & 0 deletions test/test_LensModel/test_Profiles/test_nfw_ellipse_cse.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def test_derivatives(self):
npt.assert_almost_equal(f_x_cse_low / f_x_nfw, 1, decimal=2)
npt.assert_almost_equal(f_y_cse_low, f_y_nfw, decimal=2)

x = 2
y = 2
f_x_nfw, f_y_nfw = self.nfw.derivatives(x, y, **kwargs)
f_x_cse, f_y_cse = self.nfw_cse.derivatives(x, y, e1=0, e2=0, **kwargs)
npt.assert_almost_equal(f_x_cse, f_x_nfw, decimal=5)
npt.assert_almost_equal(f_y_cse, f_y_nfw, decimal=5)

def test_hessian(self):
x = np.linspace(0.01, 2, 10)
y = np.zeros_like(x)
Expand Down

0 comments on commit 511ae21

Please sign in to comment.