Skip to content

Commit d0bb2eb

Browse files
committed
Avoid some dividing by zero in bad corner cases.
1 parent 750e2f7 commit d0bb2eb

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

crowdsource/crowdsource_base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ def compute_centroids(x, y, psflist, flux, im, resid, weight,
503503
# stamps: 0: neighbor-subtracted images,
504504
# 1: images,
505505
# 2: psfs with shifts
506-
# 3: psfs without shifts
506+
# 3: weights
507+
# 4: psfs without shifts
507508
res = (xcen, ycen, (modelst+residst, imst, modelst, weightst, psfst))
508509
return res
509510

@@ -943,9 +944,9 @@ def compute_stats(xs, ys, impsfstack, psfstack, weightstack, imstack, flux):
943944
fracfluxd = fracfluxd + (fracfluxd == 0)*1e-20
944945
fracflux = (fracfluxn / fracfluxd).astype('f4')
945946
fluxlbs, dfluxlbs = compute_lbs_flux(impsfstack, psfstack, weightstack,
946-
flux/norm)
947+
flux/(norm+(norm == 0)))
947948
fluxiso, xiso, yiso = compute_iso_fit(impsfstack, psfstack, weightstack,
948-
flux/norm, psfderiv)
949+
flux/(norm+(norm == 0)), psfderiv)
949950
fluxlbs = fluxlbs.astype('f4')
950951
dfluxlbs = dfluxlbs.astype('f4')
951952
fwhm = psfmod.neff_fwhm(psfstack).astype('f4')

crowdsource/psf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def central_stamp(stamp, censize=19):
5151
def neff_fwhm(stamp):
5252
"""FWHM-like quantity derived from N_eff = numpy.sum(PSF**2.)**-1"""
5353
norm = numpy.sum(stamp, axis=(-1, -2), keepdims=True)
54+
norm += (norm == 0)
5455
return 1.18 * (numpy.pi*numpy.sum((stamp/norm)**2., axis=(-1, -2)))**(-0.5)
5556

5657

0 commit comments

Comments
 (0)