jdaviz icon indicating copy to clipboard operation
jdaviz copied to clipboard

Fix compute_scale when fiducial coordinates are outside bounding box

Open astrofrog opened this issue 1 year ago • 4 comments

Description

This fixes a corner case in compute_scale when the fiducial coordinates provided are outside of the bounding box.

This is needed if the bounding box on data is not reset, and in order to be compatible with https://github.com/spacetelescope/gwcs/pull/498

cc @bmorris3

Change log entry

  • [ ] Is a change log needed? If yes, is it added to CHANGES.rst? If you want to avoid merge conflicts, list the proposed change log here for review and add to CHANGES.rst before merge. If no, maintainer should add a no-changelog-entry-needed label.

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • [ ] Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • [ ] Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • [ ] Do the proposed changes follow the STScI Style Guides?
  • [ ] Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • [ ] Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • [ ] Did the CI pass? If not, are the failures related?
  • [ ] Is a milestone set? Set this to bugfix milestone if this is a bug fix and needs to be released ASAP; otherwise, set this to the next major release milestone. Bugfix milestone also needs an accompanying backport label.
  • [ ] After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

astrofrog avatar May 22 '24 10:05 astrofrog

I don't think this needs a changelog entry as as far as users are concerned it won't have an impact yet, since jdaviz disables the bounding box by default. It's more to future-proof if we do want to retain the bounding boxes.

astrofrog avatar May 22 '24 10:05 astrofrog

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 88.71%. Comparing base (b89784c) to head (ce15aeb). Report is 2 commits behind head on main.

Files Patch % Lines
jdaviz/configs/imviz/wcs_utils.py 60.00% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2887      +/-   ##
==========================================
- Coverage   88.72%   88.71%   -0.01%     
==========================================
  Files         111      111              
  Lines       17102    17106       +4     
==========================================
+ Hits        15174    15176       +2     
- Misses       1928     1930       +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 22 '24 10:05 codecov[bot]

I'm re-milestoning this one to 4.0, since the related upstream GWCS changes (https://github.com/spacetelescope/gwcs/pull/498) are in draft pending strategizing and discussion from @nden and @mcara.

bmorris3 avatar Jun 06 '24 12:06 bmorris3

Something in gwcs not handling Quantity gracefully?

>       raise UnitConversionError(f"{unit_str} and {other_str} are not convertible")
E       astropy.units.errors.UnitConversionError: 'pix' and '' (dimensionless) are not convertible
...
>       self.imviz.link_data(align_by='wcs')
...
jdaviz/app.py:717: in _change_reference_data
    viewer.center_on(sky_cen)
jdaviz/core/astrowidgets_api.py:87: in center_on
    point = image.coords.world_to_pixel(point)  # 0-indexed X, Y
gwcs/api.py:325: in world_to_pixel
    result = self.invert(*world_objects, with_units=True)
gwcs/wcs.py:473: in invert
    args = self.outside_footprint(args)
gwcs/wcs.py:497: in outside_footprint
    footprint = self.footprint()
gwcs/wcs.py:1474: in footprint
    vertices = _order_clockwise(bb)
gwcs/wcs.py:1458: in _order_clockwise
    return np.asarray([[v[0][0], v[1][0]], [v[0][0], v[1][1]],
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Quantity 0. pix>
...

I don't know what is supposed to happen but you can reproduce the traceback by doing this:

from astropy import units as u
x = 0 * u.pix
float(x)  # Error

pllim avatar Jan 22 '25 22:01 pllim

@astrofrog - trying to revive this, @bmorris3 said that a bunch of these changes were included in another PR already merged, so can you rebase or pull in main and we'll try to get this in as well?

kecnry avatar Jun 13 '25 14:06 kecnry

@kecnry - rebased!

astrofrog avatar Jun 17 '25 14:06 astrofrog

@bmorris3 - does this look good to you to go in?

kecnry avatar Jun 17 '25 16:06 kecnry