-
Notifications
You must be signed in to change notification settings - Fork 32
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-3824: Fix a bug in wcs_from_sregions when crpix is provided #326
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #326 +/- ##
===========================================
+ Coverage 29.56% 86.89% +57.33%
===========================================
Files 37 49 +12
Lines 8332 8946 +614
===========================================
+ Hits 2463 7774 +5311
+ Misses 5869 1172 -4697 ☔ View full report in Codecov by Sentry. |
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 new return tuple from _calculate_offsets
needs to be verified the docstring and computation are correct. Other than that, it looks good.
for axis_range, minval, shift in zip(bbox, axis_min_values, shifts): | ||
output_bounding_box.append( | ||
( | ||
axis_range[0] + shift + minval, |
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.
In the docstring for _calculate_offsets
it says shifts
are to be subtracted, but they are added here. Is the doctrstring wrong or is the calculation wrong?
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.
Neither is wrong: basically shifts
are equivalent to 0-indexed CRPIX and should be subtracted from input coordinates to the WCS transformation. However, here we are adjusting the bounding box coordinates (not input coordinates to the WCS transform) so that it "moves" with the CRPIX value. Currently bounding box stays glued to the (0, 0) corner regardless of the output image shape or CRPIX location.
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 but just a few small questions
src/stcal/alignment/util.py
Outdated
tuple | ||
A tuple of offset *values* that are to be *subtracted* from input | ||
coordinates (negative values of offsets in the returned transform). | ||
Note: these are equivalent to an effective 0-indexed "crpix". |
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.
Does this mean that these offsets are always equal to crpix? If so, what is the point of returning this, if crpix is an input to the function? If not, can you clarify this note a little bit?
tests/test_alignment.py
Outdated
@@ -30,7 +30,7 @@ def _create_wcs_object_without_distortion( | |||
shape, | |||
): | |||
# subtract 1 to account for pixel indexing starting at 0 | |||
shift = models.Shift() & models.Shift() | |||
shift = models.Shift(0) & models.Shift(0) |
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.
Why was this change necessary? Does this shift actually subtract 1 as the comment indicates?
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.
Oh, this was a leftover from testing
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 comment is incorrect either way. The default value for the shift is 0 anyway. So my change does not have any effect. I'll undo it.
The bigger issue is: should the bounding box of the resampled image follow (i.e., be centered) at CRPIX or should it always be fixed to the bottom-left corner of the resampled image. The difference between the two approaches:
I think currently 2nd approach is implemented (albeit with a bug). 1st approach seems to be more intuitive as it allows control of where data will be in the output image and it is intuitive to estimate this based on the output shape. In the 2nd approach output shape larger than bbox makes no sense at all as it will be filled with 0s or NaN. I know this is kind of a philosophical question but it is important to make a decision and based on this I will know how to fix spacetelescope/jwst#9017. |
Co-authored-by: Ned Molter <[email protected]>
I have addressed most (all) comments, I believe. Along the way, fixed a typo in ramp test. |
Just to be clear, this PR takes approach With the other approach, both |
Oh, there is a third idea:
This actually makes me think that approach |
Resolves JP-3824
wcs_from_sregions
is used bymake_output_wcs
function in the JWST pipeline to compute output WCS of the resampled image for theResampleStep
. Currentlywcs_from_sregions
assigns a bounding box to the output WCS that is computed in the assumption thatcrpix
is(0, 0)
and it is not adjusted whencrpix
is provided by the user and when it is different from(0, 0)
. This causes unit test failures in JWST pipeline when run with master branch ofgwcs
since now inverse WCS transforms check for bounding box.A separate issue observed while working on this (which may or may not be an issue) is that currently
crpix
is considered 0-indexed while in FITS WCS standard it is 1-indexed.Tasks
docs/
pageno-changelog-entry-needed
)changes/
:echo "changed something" > changes/<PR#>.<changetype>.rst
(see below for change types)"git+https://github.com/<fork>/stcal@<branch>"
)jwst
regression testromancal
regression testnews fragment change types...
changes/<PR#>.apichange.rst
: change to public APIchanges/<PR#>.bugfix.rst
: fixes an issuechanges/<PR#>.general.rst
: infrastructure or miscellaneous change