gbrammer / msaexp

Manual extraction of JWST NIRSpec spectra
MIT License
26 stars 28 forks source link

Error propagation within msaexp #51

Open themiyan opened 1 year ago

themiyan commented 1 year ago

The erros for the optimally extracted spectra seems to be underestimated compared to the 'real' expectation. i.e. from the ETC or looking ash the error values from single exposures from the pipeline. The extract_spectrum function seems to be where the real science happens here.

We did a few experiments with some of 2565 data to see what was going on.

Removing any background subtraction we get 3 spectra with good continuum.

Screenshot 2023-11-02 at 14 07 52

The flux levels are not similar between the 3 dithers due to object entering issues, so we've fit a polynomial to 2 of the dithers to normalise the flux and errors to the first dither position. The same correction is also applied to the error spectrum.

Once this normalisation is applied, the flux variation between the individual pixels can be thought to be driven by the noise value. So the RMS of the flux values in the 3 dithers (show in solid black below) can be compared with the normalised errors of the 3 dither positions. They agree well (some sigma clipping applied to remove CR noise etc)

Screenshot 2023-11-02 at 14 11 35

Now the figure below shows the S/N for the 3 discussed above + also with background subtraction as handled by msaexp. It is a bit busy, but basically the 3 dither positions with no background subtraction are in the solid rgb colours. The 6 A-B iterations are shown by dashed colours. The black dashed in S/N = 30 to guide the eye.

The solid black is the optimally extracted spectrum produced by the extract_spectrum function.

Screenshot 2023-11-02 at 14 17 44

The S/N is ~ sqrt(6) higher compared to the individual error levels. However, since the background errors in A-B and A-C are correlated, it should be only sqrt(3) higher.

The extract_spectrum function stacks all 6 iterations together and takes the sum with optimal ivar scaling. So basically the 6 background subtractions are considered to be independent. Like https://github.com/gbrammer/msaexp/blob/d7368560cf465a0828e942454cfcc0bbe6870278/msaexp/pipeline.py#L1605

Is our understanding here correct?

themiyan commented 1 year ago

Below is the maths Karl worked out to confirm this mathematically.

PastedGraphic-2 PastedGraphic-2