Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-superonion committed Sep 26, 2023
1 parent aa5c972 commit 1ad07ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
8 changes: 2 additions & 6 deletions fpfs/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ def __init__(
self.klim_pix = min(self.klim_pix, self.ngrid // 2 - 1)

self.klim = float(self.klim_pix * self._dk)
logging.info(
"Maximum |k| is %.3f"
% (self.klim)
)
logging.info("Maximum |k| is %.3f" % (self.klim))

self._indx = jnp.arange(
self.ngrid // 2 - self.klim_pix,
Expand All @@ -110,7 +107,6 @@ def __init__(
self._ind2d = jnp.ix_(self._indx, self._indx)
return


@partial(jax.jit, static_argnames=["self"])
def deconvolve(self, data, prder=1.0, frder=1.0):
"""Deconvolves input data with the PSF or PSF power
Expand Down Expand Up @@ -306,7 +302,7 @@ def detect_sources(
self.klim,
)
if bound is None:
bound = self.ngrid//2 + 5
bound = self.ngrid // 2 + 5
dd = imgutil.find_peaks(img_conv, img_conv_det, thres, thres2, bound).T
return dd

Expand Down
27 changes: 15 additions & 12 deletions fpfs/imgutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def shapelets2d(ngrid, nord, sigma, klim):
ngrid, ngrid, sigma, klim, return_grid=True
)
rfunc = np.sqrt(xfunc**2.0 + yfunc**2.0) # radius
r2_over_sigma2 = (rfunc / sigma) ** 2.
r2_over_sigma2 = (rfunc / sigma) ** 2.0
ny, nx = gaufunc.shape

rmask = rfunc != 0.0
Expand Down Expand Up @@ -191,7 +191,7 @@ def shapelets2d(ngrid, nord, sigma, klim):
pow(-1.0, d1)
* pow(cc, 0.5)
* lfunc[c1, abs(mm), :, :]
* pow(r2_over_sigma2, abs(mm)/2)
* pow(r2_over_sigma2, abs(mm) / 2)
* gaufunc
* eulfunc**mm
* (1j) ** nn
Expand Down Expand Up @@ -252,9 +252,7 @@ def shapelets2d_real(ngrid, nord, sigma, klim):
% nord
)
# generate the complex shaplet functions
chi = shapelets2d(
ngrid, nord, sigma, klim
)[indm]
chi = shapelets2d(ngrid, nord, sigma, klim)[indm]
# transform to real shapelet functions
chi_2 = np.zeros((len(name_s), ngrid, ngrid), dtype=np.float64)
for i, ind in enumerate(ind_s):
Expand Down Expand Up @@ -484,8 +482,11 @@ def cond_fun(dist):
/ psf_array[ngrid // 2, ngrid // 2 + dist]
)
return jax.lax.cond(
v1 < v2, v1, lambda x: x > thres,
v2, lambda x: x > thres,
v1 < v2,
v1,
lambda x: x > thres,
v2,
lambda x: x > thres,
)

def body_fun(dist):
Expand All @@ -498,25 +499,27 @@ def body_fun(dist):
)
return klim


def truncate_square(arr, rcut):
if len(arr.shape) != 2 or arr.shape[0] != arr.shape[1]:
raise ValueError("Input array must be a 2D square array")

ngrid = arr.shape[0]
arr[:ngrid//2-rcut, :] = 0
arr[ngrid//2+rcut:, :] = 0
arr[:, :ngrid//2-rcut] = 0
arr[:, ngrid//2+rcut:] = 0
arr[: ngrid // 2 - rcut, :] = 0
arr[ngrid // 2 + rcut :, :] = 0
arr[:, : ngrid // 2 - rcut] = 0
arr[:, ngrid // 2 + rcut :] = 0
return


def truncate_circle(arr, rcut):
if len(arr.shape) != 2 or arr.shape[0] != arr.shape[1]:
raise ValueError("Input array must be a 2D square array")
ngrid = arr.shape[0]
y, x = np.ogrid[0:ngrid, 0:ngrid]
center_x, center_y = ngrid // 2, ngrid // 2
# Compute the squared distance to the center
distance_squared = (x - center_x)**2 + (y - center_y)**2
distance_squared = (x - center_x) ** 2 + (y - center_y) ** 2
# Mask values outside the circle
arr[distance_squared > rcut**2] = 0.0
return
12 changes: 5 additions & 7 deletions fpfs/simutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ def make_cosmo_sim(
shear_value=0.02,
nrot=nrot_default,
):

"""Makes cosmo-like blended galaxy image simulations.
Args:
Expand Down Expand Up @@ -337,6 +336,7 @@ def generate_cosmos_gal(record, truncr=5.0, gsparams=None):
Returns:
gal: Galsim galaxy
"""

# record columns:
# For 'sersicfit', the result is an array of 8 numbers for each:
# SERSICFIT[0]: intensity of light profile at the half-light radius.
Expand Down Expand Up @@ -696,10 +696,7 @@ def make_isolate_sim(
g2 = shear_const
else:
raise ValueError("cannot decide g1 or g2")
logging.info(
"Processing for %s, and shear is %s."
% (gname, shear_const)
)
logging.info("Processing for %s, and shear is %s." % (gname, shear_const))

if do_shift:
shifts = np.random.uniform(low=-0.5, high=0.5, size=(ngal, 2)) * scale
Expand Down Expand Up @@ -747,8 +744,9 @@ def make_isolate_sim(
np.pad(
array=oo,
pad_width=(buff, buff),
constant_values=0.,
) for oo in outcome
constant_values=0.0,
)
for oo in outcome
]
return outcome

Expand Down

0 comments on commit 1ad07ed

Please sign in to comment.