Exemplo n.º 1
0
    def Load_and_init_Viewer(self):

        if self.debug:
            print("function Viewer_Ini called")

        # retrieve or initialize directory path
        settings = QSettings()
        dir_path = settings.value('dir_name', os.path.curdir)

        # load a table directly
        df, err_msg, dir_path = util.load_data(dir_path, self.debug)

        if err_msg == 'cancelled':
            return
        else:
            # save the last directory
            settings.setValue('dir_name', dir_path)

        if err_msg:

            msgBox = QMessageBox()
            msgBox.setWindowTitle('Data Import Error')
            msgBox.setText(err_msg)
            msgBox.setDetailedText(
                '''Have a look at the example data directory at\n
                github.com/tensionhead/pyBOAT''')
            msgBox.exec()
            return

        self.nViewers += 1
        # initialize new DataViewer with the loaded data
        self.DataViewers[self.nViewers] = DataViewer(data=df,
                                                     pos_offset=self.nViewers *
                                                     20,
                                                     debug=self.debug)
Exemplo n.º 2
0
    def Load_and_init_Viewer(self):

        if self.debug:
            print("function Viewer_Ini called")

        # load a table directly
        df, err_msg = load_data(self.debug)

        if err_msg:
            self.error = MessageWindow(err_msg, "Loading error")
            return

        self.nViewers += 1

        # initialize new DataViewer with the loaded data
        self.DataViewers[self.nViewers] = DataViewer(data=df, debug=self.debug)
Exemplo n.º 3
0
    def import_file(self):
        """
        Reads the values from the config grid
        and prepares kwargs for the pandas read_... functions

        NaN interpolation is done here if requested
        """

        kwargs = {}

        if self.cb_header.isChecked():
            header = None  # pandas will assign numeric column names
        else:
            header = "infer"

        if not self.cb_use_ext.isChecked():

            sep = self.sep_edit.text()
            # empty field
            if sep == "":
                sep = None
            kwargs["sep"] = sep
            if self.debug:
                print(f"Separator is {sep}, with type {type(sep)}")

        NaN_value = self.NaN_edit.text()
        # empty field
        if NaN_value == "":
            NaN_value = None
        if self.debug:
            print(f"NaN value is {NaN_value}, with type {type(NaN_value)}")

        # assemble key-words for pandas read_... functions
        kwargs["header"] = header
        kwargs["na_values"] = NaN_value

        if self.debug:
            print(f"kwargs for load_data: {kwargs}")

        # -----------------------------------------------------
        df, err_msg = load_data(debug=self.debug, **kwargs)
        if err_msg:
            self.error = MessageWindow(err_msg, "Loading error")
            return
        # -----------------------------------------------------

        if self.cb_NaN.isChecked():

            N_NaNs = df.isna().to_numpy().sum()
            if N_NaNs > 0:
                msg = f"Found {N_NaNs} missing values in total\nlinearly interpolating through.."
                self.Interpolation = MessageWindow(msg, "NaN Interpolation")

            else:
                self.Interpolation = MessageWindow("No missing values found!",
                                                   "NaN Interpolation")

            name = df.name
            df = interpol_NaNs(df)
            df.name = name  # restore name

        # initialize new DataViewer with the loaded data
        # doesn't help as ini window gets destroyed..
        self.parent.DataViewers[self.parent.nViewers] = DataViewer(
            data=df, debug=self.debug)
        self.parent.nViewers += 1

        self.close()
Exemplo n.º 4
0
    def import_file(self):
        """
        Reads the values from the config grid
        and prepares kwargs for the pandas read_... functions

        NaN interpolation is done here if requested
        """

        kwargs = {}

        if self.cb_header.isChecked():
            header = None  # pandas will assign numeric column names
        else:
            header = "infer"

        if not self.cb_use_ext.isChecked():

            sep = self.sep_edit.text()
            # empty field
            if sep == "":
                sep = None
            kwargs["sep"] = sep
            if self.debug:
                print(f"Separator is {sep}, with type {type(sep)}")

        NaN_value = self.NaN_edit.text()
        # empty field
        if NaN_value == "":
            NaN_value = None
        if self.debug:
            print(f"NaN value is {NaN_value}, with type {type(NaN_value)}")

        # assemble key-words for pandas read_... functions
        kwargs["header"] = header
        kwargs["na_values"] = NaN_value

        if self.debug:
            print(f"kwargs for load_data: {kwargs}")

        # retrieve or initialize directory path
        settings = QSettings()
        dir_path = settings.value('dir_name', os.path.curdir)

        # -----------------------------------------------------
        df, err_msg, dir_path = util.load_data(dir_path,
                                               debug=self.debug,
                                               **kwargs)

        if err_msg != 'cancelled':
            # save the last directory
            settings.setValue('dir_name', dir_path)
        elif err_msg == 'cancelled':
            return

        if err_msg:
            msgBox = QMessageBox()
            msgBox.setWindowTitle('Data Import Error')
            msgBox.setText(err_msg)
            msgBox.exec()
            return
        # -----------------------------------------------------

        if self.cb_NaN.isChecked():

            N_NaNs = df.isna().to_numpy().sum()
            if N_NaNs > 0:
                msg = f"Found {N_NaNs} missing values in total\nlinearly interpolating through.."
                msgBox = QMessageBox()
                msgBox.setWindowTitle('NaNs detected')
                msgBox.setText(msg)
                msgBox.exec()

            else:
                msgBox = QMessageBox()
                msgBox.setWindowTitle("NaN Interpolation")
                msgBox.setText("No missing values found!")
                msgBox.exec()

            name = df.name
            df = util.interpol_NaNs(df)
            df.name = name  # restore name

        # initialize new DataViewer with the loaded data
        self.parent.nViewers += 1
        self.parent.DataViewers[self.parent.nViewers] = DataViewer(
            data=df, pos_offset=self.parent.nViewers * 20, debug=self.debug)

        self.close()