Found 2026-08-08 while running crowdsource (git master, post-multiband-merge
of PR #23, Mar 2026) on ZTF cutouts.
Bug: fit_once() crashes whenever a sky basis is requested (nskyx/nskyy > 0)
Symptom
from crowdsource.crowdsource_base import fit_once
fit_once(im, x, y, psflist, weights=w, psfderiv=False, nskyx=3, nskyy=3)
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
at crowdsource_base.py, line ~501, in build_sparse_matrix:
if colnorm[startidx + syloc[i]] == 0:
Cause
In the sky-parameter column loop of build_sparse_matrix (added/refactored in
the multiband work), syloc[i] is used as if it were a scalar column index.
But sky_parameters() returns
yloc = [inp.ones((nx, ny), dtype='i4').ravel() for i in range(nskypar)]
i.e. each syloc[i] is a full nxny ARRAY (constant, value i). So
colnorm[startidx + syloc[i]] is an array, and the scalar "== 0" test raises.
The intended scalar is simply startidx + i:
colnorm[startidx + i] = np.sqrt(np.sum(svalues[i] ** 2))
if colnorm[startidx + i] == 0:
colnorm[startidx + i] = 1.0
values[first:first+len(sxloc[i])] = svalues[i] / colnorm[startidx + i]
Why it goes unnoticed
fit_im() defaults to nskyx = nskyy = 0 and handles sky via the median-filter
sky_im subtraction, so the buggy code path only runs when a user calls
fit_once()/fit_im() with an explicit sky basis. Any nskyx/nskyy >= 1
triggers it, single-band or multiband.
Workaround we used
Pre-subtract a robust (sigma-clipped) sky, run fit_once with
nskyx = nskyy = 0, then refine: subtract the median of (data - model)
residual and re-fit once. Matches fit_im's own iterate-the-sky approach.
Context: found while doing forced photometry of a microlensing event
-- Peter Nugent (penugent@lbl.gov)
Found 2026-08-08 while running crowdsource (git master, post-multiband-merge
of PR #23, Mar 2026) on ZTF cutouts.
Bug: fit_once() crashes whenever a sky basis is requested (nskyx/nskyy > 0)
Symptom
from crowdsource.crowdsource_base import fit_once
fit_once(im, x, y, psflist, weights=w, psfderiv=False, nskyx=3, nskyy=3)
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
at crowdsource_base.py, line ~501, in build_sparse_matrix:
if colnorm[startidx + syloc[i]] == 0:
Cause
In the sky-parameter column loop of build_sparse_matrix (added/refactored in
the multiband work), syloc[i] is used as if it were a scalar column index.
But sky_parameters() returns
yloc = [inp.ones((nx, ny), dtype='i4').ravel() for i in range(nskypar)]
i.e. each syloc[i] is a full nxny ARRAY (constant, value i). So
colnorm[startidx + syloc[i]] is an array, and the scalar "== 0" test raises.
The intended scalar is simply startidx + i:
Why it goes unnoticed
fit_im() defaults to nskyx = nskyy = 0 and handles sky via the median-filter
sky_im subtraction, so the buggy code path only runs when a user calls
fit_once()/fit_im() with an explicit sky basis. Any nskyx/nskyy >= 1
triggers it, single-band or multiband.
Workaround we used
Pre-subtract a robust (sigma-clipped) sky, run fit_once with
nskyx = nskyy = 0, then refine: subtract the median of (data - model)
residual and re-fit once. Matches fit_im's own iterate-the-sky approach.
Context: found while doing forced photometry of a microlensing event
-- Peter Nugent (penugent@lbl.gov)