diff --git a/CHANGES.md b/CHANGES.md index 749ec314..2f136baa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,8 +4,6 @@ - Added `fwhm_smooth` keyword to pre-PSF moments routines to allow for extra smoothing of the profile before the moments are measured. - - Added `use_pix_weight` keyword to pre-PSF moments routines to enable inverse - variance pixel weighting. - Added caching of FFTs in metacal and pre-PSF moment rountines. diff --git a/ngmix/prepsfmom.py b/ngmix/prepsfmom.py index a058d55f..547d8b19 100644 --- a/ngmix/prepsfmom.py +++ b/ngmix/prepsfmom.py @@ -41,22 +41,15 @@ class PrePSFMom(object): If non-zero, this optional applies additional Gaussian smoothing to the object before computing the moments. Typically a non-zero value results in less shape noise. - use_pix_weight : bool, optional - If `True`, this option applies inverse pixel variance weighting in Fourier - space when computing the moments. Typically this optional results in poorer - performance, but for round PSFs, it results in similar performance as - `fwhm_smooth`. """ def __init__( - self, fwhm, kernel, pad_factor=4, ap_rad=1.5, - fwhm_smooth=0, use_pix_weight=False + self, fwhm, kernel, pad_factor=4, ap_rad=1.5, fwhm_smooth=0 ): self.fwhm = fwhm self.pad_factor = pad_factor self.kernel = kernel self.ap_rad = ap_rad self.fwhm_smooth = fwhm_smooth - self.use_pix_weight = use_pix_weight if self.kernel == "ksigma": self.kind = "ksigma" elif self.kernel in ["gauss", "pgauss"]: @@ -170,7 +163,6 @@ def _meas(self, obs, psf_obs, return_kernels): mom, mom_cov = _measure_moments_fft( kim, kpsf_im, tot_var, eff_pad_factor, kernels, im_row - psf_im_row, im_col - psf_im_col, - use_pix_weight=self.use_pix_weight, ) res = make_mom_result(mom, mom_cov) if res['flags'] != 0: @@ -214,18 +206,13 @@ class KSigmaMom(PrePSFMom): If non-zero, this optional applies additional Gaussian smoothing to the object before computing the moments. Typically a non-zero value results in less shape noise. - use_pix_weight : bool, optional - If `True`, this option applies inverse pixel variance weighting in Fourier - space when computing the moments. Typically this optional results in poorer - performance, but for round PSFs, it results in similar performance as - `fwhm_smooth`. """ def __init__( - self, fwhm, pad_factor=4, ap_rad=1.5, fwhm_smooth=0, use_pix_weight=False, + self, fwhm, pad_factor=4, ap_rad=1.5, fwhm_smooth=0 ): super().__init__( fwhm, 'ksigma', pad_factor=pad_factor, ap_rad=ap_rad, - fwhm_smooth=fwhm_smooth, use_pix_weight=use_pix_weight, + fwhm_smooth=fwhm_smooth, ) @@ -252,18 +239,13 @@ class PGaussMom(PrePSFMom): If non-zero, this optional applies additional Gaussian smoothing to the object before computing the moments. Typically a non-zero value results in less shape noise. - use_pix_weight : bool, optional - If `True`, this option applies inverse pixel variance weighting in Fourier - space when computing the moments. Typically this optional results in poorer - performance, but for round PSFs, it results in similar performance as - `fwhm_smooth`. """ def __init__( - self, fwhm, pad_factor=4, ap_rad=1.5, fwhm_smooth=0, use_pix_weight=False, + self, fwhm, pad_factor=4, ap_rad=1.5, fwhm_smooth=0, ): super().__init__( fwhm, 'pgauss', pad_factor=pad_factor, ap_rad=ap_rad, - fwhm_smooth=fwhm_smooth, use_pix_weight=use_pix_weight, + fwhm_smooth=fwhm_smooth, ) @@ -272,7 +254,7 @@ def __init__( def _measure_moments_fft( - kim, kpsf_im, tot_var, eff_pad_factor, kernels, drow, dcol, use_pix_weight=False, + kim, kpsf_im, tot_var, eff_pad_factor, kernels, drow, dcol, ): # we only need to do things where the kernel is non-zero # this saves a bunch of CPU cycles @@ -309,15 +291,10 @@ def _measure_moments_fft( fkp = kernels["fkp"] fkc = kernels["fkc"] - if use_pix_weight: - wgt = (kpsf_im * np.conj(kpsf_im)).real - else: - wgt = 1.0 - - mf = np.sum((kim * fkf * wgt).real) * df2 - mr = np.sum((kim * fkr * wgt).real) * df2 - mp = np.sum((kim * fkp * wgt).real) * df2 - mc = np.sum((kim * fkc * wgt).real) * df2 + mf = np.sum((kim * fkf).real) * df2 + mr = np.sum((kim * fkr).real) * df2 + mp = np.sum((kim * fkp).real) * df2 + mc = np.sum((kim * fkc).real) * df2 # build a covariance matrix of the moments # here we assume each Fourier mode is independent and sum the variances @@ -331,7 +308,7 @@ def _measure_moments_fft( m_cov[1, 1] = 1 tot_var *= eff_pad_factor**2 tot_var_df4 = tot_var * df4 - psf_kerns_fac = wgt / kpsf_im + psf_kerns_fac = 1 / kpsf_im kerns = [ fkp * psf_kerns_fac, fkc * psf_kerns_fac, diff --git a/ngmix/tests/test_prepsfmom.py b/ngmix/tests/test_prepsfmom.py index 435d370f..84b1f2aa 100644 --- a/ngmix/tests/test_prepsfmom.py +++ b/ngmix/tests/test_prepsfmom.py @@ -394,13 +394,10 @@ def test_prepsfmom_gauss( @pytest.mark.parametrize('image_size', [53]) @pytest.mark.parametrize('pad_factor', [1.5]) @pytest.mark.parametrize('round', [True, False]) -@pytest.mark.parametrize( - 'fwhm_smooth,use_pix_weight', - [(0, False), (0, True), (1, False)], -) +@pytest.mark.parametrize('fwhm_smooth', [0, 1]) def test_prepsfmom_mn_cov_psf( pad_factor, image_size, fwhm, psf_fwhm, pixel_scale, snr, mom_fwhm, cls, - use_pix_weight, fwhm_smooth, round, + fwhm_smooth, round, ): """Slower test to make sure means and errors are right w/ tons of monte carlo samples. @@ -461,35 +458,20 @@ def test_prepsfmom_mn_cov_psf( fitter = cls( fwhm=mom_fwhm, pad_factor=pad_factor, - use_pix_weight=use_pix_weight, fwhm_smooth=fwhm_smooth, ) # get true flux - if use_pix_weight: - im_true = galsim.Convolve([gal, psf]).drawImage( - nx=image_size, - ny=image_size, - wcs=gs_wcs, - method='no_pixel').array - obs = Observation( - image=im_true, - weight=wgt, - jacobian=jac, - psf=Observation(image=psf_im, jacobian=psf_jac), - ) - res = fitter.go(obs=obs) - else: - im_true = gal.drawImage( - nx=image_size, - ny=image_size, - wcs=gs_wcs, - method='no_pixel').array - obs = Observation( - image=im_true, - jacobian=jac, - ) - res = fitter.go(obs=obs, no_psf=True) + im_true = gal.drawImage( + nx=image_size, + ny=image_size, + wcs=gs_wcs, + method='no_pixel').array + obs = Observation( + image=im_true, + jacobian=jac, + ) + res = fitter.go(obs=obs, no_psf=True) flux_true = res["flux"] T_true = res["T"] g1_true = res["e"][0]