Skip to content

Commit

Permalink
Fix/sweep band selection (#806)
Browse files Browse the repository at this point in the history
* fix: band selection in sweep settings
* chore: type annotation fixes
  • Loading branch information
zarath authored Feb 24, 2025
1 parent 314b91d commit e278567
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ disable=W0614,C0410,C0321,C0111,I0011,C0103,R0401
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
[MASTER]
extension-pkg-allow-list=PySide6.QtWidgets,PySide6.QtGui,PySide6.QtCore
ignore-paths=src/NanoVNASaver/Windows/ui/about.py

16 changes: 0 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ dependencies=[
'scipy~=1.14',
]


[dependency-groups]
dev = [
# Static Code Analysis tools
Expand All @@ -54,23 +53,17 @@ dev = [
"pyinstaller~=6.11.1",
]



[project.urls]
homepage = "https://github.com/NanoVNA-Saver/nanovna-saver"
repository = "https://github.com/NanoVNA-Saver/nanovna-saver"
Issues = "https://github.com/NanoVNA-Saver/nanovna-saver/issues"



[project.scripts]
NanoVNASaver = 'NanoVNASaver.__main__:main'

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



[build-system]
requires = [
"setuptools>=64",
Expand All @@ -89,15 +82,12 @@ backend-path = ["src/tools"]
# See https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html for more details
where = ["src"]


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



[tool.taskipy.tasks]
test = "pytest ."
test-cov = "pytest --cov=src ."
Expand All @@ -113,19 +103,15 @@ clean = "python -m tools.project_clean"
ui-compile = "python -m tools.ui_compile"
ui-designer = "pyside6-designer"


build-pkg-win = "pyinstaller --onefile -p src -n nanovna-saver.exe src/NanoVNASaver/__main__.py --recursive-copy-metadata NanoVNASaver --noconsole -i NanoVNASaver_48x48.ico"
build-pkg-linux = "pyinstaller --onefile -p src -n nanovna-saver src/NanoVNASaver/__main__.py --recursive-copy-metadata NanoVNASaver"
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"



[tool.pytest.ini_options]
pythonpath = [
'.', 'src',
]


[tool.ruff]
line-length = 80
target-version = 'py311'
Expand All @@ -138,7 +124,6 @@ extend-exclude = [
"src/tools/setuptools_wrapper.py"
]


[tool.ruff.lint]
# https://docs.astral.sh/ruff/rules
select = [
Expand Down Expand Up @@ -170,7 +155,6 @@ ignore = [
[tool.ruff.lint.mccabe]
max-complexity = 10


[tool.mypy]
follow_imports = "skip"
ignore_missing_imports = true
Expand Down
6 changes: 5 additions & 1 deletion src/NanoVNASaver/Analysis/ResonanceAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import csv
import logging
import os
from typing import TYPE_CHECKING

from PySide6 import QtWidgets

Expand All @@ -29,6 +30,9 @@

logger = logging.getLogger(__name__)

if TYPE_CHECKING:
from ..NanoVNASaver.NanoVNASaver import NanoVNASaver as vna_app


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


class ResonanceAnalysis(Analysis):
def __init__(self, app):
def __init__(self, app: "vna_app"):
super().__init__(app)
self.crossings: list[int] = []
self.filename = ""
Expand Down
6 changes: 3 additions & 3 deletions src/NanoVNASaver/Calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CalData:
freq: int = 0
e00: complex = complex(0.0) # Directivity
e11: complex = complex(0.0) # Port1 match
delta_e:complex = complex(0.0) # Tracking
delta_e: complex = complex(0.0) # Tracking
e10e01: complex = complex(0.0) # Forward Reflection Tracking
# 2 port
e30: complex = complex(0.0) # Forward isolation
Expand Down Expand Up @@ -143,7 +143,7 @@ class CalElement:


class CalDataSet(UserDict):
def __init__(self):
def __init__(self) -> None:
super().__init__()
self.notes = ""
self.data: defaultdict[int, CalData] = defaultdict(CalData)
Expand Down Expand Up @@ -250,7 +250,7 @@ def freq_min(self) -> int:
def freq_max(self) -> int:
return self.frequencies()[-1] if self.frequencies() else 0

def get(self, key: int, default: Optional[CalData] = None) -> CalData: # type: ignore[override]
def get(self, key: int, default: Optional[CalData] = None) -> CalData: # type: ignore[override]
if default:
return self.data.get(key, default)
return self.data[key]
Expand Down
4 changes: 2 additions & 2 deletions src/NanoVNASaver/Charts/CLogMag.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


class CombinedLogMagChart(LogMagChart):
def __init__(self, name=""):
def __init__(self, name: str = ""):
super().__init__(name)

self.data11: list[Datapoint] = []
Expand Down Expand Up @@ -183,7 +183,7 @@ def calc_scaling(self) -> None:
self.minValue = minValue
self.maxValue = maxValue

def copy(self):
def copy(self) -> "CombinedLogMagChart":
new_chart: LogMagChart = super().copy()
new_chart.isInverted = self.isInverted
new_chart.span = self.span
Expand Down
4 changes: 1 addition & 3 deletions src/NanoVNASaver/Charts/Chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def mouseReleaseEvent(self, a0: QtGui.QMouseEvent) -> None:

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


18 changes: 10 additions & 8 deletions src/NanoVNASaver/Charts/Frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import math

import numpy as np
from PySide6 import QtCore, QtGui, QtWidgets
from PySide6 import QtGui, QtWidgets
from PySide6.QtCore import Qt

from ..Formatting import (
Expand All @@ -38,7 +38,7 @@


class FrequencyChart(Chart):
def __init__(self, name):
def __init__(self, name) -> None:
super().__init__(name)
self.maxFrequency = 100000000
self.minFrequency = 1000000
Expand All @@ -64,9 +64,9 @@ def __init__(self, name):
self.minDisplayValue = -1
self.maxDisplayValue = 1

self.minValue = -1
self.maxValue = 1
self.span = 1
self.minValue = -1.0
self.maxValue = 1.0
self.span = 1.0

self.setContextMenuPolicy(Qt.ContextMenuPolicy.DefaultContextMenu)
mode_group = QtGui.QActionGroup(self)
Expand Down Expand Up @@ -353,10 +353,12 @@ def resetDisplayLimits(self):
self.update()

def getXPosition(self, d: Datapoint) -> int:
span = self.fstop - self.fstart
span = float(self.fstop - self.fstart)
if span > 0:
if self.logarithmicX:
span = math.log(self.fstop) - math.log(self.fstart)
span = math.log(float(self.fstop)) - math.log(
float(self.fstart)
)
return self.leftMargin + round(
self.dim.width
* (math.log(d.freq) - math.log(self.fstart))
Expand Down Expand Up @@ -554,7 +556,7 @@ def drawValues(self, qp: QtGui.QPainter):
self.maxValue = max_value
self.minValue = min_value
span = max_value - min_value
if span == 0:
if span == 0.0:
logger.info(
"Span is zero for %s-Chart, setting to a small value.",
self.name,
Expand Down
10 changes: 4 additions & 6 deletions src/NanoVNASaver/Charts/GroupDelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import numpy as np
from PySide6 import QtGui

from ..RFTools import Datapoint, groupDelay
from ..RFTools import Datapoint
from .Chart import Chart
from .Frequency import FrequencyChart

Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(self, name="", reflective=True):
self.minDisplayValue = -180
self.maxDisplayValue = 180

def copy(self):
def copy(self) -> "GroupDelayChart":
new_chart: GroupDelayChart = super().copy()
new_chart.reflective = self.reflective
new_chart.groupDelay = self.groupDelay.copy()
Expand Down Expand Up @@ -113,12 +113,10 @@ def drawValues(self, qp: QtGui.QPainter):
min_delay = math.floor(np.min(self.groupDelayReference))
max_delay = math.ceil(np.max(self.groupDelayReference))

span = max_delay - min_delay
if span == 0:
span = 0.01
span = float(max_delay - min_delay)
self.minDelay = min_delay
self.maxDelay = max_delay
self.span = span
self.span = span if span != 0 else 0.01

tickcount = math.floor(self.dim.height / 60)
for i in range(tickcount):
Expand Down
2 changes: 1 addition & 1 deletion src/NanoVNASaver/Charts/LogMag.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def valueAtPosition(self, y) -> list[float]:
def logMag(self, p: Datapoint) -> float:
return -p.gain if self.isInverted else p.gain

def copy(self):
def copy(self) -> "LogMagChart":
new_chart: LogMagChart = super().copy()
new_chart.isInverted = self.isInverted
new_chart.span = self.span
Expand Down
4 changes: 2 additions & 2 deletions src/NanoVNASaver/Charts/Magnitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def drawValues(self, qp: QtGui.QPainter):
self.drawBands(qp, self.fstart, self.fstop)

if self.fixedValues:
max_value = self.maxDisplayValue
min_value = self.minDisplayValue
max_value = float(self.maxDisplayValue)
min_value = float(self.minDisplayValue)
else:
# Find scaling
min_value = 100
Expand Down
2 changes: 1 addition & 1 deletion src/NanoVNASaver/Charts/MagnitudeZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def magnitude(p: Datapoint) -> float:
def logarithmicYAllowed(self) -> bool:
return True

def copy(self):
def copy(self) -> "MagnitudeZChart":
new_chart: LogMagChart = super().copy()
new_chart.span = self.span
return new_chart
8 changes: 4 additions & 4 deletions src/NanoVNASaver/Charts/Permeability.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def drawValues(self, qp: QtGui.QPainter):

# Find scaling
if self.fixedValues:
min_val = self.minDisplayValue
max_val = self.maxDisplayValue
min_val = float(self.minDisplayValue)
max_val = float(self.maxDisplayValue)
else:
min_val = 1000
max_val = -1000
min_val = 1000.0
max_val = -1000.0
for d in self.data:
imp = d.impedance()
re, im = imp.real, imp.imag
Expand Down
6 changes: 2 additions & 4 deletions src/NanoVNASaver/Charts/Phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ def drawValues(self, qp: QPainter):
minAngle = -180
maxAngle = 180

span = maxAngle - minAngle
if span == 0:
span = 0.01
span = float(maxAngle - minAngle)
self.minAngle = minAngle
self.maxAngle = maxAngle
self.span = span
self.span = span if span != 0 else 0.01

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

Expand Down
4 changes: 2 additions & 2 deletions src/NanoVNASaver/Charts/QFactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def drawChart(self, qp: QtGui.QPainter):

# Make up some sensible scaling here
if self.fixedValues:
maxQ = self.maxDisplayValue
maxQ = float(self.maxDisplayValue)
else:
maxQ = 0
maxQ = 0.0
for d in self.data:
Q = d.qFactor()
maxQ = max(maxQ, Q)
Expand Down
2 changes: 1 addition & 1 deletion src/NanoVNASaver/Charts/RI.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, name=""):
self.y_menu.addAction(self.y_action_automatic)
self.y_menu.addAction(self.y_action_fixed_span)

def copy(self):
def copy(self) -> "RealImaginaryChart":
new_chart: RealImaginaryChart = super().copy()

new_chart.maxDisplayReal = self.maxDisplayReal
Expand Down
2 changes: 1 addition & 1 deletion src/NanoVNASaver/Charts/RIMu.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self, name=""):
self.menu.addAction(self.action_set_core_area)
self.menu.addAction(self.action_set_core_windings)

def copy(self):
def copy(self) -> "RealImaginaryMuChart":
new_chart: RealImaginaryMuChart = super().copy()

new_chart.coreLength = self.coreLength
Expand Down
12 changes: 6 additions & 6 deletions src/NanoVNASaver/Charts/SParam.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ def drawValues(self, qp: QtGui.QPainter):
maxValue = 1
self.minValue = minValue
self.maxValue = maxValue
span = maxValue - minValue
if span == 0:
span = 0.01
self.span = span
span = float(maxValue - minValue)
self.span = span if span != 0.0 else 0.01
tick_count = self.dim.height // 60
tick_step = self.span / tick_count
for i in range(tick_count):
val = int(minValue + i * tick_step)
y = self.topMargin + (maxValue - val) // span * self.dim.height
y = round(
self.topMargin + (maxValue - val) // span * self.dim.height
)
qp.setPen(QtGui.QPen(Chart.color.foreground))
qp.drawLine(
self.leftMargin - 5, y, self.leftMargin + self.dim.width, y
Expand Down Expand Up @@ -149,7 +149,7 @@ def valueAtPosition(self, y) -> list[float]:
def logMag(self, p: Datapoint) -> float:
return -p.gain if self.isInverted else p.gain

def copy(self):
def copy(self) -> "SParameterChart":
new_chart: LogMagChart = super().copy()
new_chart.isInverted = self.isInverted
new_chart.span = self.span
Expand Down
Loading

0 comments on commit e278567

Please sign in to comment.