diff --git a/NanoVNASaver/Chart.py b/NanoVNASaver/Chart.py index f7e6752..2976217 100644 --- a/NanoVNASaver/Chart.py +++ b/NanoVNASaver/Chart.py @@ -764,11 +764,15 @@ class FrequencyChart(Chart): for i in range(len(data)): x = self.getXPosition(data[i]) y = y_function(data[i]) + if y is None: + continue if self.isPlotable(x, y): qp.drawPoint(int(x), int(y)) if self.drawLines and i > 0: prevx = self.getXPosition(data[i - 1]) prevy = y_function(data[i - 1]) + if prevy is None: + continue qp.setPen(line_pen) if self.isPlotable(x, y) and self.isPlotable(prevx, prevy): qp.drawLine(x, y, prevx, prevy) @@ -795,7 +799,8 @@ class FrequencyChart(Chart): self.drawMarker(x, y, qp, m.color, self.markers.index(m)+1) def isPlotable(self, x, y): - return self.leftMargin <= x <= self.leftMargin + self.chartWidth and \ + return y is not None and x is not None and \ + self.leftMargin <= x <= self.leftMargin + self.chartWidth and \ self.topMargin <= y <= self.topMargin + self.chartHeight def getPlotable(self, x, y, distantx, distanty): @@ -1569,6 +1574,8 @@ class LogMagChart(FrequencyChart): maxValue = -100 for d in self.data: logmag = self.logMag(d) + if math.isinf(logmag): + continue if logmag > maxValue: maxValue = logmag if logmag < minValue: @@ -1577,6 +1584,8 @@ class LogMagChart(FrequencyChart): if d.freq < self.fstart or d.freq > self.fstop: continue logmag = self.logMag(d) + if math.isinf(logmag): + continue if logmag > maxValue: maxValue = logmag if logmag < minValue: @@ -1673,6 +1682,8 @@ class LogMagChart(FrequencyChart): def getYPosition(self, d: Datapoint) -> int: logMag = self.logMag(d) + if math.isinf(logMag): + return None return self.topMargin + round((self.maxValue - logMag) / self.span * self.chartHeight) def valueAtPosition(self, y) -> List[float]: @@ -1946,29 +1957,37 @@ class CombinedLogMagChart(FrequencyChart): maxValue = 0 for d in self.data11: logmag = self.logMag(d) + if math.isinf(logmag): + continue if logmag > maxValue: maxValue = logmag if logmag < minValue: minValue = logmag for d in self.data21: logmag = self.logMag(d) + if math.isinf(logmag): + continue if logmag > maxValue: maxValue = logmag if logmag < minValue: minValue = logmag - for d in self.reference11: # Also check min/max for the reference sweep + for d in self.reference11: if d.freq < self.fstart or d.freq > self.fstop: continue logmag = self.logMag(d) + if math.isinf(logmag): + continue if logmag > maxValue: maxValue = logmag if logmag < minValue: minValue = logmag - for d in self.reference21: # Also check min/max for the reference sweep + for d in self.reference21: if d.freq < self.fstart or d.freq > self.fstop: continue logmag = self.logMag(d) + if math.isinf(logmag): + continue if logmag > maxValue: maxValue = logmag if logmag < minValue: @@ -2096,6 +2115,8 @@ class CombinedLogMagChart(FrequencyChart): def getYPosition(self, d: Datapoint) -> int: logMag = self.logMag(d) + if math.isinf(logMag): + return None return self.topMargin + round((self.maxValue - logMag) / self.span * self.chartHeight) def valueAtPosition(self, y) -> List[float]: diff --git a/NanoVNASaver/RFTools.py b/NanoVNASaver/RFTools.py index b530dbd..cf22b07 100644 --- a/NanoVNASaver/RFTools.py +++ b/NanoVNASaver/RFTools.py @@ -45,7 +45,7 @@ def serial_to_parallel(z: complex) -> complex: if z.imag == 0: return complex(z_sq_sum / z.real, math.copysign(math.inf, z_sq_sum)) if z.real == 0: - return complex(math.copysign(math.inf,z_sq_sum), z_sq_sum / z.real) + return complex(math.copysign(math.inf, z_sq_sum), z_sq_sum / z.real) return complex(z_sq_sum / z.real, z_sq_sum / z.imag) @@ -112,7 +112,8 @@ class Datapoint(NamedTuple): mag = abs(self.z) if mag > 0: return 20 * math.log10(mag) - return 0 + return -math.inf + @property def vswr(self) -> float: @@ -169,4 +170,4 @@ class RFTools: @staticmethod def parseFrequency(freq: str) -> int: - return parseFrequency(freq) \ No newline at end of file + return parseFrequency(freq)