Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH apodize for DES #1

Open
wants to merge 29 commits into
base: releases/1.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
685ab81
ENH add fixed apodization for DES
beckermr Mar 1, 2024
54fba85
REF redo options a bit
beckermr Mar 1, 2024
139066a
REF no numba
beckermr Mar 1, 2024
aba23c7
Update piff/psf.py
beckermr Mar 2, 2024
8e64584
Update piff/psf.py
beckermr Jul 15, 2024
c76660a
Update piff/psf.py
beckermr Jul 15, 2024
cec733c
Update _version.py
beckermr Jul 15, 2024
f59db7a
Merge branch 'releases/1.3' into apodize
beckermr Jul 15, 2024
88755ec
Update ci.yml
beckermr Jul 15, 2024
0448559
Update requirements.txt
beckermr Jul 15, 2024
c0161b4
Update ci.yml
beckermr Jul 15, 2024
1e8280e
Update test_pixel.py
beckermr Jul 15, 2024
767f46a
Update test_simple.py
beckermr Jul 15, 2024
78494ce
Update test_simple.py
beckermr Jul 15, 2024
0309115
Update test_wcs.py
beckermr Jul 15, 2024
60b4c72
Update test_wcs.py
beckermr Jul 15, 2024
1a81a80
Update tests/test_simple.py
beckermr Jul 15, 2024
b4b5ab3
Update ci.yml
beckermr Jul 15, 2024
5105bf3
Update test_simple.py
beckermr Jul 16, 2024
acb6198
Update test_simple.py
beckermr Jul 16, 2024
99f5106
Update test_wcs.py
beckermr Jul 16, 2024
2f9d6b4
Update test_simple.py
beckermr Jul 16, 2024
4351177
REF move apodization to the pixelgrid
beckermr Jul 16, 2024
122ef5c
refactor: make code clear it is not a copy
beckermr Jul 16, 2024
44e8e2f
Update piff/psf.py
beckermr Jul 16, 2024
a7165d4
test: try this
beckermr Jul 16, 2024
e3c5292
Merge branch 'apodize' of https://github.com/beckermr/Piff into apodize
beckermr Jul 16, 2024
0271d4f
test: add test
beckermr Jul 16, 2024
c1c8eba
test: add one more test
beckermr Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
# First all python versions in basic linux
os: [ ubuntu-latest ]
Expand Down Expand Up @@ -81,13 +82,13 @@ jobs:
python -m pip install -U pip

# Do these first to clarify potential conflicts
pip install -U setuptools numpy
pip install -U setuptools "numpy<2"

# Standard dependencies
pip install -U -r requirements.txt

# Extra packages needed for testing
pip install -U nose coverage pytest nbval ipykernel
pip install -U nose coverage "pytest<8" nbval ipykernel

- name: Install Pixmappy (not on pip)
run: |
Expand Down
2 changes: 1 addition & 1 deletion piff/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
# this list of conditions and the disclaimer given in the documentation
# and/or other materials provided with the distribution.

__version__ = '1.3.3'
__version__ = '1.3.3.1'
__version_info__ = tuple(map(int, __version__.split('.')))
40 changes: 40 additions & 0 deletions piff/pixelgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
apval = np.zeros_like(m)
msk = y > 3
apval[msk] = 1
msk = (y > -3) & (~msk)
apval[msk] = (
-5 * y[msk] ** 7 / 69984
+ 7 * y[msk] ** 5 / 2592
- 35 * y[msk] ** 3 / 864
+ 35 * y[msk] / 96
+ 1 / 2
)
return apval


class PixelGrid(Model):
"""A PSF modeled as interpolation between a grid of points.

Expand Down Expand Up @@ -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)

if APODIZE_PARAMS is not None:
xpix, ypix = im.get_pixel_centers()
# use_true_center = False below
dx = xpix - im.center.x
dy = ypix - im.center.y
r2 = dx**2 + dy**2

apwidth, aprad = APODIZE_PARAMS # in arcsec
_apwidth = apwidth / self.scale # convert to pixels
_aprad = aprad / self.scale # convert to pixels

apim = im._array * _ap_kern_kern(_aprad, np.sqrt(r2), _apwidth)
im._array = apim / np.sum(apim) * np.sum(im._array)

return galsim.InterpolatedImage(im, x_interpolant=self.interp,
use_true_center=False, flux=1.)

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
numpy>=1.17
numpy>=1.17,<2
scipy>=1.2
pyyaml>=5.1
lsstdesc.coord>=1.2
treecorr>=4.3.1
fitsio>=1.0
matplotlib>=3.3
galsim>=2.3
galsim>=2.3,<2.5
treegp>=0.6
threadpoolctl>=3.1
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# turn off apodization
import piff.pixelgrid

piff.pixelgrid.set_apodize_params(None)
47 changes: 47 additions & 0 deletions tests/test_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading