- Further logging

- Preparing for Magnitude-Angle Touchstone files
- Minimum width for frequency input fields
pull/17/head
Rune B. Broberg 2019-09-17 11:13:42 +02:00
rodzic 7f48d7642e
commit 23fe8024f7
2 zmienionych plików z 43 dodań i 25 usunięć

Wyświetl plik

@ -159,6 +159,7 @@ class NanoVNASaver(QtWidgets.QWidget):
sweep_control_layout.addRow(sweep_input_layout) sweep_control_layout.addRow(sweep_input_layout)
self.sweepStartInput = QtWidgets.QLineEdit("") self.sweepStartInput = QtWidgets.QLineEdit("")
self.sweepStartInput.setMinimumWidth(60)
self.sweepStartInput.setAlignment(QtCore.Qt.AlignRight) self.sweepStartInput.setAlignment(QtCore.Qt.AlignRight)
self.sweepStartInput.textEdited.connect(self.updateCenterSpan) self.sweepStartInput.textEdited.connect(self.updateCenterSpan)
@ -171,6 +172,7 @@ class NanoVNASaver(QtWidgets.QWidget):
sweep_input_left_layout.addRow(QtWidgets.QLabel("Stop"), self.sweepEndInput) sweep_input_left_layout.addRow(QtWidgets.QLabel("Stop"), self.sweepEndInput)
self.sweepCenterInput = QtWidgets.QLineEdit("") self.sweepCenterInput = QtWidgets.QLineEdit("")
self.sweepCenterInput.setMinimumWidth(60)
self.sweepCenterInput.setAlignment(QtCore.Qt.AlignRight) self.sweepCenterInput.setAlignment(QtCore.Qt.AlignRight)
self.sweepCenterInput.textEdited.connect(self.updateStartEnd) self.sweepCenterInput.textEdited.connect(self.updateStartEnd)

Wyświetl plik

@ -14,10 +14,13 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
import collections import collections
import logging
from typing import List from typing import List
Datapoint = collections.namedtuple('Datapoint', 'freq re im') Datapoint = collections.namedtuple('Datapoint', 'freq re im')
logger = logging.getLogger(__name__)
class Touchstone: class Touchstone:
s11data: List[Datapoint] = [] s11data: List[Datapoint] = []
@ -31,62 +34,75 @@ class Touchstone:
def load(self): def load(self):
self.s11data = [] self.s11data = []
self.s21data = [] self.s21data = []
realimaginary = False
magnitudeangle = False
factor = 1 factor = 1
try: try:
logger.info("Attempting to open file %s", self.filename)
file = open(self.filename, "r") file = open(self.filename, "r")
lines = file.readlines() lines = file.readlines()
parsed_header = False parsed_header = False
for l in lines: for line in lines:
l = l.strip() line = line.strip()
if l.startswith("!"): if line.startswith("!"):
continue continue
if l.startswith("#") and not parsed_header: if line.startswith("#") and not parsed_header:
# Check that this is a valid header # Check that this is a valid header
if l == "# Hz S RI R 50": if line == "# Hz S RI R 50":
parsed_header = True parsed_header = True
realimaginary = True
factor = 1 factor = 1
continue continue
elif l == "# kHz S RI R 50": elif line == "# kHz S RI R 50":
parsed_header = True parsed_header = True
realimaginary = True
factor = 10**3 factor = 10**3
continue continue
elif l == "# MHz S RI R 50": elif line == "# MHz S RI R 50":
parsed_header = True parsed_header = True
realimaginary = True
factor = 10**6 factor = 10**6
continue continue
elif l == "# GHz S RI R 50": elif line == "# GHz S RI R 50":
parsed_header = True parsed_header = True
realimaginary = True
factor = 10**9 factor = 10**9
continue continue
else: else:
# This is some other comment line # This is some other comment line
continue continue
if not parsed_header: if not parsed_header:
print("Warning: Read line without having read header: " + l) logger.warning("Read line without having read header: %s", line)
continue continue
try: try:
values = l.split(maxsplit=5) if realimaginary:
freq = values[0] values = line.split(maxsplit=5)
re11 = values[1] freq = values[0]
im11 = values[2] re11 = values[1]
freq = int(float(freq) * factor) im11 = values[2]
re11 = float(re11) freq = int(float(freq) * factor)
im11 = float(im11) re11 = float(re11)
self.s11data.append(Datapoint(freq, re11, im11)) im11 = float(im11)
if len(values) > 3: self.s11data.append(Datapoint(freq, re11, im11))
re21 = values[3] if len(values) > 3:
im21 = values[4] re21 = values[3]
re21 = float(re21) im21 = values[4]
im21 = float(im21) re21 = float(re21)
self.s21data.append(Datapoint(freq, re21, im21)) im21 = float(im21)
self.s21data.append(Datapoint(freq, re21, im21))
elif magnitudeangle:
# TODO: Implement parsing code for Magnitude-Angle
continue
except ValueError as e: except ValueError as e:
print("Error parsing line " + l + " : " + str(e)) logger.exception("Failed to parse line: %s (%s)", line, e)
file.close() file.close()
except IOError as e: except IOError as e:
print("Failed to open " + self.filename) logger.exception("Failed to open %s: %s", self.filename, e)
return return
def setFilename(self, filename): def setFilename(self, filename):