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

Imviz: Show coordinates in degrees too #971

Merged
merged 5 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Imviz

- New plugin to perform simple aperture photometry. [#938]

- Coordinates display now also shows Right Ascension and Declination in degrees. [#971]

Mosviz
^^^^^^

Expand Down
36 changes: 35 additions & 1 deletion jdaviz/configs/imviz/plugins/coords_info/coords_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,39 @@
class CoordsInfo(TemplateMixin):
template_file = __file__, "coords_info.vue"
pixel = Unicode("").tag(sync=True)
world = Unicode("").tag(sync=True)
value = Unicode("").tag(sync=True)
world_label_prefix = Unicode("\u00A0").tag(sync=True)
world_label_icrs = Unicode("\u00A0").tag(sync=True)
world_label_deg = Unicode("\u00A0").tag(sync=True)
world_ra = Unicode("").tag(sync=True)
world_dec = Unicode("").tag(sync=True)
world_ra_deg = Unicode("").tag(sync=True)
world_dec_deg = Unicode("").tag(sync=True)

def reset_coords_display(self):
self.world_label_prefix = '\u00A0'
self.world_label_icrs = '\u00A0'
self.world_label_deg = '\u00A0'
self.world_ra = ''
self.world_dec = ''
self.world_ra_deg = ''
self.world_dec_deg = ''

def set_coords(self, sky):
celestial_coordinates = sky.to_string('hmsdms', precision=4, pad=True).split()
celestial_coordinates_deg = sky.to_string('decimal', precision=10, pad=True).split()
world_ra = celestial_coordinates[0]
world_dec = celestial_coordinates[1]
world_ra_deg = celestial_coordinates_deg[0]
world_dec_deg = celestial_coordinates_deg[1]

if "nan" in (world_ra, world_dec, world_ra_deg, world_dec_deg):
self.reset_coords_display()
else:
self.world_label_prefix = 'World'
self.world_label_icrs = '(ICRS)'
self.world_label_deg = '(deg)'
self.world_ra = world_ra
self.world_dec = world_dec
self.world_ra_deg = world_ra_deg
self.world_dec_deg = world_dec_deg
25 changes: 21 additions & 4 deletions jdaviz/configs/imviz/plugins/coords_info/coords_info.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
<template>
<div v-if="pixel" style="white-space: nowrap;">
<b v-if="pixel">Pixel </b>{{ pixel }}&nbsp;&nbsp;<b v-if="value">Value </b>{{ value }}<br>
<b v-if="world">World </b>{{ world }}<br>
</div>
<div v-if="pixel" style="white-space: nowrap; line-height: 14pt; margin: 0; position: absolute; top: 50%; transform: translateY(-50%); -ms-transform: translateY(-50%);">
<table>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My vuejs-fu is too weak. I think this accomplishes what you asked for, but I don't know how robust it is across browser and monitor settings...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. At small widths, it overlaps the plugin menu button, but that button isn't clickable while mousing over the image anyways. We have another ticket to eventually deal with minimum widths and overflowing across the app, so I don't think you need to worry about that too much right now.

<tr>
<td colspan="4">
<b v-if="pixel">Pixel </b>{{ pixel }}&nbsp;&nbsp;<b v-if="value">Value </b>{{ value }}
</td>
</tr>
<tr>
<td width="42"><b>{{ world_label_prefix }}</b></td>
<td width="115">{{ world_ra }}</td>
<td width="120">{{ world_dec }}</td>
<td>{{ world_label_icrs }}</td>
</tr>
<tr>
<td width="42"></td>
<td width="115">{{ world_ra_deg }}</td>
<td width="120">{{ world_dec_deg }}</td>
<td>{{ world_label_deg }}</td>
</tr>
</table>
</div>
</template>
14 changes: 6 additions & 8 deletions jdaviz/configs/imviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def on_mouse_or_key_event(self, data):

if x is None or y is None: # Out of bounds
self.label_mouseover.pixel = ""
self.label_mouseover.world = ""
self.label_mouseover.reset_coords_display()
self.label_mouseover.value = ""
return

Expand All @@ -91,14 +91,12 @@ def on_mouse_or_key_event(self, data):
# we aren't actually guaranteed to get a SkyCoord out, just for images
# with valid celestial WCS
try:
celestial_coordinates = (image.coords.pixel_to_world(x, y).icrs
.to_string('hmsdms', precision=4, pad=True))
coo = image.coords.pixel_to_world(x, y).icrs
self.label_mouseover.set_coords(coo)
except Exception:
self.label_mouseover.world = ''
else:
self.label_mouseover.world = f'{celestial_coordinates:32s} (ICRS)'
self.label_mouseover.reset_coords_display()
else:
self.label_mouseover.world = ''
self.label_mouseover.reset_coords_display()

# Extract data values at this position.
# TODO: for now we just use the first visible layer but we should think
Expand All @@ -116,7 +114,7 @@ def on_mouse_or_key_event(self, data):
elif data['event'] == 'mouseleave' or data['event'] == 'mouseenter':

self.label_mouseover.pixel = ""
self.label_mouseover.world = ""
self.label_mouseover.reset_coords_display()
self.label_mouseover.value = ""

elif data['event'] == 'keydown' and data['key'] == 'b':
Expand Down