def updateLabels(self, s11data: List[Datapoint], s21data: List[Datapoint]): from NanoVNASaver.Chart import PhaseChart from NanoVNASaver.NanoVNASaver import NanoVNASaver if self.location != -1: im50, re50, vswr = NanoVNASaver.vswr(s11data[self.location]) if im50 < 0: im50str = " - j" + str(round(-1 * im50, 3)) else: im50str = " + j" + str(round(im50, 3)) self.frequency_label.setText( NanoVNASaver.formatFrequency(s11data[self.location].freq)) self.impedance_label.setText(str(round(re50, 3)) + im50str) self.returnloss_label.setText( str(round(20 * math.log10((vswr - 1) / (vswr + 1)), 3)) + " dB") reactance = NanoVNASaver.reactanceEquivalent( im50, s11data[self.location].freq) self.reactance_label.setText(reactance) self.vswr_label.setText(str(round(vswr, 3))) if len(s21data) == len(s11data): _, _, vswr = NanoVNASaver.vswr(s21data[self.location]) self.gain_label.setText( str(round(20 * math.log10((vswr - 1) / (vswr + 1)), 3)) + " dB") self.phase_label.setText( str(round(PhaseChart.angle(s21data[self.location]), 2)) + "\N{DEGREE SIGN}")
def updateLabels(self, s11data: List[Datapoint], s21data: List[Datapoint]): from NanoVNASaver.Chart import PhaseChart from NanoVNASaver.NanoVNASaver import NanoVNASaver if self.location != -1: im50, re50, vswr = NanoVNASaver.vswr(s11data[self.location]) rp = (re50**2 + im50**2) / re50 xp = (re50**2 + im50**2) / im50 re50 = round(re50, 4 - max(0, math.floor(math.log10(abs(re50))))) rp = round(rp, 4 - max(0, math.floor(math.log10(abs(rp))))) im50 = round(im50, 4 - max(0, math.floor(math.log10(abs(im50))))) xp = round(xp, 4 - max(0, math.floor(math.log10(abs(xp))))) if im50 < 0: im50str = " -j" + str(-1 * im50) else: im50str = " +j" + str(im50) im50str += "\N{OHM SIGN}" if xp < 0: xpstr = NanoVNASaver.capacitanceEquivalent( xp, s11data[self.location].freq) else: xpstr = NanoVNASaver.inductanceEquivalent( xp, s11data[self.location].freq) self.frequency_label.setText( NanoVNASaver.formatFrequency(s11data[self.location].freq)) self.impedance_label.setText(str(re50) + im50str) self.parallel_r_label.setText(str(rp) + "\N{OHM SIGN}") self.parallel_x_label.setText(xpstr) self.returnloss_label.setText( str(round(20 * math.log10((vswr - 1) / (vswr + 1)), 3)) + " dB") capacitance = NanoVNASaver.capacitanceEquivalent( im50, s11data[self.location].freq) inductance = NanoVNASaver.inductanceEquivalent( im50, s11data[self.location].freq) self.inductance_label.setText(inductance) self.capacitance_label.setText(capacitance) vswr = round(vswr, 3) if vswr < 0: vswr = "-" self.vswr_label.setText(str(vswr)) self.quality_factor_label.setText( str( round(NanoVNASaver.qualifyFactor(s11data[self.location]), 1))) self.s11_phase_label.setText( str(round(-PhaseChart.angle(s11data[self.location]), 2)) + "\N{DEGREE SIGN}") if len(s21data) == len(s11data): _, _, vswr = NanoVNASaver.vswr(s21data[self.location]) self.gain_label.setText( str(round(20 * math.log10((vswr - 1) / (vswr + 1)), 3)) + " dB") self.s21_phase_label.setText( str(round(-PhaseChart.angle(s21data[self.location]), 2)) + "\N{DEGREE SIGN}")
def drawValues(self, qp: QtGui.QPainter): from NanoVNASaver.NanoVNASaver import NanoVNASaver if len(self.data) == 0 and len(self.reference) == 0: return pen = QtGui.QPen(self.sweepColor) pen.setWidth(2) line_pen = QtGui.QPen(self.sweepColor) line_pen.setWidth(1) highlighter = QtGui.QPen(QtGui.QColor(20, 0, 255)) highlighter.setWidth(1) if len(self.data) > 0: fstart = self.data[0].freq fstop = self.data[len(self.data) - 1].freq else: fstart = self.reference[0].freq fstop = self.reference[len(self.reference) - 1].freq self.fstart = fstart self.fstop = fstop fspan = fstop - fstart # Find scaling minVSWR = 1 maxVSWR = 3 for d in self.data: _, _, vswr = NanoVNASaver.vswr(d) if vswr > maxVSWR: maxVSWR = vswr maxVSWR = min(25, math.ceil(maxVSWR)) span = maxVSWR - minVSWR ticksize = 1 if span > 10 and span % 5 == 0: ticksize = 5 elif span > 12 and span % 4 == 0: ticksize = 4 elif span > 8 and span % 3 == 0: ticksize = 3 elif span > 7 and span % 2 == 0: ticksize = 2 for i in range(minVSWR, maxVSWR, ticksize): y = 30 + round((maxVSWR - i) / span * (self.chartHeight - 10)) if i != minVSWR and i != maxVSWR: qp.setPen(self.textColor) qp.drawText(3, y + 3, str(i)) qp.setPen(QtGui.QPen(QtGui.QColor("lightgray"))) qp.drawLine(self.leftMargin - 5, y, self.leftMargin + self.chartWidth, y) qp.drawLine(self.leftMargin - 5, 30, self.leftMargin + self.chartWidth, 30) qp.setPen(self.textColor) qp.drawText(3, 35, str(maxVSWR)) qp.drawText(3, self.chartHeight + 20, str(minVSWR)) # At least 100 px between ticks qp.drawText(self.leftMargin - 20, 20 + self.chartHeight + 15, Chart.shortenFrequency(fstart)) ticks = math.floor(self.chartWidth / 100) # Number of ticks does not include the origin for i in range(ticks): x = self.leftMargin + round((i + 1) * self.chartWidth / ticks) qp.setPen(QtGui.QPen(QtGui.QColor("lightgray"))) qp.drawLine(x, 20, x, 20 + self.chartHeight + 5) qp.setPen(self.textColor) qp.drawText( x - 20, 20 + self.chartHeight + 15, Chart.shortenFrequency(round(fspan / ticks * (i + 1) + fstart))) if self.mouselocation != 0: qp.setPen(QtGui.QPen(QtGui.QColor(224, 224, 224))) x = self.leftMargin + 1 + round( self.chartWidth * (self.mouselocation - fstart) / fspan) qp.drawLine(x, 20, x, 20 + self.chartHeight + 5) qp.setPen(pen) for i in range(len(self.data)): _, _, vswr = NanoVNASaver.vswr(self.data[i]) x = self.leftMargin + 1 + round( self.chartWidth / len(self.data) * i) y = 30 + round((maxVSWR - vswr) / span * (self.chartHeight - 10)) if y < 30: continue qp.drawPoint(int(x), int(y)) if self.drawLines and i > 0: _, _, vswr = NanoVNASaver.vswr(self.data[i - 1]) prevx = self.leftMargin + 1 + round( self.chartWidth / len(self.data) * (i - 1)) prevy = 30 + round( (maxVSWR - vswr) / span * (self.chartHeight - 10)) if prevy < 30: continue qp.setPen(line_pen) qp.drawLine(x, y, prevx, prevy) qp.setPen(pen) pen.setColor(self.referenceColor) line_pen.setColor(self.referenceColor) qp.setPen(pen) for i in range(len(self.reference)): if self.reference[i].freq < fstart or self.reference[ i].freq > fstop: continue _, _, vswr = NanoVNASaver.vswr(self.reference[i]) x = self.leftMargin + 1 + round( self.chartWidth * (self.reference[i].freq - fstart) / fspan) y = 30 + round((maxVSWR - vswr) / span * (self.chartHeight - 10)) if y < 30: continue qp.drawPoint(int(x), int(y)) if self.drawLines and i > 0: _, _, vswr = NanoVNASaver.vswr(self.reference[i - 1]) prevx = self.leftMargin + 1 + round( self.chartWidth * (self.reference[i - 1].freq - fstart) / fspan) prevy = 30 + round( (maxVSWR - vswr) / span * (self.chartHeight - 10)) if prevy < 30: continue qp.setPen(line_pen) qp.drawLine(x, y, prevx, prevy) qp.setPen(pen) # Now draw the markers for m in self.markers: if m.location != -1: highlighter.setColor(m.color) qp.setPen(highlighter) _, _, vswr = NanoVNASaver.vswr(self.data[m.location]) x = self.leftMargin + 1 + round( self.chartWidth / len(self.data) * m.location) y = 30 + round( (maxVSWR - vswr) / span * (self.chartHeight - 10)) if y < 30: continue qp.drawLine(int(x), int(y) + 3, int(x) - 3, int(y) - 3) qp.drawLine(int(x), int(y) + 3, int(x) + 3, int(y) - 3) qp.drawLine(int(x) - 3, int(y) - 3, int(x) + 3, int(y) - 3)