Skip to content

Commit

Permalink
feat: update with better piff tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed Jul 16, 2024
1 parent 38676d6 commit b8e1c82
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 11 deletions.
73 changes: 68 additions & 5 deletions piff_package/apodize.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down

0 comments on commit b8e1c82

Please sign in to comment.