Bad amp in only some of the input arc exposures#2732
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts specex.mean_psf() to avoid treating bundles that are missing in only some input PSFs (e.g., due to bad amps in some arc exposures) as “fit failures”, preventing psfnight from erroring when multiple inputs have rchi==0 for reasons unrelated to fit quality (ref: desispec#2723).
Changes:
- Exclude exposures where a given bundle is missing from the
rchi2==0“fit failure” counting logic. - Emit a warning when a bundle is present in only a subset of the input PSFs and therefore fewer PSFs contribute for that bundle.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # This checks and makes sure that we are only looking for bundles with fit failures | ||
|
|
||
| # We use all_missing_bundles since we want to avoid flagging bundles are flagged as | ||
| # bad for only some of the input exposures | ||
| # if bundle not in all_missing_bundles.flatten(): | ||
| mask=[bundle in missing for missing in missing_bundles] | ||
| masked_bundle_rchi2 = bundle_rchi2.copy()[~np.array(mask)] | ||
| if len(masked_bundle_rchi2)!= len(bundle_rchi2) : | ||
| log.warning(f"Bundle {bundle} is missing in some but not all input PSFs for camera {refhead['CAMERA']}. Only {len(masked_bundle_rchi2)} PSFs will be used.") | ||
| nfailed = np.sum(masked_bundle_rchi2[:,bundle]==0) |
There was a problem hiding this comment.
The missing-bundle warning and the nfailed calculation are inside the per-PARAM loop, so this warning will be emitted once per PARAM entry (potentially many times) even though missing bundles don’t depend on PARAM. Consider moving this missing-bundle filtering / nfailed check outside the for entry loop, or at least guard the warning (and nfailed check) with if entry == 0 to avoid log spam and repeated work.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Moving to WIP / draft so that we don't accidentally merge this before converging on the right long-term solution. |
|
I added some additional code as before, |
akremin
left a comment
There was a problem hiding this comment.
Thank you for your work on this! Overall these changes look to do what we want but I do have two important questions I'd like clarification on before I accept the PR.
| if len(masked_bundle_rchi2)!= len(bundle_rchi2) : | ||
| log.warning(f"Bundle {bundle} is missing in some but not all input PSFs for camera {refhead['CAMERA']}. Only {len(masked_bundle_rchi2)} PSFs will be used.") | ||
| nfailed = np.sum(masked_bundle_rchi2[:,bundle]==0) | ||
| nfailed += len(failed_bundles[failed_bundles==bundle]) |
There was a problem hiding this comment.
Can a fiber be both RCHI2=0 and STATUS>0? If so, I think you count that bundle twice and then throw out the bundle in the subsequent lines when really there is only one actual failure.
There was a problem hiding this comment.
I don't think so as RCHI2=0 is only true for missing fibers (STATUS<0). When merging the individual bundle files into the primary file, the RCHI2 is set to 0 and is populated with the correct value unless that bundle is missing (
desispec/py/desispec/scripts/specex.py
Lines 449 to 456 in 000242d
| # status_of_fibers = \ | ||
| # other_psf_hdulist["PSF"].data["COEFF"][i][:,0].astype(int) | ||
| # log.info(f'status_of_fibers: {status_of_fibers}') | ||
| bundles_to_merge.append(b) |
There was a problem hiding this comment.
Are you confident that the later additions capture all possible corner cases where this could come back to bite us? I worry about including things that failed and then try to exclude bad things later, versus only keeping good things and then explicitly adding back in the failures that we deem acceptable. The former risks corner cases where the latter doesn't. I have a very superficial understanding of this so please let me know if I'm being overly nervous.
This pull request is to fix an issue we were running into with matterhorn where some of the input arcs (>2) had bad amps which triggered an the error which triggers when more than 2 arcs have
rchi==0, usually corresponding to a fit failure. Because it was not all of the arcs, this skips over a previous check. More information can be found here: #2723My solution is to mask known exposures with missing bundles from the check for fit failures. I tested this with 20211028 and this successfully ran and produced the expected logs with the warning. See
/global/cfs/cdirs/desi/spectro/redux/banovetz/run/scripts/night/20211028/psfnight-20211028-00106397-a0123456789-51950571.logfor the log.