-
Notifications
You must be signed in to change notification settings - Fork 171
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
JP-3330: Add NIRSpec wavelength corrections to slit WCS #8376
Conversation
Regression tests run: https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1364/ |
The implementation in this PR matches the description in the note attached to the issue and the JIRA ticket. |
The new commits address the previous comments, update the documentation, and add in the wavelength correction as a separate WCS frame, |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8376 +/- ##
==========================================
+ Coverage 58.02% 58.13% +0.10%
==========================================
Files 388 388
Lines 38977 38973 -4
==========================================
+ Hits 22617 22656 +39
+ Misses 16360 16317 -43 ☔ View full report in Codecov by Sentry. |
@hayescr Is this ready for review? If so do you want to take it out of Draft and rebase? |
c2cd640
to
92f7117
Compare
This PR needs a change log entry. Another regression tests job started: https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1414/ |
I think these changes might require some changes to the flat_field step as well: in the Edited to add: also in the get_wavelengths function in lib/wcs_utils.py |
Agreed it looks like these instances primarily use the wcs to generate the uncorrected wavelengths for fixed slit background corrections (since the background will be a extended source), which will no longer work, so I can work on adding fixes here. @nden and @melanieclarke, would it be better to reproduce uncorrected wavelengths from the wcs for these steps (by skipping the wavelength correction transforms), or to add a "uniform wavelength/uncorrected wavelength" extension that would be saved in the wavecorr step in case users wanted access these after-the-fact, similar to how the The |
@hayescr - For the pathloss correction wavelengths, I think you're right that it shouldn't be using the corrected wavelength array for both corrections. It should probably use uncorrected wavelengths for uniform, corrected wavelengths for point source. But you may need to double check with Elena to make sure the pathloss correction isn't expecting uncorrected wavelengths for both. |
Thanks for working on this. I have a few comments.
That's one way to do it. Is there any benefit to providing a wavelength array without correction to users?
Am I doing something wrong or is this a reference file issue?
|
Thanks @nden for the feedback. I don't think that providing the uncorrected wavelength array is necessary (since it can still be reproduced from the WCS without rerunning the pipeline with wavecorr off), but I thought I would check. The zero-point corrections are not exactly zero for a perfectly centered point source in the reference files. For the S1600A1 slit the zero-point shift is ~0.08 pixels for a perfectly centered source, and if that was a PRISM observation, the wavelength shift would be about ~0.0015e-6, matching what you found. I see where the code is not setting model.slits[index].meta.cal_step.wavecorr to Skipped, and I can update that as well while making these changes. |
Refactoring wavecorr changes for tests minor refactoring Add wavecorr zeropoint correction to slit wcs
250a44a
to
70e72a0
Compare
@nden this is ready for re-review. I've updated the steps that depended on the old format of wavecorr. For I checked with Elena Manjavacas about the The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sending a few suggestions for cleaning up the change log.
Otherwise, I think this looks pretty good. I think the processing keywords in the slit models post-resampling are a bit beyond the scope for this ticket, but we should probably make a note of it in JP-3630.
Testing locally with PID 1492 for FS and 2736 for MOS, I mostly see the changes I expected. The wavelength correction still looks good in the x1d files.
However, I tried running the 1492 data with --steps.wavecorr.skip=True and comparing it to the data with wavecorr on. I see some differences in the cal file I did not expect: PATHLOSS_PS is set to unity when wavecorr is off; FLATFIELD_UN and PATHLOSS_UN show some small differences. Can you please check this case? Test data was jw01492003001_03104_00001_nrs1_rate.fits, for example.
Co-authored-by: Melanie Clarke <[email protected]>
@melanieclarke thanks for the review and comments on the change log. I took a look at the example you listed, some comments below on each case: PATHLOSS_PS is set to unity when wavecorr is off: This is because this example is a FS observation and currently wavecorr is what calculates the source x and y position in the slit for FS point sources. So with wavecorr off the source_xpos and source_ypos both default to 0 and by definition the path loss corrections at the center of the slit are unity. This is not introduced by this PR, but because the source positions for point sources are used in a couple places (pathloss, extract_1d for use_source_pos, etc.) it might be good to move this out of wavecorr and somewhere else in the spec2 pipeline (assign_wcs perhaps?). PATHLOSS_UN show some small differences when wavecorr is off: in my testing of this, I see that the (non-NaN) differences in PATHLOSS_UN between wavecorr on and off is either 0 or a small number (~1.2e-7) that looks like a floating point error, does this match with what you found? FLATFIELD_UN show some small differences when wavecorr is off: I also see this; the fractional differences are at the level of < ~1e-5. I think this comes from the difference in how the wavelengths are obtained. With the update I made to have flat_field use get_wavelengths, the wavelengths used for interpolating the flat_field data come from the WCS when wavecorr is on and will come from the stored wavelength array when wavecorr is off. If I force the flat_field to use the WCS for calculating the wavelengths in both cases I find no difference in the FLATFIELD_UN. Comparing the array and WCS wavelengths there is a small difference (on the order of < 1e-7um -> though that is about 1e-4 of a pixel in this case), which looks to be coming from the fact that the wavelength arrays are float32 and recalculating the wavelengths from the WCS are float64. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the investigation and explanation, @hayescr! That all makes sense.
I agree that it would probably be more useful to assign the source position in the assign_wcs step instead of in wavecorr, but that's a separate issue. Can you please file a ticket for it?
Testing a merge of your branch with a development branch of my own, I noticed one more small thing to fix. Suggested change below.
Co-authored-by: Melanie Clarke <[email protected]>
@melanieclarke yes I'll open a ticket (it's now noted on JP-3648) to move the source position assignment. Thanks for the catch on the missing wcs case. |
Thanks @hayescr. I started a new regression test run here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regression test changes look right to me: there are changes to the wavelength in wavecorr for NIRSpec spec2 for MOS, BOTS, and FS, then changes to everything downstream of flat_field. Master background and MIRI LRS failures are unrelated.
Everything looks good to me. It would be helpful if @nden can review one more time, though.
Except one thing - @hayescr, can you please fix the merge conflicts in the change log? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me overall and I agree that the regtest differences seem to comply with what's expected. Just a few minor comments/questions to address.
|
||
# Evaluate the WCS on the grid of pixel indexes, capturing only the | ||
# resulting wavelength values | ||
shape = model.data.shape | ||
grid = np.indices(shape[-2:], dtype=np.float64) | ||
|
||
# If we've been asked to use the uncorrected wavelengths we need to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there still a use case for retrieving and returning the uncorrected wavelengths? Is this necessary for steps like pathloss and/or flatfield that want to compute their calibrations based on both uncorrected and corrected wavelengths (i.e. for uniform and point sources, respectively)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct. Pathloss, flatfield, and photom need access to the uncorrected and corrected wavelengths to calculate and store the uniform/point source corrections. These corrections are then used in the master_background step in spec3 for properly handling background subtraction (with the background as a uniform source) for point sources that are observed in the NIRSpec fixed slit mode.
log.warning('Skipping wavecorr correction') | ||
slit.meta.cal_step.wavecorr = 'SKIPPED' | ||
else: | ||
slit.meta.cal_step.wavecorr = 'SKIPPED' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think cal_step
attributes are defined (in the datamodels schema) at the slit level; only at the top model.meta level. I guess this operation is still OK to do, because it will just create those attributes within each slit instance, but I doubt they will actually result in keywords in the FITS file on disk (because they aren't defined in the schema). They would only exist within the datamodel's slit meta object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is correct. I don't see any relevant FITS keywords that are produced for each slit, but the attributes do show up in the datamodel's slit meta object. So there is some way to keep track of whether this was step was performed for an individual slit.
Co-authored-by: Howard Bushouse <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thanks @hayescr and @melanieclarke for the work
Resolves JP-3330
Closes #7794
This PR updates the wavecorr step to add zero-point corrections for each slit into their model WCS. This is done with a 1D lookup table to convert between the center of slit wavelengths and the corrected wavelengths. The corrected wavelengths in the lookup tables are calculated using the pixel shifts in the associated reference file and the wavelength and dispersion in a given 2D extracted slit (averaged across the pixels in the cross-dispersion direction). Includes updates to the wavecorr tests to check that this transform roundtrips along with a few additional checks.
Checklist for maintainers
CHANGES.rst
within the relevant release sectionHow to run regression tests on a PR