desihub / desispec

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

Support cals + science when one amp is bad #2210

Closed sbailey closed 2 months ago

sbailey commented 3 months ago

Add support for processing calibrations + science when an amp is flagged as bad for the entire night. For Y3 we have 26 nights (3.4%) in this situation. In other cases of missing calibration data, we link to calibrations from other nights, but these are cases where the amp is bad all night and thus isn't needed for the sciences anyway, so we could use the data that are good to process the cals needed for the sciences.

Current pipeline

Currently the pipeline discards the entire CCD for calibrations and solves psfs + fiberflats using the other cameras. Sciences exposures are processed for all cameras, but since the camera with the bad amp doesn't have nightly cals, it falls back to old/incorrect defaults in $DESI_SPECTRO_CALIB.

The badamp info is only propagated as fibermap['FIBERSTATUS'] bits BADAMPX, where X=B,R,Z. i.e. the masking is at the fiber-level, not the wavelength-level, and it just indicates which camera had the bad amp without specifying which amp it was.

What we want

We should fit the nightly bias, psf, fiberflat for the half of the CCD that doesn't have a bad amp, and propagate enough masking information so that downstream code knows what can be used or not. In addition to masking at the fibermap.FIBERSTATUS level, we should also mask at the per-fiber per-wavelength frame.mask level.

What needs to be updated

Notes

Testing

Details

At the level of the exposure tables and desi_proc, badamps is specified e.g. as "b8A,r7C,z3D". desi_proc should strip this down to just the ABCD needed for the particular camera being processed, e.g. in preproc-b8*.fits would have BADAMPS=A, not BADAMPS=b8A or b8A,r7C,z3D. This also applies to any --badamps overrides to individual steps like desi_compute_psf.

Related

sbailey commented 3 months ago

@julienguy I have created a branch "badampcals" which updates preproc to set new MASK bit BADAMP and sets a header keyword BADAMPS=[ABCD] if an amp was flagged as bad for processing. An example preproc file is

/dvs_ro/cfs/cdirs/desi/users/sjbailey/spectro/redux/badampcals/preproc/20230428/00177975/preproc-b8-00177975.fits.gz

Please update desi_compute_psf to use that information to propagate the input PSF for traces that overlap the bad amp. This is slightly non-trivial workflow due to desi_compute_psf running specex compiled code per bundle and then merging the per-bundle files afterward. Example command that currently fails:

desi_compute_psf --broken-fibers 348,473,474 \
    --input-image /dvs_ro/cfs/cdirs/desi/users/sjbailey/spectro/redux/badampcals/preproc/20230428/00177975/preproc-b8-00177975.fits.gz \
    --input-psf /dvs_ro/cfs/cdirs/desi/users/sjbailey/spectro/redux/badampcals/exposures/20230428/00177975/shifted-input-psf-b8-00177975.fits \
    --output-psf $SCRATCH/temp/fit-psf-b8-00177975.fits

That branch also has hooks for processing other calibrations with a bad amp, but it's a bit tricky to test until the PSF fitting is working since that is such an early step in the chain.

Note to self and @akremin : this branch is intended to handle the case where an amp was flagged as bad all night, during both cals and sciences and thus isn't needed. Other cases to check for:

From my initial checks, "bad all night" is the dominant case, but I will check for these other cases too before finalizing.

akremin commented 3 months ago

I think we can leave the current badamp logic for desi_proc_tilenight. It would be nice to propagate badamps directly, but no more so that all of the other parameters that are re-derived within tilenight itself. I think that can be left for a future update, given that science exposures already get the appropriate badamps set by tilenight and I don't think the logic here changes from what is currently done for sciences.

What does need to change, as you mentioned, is that we need to identify whether the badamps are present for the whole night, whole calibration set, or individual exposures; and handle the calibrations badamps appropriately in those cases.

I agree with our assessment of the three badamp scenarios for arcs.

For the situation of a single flat exposure or subset of flat exposures having a badamp, would we also convert that to a BADCAMWORD, or will the updated code be able to meaningfully handle half of a CCD for flat fielding? (Full disclosure, I haven't checked if this case actually exists in historic data).

I'm happy to make the updates to desi_proc_night, but may wait for the other portions to be implemented so that I can test what is being submitted.

sbailey commented 3 months ago

@akremin @julienguy

For the situation of a single flat exposure or subset of flat exposures having a badamp, would we also convert that to a BADCAMWORD, or will the updated code be able to meaningfully handle half of a CCD for flat fielding? (Full disclosure, I haven't checked if this case actually exists in historic data).

Yes, I think we'd need to convert those cases to BADCAMWORD instead of BADAMP (if they exist).

I'm happy to make the updates to desi_proc_night, but may wait for the other portions to be implemented so that I can test what is being submitted.

I think I have made all the necessary changes except the PSF fitting (@julienguy volunteered for that). At the same time, I'm sure there are bugs that will be revealed with further end-to-end testing after the PSF part works too.

sbailey commented 2 months ago

implemented in PR #2217. Closing.