Skip to content

Commit

Permalink
Feature/updates (#719)
Browse files Browse the repository at this point in the history
* use python3 for clean in Makefile. fixes #713
* github workflow updates / macos removal
* updated libraries (incl. numpy-2.x.x)
* linting with black
  • Loading branch information
zarath authored Oct 18, 2024
1 parent 3614939 commit 6bcc5ca
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 204 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
run: |
python3.11 -m venv build
. build/bin/activate
python -m pip install pip==24.1 setuptools==70.1.0
python -m pip install pip==24.2 setuptools==75.2.0
pip install -r requirements.txt
pip install PyInstaller==6.8.0
pip install PyInstaller==6.11.0
python3 -m pip install -U PyQt6-sip
python3 -m pip install -U PyQt6
- name: Build binary
Expand Down
35 changes: 0 additions & 35 deletions .github/workflows/release_macos.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/release_macos_app.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/release_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
run: |
python3 -m venv venv
.\venv\Scripts\activate
python3 -m pip install pip==24.1
python3 -m pip install pip==24.2
python3 -m pip install -U setuptools setuptools-scm
python3 -m pip install -r requirements.txt
python3 -m pip install PyInstaller==6.8.0
python3 -m pip install PyInstaller==6.11.0
python3 -m pip install -U PyQt6-sip
python3 -m pip install -U PyQt6
- name: Build binary
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rpm: clean
# remove all package build artifacts (keep the *.deb)
.PHONY: clean
clean:
python setup.py clean
python3 setup.py clean
-rm -rf build deb_dist dist *.tar.gz *.egg*


Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ write_to = "src/NanoVNASaver/_version.py"
pythonpath = [
".", "src",
]

[tool.black]
line-length = 80
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pyserial==3.5
PyQt6==6.7.0
PyQt6-sip==13.6.0
sip==6.8.4
numpy==1.26.4
scipy==1.13.1
Cython==3.0.10
setuptools==70.1.0
PyQt6==6.7.1
PyQt6-sip==13.8.0
sip==6.8.6
numpy==2.1.2
scipy==1.14.1
Cython==3.0.11
setuptools==75.2.0
setuptools-scm==8.1.0
3 changes: 2 additions & 1 deletion src/NanoVNASaver/About.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from setuptools_scm import get_version

try:
version = get_version(root='../..', relative_to=__file__)
version = get_version(root="../..", relative_to=__file__)
except LookupError:
from NanoVNASaver._version import version

Expand Down
42 changes: 16 additions & 26 deletions src/NanoVNASaver/Charts/TDR.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
MIN_VSWR = 1
MAX_VSWR = 10


class TDRChart(Chart):
maxDisplayLength = 50
minDisplayLength = 0
Expand All @@ -57,7 +58,7 @@ class TDRChart(Chart):
decimals = 1

formatString = ""

fixedValues = False

markerLocation = -1
Expand Down Expand Up @@ -137,19 +138,11 @@ def __init__(self, name):
self.y_menu.addAction(self.y_action_fixed)
self.y_menu.addSeparator()

self.y_action_set_fixed_maximum = QAction(
f"Maximum ({self.maxYlim})"
)
self.y_action_set_fixed_maximum.triggered.connect(
self.setMaximumY
)
self.y_action_set_fixed_maximum = QAction(f"Maximum ({self.maxYlim})")
self.y_action_set_fixed_maximum.triggered.connect(self.setMaximumY)

self.y_action_set_fixed_minimum = QAction(
f"Minimum ({self.minYlim})"
)
self.y_action_set_fixed_minimum.triggered.connect(
self.setMinimumY
)
self.y_action_set_fixed_minimum = QAction(f"Minimum ({self.minYlim})")
self.y_action_set_fixed_minimum.triggered.connect(self.setMinimumY)

self.y_menu.addAction(self.y_action_set_fixed_maximum)
self.y_menu.addAction(self.y_action_set_fixed_minimum)
Expand All @@ -167,16 +160,11 @@ def __init__(self, name):
self.dim.width = self.width() - self.leftMargin - self.rightMargin
self.dim.height = self.height() - self.bottomMargin - self.topMargin


def contextMenuEvent(self, event):
self.action_set_fixed_start.setText(f"Start ({self.minDisplayLength})")
self.action_set_fixed_stop.setText(f"Stop ({self.maxDisplayLength})")
self.y_action_set_fixed_minimum.setText(
f"Minimum ({self.minYlim})"
)
self.y_action_set_fixed_maximum.setText(
f"Maximum ({self.maxYlim})"
)
self.y_action_set_fixed_minimum.setText(f"Minimum ({self.minYlim})")
self.y_action_set_fixed_maximum.setText(f"Maximum ({self.maxYlim})")
self.menu.exec(event.globalPos())

def isPlotable(self, x, y):
Expand Down Expand Up @@ -255,7 +243,7 @@ def setMinimumY(self):
min_val, selected = QInputDialog.getDouble(
self,
"Minimum " + self.formatString,
"Set minimum "+ self.formatString,
"Set minimum " + self.formatString,
value=self.minYlim,
decimals=self.decimals,
)
Expand All @@ -269,8 +257,8 @@ def setMinimumY(self):
def setMaximumY(self):
max_val, selected = QInputDialog.getDouble(
self,
"Maximum "+ self.formatString,
"Set maximum "+ self.formatString,
"Maximum " + self.formatString,
"Set maximum " + self.formatString,
value=self.maxYlim,
decimals=self.decimals,
)
Expand Down Expand Up @@ -383,7 +371,9 @@ def _draw_y_ticks(self, height, width, min_impedance, max_impedance):
qp.drawText(3, y + 3, str(round(y_val, self.decimals)))
qp.setPen(Chart.color.text)
qp.drawText(
3, self.topMargin + height + 3, f"{round(min_impedance, self.decimals)}"
3,
self.topMargin + height + 3,
f"{round(min_impedance, self.decimals)}",
)

def _draw_max_point(self, height, x_step, y_step, min_index):
Expand Down Expand Up @@ -444,7 +434,7 @@ def _draw_graph(self, height, width):
min_Z = np.min(self.tdrWindow.step_response_Z)
max_Z = np.max(self.tdrWindow.step_response_Z)
# Ensure that everything works even if limits are negative
min_impedance = max(self.minYlim, min_Z - 0.05 * np.abs(min_Z))
min_impedance = max(self.minYlim, min_Z - 0.05 * np.abs(min_Z))
max_impedance = min(self.maxYlim, max_Z + 0.05 * np.abs(max_Z))
if self.fixedValues:
min_impedance = self.minYlim
Expand Down Expand Up @@ -533,7 +523,7 @@ def valueAtPosition(self, y):
min_Z = np.min(self.tdrWindow.step_response_Z)
max_Z = np.max(self.tdrWindow.step_response_Z)
# Ensure that everything works even if limits are negative
min_impedance = max(self.minYlim, min_Z - 0.05 * np.abs(min_Z))
min_impedance = max(self.minYlim, min_Z - 0.05 * np.abs(min_Z))
max_impedance = min(self.maxYlim, max_Z + 0.05 * np.abs(max_Z))
y_step = (max_impedance - min_impedance) / height
return y_step * absy + min_impedance
Expand Down
2 changes: 1 addition & 1 deletion src/NanoVNASaver/Marker/Values.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Value:
"""Contains the data area to calculate marker values from"""

def __init__(
self,
self,
):
self.freq: int = 0
self.s11: list[Datapoint] = []
Expand Down
10 changes: 6 additions & 4 deletions src/NanoVNASaver/NanoVNASaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ def __init__(self):

logger.debug("Finished building interface")

def auto_connect(self): # connect if there is exactly one detected serial device
def auto_connect(
self,
): # connect if there is exactly one detected serial device
if self.serial_control.inp_port.count() == 1:
self.serial_control.connect_device()

Expand Down Expand Up @@ -510,9 +512,9 @@ def saveData(self, data, data21, source=None):
if source is not None:
self.sweepSource = source
else:
time = strftime('%Y-%m-%d %H:%M:%S', localtime())
name = self.sweep.properties.name or 'nanovna'
self.sweepSource = f'{name}_{time}'
time = strftime("%Y-%m-%d %H:%M:%S", localtime())
name = self.sweep.properties.name or "nanovna"
self.sweepSource = f"{name}_{time}"

def markerUpdated(self, marker: Marker):
with self.dataLock:
Expand Down
4 changes: 1 addition & 3 deletions src/NanoVNASaver/RFTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ def norm_to_impedance(z: complex, ref_impedance: float = 50) -> complex:
def parallel_to_serial(z: complex) -> complex:
"""Convert parallel impedance to serial impedance equivalent"""
z_sq_sum = z.real**2 + z.imag**2 or 10.0e-30
return complex(
z.real * z.imag**2 / z_sq_sum, z.real**2 * z.imag / z_sq_sum
)
return complex(z.real * z.imag**2 / z_sq_sum, z.real**2 * z.imag / z_sq_sum)


def reflection_coefficient(z: complex, ref_impedance: float = 50) -> complex:
Expand Down
63 changes: 44 additions & 19 deletions src/NanoVNASaver/Settings/Sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ class Properties(NamedTuple):


class Sweep:
def __init__(self,
start: int = 3600000,
end: int = 30000000,
points: int = 101,
segments: int = 1,
properties: "Properties" = Properties(),
):
def __init__(
self,
start: int = 3600000,
end: int = 30000000,
points: int = 101,
segments: int = 1,
properties: "Properties" = Properties(),
):
self._start = start
self._end = end
self._points = points
Expand All @@ -56,21 +57,41 @@ def __init__(self,
logger.debug("%s", self)

def __repr__(self) -> str:
return 'Sweep(' + ', '.join(map(str, (
self.start, self.end, self.points, self.segments, self.properties
))) + ')'
return (
"Sweep("
+ ", ".join(
map(
str,
(
self.start,
self.end,
self.points,
self.segments,
self.properties,
),
)
)
+ ")"
)

def __eq__(self, other) -> bool:
return (self.start == other.start
and self.end == other.end
and self.points == other.points
and self.segments == other.segments
and self.properties == other.properties)
return (
self.start == other.start
and self.end == other.end
and self.points == other.points
and self.segments == other.segments
and self.properties == other.properties
)

def copy(self) -> "Sweep":
with self._lock:
return Sweep(self.start, self.end, self.points, self.segments,
self._properties)
return Sweep(
self.start,
self.end,
self.points,
self.segments,
self._properties,
)

# Getters for attributes, either private or computed.

Expand Down Expand Up @@ -128,7 +149,9 @@ def set_mode(self, mode: "SweepMode") -> None:

def set_averages(self, amount: int, truncates: int) -> None:
with self._lock:
self._properties = self.properties._replace(averages=(amount, truncates))
self._properties = self.properties._replace(
averages=(amount, truncates)
)

def set_logarithmic(self, logarithmic: bool) -> None:
with self._lock:
Expand All @@ -145,7 +168,9 @@ def check(self):
raise ValueError(f"Illegal sweep settings: {self}")

def _exp_factor(self, index: int) -> float:
return exp(log((self.start + self.span)/self.start) / self.segments * index)
return exp(
log((self.start + self.span) / self.start) / self.segments * index
)

def get_index_range(self, index: int) -> tuple[int, int]:
if self.properties.logarithmic:
Expand Down
Loading

0 comments on commit 6bcc5ca

Please sign in to comment.