desihub / desispec

DESI spectral pipeline
BSD 3-Clause "New" or "Revised" License
35 stars 24 forks source link

traceshifts fail if half of b-camera CCD is masked #2148

Open sbailey opened 8 months ago

sbailey commented 8 months ago

On 20231202 through 20231205, b5 amps A and C (left half of CCD) were bad. We tried to recover the other half by using a PSF from a previous night, but desi_compute_trace_shifts fails:

cd $CFS/desi/users/desi/debug/traceshifts
desi_compute_trace_shifts --degxx 2 --degxy 0 --degyx 2 --degyy 0 --sky \
  --image preproc-b5-00207663.fits.gz \
  --psf psfnight-b5-20231126.fits \
  --outpsf $SCRATCH/psf-b5-00207663.fits

...
INFO:trace_shifts.py:242:fit_trace_shifts: polynomial fit of measured offsets with degx=(0,0) degy=(0,0)
WARNING:trace_shifts.py:269:fit_trace_shifts: polynomial fit failed with degx=(0,0) degy=(0,0)
ERROR:trace_shifts.py:271:fit_trace_shifts: polynomial degrees are already 0. we can't fit the offsets
Traceback (most recent call last):
  File "/global/common/software/desi/perlmutter/desiconda/20230111-2.1.0/code/desispec/main/py/desispec/scripts/trace_shifts.py", line 245, in fit_trace_shifts
    dy_coeff,dy_coeff_covariance,dy_errorfloor,dy_mod,dy_mask=polynomial_fit(z=dy,ez=ey,xx=x_for_dy,yy=y_for_dy,degx=degyx,degy=degyy)
  File "/global/common/software/desi/perlmutter/desiconda/20230111-2.1.0/code/desispec/main/py/desispec/trace_shifts.py", line 1166, in polynomial_fit
    coeff=cholesky_solve(A,B)
  File "/global/common/software/desi/perlmutter/desiconda/20230111-2.1.0/code/desispec/main/py/desispec/linalg.py", line 27, in cholesky_solve
    UorL,lower = scipy.linalg.cho_factor(A, lower=lower, overwrite_a=overwrite)
  File "/global/common/software/desi/perlmutter/desiconda/20230111-2.1.0/conda/lib/python3.10/site-packages/scipy/linalg/_decomp_cholesky.py", line 152, in cho_factor
    c, lower = _cholesky(a, lower=lower, overwrite_a=overwrite_a, clean=False,
  File "/global/common/software/desi/perlmutter/desiconda/20230111-2.1.0/conda/lib/python3.10/site-packages/scipy/linalg/_decomp_cholesky.py", line 37, in _cholesky
    raise LinAlgError("%d-th leading minor of the array is not positive "
numpy.linalg.LinAlgError: 1-th leading minor of the array is not positive definite

Ideally it would solve for the shifts for the fibers covering the masked regions, and apply an average shift (or no shift?) to the masked fibers, so that we could then proceed with extractions using shifted PSFs for the ~250 good fibers.

I'm not sure why we haven't encountered this problem before, since we do have support for masking individual amps.