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
base: master
Are you sure you want to change the base?
Conversation
Regression tests run: https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1364/ |
|
||
# Calculate the corrected wavelengths | ||
pixel_corrections = offset_model(lam_mean, source_xpos) | ||
lam_corrected = lam_mean + (pixel_corrections * disp_mean) |
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 am getting mean differences in the computed wavelengths (this method vs the old one) of the order 10**-10 which is probably too large. I believe the previous method subtracts the correction while this one adds it. Since the previous results were vetted by the NRS team I'm assuming they are correct but please let me know if this has changed. So, in short I wonder if the plus sign here is an oversight.
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.
The old method was subtracting the correction, and the difference between subtracting and adding the correction should the be source of these large differences. When reviewing the zero-point corrections the NRS team noted that the correction should be added rather than subtracted and we confirmed this looking at observed data. So the plus sign is an intentional update.
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.
Just to confirm what Chris said... The NIRSpec cal team looked at this and is convinced that the minus sign was an error, and we should use the plus sign going forward.
jwst/wavecorr/wavecorr.py
Outdated
wave2wavecorr = tabular.Tabular1D(points=lam_mean, lookup_table=lam_corrected, | ||
bounds_error=False, fill_value=None, name='wave2wavecorr') | ||
wave2wavecorr.inverse = tabular.Tabular1D(points=lam_corrected, lookup_table=lam_mean, | ||
bounds_error=False, fill_value=None) |
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.
There's probably no need to explicitly assign an inverse model to a 1D tabular model but it doesn't hurt.
lam_corrected
need to be monotonically increasing and that's probably always true but I wonder if there should be a check for this.
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.
The lam_corrected
should always be monotonically increasing, but if it would be useful, I can add a check for this that will skip the wavelength correction in case it is not monotonically increasing and would cause later errors.
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, no need to define an inverse for a Tabular1D
model as it is automatically defined since 2019.
And note there's already a check there to ensure ascending order as needed by scipy.interpolate
for the inverse. Feel free to do the same check here for the forward transform. 👍
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.
The most recent commits now remove the explicit inverse and include a check that the lam_corrected
is ascending. This should be the case for real data, but to cover the possibility that it is not monotonically increasing, the updated code will now skip the wavelength correction if lam_corrected
is not ascending. If you think it should instead throw an error, I can make that change.
jwst/wavecorr/tests/test_wavecorr.py
Outdated
@@ -171,13 +199,31 @@ def test_wavecorr_fs(): | |||
dispersion = wavecorr.compute_dispersion(slit.meta.wcs, x, y) | |||
assert_allclose(dispersion[~np.isnan(dispersion)], 1e-8, atol=1.04e-8) | |||
|
|||
# Check that the slit wcs has been updated to provide corrected wavelengths |
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.
As I see it this checks that slit.meta.wcs
is consistent with slit.wavelength
, regardless of whether it's updated or not. It's a good check but if you agree please change the comment.
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've gone ahead and changed the comment.
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 56.38% 56.40% +0.02%
==========================================
Files 387 387
Lines 38716 38747 +31
==========================================
+ Hits 21830 21857 +27
- Misses 16886 16890 +4 ☔ 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? |
Refactoring wavecorr changes for tests minor refactoring Add wavecorr zeropoint correction to slit wcs
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. |
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