def __init__(self, value, parent=None):
        QtWidgets.QGridLayout.__init__(self)
        font = tuple_to_qfont(value)
        assert font is not None

        # Font family
        self.family = QtWidgets.QFontComboBox(parent)
        self.family.setCurrentFont(font)
        self.addWidget(self.family, 0, 0, 1, -1)

        # Font size
        self.size = QtWidgets.QComboBox(parent)
        self.size.setEditable(True)
        sizelist = [*range(6, 12), *range(12, 30, 2), 36, 48, 72]
        size = font.pointSize()
        if size not in sizelist:
            sizelist.append(size)
            sizelist.sort()
        self.size.addItems([str(s) for s in sizelist])
        self.size.setCurrentIndex(sizelist.index(size))
        self.addWidget(self.size, 1, 0)

        # Italic or not
        self.italic = QtWidgets.QCheckBox(self.tr("Italic"), parent)
        self.italic.setChecked(font.italic())
        self.addWidget(self.italic, 1, 1)

        # Bold or not
        self.bold = QtWidgets.QCheckBox(self.tr("Bold"), parent)
        self.bold.setChecked(font.bold())
        self.addWidget(self.bold, 1, 2)
Exemplo n.º 2
0
    def __init__(self, trends, pr_res, clusters, id_to_name, out_dir, goea_dir,
                 tsne, cell_clusters, colors):
        super().__init__()
        self._main = QtWidgets.QWidget()
        self.setCentralWidget(self._main)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowTitle("Gene trends for ")
        layout = QtWidgets.QVBoxLayout(self._main)

        self.trends = trends
        self.clusters = clusters
        self.id_to_name = id_to_name
        self.out_dir = out_dir
        self.goea_dir = goea_dir

        self.line = False
        self.lines = list()
        self.pseudotime = 0
        self.n_lines = 0

        self.colors = colors

        ##self.colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']

        ## drop down to choose trajectory
        self.select_cluster = QtWidgets.QComboBox()
        layout.addWidget(self.select_cluster)
        self.select_cluster.addItem('Select cluster')

        for cluster in set(self.clusters):
            self.select_cluster.addItem(str(cluster))
        self.select_cluster.currentIndexChanged.connect(self._select_cluster)

        gene_trend_canvas = FigureCanvas(Figure(figsize=(5, 5)))
        layout.addWidget(gene_trend_canvas)
        self.addToolBar(NavigationToolbar(gene_trend_canvas, self))
        self._gt_fig = gene_trend_canvas.figure
        self._gt_ax = gene_trend_canvas.figure.subplots()

        ## Add listener for mouse motion to update tsne canvas
        gene_trend_canvas.mpl_connect('motion_notify_event',
                                      self._on_mouse_move)

        go_button = QtWidgets.QPushButton("GO analysis")
        go_button.clicked.connect(self._on_click_go)
        layout.addWidget(go_button)

        self.tsne_win = TsneWindow(tsne,
                                   cell_clusters,
                                   colors,
                                   out_dir,
                                   pr_res=pr_res,
                                   trends_win=self)
        self.tsne_win.show()
Exemplo n.º 3
0
 def __init__(self, parent=None):
     super(StartP, self).__init__(parent)
     comboLabel = QtWidgets.QLabel('Graphic Type:')
     self.combo = QtWidgets.QComboBox(self)
     self.combo.addItem('Pies on Map')
     self.combo.addItem('Grid')
     self.combo.addItem('Aggregated')
     self.comboValue = ''
     self.combo.activated[str].connect(self.onActivated)
     hbox = QtWidgets.QHBoxLayout()
     hbox.addWidget(comboLabel)
     hbox.addWidget(self.combo)
     self.setLayout(hbox)
Exemplo n.º 4
0
 def __init__(self, name, props): # TODO could calculate default index automatically if non-integer supplied
     super(ComboboxParam, self).__init__(name, props)
     self.setLayout( QtWidgets.QHBoxLayout() )
     self.combobox = QtWidgets.QComboBox()
     self.layout().addWidget(self.combobox)
     options = [False, True] if props['type'] == 'bool' else props['options']
     self.choices = OrderedDict(
         (str(choice), choice) for choice in options
     )
     assert str(props['default']) in self.choices
     self.combobox.addItems(list(self.choices.keys()))
     self.set_value(str(props['default']))
     self.combobox.currentIndexChanged.connect(self.update)
Exemplo n.º 5
0
    def __init__(self, pr_trajectories, trajectories):
        super().__init__()
        self._main = QtWidgets.QWidget()
        self.setCentralWidget(self._main)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowTitle("Choose trajectory for gene trend analysis")
        layout = QtWidgets.QVBoxLayout(self._main)

        self.trajectories = trajectories

        self.done_button = QtWidgets.QPushButton("Done")
        self.done_button.clicked.connect(self.on_click_done)
        layout.addWidget(self.done_button)

        self.cb = QtWidgets.QComboBox()
        self.cb.addItems(pr_trajectories)
        layout.addWidget(self.cb)
Exemplo n.º 6
0
    def __init__(self, datalist, comment="", parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)
        self.combobox = QtWidgets.QComboBox()
        layout.addWidget(self.combobox)

        self.stackwidget = QtWidgets.QStackedWidget(self)
        layout.addWidget(self.stackwidget)
        self.combobox.currentIndexChanged.connect(self.stackwidget.setCurrentIndex)

        self.widgetlist = []
        for data, title, comment in datalist:
            self.combobox.addItem(title)
            widget = FormWidget(data, comment=comment, parent=self)
            self.stackwidget.addWidget(widget)
            self.widgetlist.append(widget)
    def setup_cmap_frame(self, cmap):
        nF = QtWidgets.QFrame()
        layout = QtWidgets.QHBoxLayout(nF)
        layout.setContentsMargins(5, 0, 5, 0)

        label = QtWidgets.QLabel('cmap: ')
        layout.addWidget(label)

        # Type dropdown list, training or test images
        self.type_combobox = QtWidgets.QComboBox()
        for colormap in sorted(Settings.colormaps):
            self.type_combobox.addItem(colormap)
        self.type_combobox.currentIndexChanged.connect(self.cmap_selectionchange)
        self.type_combobox.setCurrentText(cmap)
        layout.addWidget(self.type_combobox)

        return nF
Exemplo n.º 8
0
    def __init__(self, parent=None):
        super(StartP, self).__init__(parent)
        integerValidator = QtGui.QIntValidator(0, 300, self)

        dataLabel = QtWidgets.QLabel('Data Directory:')
        self.dataLine = QtWidgets.QLineEdit()
        dataBtn = QtWidgets.QPushButton('File', self)
        dataBtn.clicked.connect(self.getDir)
        self.registerField('dataDir*', self.dataLine)

        allelesLabel = QtWidgets.QLabel('Number of alleles:')
        self.allelesLine = QtWidgets.QLineEdit()
        self.allelesLine.setValidator(integerValidator)
        self.registerField('alleleCount*', self.allelesLine)

        groupsLabel = QtWidgets.QLabel('Number of Groups:')
        self.groupsLine = QtWidgets.QLineEdit()
        self.groupsLine.setValidator(integerValidator)
        self.registerField('groupCount*', self.groupsLine)

        self.b1 = QtWidgets.QCheckBox("Females")
        self.b1.setChecked(False)
        self.registerField('females', self.b1)

        comboLabel = QtWidgets.QLabel('Graphic Type:')
        self.combo = QtWidgets.QComboBox(self)
        self.combo.addItem('Allele Counts')
        self.combo.addItem('Allele Heatmap')
        self.combo.addItem('Allele Stack')
        self.combo.addItem('Allele Geo-Map')
        self.registerField('graphic', self.combo)

        grid = QtWidgets.QGridLayout()
        grid.setSpacing(10)
        grid.addWidget(dataLabel, 1, 0)
        grid.addWidget(self.dataLine, 1, 1)
        grid.addWidget(dataBtn, 1, 2)
        grid.addWidget(allelesLabel, 2, 0)
        grid.addWidget(self.allelesLine, 2, 1)
        grid.addWidget(groupsLabel, 3, 0)
        grid.addWidget(self.groupsLine, 3, 1)
        grid.addWidget(self.b1, 5, 1)
        grid.addWidget(comboLabel, 4, 0)
        grid.addWidget(self.combo, 4, 1)
        self.setLayout(grid)
 def setup(self):
     for label, value in self.data:
         if label is None and value is None:
             # Separator: (None, None)
             self.formlayout.addRow(QtWidgets.QLabel(" "),
                                    QtWidgets.QLabel(" "))
             self.widgets.append(None)
             continue
         elif label is None:
             # Comment
             self.formlayout.addRow(QtWidgets.QLabel(value))
             self.widgets.append(None)
             continue
         elif tuple_to_qfont(value) is not None:
             field = FontLayout(value, self)
         elif (label.lower() not in BLACKLIST
               and mcolors.is_color_like(value)):
             field = ColorLayout(to_qcolor(value), self)
         elif isinstance(value, str):
             field = QtWidgets.QLineEdit(value, self)
         elif isinstance(value, (list, tuple)):
             if isinstance(value, tuple):
                 value = list(value)
             # Note: get() below checks the type of value[0] in self.data so
             # it is essential that value gets modified in-place.
             # This means that the code is actually broken in the case where
             # value is a tuple, but fortunately we always pass a list...
             selindex = value.pop(0)
             field = QtWidgets.QComboBox(self)
             if isinstance(value[0], (list, tuple)):
                 keys = [key for key, _val in value]
                 value = [val for _key, val in value]
             else:
                 keys = value
             field.addItems(value)
             if selindex in value:
                 selindex = value.index(selindex)
             elif selindex in keys:
                 selindex = keys.index(selindex)
             elif not isinstance(selindex, Integral):
                 _log.warning(
                     "index '%s' is invalid (label: %s, value: %s)",
                     selindex, label, value)
                 selindex = 0
             field.setCurrentIndex(selindex)
         elif isinstance(value, bool):
             field = QtWidgets.QCheckBox(self)
             if value:
                 field.setCheckState(QtCore.Qt.Checked)
             else:
                 field.setCheckState(QtCore.Qt.Unchecked)
         elif isinstance(value, Integral):
             field = QtWidgets.QSpinBox(self)
             field.setRange(-10**9, 10**9)
             field.setValue(value)
         elif isinstance(value, Real):
             field = QtWidgets.QLineEdit(repr(value), self)
             field.setCursorPosition(0)
             field.setValidator(QtGui.QDoubleValidator(field))
             field.validator().setLocale(QtCore.QLocale("C"))
             dialog = self.get_dialog()
             dialog.register_float_field(field)
             field.textChanged.connect(lambda text: dialog.update_buttons())
         elif isinstance(value, datetime.datetime):
             field = QtWidgets.QDateTimeEdit(self)
             field.setDateTime(value)
         elif isinstance(value, datetime.date):
             field = QtWidgets.QDateEdit(self)
             field.setDate(value)
         else:
             field = QtWidgets.QLineEdit(repr(value), self)
         self.formlayout.addRow(label, field)
         self.widgets.append(field)
Exemplo n.º 10
0
 def setup(self):
     for label, value in self.data:
         if DEBUG:
             print("value:", value)
         if label is None and value is None:
             # Separator: (None, None)
             self.formlayout.addRow(QtWidgets.QLabel(" "),
                                    QtWidgets.QLabel(" "))
             self.widgets.append(None)
             continue
         elif label is None:
             # Comment
             self.formlayout.addRow(QtWidgets.QLabel(value))
             self.widgets.append(None)
             continue
         elif tuple_to_qfont(value) is not None:
             field = FontLayout(value, self)
         elif label.lower() not in BLACKLIST and is_color_like(value):
             field = ColorLayout(to_qcolor(value), self)
         elif isinstance(value, six.string_types):
             field = QtWidgets.QLineEdit(value, self)
         elif isinstance(value, (list, tuple)):
             if isinstance(value, tuple):
                 value = list(value)
             selindex = value.pop(0)
             field = QtWidgets.QComboBox(self)
             if isinstance(value[0], (list, tuple)):
                 keys = [key for key, _val in value]
                 value = [val for _key, val in value]
             else:
                 keys = value
             field.addItems(value)
             if selindex in value:
                 selindex = value.index(selindex)
             elif selindex in keys:
                 selindex = keys.index(selindex)
             elif not isinstance(selindex, int):
                 print("Warning: '%s' index is invalid (label: "
                       "%s, value: %s)" % (selindex, label, value),
                       file=STDERR)
                 selindex = 0
             field.setCurrentIndex(selindex)
         elif isinstance(value, bool):
             field = QtWidgets.QCheckBox(self)
             if value:
                 field.setCheckState(QtCore.Qt.Checked)
             else:
                 field.setCheckState(QtCore.Qt.Unchecked)
         elif isinstance(value, float):
             field = QtWidgets.QLineEdit(repr(value), self)
             field.setCursorPosition(0)
             field.setValidator(QtGui.QDoubleValidator(field))
             field.validator().setLocale(QtCore.QLocale("C"))
             dialog = self.get_dialog()
             dialog.register_float_field(field)
             field.textChanged.connect(lambda text: dialog.update_buttons())
         elif isinstance(value, int):
             field = QtWidgets.QSpinBox(self)
             field.setRange(-1e9, 1e9)
             field.setValue(value)
         elif isinstance(value, datetime.datetime):
             field = QtWidgets.QDateTimeEdit(self)
             field.setDateTime(value)
         elif isinstance(value, datetime.date):
             field = QtWidgets.QDateEdit(self)
             field.setDate(value)
         else:
             field = QtWidgets.QLineEdit(repr(value), self)
         self.formlayout.addRow(label, field)
         self.widgets.append(field)
Exemplo n.º 11
0
    def __init__(self, dataset):
        """
        Construct the widget

        Args:
            dataset: xarray.Dataset
        """
        super().__init__()

        main_layout = QW.QVBoxLayout(self)

        self.varlist = QW.QComboBox()
        self.xdim = QW.QComboBox()
        self.ydim = QW.QComboBox()

        header = QW.QGroupBox()
        header_layout = QW.QHBoxLayout(header)
        header_layout.addWidget(self.varlist)
        header_layout.addWidget(self.xdim)
        header_layout.addWidget(self.ydim)

        main_layout.addWidget(header)

        figure_group = QW.QGroupBox()
        figure_layout = QW.QHBoxLayout(figure_group)

        figure = Figure(tight_layout=True)
        figure.set_frameon(False)
        self.canvas = FigureCanvas(figure)
        self.canvas.setStyleSheet("background-color:transparent;")
        self.axis = self.canvas.figure.subplots()

        self.colorbar = ColorBarWidget()

        figure_layout.addWidget(self.canvas)
        figure_layout.addWidget(self.colorbar)

        main_layout.addWidget(figure_group)

        #: Dataset being inspected
        self.dataset = dataset

        # Setup list of variables, further setup is done by change_variable()
        classes = classify_vars(dataset)
        variables = sorted(
            [v for v in classes['data'] if dataset[v].ndim >= 2])
        self.varlist.addItems(variables)

        # Connect slots
        self.varlist.currentIndexChanged.connect(self.change_variable)
        self.xdim.activated.connect(self.change_axes)
        self.ydim.activated.connect(self.change_axes)
        self.colorbar.valueChanged.connect(self.redraw)

        #: Currently active variable
        self.variable = None

        #: Values for non-axis dimensions
        self.dims = {}
        dims_group = QW.QGroupBox()
        dims_layout = QW.QVBoxLayout(dims_group)

        # Create widgets for coordinates
        for name in self.dataset.coords:
            self.dims[name] = DimensionWidget(self.dataset[name])
            self.dims[name].valueChanged.connect(self.redraw)
            dims_layout.addWidget(self.dims[name])

        # Create widgets for bare dims
        for name in self.dataset.dims:
            if name not in self.dims:
                da = xarray.DataArray(range(self.dataset.dims[name]))
                self.dims[name] = DimensionWidget(da)
                self.dims[name].valueChanged.connect(self.redraw)
                dims_layout.addWidget(self.dims[name])

        main_layout.addWidget(dims_group)

        if len(variables) > 0:
            self.change_variable()
Exemplo n.º 12
0
    def __init__(self):
        """
        Define all UI objects (buttons, comboboxes) and events
        """
        super().__init__()
        self._main = QtWidgets.QWidget()
        self.setCentralWidget(self._main)
        self.resize(1600, 700)
        self.pixmap = None
        self.imCounter = 0
        self.imLoadCounter = 0
        self.graphCounter = 0
        self.model = build_model()
        self.data_loader = iter(build_eval_loader(args, checkpoint,
                                                  no_gt=True))
        self.mode = "auto_withfeats"
        self.new_objs = None
        self.new_triples = None

        self.in_edge_width = 2
        self.out_edge_width = 1

        self.graph = None

        self.selected_node = None
        layout = QtWidgets.QGridLayout(self._main)

        self.btnLoad = QtWidgets.QPushButton("Load image")
        self.btnLoad.resize(self.btnLoad.minimumSizeHint())
        self.btnLoad.clicked.connect(self.getfile)

        layout.addWidget(self.btnLoad, 6, 1, 1, 1)

        self.btnSave = QtWidgets.QPushButton("Save image")
        self.btnSave.resize(self.btnSave.minimumSizeHint())
        self.btnSave.clicked.connect(self.savefile)

        layout.addWidget(self.btnSave, 6, 6, 1, 1)

        self.imb = QtWidgets.QLabel("Source Image")
        self.imb.setAlignment(QtCore.Qt.AlignCenter)
        layout.addWidget(self.imb, 0, 1, 4, 2)

        self.ima = QtWidgets.QLabel("Target Image")
        self.ima.setAlignment(QtCore.Qt.AlignCenter)
        layout.addWidget(self.ima, 0, 5, 4, 2)

        self.g_layout = self.static_layout
        self.static_canvas = FigureCanvas(Figure(figsize=(4, 8)))
        layout.addWidget(self.static_canvas, 1, 3, 2, 2)

        self._static_ax = self.static_canvas.figure.subplots()
        self._static_ax.set_xlim([0, 8])
        self._static_ax.set_ylim([0, 8])
        self.static_canvas.figure.subplots_adjust(top=1,
                                                  bottom=0,
                                                  right=1,
                                                  left=0,
                                                  hspace=0,
                                                  wspace=0)

        self.static_canvas.mpl_connect('pick_event', self.hilighter)

        self.comboBox = QtWidgets.QComboBox()
        for pred in preds[1:]:
            self.comboBox.addItem(pred)

        self.comboBoxLabel = QtWidgets.QLabel("Change relationship")
        layout.addWidget(self.comboBoxLabel, 3, 1, 1, 1)
        layout.addWidget(self.comboBox, 3, 2, 1, 1)
        self.comboBox.activated[str].connect(self.set_predicate)

        self.comboBox_obj = QtWidgets.QComboBox()
        for obj in objs[1:]:
            self.comboBox_obj.addItem(obj)

        layout.addWidget(self.comboBox_obj, 2, 2, 1, 1)
        self.comboBox_objLabel = QtWidgets.QLabel("Replace object")
        layout.addWidget(self.comboBox_objLabel, 2, 1, 1, 1)
        self.comboBox_obj.activated[str].connect(self.set_obj)

        self.comboBox_p2 = QtWidgets.QComboBox()
        for pred in preds[1:]:
            self.comboBox_p2.addItem(pred)
        layout.addWidget(self.comboBox_p2, 4, 4, 1, 1)
        self.comboBox_p2Label = QtWidgets.QLabel("Add relationship")
        layout.addWidget(self.comboBox_p2Label, 4, 3, 1, 1)

        self.comboBox_obj2 = QtWidgets.QComboBox()
        layout.addWidget(self.comboBox_obj2, 5, 4, 1, 1)
        self.comboBox_obj2Label = QtWidgets.QLabel("Connect to object")
        layout.addWidget(self.comboBox_obj2Label, 5, 3, 1, 1)

        self.comboBox_sub2 = QtWidgets.QComboBox()
        for obj in objs[1:]:
            self.comboBox_sub2.addItem(obj)
        layout.addWidget(self.comboBox_sub2, 6, 4, 1, 1)
        self.comboBox_sub2Label = QtWidgets.QLabel("Add new node")
        layout.addWidget(self.comboBox_sub2Label, 6, 3, 1, 1)

        self.btnAddSub = QtWidgets.QPushButton("Add as subject")
        self.btnAddSub.resize(self.btnAddSub.minimumSizeHint())
        self.btnAddSub.clicked.connect(self.add_as_subject)
        layout.addWidget(self.btnAddSub, 3, 3, 1, 1)

        self.btnAddObj = QtWidgets.QPushButton("Add as object")
        self.btnAddObj.resize(self.btnAddObj.minimumSizeHint())
        self.btnAddObj.clicked.connect(self.add_as_object)
        layout.addWidget(self.btnAddObj, 3, 4, 1, 1)

        self.btnPred = QtWidgets.QPushButton("Get Graph")
        self.btnPred.clicked.connect(self.reset_graph)
        self.btnPred.resize(self.btnPred.minimumSizeHint())
        layout.addWidget(self.btnPred, 6, 2, 1, 1)

        self.btn5 = QtWidgets.QPushButton("Remove node")
        self.btn5.clicked.connect(self.remove_node)
        self.btn5.resize(self.btn5.minimumSizeHint())
        layout.addWidget(self.btn5, 4, 1, 1, 2)  # 6, 3, 1, 2

        self.btnRem = QtWidgets.QPushButton("Generate Image")
        self.btnRem.clicked.connect(self.gen_image)
        self.btnRem.resize(self.btnRem.minimumSizeHint())
        layout.addWidget(self.btnRem, 6, 5, 1, 1)
Exemplo n.º 13
0
    def __init__(self, plot_callback=None):
        super(StyleBuilderMainWidget, self).__init__()
        self.setMinimumSize(600, 400)
        self.setLayout(QtWidgets.QVBoxLayout())

        self.top = QtWidgets.QWidget()
        self.top.setLayout( QtWidgets.QHBoxLayout() )
        self.layout().addWidget(self.top)

        self.top.layout().addWidget(QtWidgets.QLabel('Filter:'))
        self.filtration_field = QtWidgets.QLineEdit()
        self.top.layout().addWidget(self.filtration_field)
        self.filtration_field.textChanged.connect(self.filtration_changed)

        self.reset_all_button = QtWidgets.QPushButton('Reset all')
        self.top.layout().addWidget(self.reset_all_button)
        self.reset_all_button.clicked.connect(self.reset_all)

        self.show_changed_button = QtWidgets.QPushButton('Show changed')
        self.top.layout().addWidget(self.show_changed_button)
        self.show_changed_button.clicked.connect(
            lambda: self.display_list(sorted(self.changed))
        )

        self.mplstyle_combobox = QtWidgets.QComboBox()
        self.top.layout().addWidget(self.mplstyle_combobox)
        self.mplstyle_combobox.currentIndexChanged.connect(
            lambda _dummy: self.load_mplstyle(
                str(self.mplstyle_combobox.currentText())
            )
        )
        self.repopulate_stylelist()

        self.save_button = QtWidgets.QPushButton('Save new')
        self.top.layout().addWidget(self.save_button)
        self.save_button.clicked.connect(self.save_new_style)

        self.lower_frame = QtWidgets.QFrame()
        self.lower_frame.setLayout(QtWidgets.QHBoxLayout())
        self.layout().addWidget(self.lower_frame)

        self.tw = QtWidgets.QTreeWidget(self)
        self.tw.model().setHeaderData(0, QtCore.Qt.Horizontal, 'Category')
        self.tw.setMinimumWidth(100)
        self.lower_frame.layout().addWidget(self.tw, stretch=2)

        self.fig_widget = QtWidgets.QWidget()
        self.fig_widget.setMinimumSize(600, 400)
        self.fig_widget.setLayout(QtWidgets.QVBoxLayout())
        self.fig_widget.show()

        self.prop_frame = QtWidgets.QFrame()
        self.prop_frame.setLayout( QtWidgets.QVBoxLayout() )
        self.prop_frame.layout().addStretch()

        self.scroll_area = QtWidgets.QScrollArea()
        self.scroll_area.setWidget(self.prop_frame)
        self.scroll_area.setWidgetResizable(True)
        self.lower_frame.layout().addWidget(self.scroll_area, stretch=10)

        self.plot_callback = plot_callback
        self.prop_widgets = {}
        self.prevent_figure_update = False
        rc_yaml_path = os.path.join(os.path.dirname(__file__), 'rcParams.yaml')
        with open(rc_yaml_path) as fh:
            self.categorized_params = yaml.safe_load(fh)
        self.params = dict(chain.from_iterable(
            [subdict.items() for subdict in self.categorized_params.values()]
        ))
        self.currently_displayed = []
        self.changed = {}

        self.show()
Exemplo n.º 14
0
    def __init__(self, algSettingsDict, parent=None):
        """"""
        QtWidgets.QDialog.__init__(self, parent)
        self.setWindowTitle('Change Algorithm-Specific Settings')
        self.setWindowIcon(QtGui.QIcon('kiwi.png'))
        self.setMinimumWidth(400)
        self.cur = algSettingsDict["current"]

        # Set the font to be used for section headings
        fnt = QtGui.QFont()
        fnt.setBold(True)

        # AF-MUSIC
        self.afTitle = QtWidgets.QLabel("AF-MUSIC:")
        self.afTitle.setFont(fnt)

        self.fmax_l = QtWidgets.QLabel(u"\u0192_max (Hz):")
        self.fmax = QtWidgets.QLineEdit(self)
        self.fmax.setText(str(algSettingsDict["AF-MUSIC"]["f_max"]))

        self.fmin_l = QtWidgets.QLabel(u"\u0192_min (Hz):")
        self.fmin = QtWidgets.QLineEdit(self)
        self.fmin.setText(str(algSettingsDict["AF-MUSIC"]["f_min"]))

        self.f0_l = QtWidgets.QLabel("Focusing Frequency (Hz):")
        self.f0 = QtWidgets.QLineEdit(self)
        self.f0.setText(str(algSettingsDict["AF-MUSIC"]["f_0"]))

        # GCC
        self.GCCTitle = QtWidgets.QLabel("GCC:")
        self.GCCTitle.setFont(fnt)

        # Available processors: PHAT, p-PHAT, CC, RIR, SCOT, HB
        self.GCC_l = QtWidgets.QLabel("Processor:")
        # self.GCC.setText(algSettingsDict["GCC"]["processor"])

        self.possible_processors = ["PHAT", "p-PHAT", "CC", "RIR", "SCOT", "HB"]
        self.cb = QtWidgets.QComboBox()
        self.cb.addItems(self.possible_processors)
        self.cb.setCurrentIndex(self.possible_processors.index(algSettingsDict["GCC"]["processor"]))


        self.def_rho = algSettingsDict["GCC"]["rho"]
        self.sl_l = QtWidgets.QLabel(u"0 \u2265 \u03C1={} \u2265 1:".format(self.def_rho))
        self.sl = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        self.sl.setMinimum(0)
        self.sl.setMaximum(100)
        self.sl.setTickInterval(10)
        self.sl.setTickPosition(QtWidgets.QSlider.TicksBelow)
        self.sl.setValue(int(self.def_rho*100))
        self.sl.valueChanged.connect(self.changeRho)

        # MUSIC
        self.MUSICTitle = QtWidgets.QLabel("MUSIC:")
        self.MUSICTitle.setFont(fnt)

        self.MUSIC_l = QtWidgets.QLabel("Frequency:")
        self.MUSIC = QtWidgets.QLineEdit(self)
        self.MUSIC.setText(str(algSettingsDict["MUSIC"]["freq"]))

        self.activate = QtWidgets.QPushButton("Set")

        Box = QtWidgets.QVBoxLayout()

        Box.addWidget(self.afTitle)
        f_min = QtWidgets.QHBoxLayout()
        f_min.addWidget(self.fmin_l)
        f_min.addWidget(self.fmin)
        Box.addLayout(f_min)

        f_max = QtWidgets.QHBoxLayout()
        f_max.addWidget(self.fmax_l)
        f_max.addWidget(self.fmax)
        Box.addLayout(f_max)

        f_0 = QtWidgets.QHBoxLayout()
        f_0.addWidget(self.f0_l)
        f_0.addWidget(self.f0)
        Box.addLayout(f_0)

        Box.addSpacerItem(QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum,
                                                QtWidgets.QSizePolicy.Expanding))

        Box.addWidget(self.GCCTitle)
        procBox = QtWidgets.QHBoxLayout()
        procBox.addWidget(self.GCC_l)
        procBox.addWidget(self.cb)
        Box.addLayout(procBox)

        rhoBox = QtWidgets.QHBoxLayout()
        rhoBox.addWidget(self.sl_l)
        rhoBox.addWidget(self.sl)
        Box.addLayout(rhoBox)

        Box.addSpacerItem(QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum,
                                                QtWidgets.QSizePolicy.Expanding))

        Box.addWidget(self.MUSICTitle)
        MUSICBox = QtWidgets.QHBoxLayout()
        MUSICBox.addWidget(self.MUSIC_l)
        MUSICBox.addWidget(self.MUSIC)
        Box.addLayout(MUSICBox)

        Box.addWidget(self.activate)

        # Now put everything into the frame
        self.setLayout(Box)
Exemplo n.º 15
0
    def __init__(self):
        super().__init__()

        self.T = 60
        self.invertible_model = InvertibleModel(self.T)

        self._main = QtWidgets.QFrame(self)
        self.vertical_layout = QtWidgets.QVBoxLayout(self._main)
        self._main.setLayout(self.vertical_layout)
        self.setCentralWidget(self._main)

        self.toolbar = self.addToolBar('Toolbar')

        combo = QtWidgets.QComboBox(self)
        combo.addItem('Simple Example')
        combo.addItem('Complex Example 1')
        combo.addItem('Complex Example 2')
        combo.setCurrentIndex(0)
        combo.activated.connect(self.combo_activated)
        self.toolbar.addWidget(combo)

        compute_encode_action = QtWidgets.QAction('encode f(x) -> y,z', self)
        compute_encode_action.triggered.connect(self.compute_encode)
        self.toolbar.addAction(compute_encode_action)

        compute_decode_action = QtWidgets.QAction('decode f_inv(y,z) -> x',
                                                  self)
        compute_decode_action.triggered.connect(self.compute_decode)
        self.toolbar.addAction(compute_decode_action)

        denoise_action = QtWidgets.QAction('denoise [y, yz_pad, z]', self)
        denoise_action.triggered.connect(self.denoise)
        self.toolbar.addAction(denoise_action)

        # zero_yz_pad_action = QtWidgets.QAction('yz padding -> 0', self)
        # zero_yz_pad_action.triggered.connect(self.zero_yz_pad)
        # self.toolbar.addAction(zero_yz_pad_action)

        # confusing, leave out
        # label = 'yz padding -> N(0, {:>4.2g})'.format(self.invertible_model.model.zeros_noise_scale)
        # noise_yz_pad_action = QtWidgets.QAction(label, self)
        # noise_yz_pad_action.triggered.connect(self.noise_yz_pad)
        # self.toolbar.addAction(noise_yz_pad_action)

        gauss_z_action = QtWidgets.QAction('z -> N(0, 1)', self)
        gauss_z_action.triggered.connect(self.gauss_z)
        self.toolbar.addAction(gauss_z_action)

        self.ssim_label = QtWidgets.QLabel(
            'structural similarity(x, x_hat) = {:4.2g}'.format(0.9999), self)

        spacer = QtWidgets.QWidget()
        spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                             QtWidgets.QSizePolicy.Expanding)
        self.toolbar.addWidget(spacer)
        self.toolbar.addWidget(self.ssim_label)

        # self.threshold_slider = QtWidgets.QSlider(Qt.Horizontal, self)
        # self.threshold_slider.setMinimum(0)
        # self.threshold_slider.setMaximum(500)
        # self.threshold_slider.setValue(50)
        # self.threshold_slider.valueChanged.connect(self.changeThreshold)
        # self.toolbar.addWidget(self.threshold_slider)

        # threshold_label = 'set all values < {:4.2g} to 0'.format(
        #     self.threshold_slider.value() / 100.
        # )
        # self.threshold_action = QtWidgets.QAction(threshold_label, self)
        # self.threshold_action.triggered.connect(self.threshold)
        # self.toolbar.addAction(self.threshold_action)

        # hide_editors_action = QtWidgets.QAction('Hide Editors', self)
        # hide_editors_action.triggered.connect(self.hide_editors)
        # self.toolbar.addAction(hide_editors_action)

        self.upper = QtWidgets.QFrame(self._main)
        self.lower_single = SingleEditorWidget(self._main)
        self.lower_single.setFixedHeight(170)
        self.lower_double = DoubleEditorWidget(self._main)
        self.lower_double.setFixedHeight(210)

        self.vertical_layout.addWidget(self.upper)
        self.vertical_layout.addWidget(self.lower_single)
        self.vertical_layout.addWidget(self.lower_double)

        upper_layout = QtWidgets.QHBoxLayout(self.upper)

        #####################################################
        # these calls need to stay in this order! otherwise
        # the event handlers registered in the figure
        # will be overwritten!

        # create a mpl figure
        self.figure = create_figure()

        # create the figurecanvas object
        self.canvas = FigureCanvas(self.figure)

        # plot into the figure
        # self.combo_activated(combo.currentIndex())
        filename, start = filenames_and_starts[combo.currentIndex()]

        x, x_frames, x_velocity = get_xy_from_file(
            filename + '.flac', filename + '.mid',
            self.invertible_model.audio_options)
        print('x.shape', x.shape)
        print('x_frames.shape', x_frames.shape)
        print('x_velocity.shape', x_velocity.shape)

        self.x_true = np.array(x[start:start + self.T])

        self.z_pred, self.yz_pad_pred, self.y_pred = self.invertible_model.encode(
            self.x_true)

        self.x_inv, self.x_inv_padding = self.invertible_model.decode(
            self.z_pred, self.yz_pad_pred, self.y_pred)

        #################################################################
        # test only

        # self.x_true = np.random.uniform(0, 1, (self.T, 256))

        # self.y_pred = np.random.uniform(0, 1, (self.T, 185))
        # self.z_pred = np.random.uniform(0, 1, (self.T, 9))
        # self.yz_pad_pred = np.random.uniform(0, 1, (self.T, 62))

        # self.x_inv = np.random.uniform(0, 1, (self.T, 256))
        #################################################################
        print('self.x_true.shape', self.x_true.shape)
        print('self.y_pred.shape', self.y_pred.shape)
        print('self.yz_pad_pred.shape', self.yz_pad_pred.shape)
        print('self.z_pred.shape', self.z_pred.shape)
        print('self.x_inv.shape', self.x_inv.shape)
        print('self.x_inv_padding.shape', self.x_inv_padding.shape)

        self.all_plots = AllPlots(fig=self.figure,
                                  x_true=self.x_true.view(),
                                  y_pred=self.y_pred.view(),
                                  z_pred=self.z_pred.view(),
                                  yz_pad_pred=self.yz_pad_pred.view(),
                                  x_inv=self.x_inv.view())

        upper_layout.addWidget(self.canvas)

        # connect the signals to slots
        self.all_plots.ipo_y_instrument.do_select.connect(self.select)
        self.all_plots.ipo_y_phase.do_select.connect(self.select_pv)
        self.all_plots.ipo_y_velocity.do_select.connect(self.select_pv)
        self.all_plots.ipo_z.do_select.connect(self.select)
        self.all_plots.ipo_yz_pad_pred.do_select.connect(self.select)
        ######################################################

        self.selected_y = 8
        self.selected_ipo = self.all_plots.ipo_y_instrument
        self.select(self.selected_ipo, self.selected_y)
        self.lower_single.show()
        self.lower_double.hide()
        self.upper.setFocus()