desihub / desispec

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

Fix traceshifts when half CCD amps are masked #2150

Closed sbailey closed 8 months ago

sbailey commented 8 months ago

This PR fixes the crash reported in #2148 for traceshifts on CCDs where half of the amps are masked. The underlying problem was a median over fibers to make a median spectrum, but that can fall apart if >half of the fibers are masked (or in previous cases, luckily sort-of succeeding when 249 fibers were masked...). The solution is to only median over unmasked fibers.

This fixes the previous crash case:

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

I verified with plot_fiber_traces that the offset traces look good, including that the masked traces are ok and don't have bad solutions causing overlaps with good traces.

I also checked that previously succeeding cases continue to produce identical results, e.g.

desi_compute_trace_shifts --degxx 2 --degxy 0 --degyx 2 --degyy 0 --sky \
  --image preproc-r1-00207663.fits.gz \
  --psf psfnight-r1-20231202.fits \
  --outpsf $SCRATCH/psf-r1-00207663.fits

Along for the ride: I also updated plot_fiber_traces to use lightgray instead of white to make the traces visible on large regions of masked images (which matplotlib defaults to white).

I'm pretty sure that this PR is correct so I'm going to fast-track it for merging so that I can use it for reprocessing early December data before the next NERSC outage. Post-facto review is still welcome.