Open stscijgbot-jp opened 1 week ago
Comment by Timothy Brandt on JIRA:
I made progress on this during my weekend travel. I am attaching a notebook with an initial implementation of a new extract1d approach with most functionality implemented. I would like anyone interested to take a look at this for general comments. There are a couple of things I would like to discuss:
More generally, I would like comments on whether this includes all of the basic desired functionality, and whether the code structure is generally satisfactory.[^extract1d_framework.ipynb]
Comment by Melanie Clarke on JIRA:
Thanks for the update Timothy Brandt - I'll start taking a look at what you have so far.
Comment by Timothy Brandt on JIRA:
Updated notebook to reflect distinction between read noise, photon noise, flat field noise. Updated background noise calculations.[^extract1d_framework 9-27.ipynb]
Comment by Timothy Brandt on JIRA:
One more update to implement de-biasing approach to inverse variance weighting.
[^extract1d_framework 9-29.ipynb]
Comment by Melanie Clarke on JIRA:
Thanks again, Timothy Brandt . I think I now mostly understand your approach.
It looks like what would be needed, in addition to this engine, is a method to make the 2D spatial profiles, either from a model for PSF-based fitting, or from input parameters/references specifying the box/background location(s). I think Jane is working on the PSF end of that in JP-251, but we may need some additional effort to support the current use case, as well as integration with the step's front end. The format you’re expecting for the input profiles looks fine to me, anyway.
A few comments and questions...
For data handling and formatting:
I think we should default to ignoring NaNs in box extractions, to replicate the current behavior.
Missing/unfittable data in optimal extraction should probably be set to NaN instead of zero in the output.
We will probably still want to output separate variances for read noise, poisson noise, and flat variance components, to replicate current behavior.
For box extractions, it might be useful to update the model returned with a uniform flux in the extraction region, so it’s not all zeros.
Questions about your assumptions:
Why not allow multiple source extractions with the box method? If they don’t overlap, it seems a reasonable thing to do.
What happens with the matrix inversions in the fitted case if the spectral image is large, e.g. NIRSpec ALLSLITS or MOS used as long slit? Is that solution still workable, performance-wise, or might we need a different fitting strategy?
For the debiasing approach for inverse variance weighting… I’m a little skeptical about how well your proposal will work. It seems error prone, given the multiple levels of fitting to the same input data, and given that read noise variance is not necessarily independent of the input flux either. But I agree we should discuss more – it might be worth trying.
Comment by Timothy Brandt on JIRA:
Thank you, Melanie Clarke. Your suggestions all seem reasonable and straightforward to implement. And yes, the (difficult) task is to actually derive these spatial profiles. I can do this for the current case of polynomial interval boundaries once we are happy with this end of the implementation, since that it what should play nicely with future use cases. For your questions:
And for the debiasing, I agree that my approach is a bit too simplistic. I think it's probably much better than just using inverse-variance weighting (as is often implied in a PSF-based approach), but is far from perfect. I think that the best approach, which would be very nearly correct, would probably rely on the ramp fitting itself, finding the photon and read noise that would have been reported if the count rate matched the model count rate. I would favor leaving in something like I have now as a placeholder for doing things properly.
Issue JP-3753 was created on JIRA by Timothy Brandt:
The extract1d software is slow due to a reliance on lists and explicit for loops, it can be difficult to read, and it does not perform optimal extraction. The refactoring described in this ticket will use efficient numpy arrays and linear algebra to preserve the current behavior, improve background fitting and error estimates, and provide functionality for optimal and PSF-based extraction if the appropriate templates are supplied as arrays.
Extract1d will, by default, operate on the same reference file information as it does currently and will produce similar, though not identical, behavior (mostly in the treatment of backgrounds). In the future PSF-based and optimal extraction approaches are planned to be offered (see https://jira.stsci.edu/browse/JP-251).