Skip to content

Commit

Permalink
fix bug #455
Browse files Browse the repository at this point in the history
vswr of datapoint now returns inf instead of going negative
  • Loading branch information
zarath committed Jan 9, 2022
1 parent cbcf61a commit 28fd7e5
Show file tree
Hide file tree
Showing 5 changed files with 527 additions and 11 deletions.
6 changes: 3 additions & 3 deletions NanoVNASaver/About.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# A python program to view and export Touchstone data from a NanoVNA
# Copyright (C) 2019, 2020 Rune B. Broberg
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
# Copyright (C) 2020ff NanoVNA-Saver Authors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

VERSION = "0.3.10"
VERSION = "0.3.11-pre"
VERSION_URL = (
"https://raw.githubusercontent.com/"
"NanoVNA-Saver/nanovna-saver/master/NanoVNASaver/About.py")
Expand All @@ -26,7 +26,7 @@
INFO = f"""NanoVNASaver {VERSION}
Copyright (C) 2019, 2020 Rune B. Broberg
Copyright (C) 2020, 2021 NanoVNA-Saver Authors
Copyright (C) 2020ff NanoVNA-Saver Authors
This program comes with ABSOLUTELY NO WARRANTY
This program is licensed under the GNU General Public License version 3
Expand Down
12 changes: 9 additions & 3 deletions NanoVNASaver/Charts/VSWR.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# A python program to view and export Touchstone data from a NanoVNA
# Copyright (C) 2019, 2020 Rune B. Broberg
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
# Copyright (C) 2020ff NanoVNA-Saver Authors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -73,7 +73,10 @@ def drawValues(self, qp: QtGui.QPainter):
vswr = d.vswr
if vswr > maxVSWR:
maxVSWR = vswr
maxVSWR = min(self.maxDisplayValue, math.ceil(maxVSWR))
try:
maxVSWR = min(self.maxDisplayValue, math.ceil(maxVSWR))
except OverflowError:
maxVSWR = self.maxDisplayValue
self.maxVSWR = maxVSWR
span = maxVSWR-minVSWR
if span == 0:
Expand Down Expand Up @@ -152,7 +155,10 @@ def getYPositionFromValue(self, vswr) -> int:
return (
self.topMargin +
round((math.log(self.maxVSWR) - math.log(vswr)) / span * self.dim.height))
return self.topMargin + round((self.maxVSWR - vswr) / self.span * self.dim.height)
try:
return self.topMargin + round((self.maxVSWR - vswr) / self.span * self.dim.height)
except OverflowError:
return self.topMargin

def getYPosition(self, d: Datapoint) -> int:
return self.getYPositionFromValue(d.vswr)
Expand Down
6 changes: 3 additions & 3 deletions NanoVNASaver/RFTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# A python program to view and export Touchstone data from a NanoVNA
# Copyright (C) 2019, 2020 Rune B. Broberg
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
# Copyright (C) 2020ff NanoVNA-Saver Authors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -52,8 +52,8 @@ def gain(self) -> float:
@property
def vswr(self) -> float:
mag = abs(self.z)
if mag == 1:
return 1
if mag >= 1:
return math.inf
return (1 + mag) / (1 - mag)

@property
Expand Down
Loading

0 comments on commit 28fd7e5

Please sign in to comment.