Skip to content
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

Unnamed coordinate frames of the same type cause bounding_box error #398

Closed
rosteen opened this issue Jan 25, 2022 · 3 comments
Closed

Unnamed coordinate frames of the same type cause bounding_box error #398

rosteen opened this issue Jan 25, 2022 · 3 comments

Comments

@rosteen
Copy link

rosteen commented Jan 25, 2022

I'm trying to construct a very simple dummy GWCS to essentially just do an identity transform from pixel to pixel coordinates. I would have thought the code below would be sufficient, but I'm getting an error trace related to pixel_bounds and bounding_box. I thought that having pixel_bounds set as None was a common use case, so this surprised me. Would you please let me know if there's something wrong with my code below, or if this is a bug in GWCS?

import gwcs
from gwcs.coordinate_frames import CoordinateFrame
from astropy.modeling import models

frame1 = CoordinateFrame(2, ['SPATIAL', 'SPATIAL'], [0,1], unit=[u.pix, u.pix])
frame2frame = models.Multiply(1) & models.Multiply(1)
dummy_wcs = gwcs.WCS([(frame1, frame2frame), (frame1, None)])

This results in the following when trying to actually use the dummy GWCS:

dummy_wcs([2*u.pix, 8*u.pix])

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.9/site-packages/gwcs/wcs.py", line 363, in __call__
    if self.bounding_box is not None:
  File "/Users/rosteen/opt/anaconda3/envs/viz_dev/lib/python3.9/site-packages/gwcs/wcs.py", line 1321, in bounding_box
    bb = transform_0.bounding_box
AttributeError: 'NoneType' object has no attribute 'bounding_box'
@rosteen
Copy link
Author

rosteen commented Jan 25, 2022

In the grand tradition of figuring things out after publicly asking about them, I realized that this is because both the input and output frame end up with the identical generic name "CoordinateFrame" and the GWCS machinery seems to get confused getting the transform, instead returning None instead of the proper transform. If I give my coordinate frames names it works, but note that it still fails if I give separate unnamed CoordinateFrame as the input and output frame.

>>> frame1 = CoordinateFrame(2, ['SPATIAL', 'SPATIAL'], [0,1], unit=[u.pix, u.pix], name = "Dummy1")
>>> frame2 = CoordinateFrame(2, ['SPATIAL', 'SPATIAL'], [0,1], unit=[u.pix, u.pix], name = "Dummy2")

>>> pipeline = gwcs.WCS([(frame1, frame2frame), (frame2, None)])
(<Quantity 1. pix>, <Quantity 8. pix>)

It seems like using unnamed coordinate frames shouldn't be a failure mode, or at least that the error message resulting from that case should be more informative, so I'm going leave this issue open and rename it.

@rosteen rosteen changed the title bounding_box error with simple GWCS Unnamed coordinate frames of the same type cause bounding_box error Jan 25, 2022
@nden
Copy link
Collaborator

nden commented Jan 26, 2022

There's another report for this issue - #327.
Contributions are welcome!

@rosteen
Copy link
Author

rosteen commented Jan 27, 2022

Sorry about the duplicate! I'll go ahead and close this issue.

@rosteen rosteen closed this as completed Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants