def __init__(self, parent=None, viewer_state=None): super(AladinLiteOptionsPanel, self).__init__(parent=parent) self._data_collection = self.parent()._data self.viewer_state = viewer_state self.ui = load_ui('options_widget.ui', self, directory=os.path.dirname(__file__)) autoconnect_callbacks_to_qt(self.viewer_state, self.ui) self._ra_att_helpers = ComponentIDComboHelper(self.ui.combodata_ra_att, self._data_collection, categorical=False, default_index=0) self._dec_att_helpers = ComponentIDComboHelper( self.ui.combodata_dec_att, self._data_collection, categorical=False, default_index=1) self.viewer_state.add_callback('layers', nonpartial(self._update_data))
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]
class HistogramOptionsWidget(QtWidgets.QWidget): def __init__(self, viewer_state, session, parent=None): super(HistogramOptionsWidget, self).__init__(parent=parent) self.ui = load_ui('options_widget.ui', self, directory=os.path.dirname(__file__)) autoconnect_callbacks_to_qt(viewer_state, self.ui) viewer_state.add_callback('layers', self._update_combo_data) self.x_att_helper = ComponentIDComboHelper(self.ui.combodata_x_att, session.data_collection) self.viewer_state = viewer_state viewer_state.add_callback('x_att', nonpartial(self._update_attribute)) def _update_attribute(self): # If at least one of the components is categorical, disable log button log_enabled = not any( comp.categorical for comp in self.viewer_state._get_x_components()) self.ui.bool_x_log.setEnabled(log_enabled) if not log_enabled: self.ui.bool_x_log.setChecked(False) def _update_combo_data(self, *args): # TODO: what about if only subset and not data is present? layers = [ layer_state.layer for layer_state in self.viewer_state.layers if isinstance(layer_state.layer, Data) ] self.x_att_helper.set_multiple_data(layers)
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)
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) self._data_viewer = data_viewer self._data = None
class ImageLayerStyleEditor(QtWidgets.QWidget): def __init__(self, layer, parent=None): super(ImageLayerStyleEditor, self).__init__(parent=parent) self.ui = load_ui('layer_style_editor.ui', self, directory=os.path.dirname(__file__)) connect_kwargs = {'alpha': dict(value_range=(0, 1)), 'contrast': dict(value_range=(0.1, 10), log=True), 'bias': dict(value_range=(1.5, -0.5))} percentiles = [('Min/Max', 100), ('99.5%', 99.5), ('99%', 99), ('95%', 95), ('90%', 90), ('Custom', 'Custom')] update_combobox(self.ui.combodata_percentile, percentiles) stretches = [('Linear', 'linear'), ('Square Root', 'sqrt'), ('Arcsinh', 'arcsinh'), ('Logarithmic', 'log')] update_combobox(self.ui.combodata_stretch, stretches) self.attribute_helper = ComponentIDComboHelper(self.ui.combodata_attribute, layer.data_collection) self.attribute_helper.append_data(layer.layer) autoconnect_callbacks_to_qt(layer.state, self.ui, connect_kwargs) layer._viewer_state.add_callback('color_mode', self._update_color_mode) self._update_color_mode(layer._viewer_state.color_mode) self.ui.bool_global_sync.setToolTip('Whether to sync the color and transparency with other viewers') def _update_color_mode(self, color_mode): if color_mode == 'Colormaps': self.ui.color_color.hide() self.ui.combodata_cmap.show() else: self.ui.color_color.show() self.ui.combodata_cmap.hide()
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 setup_method(self, method): self.attribute_combo = QtWidgets.QComboBox() self.lower_value = QtWidgets.QLineEdit() self.upper_value = QtWidgets.QLineEdit() self.mode_combo = QtWidgets.QComboBox() self.flip_button = QtWidgets.QToolButton() self.log_button = QtWidgets.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_data(self.data) self.x_id = self.data.visible_components[0] self.y_id = self.data.visible_components[1]
def __init__(self, viewer_state, session, parent=None): super(HistogramOptionsWidget, self).__init__(parent=parent) self.ui = load_ui('options_widget.ui', self, directory=os.path.dirname(__file__)) autoconnect_callbacks_to_qt(viewer_state, self.ui) viewer_state.add_callback('layers', self._update_combo_data) self.x_att_helper = ComponentIDComboHelper(self.ui.combodata_x_att, session.data_collection) self.viewer_state = viewer_state viewer_state.add_callback('x_att', nonpartial(self._update_attribute))
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)
class OptionsWidget(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) 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.data) else: self.file_helper.append_data(data)
class OptionsWidget(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.data) else: self.file_helper.append_data(data) print(self.file_att)
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
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)
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
class TestAttributeLimitsHelper(): def setup_method(self, method): self.attribute_combo = QtWidgets.QComboBox() self.lower_value = QtWidgets.QLineEdit() self.upper_value = QtWidgets.QLineEdit() self.mode_combo = QtWidgets.QComboBox() self.flip_button = QtWidgets.QToolButton() self.log_button = QtWidgets.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_data(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 try: self.flip_button.clicked.emit(True) except TypeError: # PySide self.flip_button.clicked.emit() 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
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