- Values on tickmarks for LogMag charts

- Loading of Touchstone files with kHz, MHz and GHz frequency values
- Loading an S1P reference or sweep from file now also removes S21 values
pull/12/head
Rune B. Broberg 2019-09-07 13:47:13 +02:00
rodzic e706eec51e
commit 690d5a3b66
3 zmienionych plików z 42 dodań i 24 usunięć

Wyświetl plik

@ -687,7 +687,7 @@ class LogMagChart(Chart):
def drawChart(self, qp: QtGui.QPainter):
qp.setPen(QtGui.QPen(self.textColor))
qp.drawText(3, 15, self.name)
qp.drawText(3, 15, self.name + " (dB)")
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
qp.drawLine(self.leftMargin, 20, self.leftMargin, 20+self.chartHeight+5)
qp.drawLine(self.leftMargin-5, 20+self.chartHeight, self.leftMargin+self.chartWidth, 20 + self.chartHeight)
@ -735,6 +735,9 @@ class LogMagChart(Chart):
y = 30 + round((i-minValue)/span*(self.chartHeight-10))
qp.setPen(QtGui.QPen(QtGui.QColor("lightgray")))
qp.drawLine(self.leftMargin-5, y, self.leftMargin+self.chartWidth, y)
if i > minValue:
qp.setPen(QtGui.QPen(self.textColor))
qp.drawText(3, y + 4, str(-i))
qp.setPen(self.textColor)
qp.drawText(3, 35, str(-minValue))
qp.drawText(3, self.chartHeight+20, str(-maxValue))
@ -833,4 +836,4 @@ class LogMagChart(Chart):
im50 = 50 * (2 * im) / (1 + re * re + im * im - 2 * re)
# Calculate the reflection coefficient
mag = math.sqrt((re50 - 50) * (re50 - 50) + im50 * im50) / math.sqrt((re50 + 50) * (re50 + 50) + im50 * im50)
return -20 * math.log10(mag)
return -20 * math.log10(mag)

Wyświetl plik

@ -982,16 +982,21 @@ class NanoVNASaver(QtWidgets.QWidget):
def loadReferenceFile(self):
filename = self.referenceFileNameInput.text()
t = Touchstone(filename)
t.load()
self.setReference(t.s11data, t.s21data, filename)
if filename is not "":
self.resetReference()
t = Touchstone(filename)
t.load()
self.setReference(t.s11data, t.s21data, filename)
def loadSweepFile(self):
filename = self.referenceFileNameInput.text()
t = Touchstone(filename)
t.load()
self.saveData(t.s11data, t.s21data, filename)
self.dataUpdated()
if filename is not "":
self.data = []
self.data21 = []
t = Touchstone(filename)
t.load()
self.saveData(t.s11data, t.s21data, filename)
self.dataUpdated()
def sizeHint(self) -> QtCore.QSize:
return QtCore.QSize(1100, 950)

Wyświetl plik

@ -31,6 +31,7 @@ class Touchstone:
def load(self):
self.s11data = []
self.s21data = []
factor = 1
try:
file = open(self.filename, "r")
@ -44,6 +45,19 @@ class Touchstone:
# Check that this is a valid header
if l == "# Hz S RI R 50":
parsed_header = True
factor = 1
continue
elif l == "# kHz S RI R 50":
parsed_header = True
factor = 10**3
continue
elif l == "# MHz S RI R 50":
parsed_header = True
factor = 10**6
continue
elif l == "# GHz S RI R 50":
parsed_header = True
factor = 10**9
continue
else:
# This is some other comment line
@ -53,24 +67,20 @@ class Touchstone:
continue
try:
if l.count(" ") > 2:
freq, re11, im11, re21, im21, _ = l.split(maxsplit=5)
freq = int(freq)
re11 = float(re11)
im11 = float(im11)
values = l.split(maxsplit=5)
freq = values[0]
re11 = values[1]
im11 = values[2]
freq = int(float(freq) * factor)
re11 = float(re11)
im11 = float(im11)
self.s11data.append(Datapoint(freq, re11, im11))
if len(values) > 3:
re21 = values[3]
im21 = values[4]
re21 = float(re21)
im21 = float(im21)
self.s11data.append(Datapoint(freq, re11, im11))
self.s21data.append(Datapoint(freq, re21, im21))
elif l.count(" ") == 2:
freq, re11, im11 = l.split()
freq = int(freq)
re11 = float(re11)
im11 = float(im11)
self.s11data.append(Datapoint(freq, re11, im11))
else:
print("Warning: Read a line with not enough values: " + l)
continue
except ValueError as e:
print("Error parsing line " + l + " : " + str(e))