From 1ad07ed1a492ff06c85a2d57814c78f58f9d07a6 Mon Sep 17 00:00:00 2001 From: Xiangchong Li Date: Wed, 27 Sep 2023 08:56:00 +0900 Subject: [PATCH] lint --- fpfs/image.py | 8 ++------ fpfs/imgutil.py | 27 +++++++++++++++------------ fpfs/simutil.py | 12 +++++------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/fpfs/image.py b/fpfs/image.py index 76ea323..244b77f 100644 --- a/fpfs/image.py +++ b/fpfs/image.py @@ -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, @@ -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 @@ -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 diff --git a/fpfs/imgutil.py b/fpfs/imgutil.py index b051efb..b7a9ef2 100644 --- a/fpfs/imgutil.py +++ b/fpfs/imgutil.py @@ -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 @@ -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 @@ -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): @@ -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): @@ -498,17 +499,19 @@ 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") @@ -516,7 +519,7 @@ def truncate_circle(arr, rcut): 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 diff --git a/fpfs/simutil.py b/fpfs/simutil.py index 44cc684..bd04e17 100644 --- a/fpfs/simutil.py +++ b/fpfs/simutil.py @@ -187,7 +187,6 @@ def make_cosmo_sim( shear_value=0.02, nrot=nrot_default, ): - """Makes cosmo-like blended galaxy image simulations. Args: @@ -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. @@ -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 @@ -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