Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pixel model and chi2 metrics for better cosmic identification #40

Merged
merged 7 commits into from
Aug 16, 2016
Merged

Conversation

sbailey
Copy link
Contributor

@sbailey sbailey commented Jul 29, 2016

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
Copy link
Contributor

  • in ex2d.ex2d line 158
    • need to ignore masked (ivar=0) pixels in PSF weighted chi2 (otherwise flux bins affected with partially masked cosmic rays will have low weighted chi2).
    • need to test A is not zero for some values. I got a warning when running test_extract.py
  • would need to allow for a psf relative error (few %), otherwise, there is a risk to flag as bad very bright spectral bins.

@julienguy
Copy link
Contributor

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
Copy link
Member

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

@sbailey
Copy link
Contributor Author

sbailey commented Jul 30, 2016

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
Copy link
Contributor Author

sbailey commented Aug 16, 2016

I added changes to address Julien's comments:

  • chi2pix calculation now includes a PSF model error. PSFs can specify their error via a PSFERR keyword in the fits file. If that isn't specified a default of 0.01 is used. This is a global PSF error; wavelength and fiber dependent PSF errors are not supported (yet?)
  • chi2pix calculation doesn't include masked pixels
  • avoid divide by 0 warning

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

@sbailey sbailey merged commit c5cb1cb into master Aug 16, 2016
@sbailey sbailey deleted the chi2 branch August 16, 2016 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants