Example #1
0
class OptionsWidget(QtGui.QWidget):

    file_att = CurrentComboDataProperty('ui.combo_file_attribute')

    def __init__(self, parent=None, data_viewer=None):

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

        self.ui = load_ui('viewer_options.ui',
                          self,
                          directory=os.path.dirname(__file__))

        self.file_helper = ComponentIDComboHelper(self.ui.combo_file_attribute,
                                                  data_viewer._data,
                                                  categorical=True,
                                                  numeric=False)

        self._data_viewer = data_viewer

        self._data = None

    def set_data(self, data):
        self.file_helper.clear()
        if isinstance(data, Subset):
            self.file_helper.append(data.data)
        else:
            self.file_helper.append(data)
class ScatterOptionsWidget(QtGui.QWidget):

    def __init__(self, viewer_state, session, parent=None):

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

        self.ui = load_ui('options_widget.ui', self,
                          directory=os.path.dirname(__file__))

        self.viewer_state = viewer_state
        autoconnect_qt(self.viewer_state, self)

        self.viewer_state.connect('layers', self._update_combo_data)

        self.xatt_helper = ComponentIDComboHelper(self.ui.combo_xatt,
                                                  session.data_collection)
        self.yatt_helper = ComponentIDComboHelper(self.ui.combo_yatt,
                                                  session.data_collection)

    def _update_combo_data(self, *args):
        # TODO: we need to make it possible to set all the data in one go
        #       to avoid this inefficiency which will also cause the current
        #       value to not be selected anymore.
        self.xatt_helper.clear()
        self.yatt_helper.clear()
        for data in self.viewer_state.layers:
            self.xatt_helper.append(data)
            self.yatt_helper.append(data)
class OptionsWidget(QtGui.QWidget):

    x_att = TextProperty('ui.text_x_attribute')
    y_att = CurrentComboProperty('ui.combo_y_attribute')

    def __init__(self, parent=None, data_viewer=None):

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

        self.ui = load_ui('viewer_options.ui', self,
                          directory=os.path.dirname(__file__))

        self.y_helper = ComponentIDComboHelper(self.ui.combo_y_attribute,
                                               data_viewer._data, categorical=False)

        self._data_viewer = data_viewer

        self._data = None

    def append(self, data):
        self.y_helper.append(data)

    def remove(self, data):
        self.y_helper.remove(data)
Example #4
0
class OptionsWidget(QtGui.QWidget):

    file_att = CurrentComboDataProperty('ui.combo_file_attribute')

    def __init__(self, parent=None, data_viewer=None):

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

        self.ui = load_ui('viewer_options.ui', self,
                          directory=os.path.dirname(__file__))

        self.file_helper = ComponentIDComboHelper(self.ui.combo_file_attribute,
                                                  data_viewer._data, categorical=True, numeric=False)

        self._data_viewer = data_viewer

        self._data = None

    def set_data(self, data):
        self.file_helper.clear()
        if isinstance(data, Subset):
            self.file_helper.append(data.data)
        else:
            self.file_helper.append(data)
class TestAttributeLimitsHelper():
    def setup_method(self, method):

        self.attribute_combo = QtGui.QComboBox()
        self.lower_value = QtGui.QLineEdit()
        self.upper_value = QtGui.QLineEdit()
        self.mode_combo = QtGui.QComboBox()
        self.flip_button = QtGui.QToolButton()

        self.log_button = QtGui.QToolButton()
        self.log_button.setCheckable(True)

        self.data = Data(x=np.linspace(-100, 100, 10000),
                         y=np.linspace(2, 3, 10000),
                         label='test_data')

        self.data_collection = DataCollection([self.data])

        self.helper = AttributeLimitsHelper(self.attribute_combo,
                                            self.lower_value,
                                            self.upper_value,
                                            mode_combo=self.mode_combo,
                                            flip_button=self.flip_button,
                                            log_button=self.log_button)

        self.component_helper = ComponentIDComboHelper(self.attribute_combo,
                                                       self.data_collection)

        self.component_helper.append(self.data)

        self.x_id = self.data.visible_components[0]
        self.y_id = self.data.visible_components[1]

    def test_attributes(self):
        assert self.attribute_combo.count() == 2
        assert self.attribute_combo.itemText(0) == 'x'
        assert self.attribute_combo.itemData(0)[0] is self.x_id
        assert self.attribute_combo.itemData(0)[1] is self.data
        assert self.attribute_combo.itemText(1) == 'y'
        assert self.attribute_combo.itemData(1)[0] is self.y_id
        assert self.attribute_combo.itemData(1)[1] is self.data

    def test_minmax(self):
        assert self.helper.vlo == -100
        assert self.helper.vhi == +100

    def test_change_attribute(self):
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == -100
        assert self.helper.vhi == +100

    def test_change_scale_mode(self):

        # Changing scale mode updates the limits
        self.helper.scale_mode = '99.5%'
        assert self.helper.vlo == -99.5
        assert self.helper.vhi == +99.5
        self.helper.scale_mode = '99%'
        assert self.helper.vlo == -99
        assert self.helper.vhi == +99
        self.helper.scale_mode = '90%'
        assert self.helper.vlo == -90
        assert self.helper.vhi == +90

        # When switching to custom, the last limits are retained
        self.helper.scale_mode = 'Custom'
        assert self.helper.vlo == -90
        assert self.helper.vhi == +90

    def test_scale_mode_cached(self):
        # Make sure that if we change scale and change attribute, the scale
        # modes are cached on a per-attribute basis.
        self.helper.scale_mode = '99.5%'
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.scale_mode == 'Min/Max'
        self.helper.scale_mode = '99%'
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.scale_mode == '99.5%'
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.scale_mode == '99%'

    def test_flip_button(self):

        # Flipping should swap lower and upper value
        self.flip_button.clicked.emit(True)
        assert self.helper.vlo == +100
        assert self.helper.vhi == -100

        # Make sure that values were re-cached when flipping
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == +100
        assert self.helper.vhi == -100

    def test_manual_edit(self):

        # Make sure that values are re-cached when edited manually
        self.helper.scale_mode = 'Custom'
        self.lower_value.setText('-122')
        self.upper_value.setText('234')
        self.helper.vlog = True
        assert self.helper.vlo == -122
        assert self.helper.vhi == 234
        assert self.helper.vlog
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        assert not self.helper.vlog
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == -122
        assert self.helper.vhi == 234
        assert self.helper.vlog
Example #6
0
class WWTOptionPanel(QtWidgets.QWidget):

    ra_att = CurrentComboDataProperty('ui.combo_ra_att')
    dec_att = CurrentComboDataProperty('ui.combo_dec_att')

    background = CurrentComboDataProperty('ui.combo_background')
    opacity = ValueProperty('ui.value_opacity')
    foreground = CurrentComboDataProperty('ui.combo_foreground')

    galactic_plane = ButtonProperty('ui.checkbox_galactic_plane')

    def __init__(self, viewer, parent=None):

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

        self.viewer = viewer
        self.ui = load_ui('options_widget.ui',
                          self,
                          directory=os.path.dirname(__file__))

        self._setup_combos()
        self._connect()

    @property
    def ra(self):
        if self.ra_att is None:
            return None
        else:
            return self.ra_att[0]

    @property
    def dec(self):
        if self.dec_att is None:
            return None
        else:
            return self.dec_att[0]

    def _setup_combos(self):
        layers = [
            'Digitized Sky Survey (Color)',
            'VLSS: VLA Low-frequency Sky Survey (Radio)',
            'WMAP ILC 5-Year Cosmic Microwave Background',
            'SFD Dust Map (Infrared)', 'WISE All Sky (Infrared)',
            'GLIMPSE/MIPSGAL', 'Hydrogen Alpha Full Sky Map'
        ]
        labels = ['DSS', 'VLSS', 'WMAP', 'SFD', 'WISE', 'GLIMPSE', 'H Alpha']
        thumbnails = [
            'DSS', 'VLA', 'wmap5yr_ilc_200uk', 'dust', 'glimpsemipsgaltn',
            'halpha'
        ]
        base = ('http://www.worldwidetelescope.org/wwtweb/'
                'thumbnail.aspx?name=%s')

        for i, row in enumerate(zip(layers, labels, thumbnails)):
            layer, text, thumb = row
            url = base % thumb
            data = urlopen(url).read()
            pm = QtGui.QPixmap()
            pm.loadFromData(data)
            icon = QtGui.QIcon(pm)

            self.ui.combo_foreground.addItem(icon, text, layer)
            self.ui.combo_foreground.setItemData(i, layer, role=Qt.ToolTipRole)
            self.ui.combo_background.addItem(icon, text, layer)
            self.ui.combo_background.setItemData(i, layer, role=Qt.ToolTipRole)

        self.ui.combo_foreground.setIconSize(QtCore.QSize(60, 60))
        self.ui.combo_background.setIconSize(QtCore.QSize(60, 60))

        self.ra_att_helper = ComponentIDComboHelper(self.ui.combo_ra_att,
                                                    self.viewer._data,
                                                    categorical=False,
                                                    numeric=True)

        self.dec_att_helper = ComponentIDComboHelper(self.ui.combo_dec_att,
                                                     self.viewer._data,
                                                     categorical=False,
                                                     numeric=True)

    def add_data(self, data):
        # TODO: the following logic should go in the component ID helpers. It
        # isn't quite right at the moment because if there are multiple
        # datasets/subsets with the same components, we only want to show those
        # once.
        if isinstance(data, Subset):
            self.ra_att_helper.append(data.data)
            self.dec_att_helper.append(data.data)
        else:
            self.ra_att_helper.append(data)
            self.dec_att_helper.append(data)

    def remove_data(self, data):
        if isinstance(data, Subset):
            self.ra_att_helper.remove(data.data)
            self.dec_att_helper.remove(data.data)
        else:
            self.ra_att_helper.remove(data)
            self.dec_att_helper.remove(data)

    def _connect(self):

        self.ui.combo_ra_att.currentIndexChanged.connect(
            self.viewer._update_all)
        self.ui.combo_dec_att.currentIndexChanged.connect(
            self.viewer._update_all)

        self.ui.combo_foreground.currentIndexChanged.connect(
            self.viewer._update_foreground)
        self.ui.combo_background.currentIndexChanged.connect(
            self.viewer._update_background)
        self.ui.value_opacity.valueChanged.connect(self.viewer._update_opacity)
        self.ui.checkbox_galactic_plane.toggled.connect(
            self.viewer._update_galactic_plane_mode)

        self.opacity = 100
class TestAttributeLimitsHelper():

    def setup_method(self, method):

        self.attribute_combo = QtGui.QComboBox()
        self.lower_value = QtGui.QLineEdit()
        self.upper_value = QtGui.QLineEdit()
        self.mode_combo = QtGui.QComboBox()
        self.flip_button = QtGui.QToolButton()

        self.log_button = QtGui.QToolButton()
        self.log_button.setCheckable(True)

        self.data = Data(x=np.linspace(-100, 100, 10000),
                         y=np.linspace(2, 3, 10000), label='test_data')

        self.data_collection = DataCollection([self.data])

        self.helper = AttributeLimitsHelper(self.attribute_combo,
                                            self.lower_value, self.upper_value,
                                            mode_combo=self.mode_combo,
                                            flip_button=self.flip_button,
                                            log_button=self.log_button)

        self.component_helper = ComponentIDComboHelper(self.attribute_combo, self.data_collection)

        self.component_helper.append(self.data)

        self.x_id = self.data.visible_components[0]
        self.y_id = self.data.visible_components[1]

    def test_attributes(self):
        assert self.attribute_combo.count() == 2
        assert self.attribute_combo.itemText(0) == 'x'
        assert self.attribute_combo.itemData(0)[0] is self.x_id
        assert self.attribute_combo.itemData(0)[1] is self.data
        assert self.attribute_combo.itemText(1) == 'y'
        assert self.attribute_combo.itemData(1)[0] is self.y_id
        assert self.attribute_combo.itemData(1)[1] is self.data

    def test_minmax(self):
        assert self.helper.vlo == -100
        assert self.helper.vhi == +100

    def test_change_attribute(self):
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == -100
        assert self.helper.vhi == +100

    def test_change_scale_mode(self):

        # Changing scale mode updates the limits
        self.helper.scale_mode = '99.5%'
        assert self.helper.vlo == -99.5
        assert self.helper.vhi == +99.5
        self.helper.scale_mode = '99%'
        assert self.helper.vlo == -99
        assert self.helper.vhi == +99
        self.helper.scale_mode = '90%'
        assert self.helper.vlo == -90
        assert self.helper.vhi == +90

        # When switching to custom, the last limits are retained
        self.helper.scale_mode = 'Custom'
        assert self.helper.vlo == -90
        assert self.helper.vhi == +90

    def test_scale_mode_cached(self):
        # Make sure that if we change scale and change attribute, the scale
        # modes are cached on a per-attribute basis.
        self.helper.scale_mode = '99.5%'
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.scale_mode == 'Min/Max'
        self.helper.scale_mode = '99%'
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.scale_mode == '99.5%'
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.scale_mode == '99%'

    def test_flip_button(self):

        # Flipping should swap lower and upper value
        self.flip_button.clicked.emit(True)
        assert self.helper.vlo == +100
        assert self.helper.vhi == -100

        # Make sure that values were re-cached when flipping
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == +100
        assert self.helper.vhi == -100

    def test_manual_edit(self):

        # Make sure that values are re-cached when edited manually
        self.helper.scale_mode = 'Custom'
        self.lower_value.setText('-122')
        self.upper_value.setText('234')
        self.helper.vlog = True
        assert self.helper.vlo == -122
        assert self.helper.vhi == 234
        assert self.helper.vlog
        self.attribute_combo.setCurrentIndex(1)
        assert self.helper.vlo == 2
        assert self.helper.vhi == 3
        assert not self.helper.vlog
        self.attribute_combo.setCurrentIndex(0)
        assert self.helper.vlo == -122
        assert self.helper.vhi == 234
        assert self.helper.vlog