Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 30, 2024
1 parent 511ae21 commit 7839f4f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 22 deletions.
11 changes: 7 additions & 4 deletions lenstronomy/Data/psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def __init__(
self._point_source_supersampling_factor,
)
if kernel_point_source_normalisation is False:
kernel_point_source_ *= np.sum(kernel_point_source) / np.sum(kernel_point_source_)
kernel_point_source_ *= np.sum(kernel_point_source) / np.sum(
kernel_point_source_
)
# making sure the PSF is positive semi-definite and do the normalisation if kernel_point_source_normalisation is true
if np.min(kernel_point_source_) < 0:
warnings.warn(
Expand Down Expand Up @@ -183,8 +185,7 @@ def kernel_point_source_supersampled(self, supersampling_factor, updata_cache=Tr
elif self.psf_type == "PIXEL":

kernel = kernel_util.subgrid_kernel(
self.kernel_point_source
, supersampling_factor, odd=True, num_iter=5
self.kernel_point_source, supersampling_factor, odd=True, num_iter=5
)
n = len(self.kernel_point_source)
n_new = n * supersampling_factor
Expand All @@ -199,7 +200,9 @@ def kernel_point_source_supersampled(self, supersampling_factor, updata_cache=Tr
kernel_point_source_supersampled = kernel_util.cut_psf(
kernel, psf_size=n_new
)
kernel_point_source_supersampled *= self._kernel_norm / np.sum(kernel_point_source_supersampled)
kernel_point_source_supersampled *= self._kernel_norm / np.sum(
kernel_point_source_supersampled
)

elif self.psf_type == "NONE":
kernel_point_source_supersampled = self._kernel_point_source
Expand Down
4 changes: 2 additions & 2 deletions lenstronomy/LensModel/convergence_integrals.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def potential_from_kappa_grid_adaptive(
kernel_low_res, kernel_high_res = kernel_util.split_kernel(
kernel, high_res_kernel_size, low_res_factor
)
kernel_low_res /= low_res_factor ** 2
kernel_low_res /= low_res_factor**2
# , normalized = False

f_high_res = (
Expand Down Expand Up @@ -127,7 +127,7 @@ def deflection_from_kappa_grid_adaptive(
kernel_low_res_x, kernel_high_res_x = kernel_util.split_kernel(
kernel_x, high_res_kernel_size, low_res_factor
)
kernel_low_res_x /= low_res_factor ** 2
kernel_low_res_x /= low_res_factor**2
# , normalized=False
f_x_high_res = (
scp.fftconvolve(kappa_high_res, kernel_high_res_x, mode="same")
Expand Down
2 changes: 1 addition & 1 deletion lenstronomy/LightModel/light_model_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def total_flux(self, kwargs_list, norm=False, k=None):
"MULTI_GAUSSIAN_ELLIPSE",
"LINE_PROFILE",
"HERNQUIST",
"HERNQUIST_ELLIPSE"
"HERNQUIST_ELLIPSE",
]:
kwargs_new = kwargs_list_standard[i].copy()
if norm is True:
Expand Down
4 changes: 2 additions & 2 deletions lenstronomy/Util/kernel_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ def split_kernel(
:param kernel_super: super-sampled kernel
:param supersampling_kernel_size: size of super-sampled PSF in units of degraded
pixels
:param normalized: if True, preserves the sum of low and high-res kernels to be the sum of the original kernel,
else, conserves local density
:param normalized: if True, preserves the sum of low and high-res kernels to be the
sum of the original kernel, else, conserves local density
:return: degraded kernel with hole and super-sampled kernel
"""
if supersampling_factor <= 1:
Expand Down
22 changes: 16 additions & 6 deletions test/test_Data/test_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,15 @@ def test_unnormalized(self):
"psf_type": "PIXEL",
"kernel_point_source": kernel_point_source,
"point_source_supersampling_factor": 1,
"kernel_point_source_normalisation": False
"kernel_point_source_normalisation": False,
}
psf = PSF(**kwargs_psf)
npt.assert_almost_equal(np.sum(psf.kernel_point_source), psf_norm_factor)
npt.assert_almost_equal(np.sum(psf.kernel_pixel), psf_norm_factor)
npt.assert_almost_equal(np.sum(psf.kernel_point_source_supersampled(supersampling_factor=1)), psf_norm_factor)
npt.assert_almost_equal(
np.sum(psf.kernel_point_source_supersampled(supersampling_factor=1)),
psf_norm_factor,
)

kwargs_psf = {
"psf_type": "PIXEL",
Expand All @@ -236,18 +239,23 @@ def test_unnormalized(self):
psf = PSF(**kwargs_psf)
npt.assert_almost_equal(np.sum(psf.kernel_point_source), psf_norm_factor)
npt.assert_almost_equal(np.sum(psf.kernel_pixel), psf_norm_factor)
npt.assert_almost_equal(np.sum(psf.kernel_point_source_supersampled(supersampling_factor=5)), psf_norm_factor)
npt.assert_almost_equal(
np.sum(psf.kernel_point_source_supersampled(supersampling_factor=5)),
psf_norm_factor,
)

kwargs_psf = {
"psf_type": "PIXEL",
"kernel_point_source": kernel_point_source,
"point_source_supersampling_factor": 1,
"kernel_point_source_normalisation": True
"kernel_point_source_normalisation": True,
}
psf = PSF(**kwargs_psf)
npt.assert_almost_equal(np.sum(psf.kernel_point_source), 1)
npt.assert_almost_equal(np.sum(psf.kernel_pixel), 1)
npt.assert_almost_equal(np.sum(psf.kernel_point_source_supersampled(supersampling_factor=1)), 1)
npt.assert_almost_equal(
np.sum(psf.kernel_point_source_supersampled(supersampling_factor=1)), 1
)

kwargs_psf = {
"psf_type": "PIXEL",
Expand All @@ -258,7 +266,9 @@ def test_unnormalized(self):
psf = PSF(**kwargs_psf)
npt.assert_almost_equal(np.sum(psf.kernel_point_source), 1)
npt.assert_almost_equal(np.sum(psf.kernel_pixel), 1)
npt.assert_almost_equal(np.sum(psf.kernel_point_source_supersampled(supersampling_factor=5)), 1)
npt.assert_almost_equal(
np.sum(psf.kernel_point_source_supersampled(supersampling_factor=5)), 1
)


class TestRaise(unittest.TestCase):
Expand Down
24 changes: 18 additions & 6 deletions test/test_ImSim/test_Numerics/test_numerics.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def setup_method(self):

kernel_size = 9
kernel_super = kernel_util.cut_psf(
psf_data=kernel_super, psf_size=kernel_size * self._supersampling_factor, normalisation=True
psf_data=kernel_super,
psf_size=kernel_size * self._supersampling_factor,
normalisation=True,
)

# make instance of the PixelGrid class
Expand Down Expand Up @@ -240,7 +242,9 @@ def test_high_res_narrow(self):
kwargs_lens_light=self.kwargs_light, unconvolved=False
)
npt.assert_almost_equal(
(self.image_true * self.psf_norm_factor - image_conv) / self.image_true, 0, decimal=2
(self.image_true * self.psf_norm_factor - image_conv) / self.image_true,
0,
decimal=2,
)

def test_low_conv_high_grid(self):
Expand All @@ -267,7 +271,9 @@ def test_low_conv_high_grid(self):
kwargs_lens_light=self.kwargs_light, unconvolved=False
)
npt.assert_almost_equal(
(self.image_true * self.psf_norm_factor - image_conv) / self.image_true, 0, decimal=1
(self.image_true * self.psf_norm_factor - image_conv) / self.image_true,
0,
decimal=1,
)

def test_low_conv_high_adaptive(self):
Expand All @@ -294,7 +300,9 @@ def test_low_conv_high_adaptive(self):
kwargs_lens_light=self.kwargs_light, unconvolved=False
)
npt.assert_almost_equal(
(self.image_true * self.psf_norm_factor - image_conv) / self.image_true, 0, decimal=1
(self.image_true * self.psf_norm_factor - image_conv) / self.image_true,
0,
decimal=1,
)

def test_high_adaptive(self):
Expand All @@ -321,7 +329,9 @@ def test_high_adaptive(self):
kwargs_lens_light=self.kwargs_light, unconvolved=False
)
npt.assert_almost_equal(
(self.image_true * self.psf_norm_factor - image_conv) / self.image_true, 0, decimal=1
(self.image_true * self.psf_norm_factor - image_conv) / self.image_true,
0,
decimal=1,
)

def test_low_res(self):
Expand All @@ -348,7 +358,9 @@ def test_low_res(self):
kwargs_lens_light=self.kwargs_light, unconvolved=False
)
npt.assert_almost_equal(
(self.image_true * self.psf_norm_factor - image_conv) / self.image_true, 0, decimal=1
(self.image_true * self.psf_norm_factor - image_conv) / self.image_true,
0,
decimal=1,
)

def test_sub_frame(self):
Expand Down
4 changes: 3 additions & 1 deletion test/test_Util/test_kernel_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ def test_split_kernel():
supersampling_kernel_size=subsampling_size,
supersampling_factor=subgrid_res,
)
npt.assert_almost_equal(np.sum(kernel_hole) + np.sum(kernel_cutout), norm_factor, decimal=3)
npt.assert_almost_equal(
np.sum(kernel_hole) + np.sum(kernel_cutout), norm_factor, decimal=3
)


def test_cutout_source2():
Expand Down

0 comments on commit 7839f4f

Please sign in to comment.