desihub / specter

A toolkit for simulating multi-object spectrographs
Other
8 stars 7 forks source link

pixel model and chi2 metrics for better cosmic identification #40

Closed sbailey closed 7 years ago

sbailey commented 7 years ago

This PR adds several new outputs to the ex2d() spectral extractions:

  1. pixel model of the extracted spectra projected back into the CCD pixel space, useful for debugging
  2. the PSF-weighted fraction of input pixels that had ivar=0, useful for identifying ill-constrained fluxes (perhaps to be masked by downstream steps)
  3. the PSF-weighted chi^2 of the pixels that contributed to each extracted flux bin, useful for identifying bad extractions, e.g. arising from unmasked cosmics in the input pixel data

These are provided as informational numbers that downstream steps could use for masking. A future specter improvement might use the pixel-level chi2 to identify and mask poorly fitting pixels (e.g. from cosmics) and then re-extract, potentially "saving" some flux bins that otherwise would have been lost as just bad extractions. But that iterative refit isn't included in this PR.

The ipython notebook in doc/nb/unmasked_cosmics.ipynb documents more details about how this works. The following figure shows an unmasked cosmic in the DESI oak simulations that was incorrectly identified as H-alpha; the upper plot shows the extracted spectrum and the wavelengths that would be masked by applying a cut on the PSF-weighted pixel-chi2.

cosmic-r0-00000011-fiber104-wave6984

Testing on the DESI oak-lite simulations (2 spectrographs, 3 exposures) using this with a conservative 10-sigma cut improved the ELG redshifts from 90% efficiency to 94%, and LRGs from 97% to 99%. Full disclosure: compared to oak (10 spectrographs, 9 exposures) the QSO efficiency went down, but the efficiencies were already so low (50-60%) something else is going on that needs to be debugged independent of this.

Ted and Julien: I had previously reported that this was blowing memory on edison batch jobs. That turned out to be a leftover of caching the results of every subpatch extraction for debugging. Removing that, the memory footprint is only modestly larger (1.5 vs. 1.4 GB).

I'll submit a PR on the desispec side to use these features.

julienguy commented 7 years ago
julienguy commented 7 years ago

code tested successfully (along with desispec branch cosmic_masking) on one cosmic ray spike (oak1 frame r0-00000006 fiber 413 wave 6519A). with new code, cosmic shows very large CHI2PIX value in frame, and is adequately flagged in MASK.

tskisner commented 7 years ago

I defer to Julien's detailed testing on this...

sbailey commented 7 years ago

These are good comments. I'm about to leave on vacation so I'm not going to try to fix them and merge in a rush and then disappear. Will wait for late August...

sbailey commented 7 years ago

I added changes to address Julien's comments:

I updated the ipython notebook and re-tested the example shown in the original PR post (which still works fine...)