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

Update Subset Tools plugin to use display units #2195

Merged
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 @@ -14,6 +14,8 @@ New Features

- Histogram showing image values in stretch limits section of plot options plugin. [#2153]

- Subset Plugin now respects the chosen display unit after using Unit Conversion. [#2195]

Cubeviz
^^^^^^^

Expand Down
37 changes: 31 additions & 6 deletions jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import astropy.units as u
from glue.core.message import EditSubsetMessage, SubsetUpdateMessage
from glue.core.edit_subset_mode import (AndMode, AndNotMode, OrMode,
ReplaceMode, XorMode)
Expand All @@ -7,7 +8,7 @@
from glue_jupyter.widgets.subset_mode_vuetify import SelectionModeMenu
from traitlets import Any, List, Unicode, Bool, observe

from jdaviz.core.events import SnackbarMessage
from jdaviz.core.events import SnackbarMessage, GlobalDisplayUnitChanged
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import PluginTemplateMixin, DatasetSelectMixin, SubsetSelect

Expand Down Expand Up @@ -52,12 +53,15 @@ def __init__(self, *args, **kwargs):
handler=self._sync_selected_from_state)
self.session.hub.subscribe(self, SubsetUpdateMessage,
handler=self._on_subset_update)
self.session.hub.subscribe(self, GlobalDisplayUnitChanged,
handler=self._on_display_unit_changed)

self.subset_select = SubsetSelect(self,
'subset_items',
'subset_selected',
default_text="Create New")
self.subset_states = []
self.spectral_display_unit = None

def _sync_selected_from_state(self, *args):
if not hasattr(self, 'subset_select'):
Expand Down Expand Up @@ -127,7 +131,8 @@ def _unpack_get_subsets_for_ui(self):
-------

"""
subset_information = self.app.get_subsets(self.subset_selected, simplify_spectral=False)
subset_information = self.app.get_subsets(self.subset_selected, simplify_spectral=False,
use_display_units=True)
_around_decimals = 6 # Avoid 30 degrees from coming back as 29.999999999999996
if not subset_information:
return
Expand Down Expand Up @@ -175,10 +180,12 @@ def _unpack_get_subsets_for_ui(self):
subset_type = subset_state.roi.__class__.__name__

elif isinstance(subset_state, RangeSubsetState):
lo = subset_state.lo
hi = subset_state.hi
subset_definition = [{"name": "Lower bound", "att": "lo", "value": lo, "orig": lo},
{"name": "Upper bound", "att": "hi", "value": hi, "orig": hi}]
lo = spec['region'].lower
hi = spec['region'].upper
subset_definition = [{"name": "Lower bound", "att": "lo", "value": lo.value,
"orig": lo.value, "unit": str(lo.unit)},
{"name": "Upper bound", "att": "hi", "value": hi.value,
"orig": hi.value, "unit": str(hi.unit)}]
subset_type = "Range"
if len(subset_definition) > 0:
# Note: .append() does not work for List traitlet.
Expand All @@ -199,6 +206,13 @@ def _get_subset_definition(self, *args):

self._unpack_get_subsets_for_ui()

def _on_display_unit_changed(self, msg):
# We only care about the spectral units, since flux units don't affect spectral subsets
if msg.axis == "spectral":
self.spectral_display_unit = msg.unit
if self.subset_selected != self.subset_select.default_text:
self._get_subset_definition(self.subset_selected)

def vue_update_subset(self, *args):
for index, sub in enumerate(self.subset_definitions):
sub_states = self.subset_states[index]
Expand All @@ -207,6 +221,17 @@ def vue_update_subset(self, *args):
d_val = np.radians(d_att["value"])
else:
d_val = float(d_att["value"])

# Convert from display unit to original unit if necessary
if self.subset_types[index] == "Range":
if self.spectral_display_unit is not None:
x_att = sub_states.att
base_units = self.app.data_collection[0].get_component(x_att).units
if self.spectral_display_unit != base_units:
d_val = d_val*u.Unit(self.spectral_display_unit)
d_val = d_val.to(u.Unit(base_units))
d_val = d_val.value

if float(d_att["orig"]) != d_val:
if self.subset_types[index] == "Range":
setattr(sub_states, d_att["att"], d_val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
v-model.number="item.value"
type="number"
:disabled="!is_editable"
:suffix="item.unit.replace('Angstrom', 'A')"
></v-text-field>
</v-row>
</div>
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies = [
"traitlets>=5.0.5",
"bqplot>=0.12.37",
"bqplot-image-gl>=1.4.11",
"glue-core>=1.10.1",
"glue-core>=1.10.0",
"glue-jupyter>=0.16.3",
"echo>=0.5.0",
"ipykernel>=6.19.4",
Expand Down