Exemple #1
0
    def test_save(self):
        ts = Touchstone("./test/data/valid.s2p")
        self.assertEqual(ts.saves(), "# HZ S RI R 50\n")
        ts.load()
        lines = ts.saves().splitlines()
        self.assertEqual(len(lines), 1021)
        self.assertEqual(lines[0], "# HZ S RI R 50")
        self.assertEqual(lines[1], '500000 -0.333238 0.000180018')
        self.assertEqual(lines[-1], '900000000 -0.127646 0.31969')
        lines = ts.saves(4).splitlines()
        self.assertEqual(len(lines), 1021)
        self.assertEqual(lines[0], "# HZ S RI R 50")
        self.assertEqual(
            lines[1], '500000 -0.333238 0.000180018 0.67478 -8.1951e-07'
            ' 0.67529 -8.20129e-07 -0.333238 0.000308078')
        self.assertEqual(
            lines[-1], '900000000 -0.127646 0.31969 0.596287 -0.503453'
            ' 0.599076 -0.50197 -0.122713 0.326965')
        ts.filename = "./test/data/output.s2p"
        ts.save(4)
        os.remove(ts.filename)
        ts.filename = ""
        self.assertRaises(FileNotFoundError, ts.save)

        ts.s11data[0] = Datapoint(100, 0.1, 0.1)
        self.assertRaisesRegex(LookupError,
                               "Frequencies of sdata not correlated", ts.saves,
                               4)
Exemple #2
0
    def exportFile(self, nr_params: int = 1):
        if len(self.app.data.s11) == 0:
            QtWidgets.QMessageBox.warning(self, "No data to save",
                                          "There is no data to save.")
            return
        if nr_params > 2 and len(self.app.data.s21) == 0:
            QtWidgets.QMessageBox.warning(self, "No S21 data to save",
                                          "There is no S21 data to save.")
            return

        filedialog = QtWidgets.QFileDialog(self)
        if nr_params == 1:
            filedialog.setDefaultSuffix("s1p")
            filedialog.setNameFilter(
                "Touchstone 1-Port Files (*.s1p);;All files (*.*)")
        else:
            filedialog.setDefaultSuffix("s2p")
            filedialog.setNameFilter(
                "Touchstone 2-Port Files (*.s2p);;All files (*.*)")
        filedialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave)
        selected = filedialog.exec()
        if not selected:
            return
        filename = filedialog.selectedFiles()[0]
        if filename == "":
            logger.debug("No file name selected.")
            return

        ts = Touchstone(filename)
        ts.sdata[0] = self.app.data.s11
        if nr_params > 1:
            ts.sdata[1] = self.app.data.s21
            for dp in self.app.data.s11:
                ts.sdata[2].append(Datapoint(dp.freq, 0, 0))
                ts.sdata[3].append(Datapoint(dp.freq, 0, 0))
        try:
            ts.save(nr_params)
        except IOError as e:
            logger.exception("Error during file export: %s", e)
            return