Beispiel #1
0
    def submit(self):
        """
        Method that reads data from QLineEdits and saves it to a dictionary that is then passed to a DataBuffer object

        If the input data does not pass validation (start and end have to be castable to a number) then this method
        shows error message

        :return: dict: {x: {start: "...", end: "...", name: "...", unit: "..."}, y: {}, z: {}}
                            start: first point on specified axis
                            end: last point on specified axis
                            name: name of the parameter measured and displayed on that axis
                            unit: measurement unit in which this parameter is measured
        """

        x_axis = {"start": self.controls["x"]["start"].text(),
                  "end": self.controls["x"]["end"].text(),
                  "name": self.controls["x"]["name"].text(),
                  "unit": self.controls["x"]["unit"].text()}

        y_axis = {"start": self.controls["y"]["start"].text(),
                  "end": self.controls["y"]["end"].text(),
                  "name": self.controls["y"]["name"].text(),
                  "unit": self.controls["y"]["unit"].text()}

        z_axis = {"name": self.controls["z"]["name"].text(),
                  "unit": self.controls["z"]["unit"].text()}

        data_dict = {"x": x_axis, "y": y_axis, "z": z_axis}

        if not self.validate_input():
            self.submitted.emit(data_dict)
            self.close()
        else:
            title, msg = self.validate_input()
            show_error_message(title, msg)
Beispiel #2
0
    def calculate_matrix_dimensions(self):
        """
        Takes first two columns of QtLab file (x and y) and looks for unique values.

        :return: list: [len(x_axis_data), len(y_axis_data)]
        """
        self.raw_data = np.loadtxt(self.location, dtype=float)
        self.textual = np.array2string(self.raw_data)
        if len(self.raw_data) < 2:
            show_error_message(
                "Warning", "Seems like data for file {} is incomplete".format(
                    self.location))
        else:
            if self.raw_data[0][1] == self.raw_data[1][1]:
                y_axis = pd.unique([value[0] for value in self.raw_data])
                x_axis = pd.unique([value[1] for value in self.raw_data])
                self.legend[0] = "y"
                self.legend[1] = "x"
            elif self.raw_data[0][0] == self.raw_data[1][0]:
                x_axis = pd.unique([value[0] for value in self.raw_data])
                y_axis = pd.unique([value[1] for value in self.raw_data])
            else:
                x_axis = [value[0] for value in self.raw_data]
                y_axis = [value[1] for value in self.raw_data]
                self.data["x"] = x_axis
                self.data["y"] = {0: y_axis}
                return [len(x_axis)]
            self.data["x"] = x_axis
            self.data["y"] = {0: y_axis}
            return [len(x_axis), len(y_axis)]
Beispiel #3
0
    def get_axis_data(self):
        """
        Function that gets a matrix file location as parameter, and looks for snapshot.json file within the same directory.
        If such file exists then get data from it, otherwise show an error msg saying that there is no such a file

        :return: array: [x, y, z] or [x, y]
        """
        snapshot_file_location = os.path.dirname(
            self.location) + "\\snapshot.json"
        measured = {}
        if os.path.exists(snapshot_file_location):
            with open(snapshot_file_location) as file:
                json_data = json.load(file)

            data_dict = {"x": {"name": "", "unit": ""}, "y": {}, "z": {}}

            for param, data in json_data["__dataset_metadata"]["arrays"].items(
            ):
                if data["is_setpoint"]:
                    self.number_of_set_parameters += 1
                    if len(data["shape"]) == 1:
                        data_dict["x"] = data
                    else:
                        data_dict["y"][0] = data
                else:
                    measured[self.number_of_measured_parameters] = data
                    self.number_of_measured_parameters += 1

            if self.number_of_set_parameters == 1:
                data_dict["y"] = measured
            else:
                data_dict["z"] = measured

            for k, v in data_dict.items():
                print(k, v)

            return data_dict

        else:
            helpers.show_error_message(
                "Warning",
                "Aborted, snapshot.json file does not exist for this measurement"
            )
            return
Beispiel #4
0
    def submit_data(self):

        send_value = []
        for i, numeric_required in enumerate(self.numeric):
            if numeric_required:
                if is_numeric(self.textboxes[i].text()):
                    send_value.append(self.textboxes[i].text())
                else:
                    show_error_message("Warning",
                                       "Input data has to be numeric")
                    return
            else:
                send_value.append(self.textboxes[i].text())

        if self.dropdown:
            send_value.append(self.combobox.currentData())

        self.submitted.emit(send_value)
        self.close()
Beispiel #5
0
    def submit_data(self):
        # do stuff
        send_value = []
        if is_numeric(self.resistance.text()):
            send_value.append(self.resistance.text())
        else:
            show_error_message("Warning", "Input data has to be numeric")
            return

        if is_numeric(self.d_v.text()):
            send_value.append(self.d_v.text())
        else:
            show_error_message("Warning", "Input data has to be numeric")
            return

        matrix = self.matrices_dropdown.currentData()
        send_value.append(matrix)

        self.submitted.emit(send_value)
        self.close()
Beispiel #6
0
    def gaussian_fit_action(self):
        """
        As suggested by the name of the function, it tries to apply gaussian fit the the selected data. Data is then
        added and displayed in the graph for fir curves.

        Turning off the action that prompts this function removes curve from the graph

        :return:
        """
        def gauss(x, a, x0, sigma):
            """

            :param x:
            :param a:
            :param x0:
            :param sigma:
            :return:
            """
            return a * exp(-(x - x0)**2 / (2 * sigma**2))

        if self.gauss.isChecked():
            try:
                x, y = self.get_selection_area()
                mean = sum(x * y) / sum(
                    y
                )  # https://en.wikipedia.org/wiki/Weighted_arithmetic_mean
                sigma = np.sqrt(sum(y * (x - mean)**2) / sum(y))

                p0 = array([max(y), mean, sigma])
                popt, pcov = curve_fit(gauss, x, y, p0=p0)
                plot_item = pg.PlotDataItem(x, gauss(x, *popt))
                plot_item.setPen(255, 0, 0)
                self.fit_plot.addItem(plot_item)
                self.fit_curves["gauss"] = plot_item
            except Exception as e:
                print(str(e))
                show_error_message("Could not find fit", str(e))
        else:
            self.fit_plot.removeItem(self.fit_curves["gauss"])
            del self.fit_curves["gauss"]
Beispiel #7
0
    def get_axis_data(self):
        """
        Function that gets a matrix file location as parameter, and looks for snapshot.json file within the same directory.
        If such file exists then get data from it, otherwise show an error msg saying that there is no such a file

        :return: array: [x, y, z] or [x, y]
        """
        snapshot_file_location = os.path.dirname(self.location) + "\\snapshot.json"
        data_list = []
        if os.path.exists(snapshot_file_location):
            with open(snapshot_file_location) as file:
                data = json.load(file)

            data_list = self.get_sweep_param_data(data) + self.get_action_param_data(data)
            data_dict = {}
            legend = {0: "x", 1: "y", 2: "z"}
            for index in range(len(data_list)):
                data_dict[legend[index]] = data_list[index]
            return data_dict
        else:
            helpers.show_error_message("Warning", "Aborted, snapshot.json file does not exist for this measurement")
            return
Beispiel #8
0
    def hover_action(self, point: int, orientation: str):
        """
        When user is hovering its mouse over one of the custom menu items, show a preview of how the line will be
        aligned.

        :param point: can be 0, 1, 2 or 3. 0 and 1 are the edges of the lineROI, 2 and 3 are used to represent the
                      diagonal previews
        :param orientation: can be horizontal, vertical or diagonal
        :return: NoneType
        """
        if point in [0, 1]:
            handle_point = self.getSceneHandlePositions()[point]
            name, scene_coords = handle_point
            coords = self.mapSceneToParent(scene_coords)
        else:
            if point == 2:
                coords = [[self.edges[0], self.edges[2]],
                          [self.edges[1], self.edges[3]]]
            elif point == 3:
                coords = [[self.edges[0], self.edges[3]],
                          [self.edges[1], self.edges[2]]]

        if orientation == "horizontal":
            self.add_preview(coords.y(), orientation, 0)
        elif orientation == "vertical":
            self.add_preview(coords.x(), orientation, 90)
        elif orientation == "diagonal":
            angle = self.get_angle_from_points(coords[0], coords[1])
            self.add_preview(coords, orientation, angle)
        else:
            show_error_message(
                "Warning",
                "Non existent orientation. HOW THE HELL DID U MANAGE TO DO THIS !?"
            )
            return

        return