Skip to content

Commit

Permalink
Avoid some dividing by zero in bad corner cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
schlafly committed May 9, 2022
1 parent 750e2f7 commit d0bb2eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crowdsource/crowdsource_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ def compute_centroids(x, y, psflist, flux, im, resid, weight,
# stamps: 0: neighbor-subtracted images,
# 1: images,
# 2: psfs with shifts
# 3: psfs without shifts
# 3: weights
# 4: psfs without shifts
res = (xcen, ycen, (modelst+residst, imst, modelst, weightst, psfst))
return res

Expand Down Expand Up @@ -943,9 +944,9 @@ def compute_stats(xs, ys, impsfstack, psfstack, weightstack, imstack, flux):
fracfluxd = fracfluxd + (fracfluxd == 0)*1e-20
fracflux = (fracfluxn / fracfluxd).astype('f4')
fluxlbs, dfluxlbs = compute_lbs_flux(impsfstack, psfstack, weightstack,
flux/norm)
flux/(norm+(norm == 0)))
fluxiso, xiso, yiso = compute_iso_fit(impsfstack, psfstack, weightstack,
flux/norm, psfderiv)
flux/(norm+(norm == 0)), psfderiv)
fluxlbs = fluxlbs.astype('f4')
dfluxlbs = dfluxlbs.astype('f4')
fwhm = psfmod.neff_fwhm(psfstack).astype('f4')
Expand Down
1 change: 1 addition & 0 deletions crowdsource/psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def central_stamp(stamp, censize=19):
def neff_fwhm(stamp):
"""FWHM-like quantity derived from N_eff = numpy.sum(PSF**2.)**-1"""
norm = numpy.sum(stamp, axis=(-1, -2), keepdims=True)
norm += (norm == 0)
return 1.18 * (numpy.pi*numpy.sum((stamp/norm)**2., axis=(-1, -2)))**(-0.5)


Expand Down

0 comments on commit d0bb2eb

Please sign in to comment.