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

Fix Cubeviz coordinates panel with inaccurate sky coordinates sometimes #2002

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Bug Fixes
Cubeviz
^^^^^^^

- Fixed a bug where sky coordinates reported to coordinates info panel
might be wrong for "uncert" and "mask" data. This bug only happens when
certain parsing conditions were met. When in doubt, always verify with
info from "flux" data. [#2002]

Imviz
^^^^^

Expand Down
20 changes: 18 additions & 2 deletions jdaviz/configs/cubeviz/plugins/viewers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import numpy as np
from astropy.coordinates import SkyCoord
from astropy.wcs import WCS
from glue.core import BaseData
from glue.core.subset import RoiSubsetState, RangeSubsetState
from glue_jupyter.bqplot.image import BqplotImageView
Expand Down Expand Up @@ -49,6 +51,20 @@ def __init__(self, *args, **kwargs):
self.add_event_callback(self.on_mouse_or_key_event, events=['mousemove', 'mouseenter',
'mouseleave'])

def _get_cube_skycoord(self, w, x, y):
if isinstance(w, WCS):
# TODO: Is x always RA and y always DEC?
pllim marked this conversation as resolved.
Show resolved Hide resolved
if w.celestial.axis_type_names == ['RA', 'DEC']:
sky = w.celestial.pixel_to_world(x, y)
else: # ['DEC', 'RA']
sky = w.celestial.pixel_to_world(y, x)
else: # The old and possibly incorrect way
sky_list = w.pixel_to_world(x, y, self.state.slices[-1])
for sky in sky_list:
if isinstance(sky, SkyCoord):
break
return sky.icrs

def on_mouse_or_key_event(self, data):

# Find visible layers
Expand Down Expand Up @@ -100,11 +116,11 @@ def on_mouse_or_key_event(self, data):

# Hack around various WCS propagation issues in Cubeviz.
if '_orig_wcs' in coo_data.meta:
coo = coo_data.meta['_orig_wcs'].pixel_to_world(x, y, self.state.slices[-1])[0].icrs
coo = self._get_cube_skycoord(coo_data.meta['_orig_wcs'], x, y)
self.label_mouseover.set_coords(coo)
elif data_has_valid_wcs(coo_data):
try:
coo = coo_data.coords.pixel_to_world(x, y, self.state.slices[-1])[-1].icrs
coo = self._get_cube_skycoord(coo_data.coords, x, y)
except Exception:
self.label_mouseover.reset_coords_display()
else:
Expand Down