Skip to content

Commit

Permalink
add unit test with the original problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
PFLeget authored and rmjarvis committed Mar 3, 2025
1 parent 17f22cd commit 2a6986f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
Binary file added tests/input/testStarsRubin.fits
Binary file not shown.
78 changes: 77 additions & 1 deletion tests/test_pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import time
import os
import fitsio
import copy

from piff_test_helper import get_script_name, timer, CaptureLog

Expand Down Expand Up @@ -1790,6 +1789,83 @@ def test_convert_func():
print('fitted params = ',star1.fit.params)
np.testing.assert_allclose(star1.fit.params, model_im.array.ravel(), rtol=2.e-3)

@timer
def test_convergence_centering_failed():

# Before https://rubinobs.atlassian.net/browse/DM-49152, it was
# running an infinite number of time. Reason is because fitting center
# looks to fail in some cases. So now it should converge if center fail.
# It should converged now and exclude properly stars that were not
# able to be get a good center fit and then being reflux. If centering,
# is fixed, this test might need to be removed.

piffConfig = {
'type': 'Simple',
'model': {
'type': 'PixelGrid',
'scale': 0.2,
'size': 25,
'interp': 'Lanczos(11)'
},
'interp': {
'type': 'BasisPolynomial',
'order': 1,
'solver': 'scipy'
},
'outliers': {
'type': 'Chisq',
'nsigma': 4.0,
'max_remove': 0.05
},
'max_iter': 30
}

starData = fitsio.read('input/testStarsRubin.fits')
image = starData["IMAGE"][0]
weight = starData["WEIGHT"][0]
x = starData["X"][0]
y = starData["Y"][0]
xmin = starData["XMIN"][0]
xmax = starData["XMAX"][0]
ymin = starData["YMIN"][0]
ymax = starData["YMAX"][0]

nstars = len(x)
stars = []

gswcs = galsim.PixelScale(0.20038369063248057)
wcs = {0: gswcs}
pointing = None

stars = []

for i in range(nstars):

bds = galsim.BoundsI(
galsim.PositionI(xmin[i], ymin[i]),
galsim.PositionI(xmax[i], ymax[i])
)
gsImage = galsim.Image(bds, wcs=gswcs, dtype=float)
gsImage.array[:] = image[i]

gsWeight = galsim.Image(bds, wcs=gswcs, dtype=float)
gsWeight.array[:] = weight[i]

image_pos = galsim.PositionD(x[i], y[i])
data = piff.StarData(
gsImage,
image_pos,
weight=gsWeight,
pointing=pointing
)
stars.append(piff.Star(data, None))


piffResult = piff.PSF.process(piffConfig)
piffResult.fit(stars, wcs, pointing)

assert piffResult.niter == 6, 'Maximum number of iterations in this example must be 6.'
assert np.shape(piffResult.stars[28].fit.A) == (0, 625), 'Centroid failed for this star, expected shape of A is (0,625)'

if __name__ == '__main__':
#import cProfile, pstats
Expand Down

0 comments on commit 2a6986f

Please sign in to comment.