Skip to content

Commit

Permalink
Update 1D Profile viewer to use wcsaxes for plotting and add sliders
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Stern authored and Nabil Freij committed May 6, 2022
1 parent 1c71837 commit 18a86e1
Show file tree
Hide file tree
Showing 18 changed files with 581 additions and 67 deletions.
250 changes: 250 additions & 0 deletions .qt_for_python/uic/options_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'options_widget.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

from glue.viewers.matplotlib.qt.axes_editor import AxesEditorWidget
from glue.viewers.matplotlib.qt.legend_editor import LegendEditorWidget


class Ui_Widget(object):
def setupUi(self, Widget):
if not Widget.objectName():
Widget.setObjectName(u"Widget")
Widget.resize(269, 418)
self.gridLayout_5 = QGridLayout(Widget)
self.gridLayout_5.setSpacing(6)
self.gridLayout_5.setContentsMargins(11, 11, 11, 11)
self.gridLayout_5.setObjectName(u"gridLayout_5")
self.gridLayout_5.setVerticalSpacing(5)
self.gridLayout_5.setContentsMargins(5, 5, 5, 5)
self.tab_widget = QTabWidget(Widget)
self.tab_widget.setObjectName(u"tab_widget")
self.tab = QWidget()
self.tab.setObjectName(u"tab")
self.gridLayout_2 = QGridLayout(self.tab)
self.gridLayout_2.setSpacing(6)
self.gridLayout_2.setContentsMargins(11, 11, 11, 11)
self.gridLayout_2.setObjectName(u"gridLayout_2")
self.gridLayout_2.setHorizontalSpacing(10)
self.gridLayout_2.setVerticalSpacing(5)
self.gridLayout_2.setContentsMargins(10, 10, 10, 10)
self.label_6 = QLabel(self.tab)
self.label_6.setObjectName(u"label_6")
font = QFont()
font.setBold(True)
font.setWeight(75)
self.label_6.setFont(font)
self.label_6.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)

self.gridLayout_2.addWidget(self.label_6, 1, 0, 1, 1)

self.combosel_function = QComboBox(self.tab)
self.combosel_function.setObjectName(u"combosel_function")

self.gridLayout_2.addWidget(self.combosel_function, 0, 1, 1, 2)

self.combosel_x_att = QComboBox(self.tab)
self.combosel_x_att.setObjectName(u"combosel_x_att")
self.combosel_x_att.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)

self.gridLayout_2.addWidget(self.combosel_x_att, 2, 1, 1, 2)

self.label = QLabel(self.tab)
self.label.setObjectName(u"label")
self.label.setFont(font)
self.label.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)

self.gridLayout_2.addWidget(self.label, 0, 0, 1, 1)

self.label_3 = QLabel(self.tab)
self.label_3.setObjectName(u"label_3")
self.label_3.setFont(font)
self.label_3.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)

self.gridLayout_2.addWidget(self.label_3, 2, 0, 1, 1)

self.bool_normalize = QCheckBox(self.tab)
self.bool_normalize.setObjectName(u"bool_normalize")

self.gridLayout_2.addWidget(self.bool_normalize, 4, 1, 1, 1)

self.horizontalSpacer = QSpacerItem(40, 5, QSizePolicy.Expanding, QSizePolicy.Minimum)

self.gridLayout_2.addItem(self.horizontalSpacer, 6, 1, 1, 2)

self.label_7 = QLabel(self.tab)
self.label_7.setObjectName(u"label_7")
self.label_7.setFont(font)
self.label_7.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)

self.gridLayout_2.addWidget(self.label_7, 4, 0, 1, 1)

self.text_warning = QLabel(self.tab)
self.text_warning.setObjectName(u"text_warning")
self.text_warning.setStyleSheet(u"color: rgb(255, 33, 28)")
self.text_warning.setAlignment(Qt.AlignCenter)
self.text_warning.setWordWrap(True)

self.gridLayout_2.addWidget(self.text_warning, 5, 1, 1, 2)

self.layout_slices = QVBoxLayout()
self.layout_slices.setSpacing(6)
self.layout_slices.setObjectName(u"layout_slices")

self.gridLayout_2.addLayout(self.layout_slices, 6, 0, 1, 3)

self.combosel_reference_data = QComboBox(self.tab)
self.combosel_reference_data.setObjectName(u"combosel_reference_data")
self.combosel_reference_data.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)

self.gridLayout_2.addWidget(self.combosel_reference_data, 1, 1, 1, 2)

self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

self.gridLayout_2.addItem(self.verticalSpacer_2, 6, 0, 1, 1)

self.tab_widget.addTab(self.tab, "")
self.tab_2 = QWidget()
self.tab_2.setObjectName(u"tab_2")
self.gridLayout = QGridLayout(self.tab_2)
self.gridLayout.setSpacing(6)
self.gridLayout.setContentsMargins(11, 11, 11, 11)
self.gridLayout.setObjectName(u"gridLayout")
self.gridLayout.setHorizontalSpacing(10)
self.gridLayout.setVerticalSpacing(5)
self.gridLayout.setContentsMargins(10, 10, 10, 10)
self.button_flip_x = QToolButton(self.tab_2)
self.button_flip_x.setObjectName(u"button_flip_x")
self.button_flip_x.setStyleSheet(u"padding: 0px")

self.gridLayout.addWidget(self.button_flip_x, 0, 2, 1, 1)

self.valuetext_y_min = QLineEdit(self.tab_2)
self.valuetext_y_min.setObjectName(u"valuetext_y_min")

self.gridLayout.addWidget(self.valuetext_y_min, 1, 1, 1, 1)

self.valuetext_x_max = QLineEdit(self.tab_2)
self.valuetext_x_max.setObjectName(u"valuetext_x_max")

self.gridLayout.addWidget(self.valuetext_x_max, 0, 3, 1, 1)

self.valuetext_x_min = QLineEdit(self.tab_2)
self.valuetext_x_min.setObjectName(u"valuetext_x_min")

self.gridLayout.addWidget(self.valuetext_x_min, 0, 1, 1, 1)

self.label_2 = QLabel(self.tab_2)
self.label_2.setObjectName(u"label_2")
self.label_2.setFont(font)

self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1)

self.label_5 = QLabel(self.tab_2)
self.label_5.setObjectName(u"label_5")
self.label_5.setFont(font)

self.gridLayout.addWidget(self.label_5, 1, 0, 1, 1)

self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

self.gridLayout.addItem(self.verticalSpacer, 3, 3, 1, 1)

self.valuetext_y_max = QLineEdit(self.tab_2)
self.valuetext_y_max.setObjectName(u"valuetext_y_max")

self.gridLayout.addWidget(self.valuetext_y_max, 1, 3, 1, 1)

self.horizontalSpacer_2 = QSpacerItem(40, 5, QSizePolicy.Expanding, QSizePolicy.Minimum)

self.gridLayout.addItem(self.horizontalSpacer_2, 2, 1, 1, 4)

self.bool_y_log = QToolButton(self.tab_2)
self.bool_y_log.setObjectName(u"bool_y_log")
self.bool_y_log.setCheckable(True)

self.gridLayout.addWidget(self.bool_y_log, 1, 4, 1, 1)

self.bool_x_log = QToolButton(self.tab_2)
self.bool_x_log.setObjectName(u"bool_x_log")
self.bool_x_log.setCheckable(True)

self.gridLayout.addWidget(self.bool_x_log, 0, 4, 1, 1)

self.tab_widget.addTab(self.tab_2, "")
self.bool_x_log.raise_()
self.valuetext_x_max.raise_()
self.button_flip_x.raise_()
self.valuetext_x_min.raise_()
self.valuetext_y_min.raise_()
self.valuetext_y_max.raise_()
self.bool_y_log.raise_()
self.label_2.raise_()
self.label_5.raise_()
self.tab_3 = QWidget()
self.tab_3.setObjectName(u"tab_3")
self.horizontalLayout = QHBoxLayout(self.tab_3)
self.horizontalLayout.setSpacing(6)
self.horizontalLayout.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.horizontalLayout.setContentsMargins(5, 5, 5, 5)
self.axes_editor = AxesEditorWidget(self.tab_3)
self.axes_editor.setObjectName(u"axes_editor")

self.horizontalLayout.addWidget(self.axes_editor)

self.tab_widget.addTab(self.tab_3, "")
self.tab_4 = QWidget()
self.tab_4.setObjectName(u"tab_4")
self.horizontalLayout1 = QHBoxLayout(self.tab_4)
self.horizontalLayout1.setSpacing(6)
self.horizontalLayout1.setContentsMargins(11, 11, 11, 11)
self.horizontalLayout1.setObjectName(u"horizontalLayout1")
self.horizontalLayout1.setContentsMargins(5, 5, 5, 5)
self.legend_editor = LegendEditorWidget(self.tab_4)
self.legend_editor.setObjectName(u"legend_editor")

self.horizontalLayout1.addWidget(self.legend_editor)

self.tab_widget.addTab(self.tab_4, "")

self.gridLayout_5.addWidget(self.tab_widget, 9, 2, 1, 1)


self.retranslateUi(Widget)

self.tab_widget.setCurrentIndex(0)


QMetaObject.connectSlotsByName(Widget)
# setupUi

def retranslateUi(self, Widget):
Widget.setWindowTitle(QCoreApplication.translate("Widget", u"1D Profile", None))
self.label_6.setText(QCoreApplication.translate("Widget", u"reference", None))
self.label.setText(QCoreApplication.translate("Widget", u"function", None))
self.label_3.setText(QCoreApplication.translate("Widget", u"x axis", None))
self.bool_normalize.setText("")
self.label_7.setText(QCoreApplication.translate("Widget", u"normalize", None))
self.text_warning.setText(QCoreApplication.translate("Widget", u"Warning", None))
self.tab_widget.setTabText(self.tab_widget.indexOf(self.tab), QCoreApplication.translate("Widget", u"General", None))
self.button_flip_x.setText(QCoreApplication.translate("Widget", u"\u21c4", None))
self.label_2.setText(QCoreApplication.translate("Widget", u"x axis", None))
self.label_5.setText(QCoreApplication.translate("Widget", u"y axis", None))
self.bool_y_log.setText(QCoreApplication.translate("Widget", u"log", None))
self.bool_x_log.setText(QCoreApplication.translate("Widget", u"log", None))
self.tab_widget.setTabText(self.tab_widget.indexOf(self.tab_2), QCoreApplication.translate("Widget", u"Limits", None))
self.tab_widget.setTabText(self.tab_widget.indexOf(self.tab_3), QCoreApplication.translate("Widget", u"Axes", None))
self.tab_widget.setTabText(self.tab_widget.indexOf(self.tab_4), QCoreApplication.translate("Widget", u"Legend", None))
# retranslateUi

4 changes: 2 additions & 2 deletions glue/app/qt/layer_tree_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ class DeleteAction(LayerAction):

def _can_trigger(self):
selection = self.selected_layers()
return all(isinstance(s, (core.Data, core.SubsetGroup))
return all(isinstance(s, (core.BaseData, core.SubsetGroup))
for s in selection)

def _do_action(self):
assert self._can_trigger()
selection = self.selected_layers()
for s in selection:
if isinstance(s, core.Data):
if isinstance(s, core.BaseData):
self._layer_tree.data_collection.remove(s)
else:
assert isinstance(s, core.SubsetGroup)
Expand Down
8 changes: 5 additions & 3 deletions glue/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
from glue.core.contracts import contract
from glue.core.joins import get_mask_with_key_joins
from glue.config import settings, data_translator, subset_state_translator
from glue.utils import (compute_statistic, unbroadcast, iterate_chunks,
from glue.utils import (compute_statistic,
unbroadcast, iterate_chunks,
datetime64_to_mpl, broadcast_to, categorical_ndarray,
format_choices, random_views_for_dask_array)
from glue.core.coordinate_helpers import axis_label
Expand Down Expand Up @@ -241,7 +242,7 @@ def add_subset(self, subset, label=None):
if subset.data is not self:
subset.do_broadcast(False)
subset.data = self
subset.label = subset.label # hacky. disambiguates name if needed
subset.label = subset.label # hacky, disambiguates name if needed

if self.hub is not None:
msg = SubsetCreateMessage(subset)
Expand Down Expand Up @@ -1659,7 +1660,7 @@ def compute_statistic(self, statistic, cid, subset_state=None, axis=None,
# from glue.core.link_manager import pixel_cid_to_pixel_cid_matrix
# for att in subset_state.attributes:
# # TODO: in principle we cold still deal with non-pixel
# # componnet IDs, so this should be fixed.
# # component IDs, so this should be fixed.
# if not isinstance(att, PixelComponentID):
# break
# matrix = pixel_cid_to_pixel_cid_matrix(att.parent, self)
Expand All @@ -1686,6 +1687,7 @@ def compute_statistic(self, statistic, cid, subset_state=None, axis=None,
values = self.compute_statistic(statistic, cid, subset_state=subset_state,
axis=axis, finite=finite, positive=positive,
percentile=percentile, view=chunk_view)

result[chunk_view[axis_index]] = values

return result
Expand Down
12 changes: 12 additions & 0 deletions glue/utils/wcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from astropy.wcs import WCS


def get_identity_wcs(naxis):

wcs = WCS(naxis=naxis)
wcs.wcs.ctype = ['X'] * naxis
wcs.wcs.crval = [0.] * naxis
wcs.wcs.crpix = [1.] * naxis
wcs.wcs.cdelt = [1.] * naxis

return wcs
3 changes: 2 additions & 1 deletion glue/viewers/common/qt/data_slice_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, label='', world=None, lo=0, hi=10,
parent=None, world_unit=None,
world_warning=False):

super(SliceWidget, self).__init__(parent)
super(SliceWidget, self).__init__(parent=parent)

self.state = SliceState()
self.state.label = label
Expand Down Expand Up @@ -109,6 +109,7 @@ def __init__(self, label='', world=None, lo=0, hi=10,

def set_label_from_slider(self):
value = self.state.slice_center

if self.state.use_world:
value = self._world[value]
if self._world_warning:
Expand Down
3 changes: 2 additions & 1 deletion glue/viewers/image/qt/data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class ImageViewer(MatplotlibImageMixin, MatplotlibDataViewer):

tools = ['select:rectangle', 'select:xrange',
'select:yrange', 'select:circle',
'select:polygon', 'image:point_selection', 'image:contrast_bias',
'select:polygon', 'image:point_selection',
'image:contrast_bias',
'profile-viewer']

def __init__(self, session, parent=None, state=None):
Expand Down
4 changes: 3 additions & 1 deletion glue/viewers/image/qt/options_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ def __init__(self, viewer_state, session, parent=None):

self.viewer_state = viewer_state

self.session = session

self.slice_helper = MultiSliceWidgetHelper(viewer_state=self.viewer_state,
session=self.session,
layout=self.ui.layout_slices)

self.session = session
self.ui.axes_editor.button_apply_all.clicked.connect(self._apply_all_viewers)

def _apply_all_viewers(self):
Expand Down
1 change: 0 additions & 1 deletion glue/viewers/image/qt/profile_viewer_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def activate(self):
# be a pixel attribute or world attribute depending on what information
# is available in the coordinates, so we need to be careful about that.

x_att = profile_viewer.state.x_att
reference_data = self.viewer.state.reference_data

if isinstance(profile_viewer.state.x_att, PixelComponentID):
Expand Down
Loading

0 comments on commit 18a86e1

Please sign in to comment.