From b8e1c8265e7128f98ae33a60e47a89b53def1522 Mon Sep 17 00:00:00 2001 From: beckermr Date: Tue, 16 Jul 2024 15:43:01 -0500 Subject: [PATCH] feat: update with better piff tests --- piff_package/apodize.patch | 73 +++++++++++++++++++++++++++++++++++--- setup.py | 7 +--- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/piff_package/apodize.patch b/piff_package/apodize.patch index 1178d52..17a03ca 100644 --- a/piff_package/apodize.patch +++ b/piff_package/apodize.patch @@ -10,16 +10,21 @@ index 4f4c623a..c1ba101f 100644 +__version__ = '1.3.3.1' __version_info__ = tuple(map(int, __version__.split('.'))) diff --git a/piff/pixelgrid.py b/piff/pixelgrid.py -index 4d113c77..0c10bb8c 100644 +index 4d113c77..a7765afd 100644 --- a/piff/pixelgrid.py +++ b/piff/pixelgrid.py -@@ -25,6 +25,26 @@ +@@ -25,6 +25,31 @@ from .model import Model from .star import Star, StarData, StarFit +APODIZE_PARAMS = (1.0 * 0.263, 4.25 * 0.263) + + ++def set_apodize_params(pars): ++ global APODIZE_PARAMS ++ APODIZE_PARAMS = pars ++ ++ +def _ap_kern_kern(x, m, h): + # cumulative triweight kernel + y = (x - m) / h + 3 @@ -40,7 +45,7 @@ index 4d113c77..0c10bb8c 100644 class PixelGrid(Model): """A PSF modeled as interpolation between a grid of points. -@@ -445,6 +465,21 @@ def getProfile(self, params): +@@ -445,6 +470,21 @@ def getProfile(self, params): :returns: a galsim.GSObject instance """ im = galsim.Image(params.reshape(self.size,self.size), scale=self.scale) @@ -81,11 +86,69 @@ index d03b7b19..cfd6693b 100644 threadpoolctl>=3.1 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 -index 00000000..079d67ae +index 00000000..cf6d85c5 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,4 @@ +# turn off apodization +import piff.pixelgrid + -+piff.pixelgrid.APODIZE_PARAMS = None ++piff.pixelgrid.set_apodize_params(None) +diff --git a/tests/test_wcs.py b/tests/test_wcs.py +index 2a373671..68f54ab3 100644 +--- a/tests/test_wcs.py ++++ b/tests/test_wcs.py +@@ -747,6 +747,53 @@ def test_des_wcs(): + np.testing.assert_allclose(wcs3.toWorld(im.center).y, wcs1.toWorld(im.center).y, + rtol=0.04) + ++@timer ++def test_newdes_apodize(): ++ # This is a DES Y6 PSF file made by Robert Gruendl using python 2, so ++ # check that this also works correctly. ++ try: ++ import pixmappy ++ except ImportError: ++ print('pixmappy not installed. Skipping test_newdes()') ++ return ++ # Also make sure pixmappy is recent enough to work. ++ if 'exposure_file' not in pixmappy.GalSimWCS._opt_params: ++ print('pixmappy not recent enough version. Skipping test_newdes()') ++ return ++ ++ import piff ++ import piff.pixelgrid ++ ++ if __name__ == '__main__': ++ logger = piff.config.setup_logger(verbose=2) ++ else: ++ logger = piff.config.setup_logger(log_file='output/test_newdes.log') ++ ++ fname = os.path.join('input', 'D00232418_i_c19_r5006p01_piff-model.fits') ++ with warnings.catch_warnings(): ++ # This file was written with GalSim 2.1, and now raises a deprecation warning for 2.2. ++ warnings.simplefilter("ignore", galsim.GalSimDeprecationWarning) ++ warnings.simplefilter("ignore", DeprecationWarning) ++ psf = piff.PSF.read(fname, logger=logger) ++ ++ ims = [] ++ for appars in [None, (1.0 * 0.263, 4.25 * 0.263)]: ++ piff.pixelgrid.set_apodize_params(appars) ++ ims.append(psf.draw(x=103.3, y=592.0, logger=logger)) ++ ++ print('sum = ',ims[1].array.sum()) ++ assert not np.allclose(ims[0].array, ims[1].array) ++ assert np.allclose(ims[1].array[0, :], 0, rtol=1.e-2) ++ assert np.allclose(ims[1].array[-1, :], 0, rtol=1.e-2) ++ assert np.allclose(ims[1].array[:, 0], 0, rtol=1.e-2) ++ assert np.allclose(ims[1].array[:, -1], 0, rtol=1.e-2) ++ assert ims[1].array.sum() > 0 ++ np.testing.assert_allclose( ++ ims[0].array[23:26,22:25] / ims[0].array[23:26,22:25].sum(), ++ ims[1].array[23:26,22:25] / ims[1].array[23:26,22:25].sum(), ++ rtol=1.e-5, ++ ) ++ + if __name__ == '__main__': + #import cProfile, pstats + #pr = cProfile.Profile() diff --git a/setup.py b/setup.py index c51bca2..30a26c3 100644 --- a/setup.py +++ b/setup.py @@ -196,12 +196,7 @@ def run(self): cwd="piff_package", ) subprocess.run( - ["patch", "-p1", "-i", "apodize.patch"], - check=True, - cwd="piff_package", -) -subprocess.run( - ["rm", "-f", "piff/psf.py.orig"], + ["patch", "-p1", "-u", "-i", "apodize.patch"], check=True, cwd="piff_package", )