Esempio n. 1
0
    def update_text_display(self):
        """
        Updates displayed data in the text browser area of the main window to display data of the selected data buffer.
        It is called upon changing selection in the table of buffers in main window.

        :return: NoneType
        """
        print("Updating text display . . .")
        self.selected_dataset_textbrowser.clear()
        row = self.opened_datasets_tablewidget.currentRow()
        if row != -1:
            item = self.opened_datasets_tablewidget.item(row, 1)
            location = item.text()
            name = get_location_basename(os.path.dirname(location))
            dataset = self.datasets[name]

            self.selected_dataset_textbrowser.append(
                "X:\n\t[Name: {}]\n\t[Unit: {}]\n\t[Step: {}]\n".format(
                    dataset.axis_values["x"]["name"],
                    dataset.axis_values["x"]["unit"],
                    (dataset.get_x_axis_values()[-1] -
                     dataset.get_x_axis_values()[0]) /
                    len(dataset.get_x_axis_values()) - 1))
            self.selected_dataset_textbrowser.append(
                "Y:\n\t[Name: {}]\n\t[Unit: {}]\n\t[Step: {}]\n".format(
                    dataset.axis_values["y"][0]["name"],
                    dataset.axis_values["y"][0]["unit"],
                    (dataset.get_y_axis_values()[0][-1] -
                     dataset.get_y_axis_values()[0][0]) /
                    len(dataset.get_y_axis_values()[0]) - 1))
            self.selected_dataset_textbrowser.append("Matrix:\n {}".format(
                dataset.textual_data_representation()))
Esempio n. 2
0
    def add_buffer_to_table(self, buffer, item_type=None):
        """
        Actual method that creates a row in the table in the main window and adds the data buffer to that table.

        :param buffer: DataBuffer(): instance of data buffer that is being added to the table in the main window
        :param item_type: string: string that is added to table to display type of the buffer in that row
        :return: NoneType
        """
        print("Adding buffer to the table . . .")
        if buffer.is_data_ready():
            name = get_location_basename(os.path.dirname(
                buffer.get_location()))
            rows = self.opened_datasets_tablewidget.rowCount()
            self.opened_datasets_tablewidget.insertRow(rows)
            table_item = QTableWidgetItem(name)
            table_item.setFlags(QtCore.Qt.ItemIsSelectable
                                | QtCore.Qt.ItemIsEnabled)
            self.opened_datasets_tablewidget.setItem(rows, 0, table_item)
            location_item = QTableWidgetItem(buffer.get_location())
            location_item.setFlags(QtCore.Qt.ItemIsSelectable
                                   | QtCore.Qt.ItemIsEnabled)
            self.opened_datasets_tablewidget.setItem(rows, 1, location_item)
            delete_current_file_btn = QPushButton("Delete")
            delete_current_file_btn.clicked.connect(
                self.make_delete_file_from_list(location_item))
            self.opened_datasets_tablewidget.setCellWidget(
                rows, 2, delete_current_file_btn)
            self.opened_datasets_tablewidget.setItem(rows, 3, item_type)
            print("Added to the table . . .")
        else:
            print("Data not ready ! Abort.")
Esempio n. 3
0
    def build_data_buffer_tab(self):
        """

        :return:
        """
        layout = QVBoxLayout()

        location_layout = QHBoxLayout()
        location_label = QLabel("Location of the file: ")
        if self.window is not None:
            location_line_edit = QLineEdit(self.window.data_buffer.location)
        else:
            location_line_edit = QLineEdit("test")
        location_line_edit.setDisabled(True)
        location_layout.addWidget(location_label)
        location_layout.addWidget(location_line_edit)

        name_layout = QHBoxLayout()
        name_label = QLabel("Displayed name: ")
        if self.window is not None:
            name_line_edit = QLineEdit(get_location_basename(self.window.data_buffer.location))
        else:
            name_line_edit = QLineEdit(get_location_basename("test"))
        show_name_label = QLabel("Show name: ")
        show_name_checkbox = QCheckBox()
        name_layout.addWidget(name_label)
        name_layout.addWidget(name_line_edit)
        name_layout.addWidget(show_name_label)
        name_layout.addWidget(show_name_checkbox)

        dimensions_layout = QHBoxLayout()
        dimensions_label = QLabel("Dimensions: ")
        if self.window is not None:
            dimensions_line_edit = QLineEdit(str(self.window.data_buffer.get_matrix_dimensions()))
        else:
            dimensions_line_edit = QLineEdit("[25, 51]")
        dimensions_line_edit.setDisabled(True)
        dimensions_layout.addWidget(dimensions_label)
        dimensions_layout.addWidget(dimensions_line_edit)

        layout.addLayout(location_layout)
        layout.addLayout(name_layout)
        layout.addLayout(dimensions_layout)

        return layout
Esempio n. 4
0
    def update_mini_graph(self):
        """
        Updates displayed data in the miniature graph area on the main window to display data of the selected data
        buffer. It is called upon changing selection in the table of buffers in main window.

        :return: NoneType
        """
        print("Updating mini graph . . .")
        row = self.opened_datasets_tablewidget.currentRow()
        if row != -1:
            item = self.opened_datasets_tablewidget.item(row, 1)
            location = item.text()
            name = get_location_basename(os.path.dirname(location))
            dataset = self.datasets[name]

            if dataset.get_number_of_dimension() == 2:
                print(" Drawing 2d plot . . .")
                self.mini_plot_items["main_subplot"].clear()
                self.mini_plot_items["main_subplot"].plot(
                    x=dataset.get_x_axis_values(),
                    y=dataset.get_y_axis_values()[0],
                    pen=(60, 60, 60))
            else:
                print(" Drawing 3d plot . . .")
                self.mini_plot_items["main_subplot"].clear()
                print(" Fetching image data . . .")
                img = pg.ImageItem()
                img.setImage(dataset.get_matrix(index=0))
                (x_scale, y_scale) = dataset.get_scale()
                img.transform().translate(dataset.get_x_axis_values()[0],
                                          dataset.get_y_axis_values()[0][0])
                img.transform().scale(x_scale, y_scale)
                print(" Drawing histogram . . .")
                histogram = pg.HistogramLUTItem()
                histogram.setImageItem(img)
                histogram.gradient.loadPreset("thermal")
                self.mini_plot_items["main_subplot"].addItem(img)

                print(" Drawing axes . . .")
                legend = {"left": "y", "bottom": "x"}
                for side in ('left', 'bottom'):
                    ax = self.mini_plot_items["main_subplot"].getAxis(side)
                    ax.setPen((60, 60, 60))
                    if legend[side] == "y":
                        axis_data = self.datasets[name].axis_values[
                            legend[side]][0]
                    else:
                        axis_data = self.datasets[name].axis_values[
                            legend[side]]
                    label_style = {'font-size': '7pt'}
                    ax.setLabel(axis_data["name"], axis_data["unit"],
                                **label_style)
Esempio n. 5
0
    def get_buffers_from_signal(self, buffers):
        """
        Slot that gets data from BufferExplorers signals and adds buffers to the main window opened_datasets_table

        :param buffers: dictionary: contins key: string representation of the buffers location on file system
                                            value: instance of DataBuffer
        :return: NoneType
        """
        for path, buffer in buffers.items():
            self.add_buffer_to_table(buffer,
                                     QTableWidgetItem(buffer.string_type))
            name = get_location_basename(os.path.dirname(
                buffer.get_location()))
            self.datasets[name] = buffer
Esempio n. 6
0
    def __init__(self, location):
        """
        A constructor for DataBuffer class. This is an abstract class. Contains some methods common to all of the
        DataBuffer classes but most of the methods are abstract methods.

        :param location: A string representing the location of the file on the disk
        :type location: str
        """
        super().__init__()

        # location is absolute path to a location of the file on the disk
        self.location = location

        self.name = get_location_basename(os.path.dirname(self.location))

        # data is a dictionary containing:
        #   For 3D measurement: matrix, x, y
        #       matrix: np.array containing z axis data
        #       x: list of x axis values
        #       y: list of y axis values
        #   For 2D measurement: x, y
        #       x and y same as in 3D
        self.data = {}

        # Not all measurements have the same numbers of parameters that are being set. We might have a measurement that
        # sets two different parameters and measures one, also a measurement that is a loop in a loop which also sets
        # two parameters and measures one but its not the same thing. Also there might be more then one measured
        # parameter
        self.number_of_set_parameters = 0

        # Same as number of set parameters. Its usefull to have this number available at all times. its usefull to some
        # other windows when displaying data to know how many columns are set parameters, and how many columns are data
        # to be displayed. (Example: Loop in a loop measurement has 2 parameters that are being measured. In this case
        # we want to give user to option to chose which measured parameter is displayed as a graph)
        self.number_of_measured_parameters = 0

        # Textual representetion of data set. Enables wuick overview of the data in the main window
        self.textual = None

        self.string_type = ""

        # list of values containing number of steps for x and y dimensions
        self.matrix_dimensions = None
Esempio n. 7
0
    def display_dataset(self):
        """
        TODO: Keep traack of all opened windows separately, currently the older ones are overwritten by newer ones
        A method that opens LineTrace or Heatmap window depending on number of dimension that the selected buffer has.

        :return: NoneType
        """
        row = self.opened_datasets_tablewidget.currentRow()
        if row != -1:
            item = self.opened_datasets_tablewidget.item(row, 1)
            location = item.text()
            name = get_location_basename(os.path.dirname(location))
            dataset = self.datasets[name]

            if dataset.get_number_of_dimension() == 3:
                self.hm = Heatmap(dataset, self)
                self.hm.show()
            else:
                self.lt = LineTrace(dataset, None)
                self.lt.show()
Esempio n. 8
0
    def open_file_dialog(self):
        """
        Opens a file dialog for selecting file to load into application. Depending on type of file the headers of the
        files differ allowing to recognize which type of DataBuffer needs to be instantiated.

        :return: NoneType
        """
        print("Opening FileDialog for selecting files . . .")
        file_dialog = QFileDialog.getOpenFileNames()

        for file in file_dialog[0]:
            name = get_location_basename(os.path.dirname(file))
            with open(file, "r") as current_file:
                if file.lower().endswith(".hdf5"):
                    type_item = QTableWidgetItem("Labber")
                    buffer = LabberDataBuffer.LabberData(file)
                    worker = Worker(buffer.prepare_data)
                    progress_bar = self.add_progress_widget(buffer)
                    buffer.progress.connect(lambda progress: self.get_progress(
                        progress, progress_bar))
                    self.datasets[name] = buffer
                    buffer.ready.connect(
                        self.make_add_to_table(self.datasets[name]))
                    worker.signals.finished.connect(
                        lambda: self.add_buffer_to_table(
                            self.datasets[name], type_item))
                    self.thread_pool.start(worker)
                elif file.lower().endswith(".txt"):
                    type_item = QTableWidgetItem("VIP")
                    buffer = VipDataBuffer.VipData(file)
                    worker = Worker(buffer.prepare_data)
                    progress_bar = self.add_progress_widget(buffer)
                    buffer.progress.connect(lambda progress: self.get_progress(
                        progress, progress_bar))
                    self.datasets[name] = buffer
                    buffer.ready.connect(
                        self.make_add_to_table(self.datasets[name]))
                    worker.signals.finished.connect(
                        lambda: self.add_buffer_to_table(
                            self.datasets[name], type_item))
                else:
                    for i, line in enumerate(current_file):
                        if i == 2:
                            if line.strip(" \n") == "":
                                type_item = QTableWidgetItem("QtLab")
                                buffer = QtLabDataBuffer.QtLabData(file)
                                worker = Worker(buffer.prepare_data)
                            elif line.startswith("#"):

                                msg_box = QMessageBox(self)
                                msg_box.setWindowTitle("I don't know ...")
                                msg_box.setText("... which one is it ?")
                                msg_box.setStandardButtons(QMessageBox.Yes
                                                           | QMessageBox.No)
                                qc = msg_box.button(QMessageBox.Yes)
                                qc.setText("QCoDeS")
                                qtt = msg_box.button(QMessageBox.No)
                                qtt.setText("Qtt")
                                msg_box.exec_()

                                if msg_box.clickedButton() == qc:
                                    type_item = QTableWidgetItem("QCoDeS")
                                    buffer = QcodesDataBuffer.QcodesData(file)
                                elif msg_box.clickedButton() == qtt:
                                    type_item = QTableWidgetItem("Qtt")
                                    buffer = QttDataBuffer.QttData(file)

                                worker = Worker(buffer.prepare_data)
                            else:
                                type_item = QTableWidgetItem("Matrix")
                                buffer = MatrixFileDataBuffer.MatrixData(file)
                                worker = Worker(buffer.prepare_data)

                            progress_bar = self.add_progress_widget(buffer)
                            buffer.progress.connect(
                                lambda progress: self.get_progress(
                                    progress, progress_bar))
                            self.datasets[name] = buffer
                            buffer.ready.connect(
                                self.make_add_to_table(self.datasets[name]))
                            worker.signals.finished.connect(
                                lambda: self.add_buffer_to_table(
                                    self.datasets[name], type_item))
                            self.thread_pool.start(worker)

                            break
Esempio n. 9
0
    def init_ui(self):
        """
        Method that builds user interface of buffer explorer window.

        :return:
        """
        # find dimensions of the monitor (screen)
        _, _, width, height = QDesktopWidget().screenGeometry().getCoords()
        self.setGeometry(int(0.2 * width), int(0.2 * height), 900, 600)

        print("Setting window title and icon . . .")
        self.setWindowTitle("Browse files")
        self.setWindowIcon(QIcon("img/dataStructure.png"))

        # It is possible that there is a lot of measurements in one folder, therefor i create a scroll area and add all
        # of them to this area. If there is more of them then it can fit, you will be able to scroll to see others
        print("Creating scroll area . . .")
        self.scroll = QScrollArea(self)
        self.scroll.setWidgetResizable(True)
        scroll_content = QWidget(self.scroll)

        main_layout = QGridLayout(self)
        main_layout.addWidget(self.scroll)

        layout = QGridLayout()
        row, column = 0, 0

        print("Instantiating data buffer objects . . .")
        for candidate in self.candidates:
            if candidate.endswith(".dat"):
                with open(candidate, "r") as current_file:
                    for i, line in enumerate(current_file):
                        if i == 2:
                            if line.strip(" \n") == "":
                                self.buffers[candidate] = QtLabData(candidate)
                                self.buffers[candidate].prepare_data()
                            elif line.startswith("#"):
                                self.buffers[candidate] = QcodesData(candidate)
                                self.buffers[candidate].prepare_data()
                            else:
                                self.buffers[candidate] = MatrixData(candidate)
                                self.buffers[candidate].prepare_data()

                            break
            else:
                self.buffers[candidate] = LabberData(candidate)
                self.buffers[candidate].prepare_data()

            if self.buffers[candidate].is_data_ready():
                print("{} data is ready. Adding plot and info buttons . . .".
                      format(candidate))
                mini_plot_widget = QWidget(self)
                mini_plot_widget.setMinimumHeight(250)

                preview_plt = pg.GraphicsView()
                mini_plot = pg.GraphicsLayout()
                main_subplot = mini_plot.addPlot()
                for axis in ["left", "bottom"]:
                    ax = main_subplot.getAxis(axis)
                    ax.setPen((60, 60, 60))

                preview_plt.setCentralItem(mini_plot)
                preview_plt.setBackground('w')

                if self.buffers[candidate].get_number_of_dimension() == 2:
                    main_subplot.clear()
                    main_subplot.plot(
                        x=self.buffers[candidate].get_x_axis_values(),
                        y=self.buffers[candidate].get_y_axis_values()[0],
                        pen=(60, 60, 60))
                else:
                    main_subplot.clear()
                    img = pg.ImageItem()
                    img.setImage(self.buffers[candidate].get_matrix(index=0))
                    (x_scale, y_scale) = self.buffers[candidate].get_scale()
                    img.translate(
                        self.buffers[candidate].get_x_axis_values()[0],
                        self.buffers[candidate].get_y_axis_values()[0][0])
                    img.scale(x_scale, y_scale)
                    histogram = pg.HistogramLUTItem()
                    histogram.setImageItem(img)
                    histogram.gradient.loadPreset("thermal")
                    main_subplot.addItem(img)
                    legend = {"left": "y", "bottom": "x"}
                    for side in ('left', 'bottom'):
                        ax = main_subplot.getAxis(side)
                        ax.setPen((60, 60, 60))
                        axis_data = self.buffers[candidate].axis_values[
                            legend[side]]
                        label_style = {'font-size': '7pt'}
                        if side == "bottom":
                            ax.setLabel(axis_data["name"], axis_data["unit"],
                                        **label_style)
                        else:
                            ax.setLabel(axis_data[0]["name"],
                                        axis_data[0]["unit"], **label_style)

                v_layout = QVBoxLayout()
                v_layout.addWidget(
                    QLabel(get_location_basename(candidate)[:30]))
                h_layout = QHBoxLayout()
                checkbox = QCheckBox(self)
                info_btn = QPushButton("Info", self)
                info_btn.clicked.connect(
                    self.make_show_buffer_info(self.buffers[candidate]))
                what_btn = QPushButton("What is this", self)
                what_btn.clicked.connect(
                    self.make_go_to_location(self.buffers[candidate]))
                add_btn = QPushButton("Quick add", self)
                add_btn.clicked.connect(self.make_quick_add(candidate))
                self.checkboxes[candidate] = checkbox
                h_layout.addWidget(checkbox)
                h_layout.addWidget(info_btn)
                h_layout.addWidget(what_btn)
                h_layout.addWidget(add_btn)
                v_layout.addLayout(h_layout)
                v_layout.addWidget(preview_plt)
                mini_plot_widget.setLayout(v_layout)
                layout.addWidget(mini_plot_widget, row, column, 1, 1)

                if column == 2:
                    row += 1
                    column = 0
                else:
                    column += 1

        submit_btn = QPushButton("OK", self)
        submit_btn.clicked.connect(self.submit)
        main_layout.addWidget(submit_btn, row + 1, 0, 1, 3)
        scroll_content.setLayout(layout)
        self.scroll.setWidget(scroll_content)
        self.setLayout(main_layout)

        self.show()