Skip to content

Commit e278567

Browse files
authored
Fix/sweep band selection (#806)
* fix: band selection in sweep settings * chore: type annotation fixes
1 parent 314b91d commit e278567

24 files changed

+177
-137
lines changed

.pylintrc

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ disable=W0614,C0410,C0321,C0111,I0011,C0103,R0401
1313
good-names=_,a,b,c,dt,db,e,f,fn,fd,i,j,k,v,kv,kw,l,m,n,ls,t,t0,t1,t2,t3,w,h,x,y,z,it,op
1414
[MASTER]
1515
extension-pkg-allow-list=PySide6.QtWidgets,PySide6.QtGui,PySide6.QtCore
16+
ignore-paths=src/NanoVNASaver/Windows/ui/about.py
17+

pyproject.toml

-16
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ dependencies=[
3232
'scipy~=1.14',
3333
]
3434

35-
3635
[dependency-groups]
3736
dev = [
3837
# Static Code Analysis tools
@@ -54,23 +53,17 @@ dev = [
5453
"pyinstaller~=6.11.1",
5554
]
5655

57-
58-
5956
[project.urls]
6057
homepage = "https://github.com/NanoVNA-Saver/nanovna-saver"
6158
repository = "https://github.com/NanoVNA-Saver/nanovna-saver"
6259
Issues = "https://github.com/NanoVNA-Saver/nanovna-saver/issues"
6360

64-
65-
6661
[project.scripts]
6762
NanoVNASaver = 'NanoVNASaver.__main__:main'
6863

6964
[project.gui-scripts]
7065
NanoVNASaver-gui = 'NanoVNASaver.__main__:main'
7166

72-
73-
7467
[build-system]
7568
requires = [
7669
"setuptools>=64",
@@ -89,15 +82,12 @@ backend-path = ["src/tools"]
8982
# See https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html for more details
9083
where = ["src"]
9184

92-
9385
[tool.setuptools_scm]
9486
# For smarter version schemes and other configuration options,
9587
# check out https://github.com/pypa/setuptools_scm
9688
root='.'
9789
version_scheme = 'no-guess-dev'
9890

99-
100-
10191
[tool.taskipy.tasks]
10292
test = "pytest ."
10393
test-cov = "pytest --cov=src ."
@@ -113,19 +103,15 @@ clean = "python -m tools.project_clean"
113103
ui-compile = "python -m tools.ui_compile"
114104
ui-designer = "pyside6-designer"
115105

116-
117106
build-pkg-win = "pyinstaller --onefile -p src -n nanovna-saver.exe src/NanoVNASaver/__main__.py --recursive-copy-metadata NanoVNASaver --noconsole -i NanoVNASaver_48x48.ico"
118107
build-pkg-linux = "pyinstaller --onefile -p src -n nanovna-saver src/NanoVNASaver/__main__.py --recursive-copy-metadata NanoVNASaver"
119108
build-pkg-macos = "pyinstaller --onedir -p src -n NanoVNASaver src/NanoVNASaver/__main__.py --recursive-copy-metadata NanoVNASaver --window --clean -y -i NanoVNASaver_48x48.icns && tar -C dist -zcf ./dist/NanoVNASaver.app-`uname -m`.tar.gz NanoVNASaver.app"
120109

121-
122-
123110
[tool.pytest.ini_options]
124111
pythonpath = [
125112
'.', 'src',
126113
]
127114

128-
129115
[tool.ruff]
130116
line-length = 80
131117
target-version = 'py311'
@@ -138,7 +124,6 @@ extend-exclude = [
138124
"src/tools/setuptools_wrapper.py"
139125
]
140126

141-
142127
[tool.ruff.lint]
143128
# https://docs.astral.sh/ruff/rules
144129
select = [
@@ -170,7 +155,6 @@ ignore = [
170155
[tool.ruff.lint.mccabe]
171156
max-complexity = 10
172157

173-
174158
[tool.mypy]
175159
follow_imports = "skip"
176160
ignore_missing_imports = true

src/NanoVNASaver/Analysis/ResonanceAnalysis.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import csv
2020
import logging
2121
import os
22+
from typing import TYPE_CHECKING
2223

2324
from PySide6 import QtWidgets
2425

@@ -29,6 +30,9 @@
2930

3031
logger = logging.getLogger(__name__)
3132

33+
if TYPE_CHECKING:
34+
from ..NanoVNASaver.NanoVNASaver import NanoVNASaver as vna_app
35+
3236

3337
def format_resistence_neg(x):
3438
return format_resistance(x, allow_negative=True)
@@ -41,7 +45,7 @@ def vswr_transformed(z, ratio=49) -> float:
4145

4246

4347
class ResonanceAnalysis(Analysis):
44-
def __init__(self, app):
48+
def __init__(self, app: "vna_app"):
4549
super().__init__(app)
4650
self.crossings: list[int] = []
4751
self.filename = ""

src/NanoVNASaver/Calibration.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class CalData:
8686
freq: int = 0
8787
e00: complex = complex(0.0) # Directivity
8888
e11: complex = complex(0.0) # Port1 match
89-
delta_e:complex = complex(0.0) # Tracking
89+
delta_e: complex = complex(0.0) # Tracking
9090
e10e01: complex = complex(0.0) # Forward Reflection Tracking
9191
# 2 port
9292
e30: complex = complex(0.0) # Forward isolation
@@ -143,7 +143,7 @@ class CalElement:
143143

144144

145145
class CalDataSet(UserDict):
146-
def __init__(self):
146+
def __init__(self) -> None:
147147
super().__init__()
148148
self.notes = ""
149149
self.data: defaultdict[int, CalData] = defaultdict(CalData)
@@ -250,7 +250,7 @@ def freq_min(self) -> int:
250250
def freq_max(self) -> int:
251251
return self.frequencies()[-1] if self.frequencies() else 0
252252

253-
def get(self, key: int, default: Optional[CalData] = None) -> CalData: # type: ignore[override]
253+
def get(self, key: int, default: Optional[CalData] = None) -> CalData: # type: ignore[override]
254254
if default:
255255
return self.data.get(key, default)
256256
return self.data[key]

src/NanoVNASaver/Charts/CLogMag.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
class CombinedLogMagChart(LogMagChart):
32-
def __init__(self, name=""):
32+
def __init__(self, name: str = ""):
3333
super().__init__(name)
3434

3535
self.data11: list[Datapoint] = []
@@ -183,7 +183,7 @@ def calc_scaling(self) -> None:
183183
self.minValue = minValue
184184
self.maxValue = maxValue
185185

186-
def copy(self):
186+
def copy(self) -> "CombinedLogMagChart":
187187
new_chart: LogMagChart = super().copy()
188188
new_chart.isInverted = self.isInverted
189189
new_chart.span = self.span

src/NanoVNASaver/Charts/Chart.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def mouseReleaseEvent(self, a0: QtGui.QMouseEvent) -> None:
258258

259259
def wheelEvent(self, a0: QtGui.QWheelEvent) -> None:
260260
delta = a0.angleDelta().y()
261-
logger.debug(f"wheelEvent {delta}, {self.data}, {self.reference}")
261+
logger.debug("wheelEvent %s, %s, %s", delta, self.data, self.reference)
262262
if not delta or (not self.data and not self.reference):
263263
a0.ignore()
264264
logger.debug("nothing to do, returning")
@@ -368,5 +368,3 @@ def drawDragbog(self, qp: QtGui.QPainter):
368368
bottom_right = QtCore.QPoint(self.dragbox.pos[0], self.dragbox.pos[1])
369369
rect = QtCore.QRect(top_left, bottom_right)
370370
qp.drawRect(rect)
371-
372-

src/NanoVNASaver/Charts/Frequency.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import math
2121

2222
import numpy as np
23-
from PySide6 import QtCore, QtGui, QtWidgets
23+
from PySide6 import QtGui, QtWidgets
2424
from PySide6.QtCore import Qt
2525

2626
from ..Formatting import (
@@ -38,7 +38,7 @@
3838

3939

4040
class FrequencyChart(Chart):
41-
def __init__(self, name):
41+
def __init__(self, name) -> None:
4242
super().__init__(name)
4343
self.maxFrequency = 100000000
4444
self.minFrequency = 1000000
@@ -64,9 +64,9 @@ def __init__(self, name):
6464
self.minDisplayValue = -1
6565
self.maxDisplayValue = 1
6666

67-
self.minValue = -1
68-
self.maxValue = 1
69-
self.span = 1
67+
self.minValue = -1.0
68+
self.maxValue = 1.0
69+
self.span = 1.0
7070

7171
self.setContextMenuPolicy(Qt.ContextMenuPolicy.DefaultContextMenu)
7272
mode_group = QtGui.QActionGroup(self)
@@ -353,10 +353,12 @@ def resetDisplayLimits(self):
353353
self.update()
354354

355355
def getXPosition(self, d: Datapoint) -> int:
356-
span = self.fstop - self.fstart
356+
span = float(self.fstop - self.fstart)
357357
if span > 0:
358358
if self.logarithmicX:
359-
span = math.log(self.fstop) - math.log(self.fstart)
359+
span = math.log(float(self.fstop)) - math.log(
360+
float(self.fstart)
361+
)
360362
return self.leftMargin + round(
361363
self.dim.width
362364
* (math.log(d.freq) - math.log(self.fstart))
@@ -554,7 +556,7 @@ def drawValues(self, qp: QtGui.QPainter):
554556
self.maxValue = max_value
555557
self.minValue = min_value
556558
span = max_value - min_value
557-
if span == 0:
559+
if span == 0.0:
558560
logger.info(
559561
"Span is zero for %s-Chart, setting to a small value.",
560562
self.name,

src/NanoVNASaver/Charts/GroupDelay.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import numpy as np
2323
from PySide6 import QtGui
2424

25-
from ..RFTools import Datapoint, groupDelay
25+
from ..RFTools import Datapoint
2626
from .Chart import Chart
2727
from .Frequency import FrequencyChart
2828

@@ -52,7 +52,7 @@ def __init__(self, name="", reflective=True):
5252
self.minDisplayValue = -180
5353
self.maxDisplayValue = 180
5454

55-
def copy(self):
55+
def copy(self) -> "GroupDelayChart":
5656
new_chart: GroupDelayChart = super().copy()
5757
new_chart.reflective = self.reflective
5858
new_chart.groupDelay = self.groupDelay.copy()
@@ -113,12 +113,10 @@ def drawValues(self, qp: QtGui.QPainter):
113113
min_delay = math.floor(np.min(self.groupDelayReference))
114114
max_delay = math.ceil(np.max(self.groupDelayReference))
115115

116-
span = max_delay - min_delay
117-
if span == 0:
118-
span = 0.01
116+
span = float(max_delay - min_delay)
119117
self.minDelay = min_delay
120118
self.maxDelay = max_delay
121-
self.span = span
119+
self.span = span if span != 0 else 0.01
122120

123121
tickcount = math.floor(self.dim.height / 60)
124122
for i in range(tickcount):

src/NanoVNASaver/Charts/LogMag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def valueAtPosition(self, y) -> list[float]:
172172
def logMag(self, p: Datapoint) -> float:
173173
return -p.gain if self.isInverted else p.gain
174174

175-
def copy(self):
175+
def copy(self) -> "LogMagChart":
176176
new_chart: LogMagChart = super().copy()
177177
new_chart.isInverted = self.isInverted
178178
new_chart.span = self.span

src/NanoVNASaver/Charts/Magnitude.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def drawValues(self, qp: QtGui.QPainter):
5151
self.drawBands(qp, self.fstart, self.fstop)
5252

5353
if self.fixedValues:
54-
max_value = self.maxDisplayValue
55-
min_value = self.minDisplayValue
54+
max_value = float(self.maxDisplayValue)
55+
min_value = float(self.minDisplayValue)
5656
else:
5757
# Find scaling
5858
min_value = 100

src/NanoVNASaver/Charts/MagnitudeZ.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def magnitude(p: Datapoint) -> float:
145145
def logarithmicYAllowed(self) -> bool:
146146
return True
147147

148-
def copy(self):
148+
def copy(self) -> "MagnitudeZChart":
149149
new_chart: LogMagChart = super().copy()
150150
new_chart.span = self.span
151151
return new_chart

src/NanoVNASaver/Charts/Permeability.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ def drawValues(self, qp: QtGui.QPainter):
8989

9090
# Find scaling
9191
if self.fixedValues:
92-
min_val = self.minDisplayValue
93-
max_val = self.maxDisplayValue
92+
min_val = float(self.minDisplayValue)
93+
max_val = float(self.maxDisplayValue)
9494
else:
95-
min_val = 1000
96-
max_val = -1000
95+
min_val = 1000.0
96+
max_val = -1000.0
9797
for d in self.data:
9898
imp = d.impedance()
9999
re, im = imp.real, imp.imag

src/NanoVNASaver/Charts/Phase.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ def drawValues(self, qp: QPainter):
8585
minAngle = -180
8686
maxAngle = 180
8787

88-
span = maxAngle - minAngle
89-
if span == 0:
90-
span = 0.01
88+
span = float(maxAngle - minAngle)
9189
self.minAngle = minAngle
9290
self.maxAngle = maxAngle
93-
self.span = span
91+
self.span = span if span != 0 else 0.01
9492

9593
tickcount = math.floor(self.dim.height / 60)
9694

src/NanoVNASaver/Charts/QFactor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def drawChart(self, qp: QtGui.QPainter):
4949

5050
# Make up some sensible scaling here
5151
if self.fixedValues:
52-
maxQ = self.maxDisplayValue
52+
maxQ = float(self.maxDisplayValue)
5353
else:
54-
maxQ = 0
54+
maxQ = 0.0
5555
for d in self.data:
5656
Q = d.qFactor()
5757
maxQ = max(maxQ, Q)

src/NanoVNASaver/Charts/RI.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(self, name=""):
7373
self.y_menu.addAction(self.y_action_automatic)
7474
self.y_menu.addAction(self.y_action_fixed_span)
7575

76-
def copy(self):
76+
def copy(self) -> "RealImaginaryChart":
7777
new_chart: RealImaginaryChart = super().copy()
7878

7979
new_chart.maxDisplayReal = self.maxDisplayReal

src/NanoVNASaver/Charts/RIMu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def __init__(self, name=""):
9292
self.menu.addAction(self.action_set_core_area)
9393
self.menu.addAction(self.action_set_core_windings)
9494

95-
def copy(self):
95+
def copy(self) -> "RealImaginaryMuChart":
9696
new_chart: RealImaginaryMuChart = super().copy()
9797

9898
new_chart.coreLength = self.coreLength

src/NanoVNASaver/Charts/SParam.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ def drawValues(self, qp: QtGui.QPainter):
7878
maxValue = 1
7979
self.minValue = minValue
8080
self.maxValue = maxValue
81-
span = maxValue - minValue
82-
if span == 0:
83-
span = 0.01
84-
self.span = span
81+
span = float(maxValue - minValue)
82+
self.span = span if span != 0.0 else 0.01
8583
tick_count = self.dim.height // 60
8684
tick_step = self.span / tick_count
8785
for i in range(tick_count):
8886
val = int(minValue + i * tick_step)
89-
y = self.topMargin + (maxValue - val) // span * self.dim.height
87+
y = round(
88+
self.topMargin + (maxValue - val) // span * self.dim.height
89+
)
9090
qp.setPen(QtGui.QPen(Chart.color.foreground))
9191
qp.drawLine(
9292
self.leftMargin - 5, y, self.leftMargin + self.dim.width, y
@@ -149,7 +149,7 @@ def valueAtPosition(self, y) -> list[float]:
149149
def logMag(self, p: Datapoint) -> float:
150150
return -p.gain if self.isInverted else p.gain
151151

152-
def copy(self):
152+
def copy(self) -> "SParameterChart":
153153
new_chart: LogMagChart = super().copy()
154154
new_chart.isInverted = self.isInverted
155155
new_chart.span = self.span

0 commit comments

Comments
 (0)