-
Notifications
You must be signed in to change notification settings - Fork 28
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
Clean up bounding box assignment #1527
Clean up bounding box assignment #1527
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1527 +/- ##
==========================================
- Coverage 76.68% 76.68% -0.01%
==========================================
Files 120 120
Lines 7832 7831 -1
==========================================
- Hits 6006 6005 -1
Misses 1826 1826 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
8e0b60c
to
74a3ac7
Compare
Regression tests pass. Note that these tests were specifically run with pytest turning all the bounding box warnings from GWCS into errors. https://github.com/spacetelescope/RegressionTests/actions/runs/11916504320 |
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.
Fix the bounding box assignments so they all follow the GWCS ordering this way GWCS will not flag them as possibly suspect by raising a warning.
5ad0dd8
to
2430655
Compare
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.
FWIW, bind_bounding_box is new to me. Would you mind saying a few words about when this is needed? i.e., in parts of this PR you do wcs_obj.bounding_box = box, but for adding it to the transform you use the bind_bounding_box routine rather than the previous simpler-looking direct assignment. Relatedly, it looks like when you assign to the wcs object you don't specify an order (presumably 'F' is assumed), but you are more explicit when assigning to the transform. What motivates being more explicit in one case than in the other?
The use of tuples of tuples to represent bounding boxes for 2D+ circumstances has annoying consequences due to choices within model.bounding_box = ((y_min, y_max), (x_min, x_max)) This is the so called wcs.bounding_box = ((ra_min, ra_max), (dec_min, dec_max)) This is the so called
In either case, one ends up with the bounding box in reverse order to what it should be. The bugs resulting from this can be rather difficult to find (ask me how I know), especially when the box is nearly but not total square. Hence, GWCS's new attempts to warn users that there maybe a possible issue. Note that GWCS uses the "first" The method GWCS uses for issuing the warning for a possible bounding box issue is interrogation of the bounding box's order when it grabs said bounding box from the first forward transform. If that order is '"C"' (is dimension > 2, and not a default bounding box from the model class itself), GWCS knows that the bounding box was set outside of its control meaning the user had to remember to reverse it.
As to why Ideally, the bounding box should always be computed in such a way we can pass directly to the transform; however, that was not always the easiest thing to do without more significant changes. I am planning to clean up all the WCS stuff in |
bind_bounding_box( | ||
transform, | ||
wcs_bbox_from_shape(model.data.shape) if bbox is None else bbox, | ||
order="F", | ||
) |
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.
This is a case where the GWCS warning identified a bug. It just did not get picked up by any tests...
Note
romancal/romancal/assign_wcs/utils.py
Lines 20 to 35 in 281aa55
def wcs_bbox_from_shape(shape): | |
"""Create a bounding box from the shape of the data. | |
This is appropriate to attach to a wcs object. | |
Parameters | |
---------- | |
shape : tuple | |
The shape attribute from a `numpy.ndarray` array. | |
Returns | |
------- | |
bbox : tuple | |
Bounding box in x, y order. | |
""" | |
bbox = ((-0.5, shape[-1] - 0.5), (-0.5, shape[-2] - 0.5)) | |
return bbox |
Reports to create a bounding box in the x, y
ordering but the transform.bounding_box =
was making the assumption this was a y, x
box.
With this change it is now being assigned correctly with an x, y
ordering.
Ah, good, astropy.modeling uses the other convention and has this box convention---thanks, that makes sense.
Yup, great, this makes sense, thanks! |
spacetelescope/gwcs#522 adds a warning to flag instances where bounding boxes that GWCS uses are ordered using the
C
(y, x) ordering rather than theF
ordering the GWCS defaults to. GWCS handles the alternate ordering by default however tuple assignment to the forward transform before creating the GWCS causes astropy to assume aC
ordering while if one assigns the same tuple directly to the wcs, GWCS will assume aF
order. Due to this source of issues GWCS now throws a warning when it discovers an assigned bounding box with theC
ordering as GWCS will always attach and handle bounding boxes specifically in theF
ordering.This PR updates
romancal
so that bounding boxes are always attached with the tuple correctly ordered and flagged asF
order.Tasks
24Q4_B15
(use the latest build if not sure)no-changelog-entry-needed
)changes/
:echo "changed something" > changes/<PR#>.<changetype>.rst
(see below for change types)docs/
pageokify_regtests
to update the truth filesnews fragment change types...
changes/<PR#>.general.rst
: infrastructure or miscellaneous changechanges/<PR#>.docs.rst
changes/<PR#>.stpipe.rst
changes/<PR#>.associations.rst
changes/<PR#>.scripts.rst
changes/<PR#>.mosaic_pipeline.rst
changes/<PR#>.patch_match.rst
steps
changes/<PR#>.dq_init.rst
changes/<PR#>.saturation.rst
changes/<PR#>.refpix.rst
changes/<PR#>.linearity.rst
changes/<PR#>.dark_current.rst
changes/<PR#>.jump_detection.rst
changes/<PR#>.ramp_fitting.rst
changes/<PR#>.assign_wcs.rst
changes/<PR#>.flatfield.rst
changes/<PR#>.photom.rst
changes/<PR#>.flux.rst
changes/<PR#>.source_detection.rst
changes/<PR#>.tweakreg.rst
changes/<PR#>.skymatch.rst
changes/<PR#>.outlier_detection.rst
changes/<PR#>.resample.rst
changes/<PR#>.source_catalog.rst