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

Improvements to faciliate showing world coordinates in profile viewer in glue-jupyter #2378

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
30 changes: 20 additions & 10 deletions glue/viewers/profile/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from glue.core.exceptions import IncompatibleDataException
from glue.core.message import SubsetUpdateMessage
from glue.core.units import find_unit_choices, UnitConverter
from glue.core.component_id import PixelComponentID

__all__ = ['ProfileViewerState', 'ProfileLayerState']

Expand All @@ -41,6 +42,8 @@ class ProfileViewerState(MatplotlibDataViewerState):
x_display_unit = DDSCProperty(docstring='The units to use to display the x-axis.')
y_display_unit = DDSCProperty(docstring='The units to use to display the y-axis')

x_show_world = DDCProperty(False, docstring='Whether to show world coordinate labels even if in pixel space.')

reference_data = DDSCProperty(docstring='The dataset that is used to define the '
'available pixel/world components, and '
'which defines the coordinate frame in '
Expand All @@ -64,6 +67,7 @@ def __init__(self, **kwargs):
self.add_callback('x_att', self._update_att)
self.add_callback('x_display_unit', self._reset_x_limits)
self.add_callback('y_display_unit', self._reset_y_limits_if_changed, echo_old=True)
self.add_callback('x_show_world', self._update_x_display_unit_choices)
self.add_callback('normalize', self._reset_y_limits)
self.add_callback('function', self._reset_y_limits)

Expand Down Expand Up @@ -114,8 +118,8 @@ def _update_att(self, *args):
self.x_att_pixel = self.reference_data.pixel_component_ids[index]
else:
self.x_att_pixel = self.x_att
self._reset_x_limits()
self._update_x_display_unit_choices()
self._reset_x_limits()

def _reset_x_limits(self, *event):

Expand Down Expand Up @@ -193,15 +197,20 @@ def _layers_changed(self, *args):
self._update_y_display_unit_choices()
self._last_layers = current_layers

def _update_x_display_unit_choices(self):
def _update_x_display_unit_choices(self, *args):

if self.reference_data is None:
ProfileViewerState.x_display_unit.set_choices(self, [])
return

component = self.reference_data.get_component(self.x_att)
if self.x_show_world and isinstance(self.x_att, PixelComponentID):
x_att = self.reference_data.world_component_ids[self.x_att.axis]
else:
x_att = self.x_att

component = self.reference_data.get_component(x_att)
if component.units:
x_choices = find_unit_choices([(self.reference_data, self.x_att, component.units)])
x_choices = find_unit_choices([(self.reference_data, x_att, component.units)])
else:
x_choices = ['']
ProfileViewerState.x_display_unit.set_choices(self, x_choices)
Expand Down Expand Up @@ -402,12 +411,13 @@ def update_profile(self, update_limits=True):
axis_view[pix_cid.axis] = slice(None)
axis_values = data[self.viewer_state.x_att, tuple(axis_view)]

converter = UnitConverter()
axis_values = converter.to_unit(self.viewer_state.reference_data,
self.viewer_state.x_att, axis_values,
self.viewer_state.x_display_unit)
profile_values = converter.to_unit(data, self.attribute, profile_values,
self.viewer_state.y_display_unit)
if not isinstance(self.viewer_state.x_att, PixelComponentID):
converter = UnitConverter()
axis_values = converter.to_unit(self.viewer_state.reference_data,
self.viewer_state.x_att, axis_values,
self.viewer_state.x_display_unit)
profile_values = converter.to_unit(data, self.attribute, profile_values,
self.viewer_state.y_display_unit)

self._profile_cache = axis_values, profile_values

Expand Down