-
Notifications
You must be signed in to change notification settings - Fork 48
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
Bounding box refactor support #376
Bounding box refactor support #376
Conversation
dfdbe2d
to
956b75e
Compare
ed1cb33
to
0aaadcf
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.
Shouldn't you be using astropy version check with this patch? That way in the future, when your astropy minversion is 5.0, you can drop the old compatibility code.
Also, I was using gwcs with dev astropy, and that broke my code downstream in Jdaviz (spacetelescope/jdaviz#938). I don't know if there is any good fix for this except to tell each user to update gwcs and their code to be compatible with astropy/astropy#11930 ... but I have a feeling I won't be the only one affected here. 🤷
.../jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py in vue_do_aper_phot(self, *args, **kwargs)
167 'ycenter': reg.center.y * u.pix}
168 if data.coords is not None:
--> 169 d['sky_center'] = data.coords.pixel_to_world(reg.center.x, reg.center.y)
170 else:
171 d['sky_center'] = None
.../gwcs/api.py in pixel_to_world(self, *pixel_arrays)
297 """
298 pixels = self._sanitize_pixel_inputs(*pixel_arrays)
--> 299 return self(*pixels, with_units=True)
300
301 def array_index_to_world(self, *index_arrays):
.../gwcs/wcs.py in __call__(self, *args, **kwargs)
312 kwargs['fill_value'] = np.nan
313
--> 314 if self.bounding_box is not None:
315 # Currently compound models do not attempt to combine individual model
316 # bounding boxes. Get the forward transform and assign the bounding_box to it
.../gwcs/wcs.py in bounding_box(self)
1272 axes_order = np.arange(transform_0.n_inputs)
1273 # Model.bounding_box is in python order, need to reverse it first.
-> 1274 return tuple(bb[::-1][i] for i in axes_order)
1275
1276 @bounding_box.setter
.../gwcs/wcs.py in <genexpr>(.0)
1272 axes_order = np.arange(transform_0.n_inputs)
1273 # Model.bounding_box is in python order, need to reverse it first.
-> 1274 return tuple(bb[::-1][i] for i in axes_order)
1275
1276 @bounding_box.setter
.../astropy/modeling/bounding_box.py in __getitem__(self, key)
235 def __getitem__(self, key):
236 """Get bounding_box entries by either input name or input index"""
--> 237 return self._intervals[self._get_index(key)]
238
239 def _get_order(self, order: str = None) -> str:
.../astropy/modeling/bounding_box.py in _get_index(self, key)
220 raise IndexError(f"Integer key: {key} must be < {len(self._model.inputs)}.")
221 else:
--> 222 raise ValueError(f"Key value: {key} must be string or integer.")
223
224 return index
ValueError: Key value: slice(None, None, -1) must be string or integer.
Maybe a clearer error message would help. Regardless I think a memo to astropy-dev mailing list is necessary.
Codecov Report
@@ Coverage Diff @@
## master #376 +/- ##
==========================================
- Coverage 86.34% 86.08% -0.26%
==========================================
Files 21 21
Lines 3624 3643 +19
==========================================
+ Hits 3129 3136 +7
- Misses 495 507 +12
Continue to review full report at Codecov.
|
5b92019
to
f500688
Compare
|
Re: minversion -- As long as you (as a team) have a way to search for these old code and remove them when they are no longer necessary. You might not be the one who will do the update. I'll leave that to your good judgement. |
The old code may be necessary for a very long time in order to be able to read files with the old WCS stored in them. |
I will merge it as is to fix failing tests in jwst but it needs a Change log . |
This PR enables GWCS to support the recently merged PR astropy/astropy#11930 which refactors how
astropy.modeling
handles bounding boxes. In particular this PR removes the private classastropy.modeling.utils._BoundingBox
and replaces it with theastropy.modeling.bounding_box.BoundingBox
class while retaining nearly identical functionality.This PR primarily switches GWCS over to using this new class. Additionally, it implements the new feature from
BoundingBox
which allows users to specify the storage ordering of bounding box intervals. This removes the need for reversal of bounding box orderings within GWCS under some circumstances by allowing astropy to automatically detect and handle these circumstances.